From 4b591db099860cf0b1908cff960e0087d68385fc Mon Sep 17 00:00:00 2001 From: Goetz Lindenmaier Date: Sat, 20 Nov 2021 20:04:13 +0000 Subject: [PATCH] 8209611: use C++ compiler for hotspot tests Reviewed-by: mbaesken, stuefe Backport-of: 8c47dc4a946723de202c943bc577765cefa8d24a --- make/common/TestFilesCompilation.gmk | 3 +- make/test/JtregNativeHotspot.gmk | 7 +- .../vmTestbase/gc/g1/unloading/libdefine.c | 194 - .../vmTestbase/gc/g1/unloading/libdefine.cpp | 194 + .../gctests/mallocWithGC1/libmallocWithGC1.c | 40 - .../mallocWithGC1/libmallocWithGC1.cpp | 48 + .../gctests/mallocWithGC2/libmallocWithGC2.c | 40 - .../mallocWithGC2/libmallocWithGC2.cpp | 48 + .../gctests/mallocWithGC3/libmallocWithGC3.c | 41 - .../mallocWithGC3/libmallocWithGC3.cpp | 49 + .../gc/gctests/nativeGC01/libnativeGC01.c | 62 - .../gc/gctests/nativeGC01/libnativeGC01.cpp | 71 + .../gc/gctests/nativeGC02/libnativeGC02.c | 73 - .../gc/gctests/nativeGC02/libnativeGC02.cpp | 81 + .../gc/gctests/nativeGC03/libnativeGC03.c | 54 - .../gc/gctests/nativeGC03/libnativeGC03.cpp | 62 + .../gc/gctests/nativeGC05/libnativeGC05.c | 88 - .../gc/gctests/nativeGC05/libnativeGC05.cpp | 96 + .../{agent00.c => agent00.cpp} | 0 .../{agent01.c => agent01.cpp} | 0 .../{agent02.c => agent02.cpp} | 0 .../{agent03.c => agent03.cpp} | 0 .../libVirtualMachine07agent00.c | 27 - .../libVirtualMachine07agent00.cpp | 27 + .../libVirtualMachine07agent01.c | 27 - .../libVirtualMachine07agent01.cpp | 27 + .../libVirtualMachine07agent02.c | 27 - .../libVirtualMachine07agent02.cpp | 27 + .../libVirtualMachine07agent03.c | 27 - .../libVirtualMachine07agent03.cpp | 27 + .../{agent00.c => agent00.cpp} | 0 .../libVirtualMachine09agent00.c | 27 - .../libVirtualMachine09agent00.cpp | 27 + ...turn004a.c => libforceEarlyReturn004a.cpp} | 0 .../libforceEarlyReturn005a.c | 60 - .../libforceEarlyReturn005a.cpp | 60 + ...turn002a.c => libforceEarlyReturn002a.cpp} | 0 .../{addcaps001.c => addcaps001.cpp} | 0 .../addcaps001/libaddcaps001.c | 33 - .../addcaps001/libaddcaps001.cpp | 33 + .../{addcaps002.c => addcaps002.cpp} | 0 .../addcaps002/libaddcaps002.c | 33 - .../addcaps002/libaddcaps002.cpp | 33 + .../{addcaps003.c => addcaps003.cpp} | 0 .../addcaps003/libaddcaps003.c | 33 - .../addcaps003/libaddcaps003.cpp | 33 + .../{agentonload001.c => agentonload001.cpp} | 0 .../agentonload001/libagentonload001.c | 33 - .../agentonload001/libagentonload001.cpp | 33 + .../{agentonload002.c => agentonload002.cpp} | 0 .../agentonload002/libagentonload002.c | 33 - .../agentonload002/libagentonload002.cpp | 33 + .../{agentonload003.c => agentonload003.cpp} | 0 .../agentonload003/libagentonload003.c | 33 - .../agentonload003/libagentonload003.cpp | 33 + ...gentonunload001.c => agentonunload001.cpp} | 0 .../agentonunload001/libagentonunload001.c | 33 - .../agentonunload001/libagentonunload001.cpp | 33 + .../nsk/jvmti/Allocate/alloc001/alloc001.c | 190 - .../nsk/jvmti/Allocate/alloc001/alloc001.cpp | 190 + .../nsk/jvmti/Allocate/alloc001/liballoc001.c | 33 - .../jvmti/Allocate/alloc001/liballoc001.cpp | 33 + .../attach002/attach002Agent00.c | 246 -- .../attach002/attach002Agent00.cpp | 246 ++ .../attach002/libattach002Agent00.c | 34 - .../attach002/libattach002Agent00.cpp | 34 + ...ach002aAgent00.c => attach002aAgent00.cpp} | 0 .../attach002a/libattach002aAgent00.c | 34 - .../attach002a/libattach002aAgent00.cpp | 34 + ...ttach008Agent00.c => attach008Agent00.cpp} | 0 .../attach008/libattach008Agent00.c | 34 - .../attach008/libattach008Agent00.cpp | 34 + ...ttach009Agent00.c => attach009Agent00.cpp} | 0 .../attach009/libattach009Agent00.c | 34 - .../attach009/libattach009Agent00.cpp | 34 + ...ttach012Agent00.c => attach012Agent00.cpp} | 0 .../attach012/libattach012Agent00.c | 34 - .../attach012/libattach012Agent00.cpp | 34 + ...ttach014Agent00.c => attach014Agent00.cpp} | 0 .../attach014/libattach014Agent00.c | 34 - .../attach014/libattach014Agent00.cpp | 34 + ...ttach015Agent00.c => attach015Agent00.cpp} | 0 ...ttach015Agent01.c => attach015Agent01.cpp} | 0 ...{attach015Target.c => attach015Target.cpp} | 0 .../attach015/libattach015Agent00.c | 34 - .../attach015/libattach015Agent00.cpp | 34 + .../attach015/libattach015Agent01.c | 34 - .../attach015/libattach015Agent01.cpp | 34 + .../attach015/libattach015Target.c | 34 - .../attach015/libattach015Target.cpp | 34 + ...ttach020Agent00.c => attach020Agent00.cpp} | 0 .../attach020/libattach020Agent00.c | 34 - .../attach020/libattach020Agent00.cpp | 34 + .../attach021/attach021Agent00.c | 171 - .../attach021/attach021Agent00.cpp | 171 + .../attach021/libattach021Agent00.c | 34 - .../attach021/libattach021Agent00.cpp | 34 + .../attach022/attach022Agent00.c | 236 -- .../attach022/attach022Agent00.cpp | 237 ++ .../attach022/libattach022Agent00.c | 34 - .../attach022/libattach022Agent00.cpp | 34 + ...ttach037Agent00.c => attach037Agent00.cpp} | 0 .../attach037/libattach037Agent00.c | 34 - .../attach037/libattach037Agent00.cpp | 34 + ...ttach038Agent00.c => attach038Agent00.cpp} | 0 .../attach038/libattach038Agent00.c | 34 - .../attach038/libattach038Agent00.cpp | 34 + ...ttach039Agent00.c => attach039Agent00.cpp} | 0 .../attach039/libattach039Agent00.c | 34 - .../attach039/libattach039Agent00.cpp | 34 + .../attach040/attach040Agent00.c | 174 - .../attach040/attach040Agent00.cpp | 174 + .../attach040/libattach040Agent00.c | 34 - .../attach040/libattach040Agent00.cpp | 34 + ...ttach041Agent00.c => attach041Agent00.cpp} | 0 .../attach041/libattach041Agent00.c | 34 - .../attach041/libattach041Agent00.cpp | 34 + ...ttach042Agent00.c => attach042Agent00.cpp} | 0 .../attach042/libattach042Agent00.c | 34 - .../attach042/libattach042Agent00.cpp | 34 + ...ttach045Agent00.c => attach045Agent00.cpp} | 0 ...ttach045Agent01.c => attach045Agent01.cpp} | 0 .../attach045/attach045Agent02.c | 171 - .../attach045/attach045Agent02.cpp | 171 + ...ttach045Agent03.c => attach045Agent03.cpp} | 0 .../attach045/libattach045Agent00.c | 34 - .../attach045/libattach045Agent00.cpp | 34 + .../attach045/libattach045Agent01.c | 34 - .../attach045/libattach045Agent01.cpp | 34 + .../attach045/libattach045Agent02.c | 34 - .../attach045/libattach045Agent02.cpp | 34 + .../attach045/libattach045Agent03.c | 34 - .../attach045/libattach045Agent03.cpp | 34 + ...ttach046Agent00.c => attach046Agent00.cpp} | 0 .../attach046/libattach046Agent00.c | 34 - .../attach046/libattach046Agent00.cpp | 34 + ...ttach050Agent00.c => attach050Agent00.cpp} | 0 .../attach050/libattach050Agent00.c | 34 - .../attach050/libattach050Agent00.cpp | 34 + .../sharedAgents/libsimpleAgent00.c | 34 - .../sharedAgents/libsimpleAgent00.cpp | 34 + .../{simpleAgent00.c => simpleAgent00.cpp} | 0 .../Breakpoint/breakpoint001/breakpoint001.c | 308 -- .../breakpoint001/breakpoint001.cpp | 308 ++ .../breakpoint001/libbreakpoint001.c | 33 - .../breakpoint001/libbreakpoint001.cpp | 33 + ...{classfloadhk001.c => classfloadhk001.cpp} | 0 .../classfloadhk001/libclassfloadhk001.c | 33 - .../classfloadhk001/libclassfloadhk001.cpp | 33 + .../classfloadhk002/classfloadhk002.c | 355 -- .../classfloadhk002/classfloadhk002.cpp | 355 ++ .../classfloadhk002/libclassfloadhk002.c | 33 - .../classfloadhk002/libclassfloadhk002.cpp | 33 + .../classfloadhk003/classfloadhk003.c | 417 -- .../classfloadhk003/classfloadhk003.cpp | 417 ++ .../classfloadhk003/libclassfloadhk003.c | 33 - .../classfloadhk003/libclassfloadhk003.cpp | 33 + .../classfloadhk004/classfloadhk004.c | 308 -- .../classfloadhk004/classfloadhk004.cpp | 308 ++ .../classfloadhk004/libclassfloadhk004.c | 33 - .../classfloadhk004/libclassfloadhk004.cpp | 33 + .../classfloadhk005/classfloadhk005.c | 370 -- .../classfloadhk005/classfloadhk005.cpp | 370 ++ .../classfloadhk005/libclassfloadhk005.c | 33 - .../classfloadhk005/libclassfloadhk005.cpp | 33 + .../classfloadhk006/classfloadhk006.c | 434 --- .../classfloadhk006/classfloadhk006.cpp | 434 +++ .../classfloadhk006/libclassfloadhk006.c | 33 - .../classfloadhk006/libclassfloadhk006.cpp | 33 + .../classfloadhk007/classfloadhk007.c | 460 --- .../classfloadhk007/classfloadhk007.cpp | 460 +++ .../classfloadhk007/libclassfloadhk007.c | 33 - .../classfloadhk007/libclassfloadhk007.cpp | 33 + .../classfloadhk008/classfloadhk008.c | 396 -- .../classfloadhk008/classfloadhk008.cpp | 396 ++ .../classfloadhk008/libclassfloadhk008.c | 33 - .../classfloadhk008/libclassfloadhk008.cpp | 33 + .../classfloadhk009/classfloadhk009.c | 396 -- .../classfloadhk009/classfloadhk009.cpp | 396 ++ .../classfloadhk009/libclassfloadhk009.c | 33 - .../classfloadhk009/libclassfloadhk009.cpp | 33 + .../{classload001.c => classload001.cpp} | 0 .../ClassLoad/classload001/libclassload001.c | 33 - .../classload001/libclassload001.cpp | 33 + .../ClassPrepare/classprep001/classprep001.c | 330 -- .../classprep001/classprep001.cpp | 338 ++ .../classprep001/libclassprep001.c | 33 - .../classprep001/libclassprep001.cpp | 33 + .../ClearBreakpoint/clrbrk001/clrbrk001.c | 218 -- .../ClearBreakpoint/clrbrk001/clrbrk001.cpp | 218 ++ .../ClearBreakpoint/clrbrk001/libclrbrk001.c | 33 - .../clrbrk001/libclrbrk001.cpp | 33 + .../ClearBreakpoint/clrbrk002/clrbrk002.c | 163 - .../ClearBreakpoint/clrbrk002/clrbrk002.cpp | 163 + .../ClearBreakpoint/clrbrk002/libclrbrk002.c | 33 - .../clrbrk002/libclrbrk002.cpp | 33 + .../ClearBreakpoint/clrbrk005/clrbrk005.c | 158 - .../ClearBreakpoint/clrbrk005/clrbrk005.cpp | 158 + .../ClearBreakpoint/clrbrk005/libclrbrk005.c | 33 - .../clrbrk005/libclrbrk005.cpp | 33 + .../clrfldw001/clrfldw001.c | 221 -- .../clrfldw001/clrfldw001.cpp | 221 ++ .../clrfldw001/libclrfldw001.c | 33 - .../clrfldw001/libclrfldw001.cpp | 33 + .../clrfldw002/clrfldw002.c | 174 - .../clrfldw002/clrfldw002.cpp | 174 + .../clrfldw002/libclrfldw002.c | 33 - .../clrfldw002/libclrfldw002.cpp | 33 + .../clrfmodw001/clrfmodw001.c | 213 - .../clrfmodw001/clrfmodw001.cpp | 213 + .../clrfmodw001/libclrfmodw001.c | 33 - .../clrfmodw001/libclrfmodw001.cpp | 33 + .../clrfmodw002/clrfmodw002.c | 177 - .../clrfmodw002/clrfmodw002.cpp | 177 + .../clrfmodw002/libclrfmodw002.c | 33 - .../clrfmodw002/libclrfmodw002.cpp | 33 + ...{compmethload001.c => compmethload001.cpp} | 0 .../compmethload001/libcompmethload001.c | 33 - .../compmethload001/libcompmethload001.cpp | 33 + .../compmethunload001/compmethunload001.c | 209 - .../compmethunload001/compmethunload001.cpp | 209 + .../compmethunload001/libcompmethunload001.c | 33 - .../libcompmethunload001.cpp | 33 + .../crrawmon001/crrawmon001.c | 131 - .../crrawmon001/crrawmon001.cpp | 131 + .../crrawmon001/libcrrawmon001.c | 33 - .../crrawmon001/libcrrawmon001.cpp | 33 + .../crrawmon002/crrawmon002.c | 116 - .../crrawmon002/crrawmon002.cpp | 116 + .../crrawmon002/libcrrawmon002.c | 33 - .../crrawmon002/libcrrawmon002.cpp | 33 + .../{datadumpreq001.c => datadumpreq001.cpp} | 0 .../datadumpreq001/libdatadumpreq001.c | 33 - .../datadumpreq001/libdatadumpreq001.cpp | 33 + .../jvmti/Deallocate/dealloc001/dealloc001.c | 108 - .../Deallocate/dealloc001/dealloc001.cpp | 108 + .../Deallocate/dealloc001/libdealloc001.c | 33 - .../Deallocate/dealloc001/libdealloc001.cpp | 33 + .../drrawmon001/drrawmon001.c | 144 - .../drrawmon001/drrawmon001.cpp | 144 + .../drrawmon001/libdrrawmon001.c | 33 - .../drrawmon001/libdrrawmon001.cpp | 33 + .../drrawmon003/drrawmon003.c | 129 - .../drrawmon003/drrawmon003.cpp | 129 + .../drrawmon003/libdrrawmon003.c | 33 - .../drrawmon003/libdrrawmon003.cpp | 33 + .../drrawmon004/drrawmon004.c | 110 - .../drrawmon004/drrawmon004.cpp | 110 + .../drrawmon004/libdrrawmon004.c | 33 - .../drrawmon004/libdrrawmon004.cpp | 33 + .../{disposeenv001.c => disposeenv001.cpp} | 0 .../disposeenv001/libdisposeenv001.c | 33 - .../disposeenv001/libdisposeenv001.cpp | 33 + .../{disposeenv002.c => disposeenv002.cpp} | 0 .../disposeenv002/libdisposeenv002.c | 33 - .../disposeenv002/libdisposeenv002.cpp | 33 + .../{dyncodgen001.c => dyncodgen001.cpp} | 0 .../dyncodgen001/libdyncodgen001.c | 33 - .../dyncodgen001/libdyncodgen001.cpp | 33 + .../Exception/exception001/exception001.c | 315 -- .../Exception/exception001/exception001.cpp | 327 ++ .../Exception/exception001/libexception001.c | 33 - .../exception001/libexception001.cpp | 33 + .../ExceptionCatch/excatch001/excatch001.c | 271 -- .../ExceptionCatch/excatch001/excatch001.cpp | 279 ++ .../ExceptionCatch/excatch001/libexcatch001.c | 33 - .../excatch001/libexcatch001.cpp | 33 + .../FieldAccess/fieldacc001/fieldacc001.c | 360 -- .../FieldAccess/fieldacc001/fieldacc001.cpp | 372 ++ .../FieldAccess/fieldacc001/libfieldacc001.c | 33 - .../fieldacc001/libfieldacc001.cpp | 33 + .../FieldAccess/fieldacc002/fieldacc002.c | 412 -- .../FieldAccess/fieldacc002/fieldacc002.cpp | 424 ++ .../FieldAccess/fieldacc002/libfieldacc002.c | 33 - .../fieldacc002/libfieldacc002.cpp | 33 + .../FieldAccess/fieldacc003/fieldacc003.c | 338 -- .../FieldAccess/fieldacc003/fieldacc003.cpp | 350 ++ .../FieldAccess/fieldacc003/libfieldacc003.c | 33 - .../fieldacc003/libfieldacc003.cpp | 33 + .../FieldAccess/fieldacc004/fieldacc004.c | 324 -- .../FieldAccess/fieldacc004/fieldacc004.cpp | 336 ++ .../FieldAccess/fieldacc004/libfieldacc004.c | 33 - .../fieldacc004/libfieldacc004.cpp | 33 + .../fieldmod001/fieldmod001.c | 460 --- .../fieldmod001/fieldmod001.cpp | 473 +++ .../fieldmod001/libfieldmod001.c | 33 - .../fieldmod001/libfieldmod001.cpp | 33 + .../fieldmod002/fieldmod002.c | 539 --- .../fieldmod002/fieldmod002.cpp | 552 +++ .../fieldmod002/libfieldmod002.c | 33 - .../fieldmod002/libfieldmod002.cpp | 33 + ...rlyReturn001.c => ForceEarlyReturn001.cpp} | 0 .../libForceEarlyReturn001.c | 33 - .../libForceEarlyReturn001.cpp | 33 + .../{forcegc001.c => forcegc001.cpp} | 0 .../forcegc001/libforcegc001.c | 33 - .../forcegc001/libforcegc001.cpp | 33 + .../{forcegc002.c => forcegc002.cpp} | 0 .../forcegc002/libforcegc002.c | 33 - .../forcegc002/libforcegc002.cpp | 33 + .../jvmti/FramePop/framepop001/framepop001.c | 305 -- .../FramePop/framepop001/framepop001.cpp | 305 ++ .../FramePop/framepop001/libframepop001.c | 33 - .../FramePop/framepop001/libframepop001.cpp | 33 + .../jvmti/FramePop/framepop002/framepop002.c | 441 --- .../FramePop/framepop002/framepop002.cpp | 441 +++ .../FramePop/framepop002/libframepop002.c | 33 - .../FramePop/framepop002/libframepop002.cpp | 33 + .../{gcfinish001.c => gcfinish001.cpp} | 0 .../gcfinish001/libgcfinish001.c | 33 - .../gcfinish001/libgcfinish001.cpp | 33 + .../{gcstart001.c => gcstart001.cpp} | 0 .../gcstart001/libgcstart001.c | 33 - .../gcstart001/libgcstart001.cpp | 33 + .../{gcstart002.c => gcstart002.cpp} | 0 .../gcstart002/libgcstart002.c | 33 - .../gcstart002/libgcstart002.cpp | 33 + .../{genevents001.c => genevents001.cpp} | 0 .../genevents001/libgenevents001.c | 33 - .../genevents001/libgenevents001.cpp | 33 + .../jvmti/GetAllThreads/allthr001/allthr001.c | 318 -- .../GetAllThreads/allthr001/allthr001.cpp | 318 ++ .../GetAllThreads/allthr001/liballthr001.c | 33 - .../GetAllThreads/allthr001/liballthr001.cpp | 33 + .../jvmti/GetAllThreads/allthr002/allthr002.c | 121 - .../GetAllThreads/allthr002/allthr002.cpp | 121 + .../GetAllThreads/allthr002/liballthr002.c | 33 - .../GetAllThreads/allthr002/liballthr002.cpp | 33 + .../GetArgumentsSize/argsize001/argsize001.c | 119 - .../argsize001/argsize001.cpp | 119 + .../argsize001/libargsize001.c | 33 - .../argsize001/libargsize001.cpp | 33 + .../GetArgumentsSize/argsize002/argsize002.c | 144 - .../argsize002/argsize002.cpp | 144 + .../argsize002/libargsize002.c | 33 - .../argsize002/libargsize002.cpp | 33 + ...{getavailproc001.c => getavailproc001.cpp} | 0 .../getavailproc001/libgetavailproc001.c | 33 - .../getavailproc001/libgetavailproc001.cpp | 33 + .../GetBytecodes/bytecodes001/bytecodes001.c | 199 - .../bytecodes001/bytecodes001.cpp | 199 + .../bytecodes001/libbytecodes001.c | 33 - .../bytecodes001/libbytecodes001.cpp | 33 + .../GetBytecodes/bytecodes002/bytecodes002.c | 195 - .../bytecodes002/bytecodes002.cpp | 195 + .../bytecodes002/libbytecodes002.c | 33 - .../bytecodes002/libbytecodes002.cpp | 33 + .../GetBytecodes/bytecodes003/bytecodes003.c | 540 --- .../bytecodes003/bytecodes003.cpp | 540 +++ .../bytecodes003/libbytecodes003.c | 32 - .../bytecodes003/libbytecodes003.cpp | 32 + .../GetCapabilities/getcaps001/getcaps001.c | 109 - .../GetCapabilities/getcaps001/getcaps001.cpp | 109 + .../getcaps001/libgetcaps001.c | 33 - .../getcaps001/libgetcaps001.cpp | 33 + .../{getcaps002.c => getcaps002.cpp} | 0 .../getcaps002/libgetcaps002.c | 33 - .../getcaps002/libgetcaps002.cpp | 33 + .../GetClassFields/getclfld005/getclfld005.c | 131 - .../getclfld005/getclfld005.cpp | 131 + .../getclfld005/libgetclfld005.c | 33 - .../getclfld005/libgetclfld005.cpp | 33 + .../GetClassFields/getclfld006/getclfld006.c | 117 - .../getclfld006/getclfld006.cpp | 117 + .../getclfld006/libgetclfld006.c | 33 - .../getclfld006/libgetclfld006.cpp | 33 + .../GetClassFields/getclfld007/getclfld007.c | 206 - .../getclfld007/getclfld007.cpp | 206 + .../getclfld007/libgetclfld007.c | 33 - .../getclfld007/libgetclfld007.cpp | 33 + .../getclsldr001/getclsldr001.c | 120 - .../getclsldr001/getclsldr001.cpp | 120 + .../getclsldr001/libgetclsldr001.c | 33 - .../getclsldr001/libgetclsldr001.cpp | 33 + .../getclsldr002/getclsldr002.c | 126 - .../getclsldr002/getclsldr002.cpp | 126 + .../getclsldr002/libgetclsldr002.c | 33 - .../getclsldr002/libgetclsldr002.cpp | 33 + .../getclsldr003/getclsldr003.c | 126 - .../getclsldr003/getclsldr003.cpp | 126 + .../getclsldr003/libgetclsldr003.c | 33 - .../getclsldr003/libgetclsldr003.cpp | 33 + .../clsldrclss001/clsldrclss001.c | 139 - .../clsldrclss001/clsldrclss001.cpp | 139 + .../clsldrclss001/libclsldrclss001.c | 33 - .../clsldrclss001/libclsldrclss001.cpp | 33 + .../clsldrclss002/clsldrclss002.c | 234 -- .../clsldrclss002/clsldrclss002.cpp | 234 ++ .../clsldrclss002/libclsldrclss002.c | 33 - .../clsldrclss002/libclsldrclss002.cpp | 33 + .../getclmthd005/getclmthd005.c | 131 - .../getclmthd005/getclmthd005.cpp | 131 + .../getclmthd005/libgetclmthd005.c | 33 - .../getclmthd005/libgetclmthd005.cpp | 33 + .../getclmthd006/getclmthd006.c | 117 - .../getclmthd006/getclmthd006.cpp | 117 + .../getclmthd006/libgetclmthd006.c | 33 - .../getclmthd006/libgetclmthd006.cpp | 33 + .../getclmthd007/getclmthd007.c | 233 -- .../getclmthd007/getclmthd007.cpp | 233 ++ .../getclmthd007/libgetclmthd007.c | 33 - .../getclmthd007/libgetclmthd007.cpp | 33 + .../getclmdf004/getclmdf004.c | 120 - .../getclmdf004/getclmdf004.cpp | 120 + .../getclmdf004/libgetclmdf004.c | 33 - .../getclmdf004/libgetclmdf004.cpp | 33 + .../getclmdf005/getclmdf005.c | 142 - .../getclmdf005/getclmdf005.cpp | 142 + .../getclmdf005/libgetclmdf005.c | 33 - .../getclmdf005/libgetclmdf005.cpp | 33 + .../getclmdf006/getclmdf006.c | 143 - .../getclmdf006/getclmdf006.cpp | 143 + .../getclmdf006/libgetclmdf006.c | 33 - .../getclmdf006/libgetclmdf006.cpp | 33 + .../getclmdf007/getclmdf007.c | 165 - .../getclmdf007/getclmdf007.cpp | 165 + .../getclmdf007/libgetclmdf007.c | 33 - .../getclmdf007/libgetclmdf007.cpp | 33 + .../getclsig004/getclsig004.c | 130 - .../getclsig004/getclsig004.cpp | 130 + .../getclsig004/libgetclsig004.c | 33 - .../getclsig004/libgetclsig004.cpp | 33 + .../getclsig005/getclsig005.c | 144 - .../getclsig005/getclsig005.cpp | 144 + .../getclsig005/libgetclsig005.c | 33 - .../getclsig005/libgetclsig005.cpp | 33 + .../{getclsig006.c => getclsig006.cpp} | 0 .../getclsig006/libgetclsig006.c | 33 - .../getclsig006/libgetclsig006.cpp | 33 + .../getclstat005/getclstat005.c | 120 - .../getclstat005/getclstat005.cpp | 120 + .../getclstat005/libgetclstat005.c | 33 - .../getclstat005/libgetclstat005.cpp | 33 + .../getclstat006/getclstat006.c | 125 - .../getclstat006/getclstat006.cpp | 125 + .../getclstat006/libgetclstat006.c | 33 - .../getclstat006/libgetclstat006.cpp | 33 + .../getclstat007/getclstat007.c | 160 - .../getclstat007/getclstat007.cpp | 160 + .../getclstat007/libgetclstat007.c | 33 - .../getclstat007/libgetclstat007.cpp | 33 + .../contmon001/contmon001.c | 140 - .../contmon001/contmon001.cpp | 140 + .../contmon001/libcontmon001.c | 33 - .../contmon001/libcontmon001.cpp | 33 + .../contmon002/contmon002.c | 138 - .../contmon002/contmon002.cpp | 138 + .../contmon002/libcontmon002.c | 33 - .../contmon002/libcontmon002.cpp | 33 + .../contmon003/contmon003.c | 160 - .../contmon003/contmon003.cpp | 160 + .../contmon003/libcontmon003.c | 33 - .../contmon003/libcontmon003.cpp | 33 + ...urthrcputime001.c => curthrcputime001.cpp} | 0 .../curthrcputime001/libcurthrcputime001.c | 33 - .../curthrcputime001/libcurthrcputime001.cpp | 33 + ...rtimerinfo001.c => curthrtimerinfo001.cpp} | 0 .../libcurthrtimerinfo001.c | 33 - .../libcurthrtimerinfo001.cpp | 33 + .../nsk/jvmti/GetEnv/GetEnv001/GetEnv001.c | 149 - .../nsk/jvmti/GetEnv/GetEnv001/GetEnv001.cpp | 157 + .../nsk/jvmti/GetEnv/GetEnv001/libGetEnv001.c | 33 - .../jvmti/GetEnv/GetEnv001/libGetEnv001.cpp | 33 + .../{getenvstor001.c => getenvstor001.cpp} | 0 .../getenvstor001/libgetenvstor001.c | 33 - .../getenvstor001/libgetenvstor001.cpp | 33 + .../{geterrname001.c => geterrname001.cpp} | 0 .../geterrname001/libgeterrname001.c | 33 - .../geterrname001/libgeterrname001.cpp | 33 + .../{geterrname002.c => geterrname002.cpp} | 0 .../geterrname002/libgeterrname002.c | 33 - .../geterrname002/libgeterrname002.cpp | 33 + .../{extevents001.c => extevents001.cpp} | 0 .../extevents001/libextevents001.c | 33 - .../extevents001/libextevents001.cpp | 33 + .../{extfuncs001.c => extfuncs001.cpp} | 0 .../extfuncs001/libextfuncs001.c | 33 - .../extfuncs001/libextfuncs001.cpp | 33 + .../getfldecl001/getfldecl001.c | 144 - .../getfldecl001/getfldecl001.cpp | 144 + .../getfldecl001/libgetfldecl001.c | 33 - .../getfldecl001/libgetfldecl001.cpp | 33 + .../getfldecl002/getfldecl002.c | 142 - .../getfldecl002/getfldecl002.cpp | 142 + .../getfldecl002/libgetfldecl002.c | 33 - .../getfldecl002/libgetfldecl002.cpp | 33 + .../getfldecl004/getfldecl004.c | 162 - .../getfldecl004/getfldecl004.cpp | 162 + .../getfldecl004/libgetfldecl004.c | 33 - .../getfldecl004/libgetfldecl004.cpp | 33 + .../getfldmdf003/getfldmdf003.c | 137 - .../getfldmdf003/getfldmdf003.cpp | 137 + .../getfldmdf003/libgetfldmdf003.c | 33 - .../getfldmdf003/libgetfldmdf003.cpp | 33 + .../getfldmdf004/getfldmdf004.c | 223 -- .../getfldmdf004/getfldmdf004.cpp | 223 ++ .../getfldmdf004/libgetfldmdf004.c | 33 - .../getfldmdf004/libgetfldmdf004.cpp | 33 + .../GetFieldName/getfldnm003/getfldnm003.c | 185 - .../GetFieldName/getfldnm003/getfldnm003.cpp | 185 + .../GetFieldName/getfldnm003/libgetfldnm003.c | 33 - .../getfldnm003/libgetfldnm003.cpp | 33 + .../GetFieldName/getfldnm004/getfldnm004.c | 165 - .../GetFieldName/getfldnm004/getfldnm004.cpp | 165 + .../GetFieldName/getfldnm004/libgetfldnm004.c | 33 - .../getfldnm004/libgetfldnm004.cpp | 33 + .../{getfldnm005.c => getfldnm005.cpp} | 0 .../GetFieldName/getfldnm005/libgetfldnm005.c | 33 - .../getfldnm005/libgetfldnm005.cpp | 33 + .../GetFrameCount/framecnt001/framecnt001.c | 146 - .../GetFrameCount/framecnt001/framecnt001.cpp | 146 + .../framecnt001/libframecnt001.c | 33 - .../framecnt001/libframecnt001.cpp | 33 + .../GetFrameCount/framecnt002/framecnt002.c | 104 - .../GetFrameCount/framecnt002/framecnt002.cpp | 104 + .../framecnt002/libframecnt002.c | 33 - .../framecnt002/libframecnt002.cpp | 33 + .../GetFrameCount/framecnt003/framecnt003.c | 98 - .../GetFrameCount/framecnt003/framecnt003.cpp | 98 + .../framecnt003/libframecnt003.c | 33 - .../framecnt003/libframecnt003.cpp | 33 + .../frameloc001/frameloc001.c | 246 -- .../frameloc001/frameloc001.cpp | 246 ++ .../frameloc001/libframeloc001.c | 33 - .../frameloc001/libframeloc001.cpp | 33 + .../frameloc002/frameloc002.c | 180 - .../frameloc002/frameloc002.cpp | 180 + .../frameloc002/libframeloc002.c | 33 - .../frameloc002/libframeloc002.cpp | 33 + .../frameloc003/frameloc003.c | 186 - .../frameloc003/frameloc003.cpp | 186 + .../frameloc003/libframeloc003.c | 33 - .../frameloc003/libframeloc003.cpp | 33 + .../getintrf005/getintrf005.c | 131 - .../getintrf005/getintrf005.cpp | 131 + .../getintrf005/libgetintrf005.c | 33 - .../getintrf005/libgetintrf005.cpp | 33 + .../getintrf006/getintrf006.c | 117 - .../getintrf006/getintrf006.cpp | 117 + .../getintrf006/libgetintrf006.c | 33 - .../getintrf006/libgetintrf006.cpp | 33 + .../getintrf007/getintrf007.c | 187 - .../getintrf007/getintrf007.cpp | 187 + .../getintrf007/libgetintrf007.c | 33 - .../getintrf007/libgetintrf007.cpp | 33 + .../{getjlocfmt001.c => getjlocfmt001.cpp} | 0 .../getjlocfmt001/libgetjlocfmt001.c | 33 - .../getjlocfmt001/libgetjlocfmt001.cpp | 33 + .../{getjlocfmt002.c => getjlocfmt002.cpp} | 0 .../getjlocfmt002/libgetjlocfmt002.c | 33 - .../getjlocfmt002/libgetjlocfmt002.cpp | 33 + .../getjniftab001/getjniftab001.c | 238 -- .../getjniftab001/getjniftab001.cpp | 237 ++ .../getjniftab001/libgetjniftab001.c | 33 - .../getjniftab001/libgetjniftab001.cpp | 33 + .../getjniftab002/getjniftab002.c | 160 - .../getjniftab002/getjniftab002.cpp | 160 + .../getjniftab002/libgetjniftab002.c | 33 - .../getjniftab002/libgetjniftab002.cpp | 33 + .../linetab001/liblinetab001.c | 33 - .../linetab001/liblinetab001.cpp | 33 + .../linetab001/linetab001.c | 193 - .../linetab001/linetab001.cpp | 193 + .../linetab002/liblinetab002.c | 33 - .../linetab002/liblinetab002.cpp | 33 + .../linetab002/linetab002.c | 169 - .../linetab002/linetab002.cpp | 169 + .../linetab003/liblinetab003.c | 33 - .../linetab003/liblinetab003.cpp | 33 + .../linetab003/linetab003.c | 158 - .../linetab003/linetab003.cpp | 158 + .../loadedclss001/libloadedclss001.c | 33 - .../loadedclss001/libloadedclss001.cpp | 33 + .../loadedclss001/loadedclss001.c | 120 - .../loadedclss001/loadedclss001.cpp | 120 + .../loadedclss002/libloadedclss002.c | 33 - .../loadedclss002/libloadedclss002.cpp | 33 + .../{loadedclss002.c => loadedclss002.cpp} | 0 .../getlocal001/getlocal001.c | 531 --- .../getlocal001/getlocal001.cpp | 531 +++ .../getlocal001/libgetlocal001.c | 33 - .../getlocal001/libgetlocal001.cpp | 33 + .../getlocal002/getlocal002.c | 292 -- .../getlocal002/getlocal002.cpp | 292 ++ .../getlocal002/libgetlocal002.c | 33 - .../getlocal002/libgetlocal002.cpp | 33 + .../localtab001/liblocaltab001.c | 33 - .../localtab001/liblocaltab001.cpp | 33 + .../localtab001/localtab001.c | 262 -- .../localtab001/localtab001.cpp | 262 ++ .../localtab002/liblocaltab002.c | 33 - .../localtab002/liblocaltab002.cpp | 33 + .../localtab002/localtab002.c | 184 - .../localtab002/localtab002.cpp | 184 + .../localtab003/liblocaltab003.c | 33 - .../localtab003/liblocaltab003.cpp | 33 + .../localtab003/localtab003.c | 159 - .../localtab003/localtab003.cpp | 159 + .../localtab004/liblocaltab004.c | 33 - .../localtab004/liblocaltab004.cpp | 33 + .../{localtab004.c => localtab004.cpp} | 0 .../localtab005/liblocaltab005.c | 33 - .../localtab005/liblocaltab005.cpp | 33 + .../localtab005/localtab005.c | 247 -- .../localtab005/localtab005.cpp | 247 ++ .../GetMaxLocals/maxloc001/libmaxloc001.c | 33 - .../GetMaxLocals/maxloc001/libmaxloc001.cpp | 33 + .../jvmti/GetMaxLocals/maxloc001/maxloc001.c | 123 - .../GetMaxLocals/maxloc001/maxloc001.cpp | 123 + .../GetMaxLocals/maxloc002/libmaxloc002.c | 33 - .../GetMaxLocals/maxloc002/libmaxloc002.cpp | 33 + .../jvmti/GetMaxLocals/maxloc002/maxloc002.c | 144 - .../GetMaxLocals/maxloc002/maxloc002.cpp | 144 + .../declcls001/declcls001.c | 144 - .../declcls001/declcls001.cpp | 144 + .../declcls001/libdeclcls001.c | 33 - .../declcls001/libdeclcls001.cpp | 33 + .../declcls002/declcls002.c | 128 - .../declcls002/declcls002.cpp | 128 + .../declcls002/libdeclcls002.c | 33 - .../declcls002/libdeclcls002.cpp | 33 + .../declcls003/declcls003.c | 158 - .../declcls003/declcls003.cpp | 158 + .../declcls003/libdeclcls003.c | 33 - .../declcls003/libdeclcls003.cpp | 33 + .../methloc001/libmethloc001.c | 33 - .../methloc001/libmethloc001.cpp | 33 + .../GetMethodLocation/methloc001/methloc001.c | 138 - .../methloc001/methloc001.cpp | 138 + .../methloc002/libmethloc002.c | 33 - .../methloc002/libmethloc002.cpp | 33 + .../GetMethodLocation/methloc002/methloc002.c | 155 - .../methloc002/methloc002.cpp | 155 + .../methmod001/libmethmod001.c | 33 - .../methmod001/libmethmod001.cpp | 33 + .../methmod001/methmod001.c | 206 - .../methmod001/methmod001.cpp | 206 + .../methmod002/libmethmod002.c | 33 - .../methmod002/libmethmod002.cpp | 33 + .../methmod002/methmod002.c | 128 - .../methmod002/methmod002.cpp | 128 + .../methname001/libmethname001.c | 33 - .../methname001/libmethname001.cpp | 33 + .../GetMethodName/methname001/methname001.c | 182 - .../GetMethodName/methname001/methname001.cpp | 182 + .../methname002/libmethname002.c | 33 - .../methname002/libmethname002.cpp | 33 + .../GetMethodName/methname002/methname002.c | 176 - .../GetMethodName/methname002/methname002.cpp | 176 + .../methname003/libmethname003.c | 33 - .../methname003/libmethname003.cpp | 33 + .../{methname003.c => methname003.cpp} | 0 .../objhashcode001/libobjhashcode001.c | 33 - .../objhashcode001/libobjhashcode001.cpp | 33 + .../objhashcode001/objhashcode001.c | 215 - .../objhashcode001/objhashcode001.cpp | 215 + .../objmonusage001/libobjmonusage001.c | 33 - .../objmonusage001/libobjmonusage001.cpp | 33 + .../objmonusage001/objmonusage001.c | 189 - .../objmonusage001/objmonusage001.cpp | 189 + .../objmonusage002/libobjmonusage002.c | 33 - .../objmonusage002/libobjmonusage002.cpp | 33 + .../objmonusage002/objmonusage002.c | 150 - .../objmonusage002/objmonusage002.cpp | 150 + .../objmonusage003/libobjmonusage003.c | 33 - .../objmonusage003/libobjmonusage003.cpp | 33 + .../objmonusage003/objmonusage003.c | 178 - .../objmonusage003/objmonusage003.cpp | 178 + .../objmonusage004/libobjmonusage004.c | 33 - .../objmonusage004/libobjmonusage004.cpp | 33 + .../objmonusage004/objmonusage004.c | 178 - .../objmonusage004/objmonusage004.cpp | 178 + .../objmonusage005/libobjmonusage005.c | 33 - .../objmonusage005/libobjmonusage005.cpp | 33 + .../objmonusage005/objmonusage005.c | 126 - .../objmonusage005/objmonusage005.cpp | 126 + .../objmonusage006/libobjmonusage006.c | 33 - .../objmonusage006/libobjmonusage006.cpp | 33 + .../objmonusage006/objmonusage006.c | 126 - .../objmonusage006/objmonusage006.cpp | 126 + .../GetObjectSize/objsize001/libobjsize001.c | 33 - .../objsize001/libobjsize001.cpp | 33 + .../GetObjectSize/objsize001/objsize001.c | 213 - .../GetObjectSize/objsize001/objsize001.cpp | 213 + .../objwithtags001/libobjwithtags001.c | 33 - .../objwithtags001/libobjwithtags001.cpp | 33 + .../objwithtags001/objwithtags001.c | 477 --- .../objwithtags001/objwithtags001.cpp | 477 +++ .../ownmoninf001/libownmoninf001.c | 33 - .../ownmoninf001/libownmoninf001.cpp | 33 + .../ownmoninf001/ownmoninf001.c | 181 - .../ownmoninf001/ownmoninf001.cpp | 181 + .../ownmoninf002/libownmoninf002.c | 33 - .../ownmoninf002/libownmoninf002.cpp | 33 + .../ownmoninf002/ownmoninf002.c | 129 - .../ownmoninf002/ownmoninf002.cpp | 129 + .../ownmoninf003/libownmoninf003.c | 33 - .../ownmoninf003/libownmoninf003.cpp | 33 + .../ownmoninf003/ownmoninf003.c | 165 - .../ownmoninf003/ownmoninf003.cpp | 165 + .../{getphase001.c => getphase001.cpp} | 0 .../GetPhase/getphase001/libgetphase001.c | 33 - .../GetPhase/getphase001/libgetphase001.cpp | 33 + .../{getphase002.c => getphase002.cpp} | 0 .../GetPhase/getphase002/libgetphase002.c | 33 - .../GetPhase/getphase002/libgetphase002.cpp | 33 + .../{getpotcaps001.c => getpotcaps001.cpp} | 0 .../getpotcaps001/libgetpotcaps001.c | 33 - .../getpotcaps001/libgetpotcaps001.cpp | 33 + .../srcdebugex001/libsrcdebugex001.c | 33 - .../srcdebugex001/libsrcdebugex001.cpp | 33 + .../srcdebugex001/srcdebugex001.c | 143 - .../srcdebugex001/srcdebugex001.cpp | 143 + .../srcdebugex002/libsrcdebugex002.c | 33 - .../srcdebugex002/libsrcdebugex002.cpp | 33 + .../srcdebugex002/srcdebugex002.c | 154 - .../srcdebugex002/srcdebugex002.cpp | 154 + .../srcdebugex003/libsrcdebugex003.c | 33 - .../srcdebugex003/libsrcdebugex003.cpp | 33 + .../srcdebugex003/srcdebugex003.c | 149 - .../srcdebugex003/srcdebugex003.cpp | 149 + .../getsrcfn004/getsrcfn004.c | 154 - .../getsrcfn004/getsrcfn004.cpp | 155 + .../getsrcfn004/libgetsrcfn004.c | 33 - .../getsrcfn004/libgetsrcfn004.cpp | 33 + .../getsrcfn005/getsrcfn005.c | 140 - .../getsrcfn005/getsrcfn005.cpp | 141 + .../getsrcfn005/libgetsrcfn005.c | 33 - .../getsrcfn005/libgetsrcfn005.cpp | 33 + .../getsrcfn006/getsrcfn006.c | 149 - .../getsrcfn006/getsrcfn006.cpp | 150 + .../getsrcfn006/libgetsrcfn006.c | 33 - .../getsrcfn006/libgetsrcfn006.cpp | 33 + .../getstacktr001/getstacktr001.c | 191 - .../getstacktr001/getstacktr001.cpp | 191 + .../getstacktr001/libgetstacktr001.c | 33 - .../getstacktr001/libgetstacktr001.cpp | 33 + .../getstacktr002/getstacktr002.c | 141 - .../getstacktr002/getstacktr002.cpp | 141 + .../getstacktr002/libgetstacktr002.c | 33 - .../getstacktr002/libgetstacktr002.cpp | 33 + .../getstacktr003/getstacktr003.c | 240 -- .../getstacktr003/getstacktr003.cpp | 240 ++ .../getstacktr003/libgetstacktr003.c | 33 - .../getstacktr003/libgetstacktr003.cpp | 33 + .../getstacktr004/getstacktr004.c | 265 -- .../getstacktr004/getstacktr004.cpp | 265 ++ .../getstacktr004/libgetstacktr004.c | 33 - .../getstacktr004/libgetstacktr004.cpp | 33 + .../getstacktr005/getstacktr005.c | 317 -- .../getstacktr005/getstacktr005.cpp | 317 ++ .../getstacktr005/libgetstacktr005.c | 33 - .../getstacktr005/libgetstacktr005.cpp | 33 + .../getstacktr006/getstacktr006.c | 325 -- .../getstacktr006/getstacktr006.cpp | 325 ++ .../getstacktr006/libgetstacktr006.c | 33 - .../getstacktr006/libgetstacktr006.cpp | 33 + .../getstacktr007/getstacktr007.c | 315 -- .../getstacktr007/getstacktr007.cpp | 315 ++ .../getstacktr007/libgetstacktr007.c | 33 - .../getstacktr007/libgetstacktr007.cpp | 33 + .../getstacktr008/getstacktr008.c | 411 -- .../getstacktr008/getstacktr008.cpp | 411 ++ .../getstacktr008/libgetstacktr008.c | 33 - .../getstacktr008/libgetstacktr008.cpp | 33 + .../getstacktr009/getstacktr009.c | 124 - .../getstacktr009/getstacktr009.cpp | 124 + .../getstacktr009/libgetstacktr009.c | 33 - .../getstacktr009/libgetstacktr009.cpp | 33 + .../{getsysprops001.c => getsysprops001.cpp} | 0 .../getsysprops001/libgetsysprops001.c | 33 - .../getsysprops001/libgetsysprops001.cpp | 33 + .../{getsysprops002.c => getsysprops002.cpp} | 0 .../getsysprops002/libgetsysprops002.c | 33 - .../getsysprops002/libgetsysprops002.cpp | 33 + .../{getsysprop001.c => getsysprop001.cpp} | 0 .../getsysprop001/libgetsysprop001.c | 33 - .../getsysprop001/libgetsysprop001.cpp | 33 + .../{getsysprop002.c => getsysprop002.cpp} | 0 .../getsysprop002/libgetsysprop002.c | 33 - .../getsysprop002/libgetsysprop002.cpp | 33 + .../nsk/jvmti/GetTag/gettag001/gettag001.c | 185 - .../nsk/jvmti/GetTag/gettag001/gettag001.cpp | 185 + .../nsk/jvmti/GetTag/gettag001/libgettag001.c | 33 - .../jvmti/GetTag/gettag001/libgettag001.cpp | 33 + .../thrcputime001/libthrcputime001.c | 33 - .../thrcputime001/libthrcputime001.cpp | 33 + .../{thrcputime001.c => thrcputime001.cpp} | 0 .../thrcputime002/libthrcputime002.c | 33 - .../thrcputime002/libthrcputime002.cpp | 33 + .../{thrcputime002.c => thrcputime002.cpp} | 0 .../thrtimerinfo001/libthrtimerinfo001.c | 33 - .../thrtimerinfo001/libthrtimerinfo001.cpp | 33 + ...{thrtimerinfo001.c => thrtimerinfo001.cpp} | 0 ...thrdgrpchld001.c => getthrdgrpchld001.cpp} | 0 .../getthrdgrpchld001/libgetthrdgrpchld001.c | 33 - .../libgetthrdgrpchld001.cpp | 33 + .../thrgrpinfo001/libthrgrpinfo001.c | 33 - .../thrgrpinfo001/libthrgrpinfo001.cpp | 33 + .../thrgrpinfo001/thrgrpinfo001.c | 148 - .../thrgrpinfo001/thrgrpinfo001.cpp | 148 + .../thrgrpinfo002/libthrgrpinfo002.c | 33 - .../thrgrpinfo002/libthrgrpinfo002.cpp | 33 + .../thrgrpinfo002/thrgrpinfo002.c | 132 - .../thrgrpinfo002/thrgrpinfo002.cpp | 132 + .../GetThreadInfo/thrinfo001/libthrinfo001.c | 33 - .../thrinfo001/libthrinfo001.cpp | 33 + .../GetThreadInfo/thrinfo001/thrinfo001.c | 128 - .../GetThreadInfo/thrinfo001/thrinfo001.cpp | 128 + .../GetThreadInfo/thrinfo002/libthrinfo002.c | 33 - .../thrinfo002/libthrinfo002.cpp | 33 + .../GetThreadInfo/thrinfo002/thrinfo002.c | 137 - .../GetThreadInfo/thrinfo002/thrinfo002.cpp | 137 + .../{getthrdstor001.c => getthrdstor001.cpp} | 0 .../getthrdstor001/libgetthrdstor001.c | 33 - .../getthrdstor001/libgetthrdstor001.cpp | 33 + .../GetThreadState/thrstat001/libthrstat001.c | 33 - .../thrstat001/libthrstat001.cpp | 33 + .../GetThreadState/thrstat001/thrstat001.c | 442 --- .../GetThreadState/thrstat001/thrstat001.cpp | 442 +++ .../GetThreadState/thrstat002/libthrstat002.c | 33 - .../thrstat002/libthrstat002.cpp | 33 + .../GetThreadState/thrstat002/thrstat002.c | 381 -- .../GetThreadState/thrstat002/thrstat002.cpp | 381 ++ .../GetThreadState/thrstat003/libthrstat003.c | 33 - .../thrstat003/libthrstat003.cpp | 33 + .../GetThreadState/thrstat003/thrstat003.c | 175 - .../GetThreadState/thrstat003/thrstat003.cpp | 175 + .../GetThreadState/thrstat004/libthrstat004.c | 33 - .../thrstat004/libthrstat004.cpp | 33 + .../GetThreadState/thrstat004/thrstat004.c | 116 - .../GetThreadState/thrstat004/thrstat004.cpp | 116 + .../GetThreadState/thrstat005/libthrstat005.c | 33 - .../thrstat005/libthrstat005.cpp | 33 + .../GetThreadState/thrstat005/thrstat005.c | 175 - .../GetThreadState/thrstat005/thrstat005.cpp | 176 + .../{gettime001.c => gettime001.cpp} | 0 .../jvmti/GetTime/gettime001/libgettime001.c | 33 - .../GetTime/gettime001/libgettime001.cpp | 33 + .../timerinfo001/libtimerinfo001.c | 33 - .../timerinfo001/libtimerinfo001.cpp | 33 + .../{timerinfo001.c => timerinfo001.cpp} | 0 .../topthrgrp001/libtopthrgrp001.c | 33 - .../topthrgrp001/libtopthrgrp001.cpp | 33 + .../topthrgrp001/topthrgrp001.c | 139 - .../topthrgrp001/topthrgrp001.cpp | 139 + .../topthrgrp002/libtopthrgrp002.c | 33 - .../topthrgrp002/libtopthrgrp002.cpp | 33 + .../topthrgrp002/topthrgrp002.c | 121 - .../topthrgrp002/topthrgrp002.cpp | 121 + .../GetVersionNumber/getvern001/getvern001.c | 122 - .../getvern001/getvern001.cpp | 122 + .../getvern001/libgetvern001.c | 33 - .../getvern001/libgetvern001.cpp | 33 + .../{intrpthrd001.c => intrpthrd001.cpp} | 0 .../intrpthrd001/libintrpthrd001.c | 33 - .../intrpthrd001/libintrpthrd001.cpp | 33 + .../intrpthrd002/intrpthrd002.c | 129 - .../intrpthrd002/intrpthrd002.cpp | 129 + .../intrpthrd002/libintrpthrd002.c | 33 - .../intrpthrd002/libintrpthrd002.cpp | 33 + .../intrpthrd003/intrpthrd003.c | 145 - .../intrpthrd003/intrpthrd003.cpp | 145 + .../intrpthrd003/libintrpthrd003.c | 33 - .../intrpthrd003/libintrpthrd003.cpp | 33 + .../IsArrayClass/isarray004/isarray004.c | 120 - .../IsArrayClass/isarray004/isarray004.cpp | 120 + .../IsArrayClass/isarray004/libisarray004.c | 33 - .../IsArrayClass/isarray004/libisarray004.cpp | 33 + .../IsArrayClass/isarray005/isarray005.c | 130 - .../IsArrayClass/isarray005/isarray005.cpp | 130 + .../IsArrayClass/isarray005/libisarray005.c | 33 - .../IsArrayClass/isarray005/libisarray005.cpp | 33 + .../isfldsin002/isfldsin002.c | 173 - .../isfldsin002/isfldsin002.cpp | 173 + .../isfldsin002/libisfldsin002.c | 33 - .../isfldsin002/libisfldsin002.cpp | 33 + .../isfldsin003/isfldsin003.c | 180 - .../isfldsin003/isfldsin003.cpp | 180 + .../isfldsin003/libisfldsin003.c | 33 - .../isfldsin003/libisfldsin003.cpp | 33 + .../jvmti/IsInterface/isintrf004/isintrf004.c | 120 - .../IsInterface/isintrf004/isintrf004.cpp | 120 + .../IsInterface/isintrf004/libisintrf004.c | 33 - .../IsInterface/isintrf004/libisintrf004.cpp | 33 + .../jvmti/IsInterface/isintrf005/isintrf005.c | 128 - .../IsInterface/isintrf005/isintrf005.cpp | 128 + .../IsInterface/isintrf005/libisintrf005.c | 33 - .../IsInterface/isintrf005/libisintrf005.cpp | 33 + .../IsMethodNative/isnative001/isnative001.c | 146 - .../isnative001/isnative001.cpp | 146 + .../isnative001/libisnative001.c | 33 - .../isnative001/libisnative001.cpp | 33 + .../IsMethodNative/isnative002/isnative002.c | 128 - .../isnative002/isnative002.cpp | 128 + .../isnative002/libisnative002.c | 33 - .../isnative002/libisnative002.cpp | 33 + .../isobsolete001/isobsolete001.c | 415 -- .../isobsolete001/isobsolete001.cpp | 415 ++ .../isobsolete001/libisobsolete001.c | 33 - .../isobsolete001/libisobsolete001.cpp | 33 + .../IsMethodSynthetic/issynth001/issynth001.c | 195 - .../issynth001/issynth001.cpp | 195 + .../libIsMethodSyntheticIssynth001.c | 33 - .../libIsMethodSyntheticIssynth001.cpp | 33 + .../IsMethodSynthetic/issynth002/issynth002.c | 161 - .../issynth002/issynth002.cpp | 161 + .../issynth002/libissynth002.c | 33 - .../issynth002/libissynth002.cpp | 33 + .../IterateOverHeap/iterheap001/iterheap001.c | 572 --- .../iterheap001/iterheap001.cpp | 572 +++ .../iterheap001/libiterheap001.c | 33 - .../iterheap001/libiterheap001.cpp | 33 + .../IterateOverHeap/iterheap002/iterheap002.c | 580 --- .../iterheap002/iterheap002.cpp | 580 +++ .../iterheap002/libiterheap002.c | 33 - .../iterheap002/libiterheap002.cpp | 33 + .../IterateOverHeap/iterheap003/iterheap003.c | 581 --- .../iterheap003/iterheap003.cpp | 581 +++ .../iterheap003/libiterheap003.c | 33 - .../iterheap003/libiterheap003.cpp | 33 + .../{iterheap004.c => iterheap004.cpp} | 0 .../iterheap004/libiterheap004.c | 33 - .../iterheap004/libiterheap004.cpp | 33 + .../{iterheap005.c => iterheap005.cpp} | 0 .../iterheap005/libiterheap005.c | 33 - .../iterheap005/libiterheap005.cpp | 33 + .../{iterheap006.c => iterheap006.cpp} | 0 .../iterheap006/libiterheap006.c | 33 - .../iterheap006/libiterheap006.cpp | 33 + .../{iterheap007.c => iterheap007.cpp} | 0 .../iterheap007/libiterheap007.c | 33 - .../iterheap007/libiterheap007.cpp | 33 + .../iterinstcls001/iterinstcls001.c | 591 --- .../iterinstcls001/iterinstcls001.cpp | 591 +++ .../iterinstcls001/libiterinstcls001.c | 33 - .../iterinstcls001/libiterinstcls001.cpp | 33 + .../iterinstcls002/iterinstcls002.c | 599 --- .../iterinstcls002/iterinstcls002.cpp | 599 +++ .../iterinstcls002/libiterinstcls002.c | 33 - .../iterinstcls002/libiterinstcls002.cpp | 33 + .../iterinstcls003/iterinstcls003.c | 600 --- .../iterinstcls003/iterinstcls003.cpp | 600 +++ .../iterinstcls003/libiterinstcls003.c | 33 - .../iterinstcls003/libiterinstcls003.cpp | 33 + .../{iterinstcls004.c => iterinstcls004.cpp} | 0 .../iterinstcls004/libiterinstcls004.c | 33 - .../iterinstcls004/libiterinstcls004.cpp | 33 + .../{iterinstcls005.c => iterinstcls005.cpp} | 0 .../iterinstcls005/libiterinstcls005.c | 33 - .../iterinstcls005/libiterinstcls005.cpp | 33 + .../{iterinstcls006.c => iterinstcls006.cpp} | 0 .../iterinstcls006/libiterinstcls006.c | 33 - .../iterinstcls006/libiterinstcls006.cpp | 33 + .../{iterinstcls007.c => iterinstcls007.cpp} | 0 .../iterinstcls007/libiterinstcls007.c | 33 - .../iterinstcls007/libiterinstcls007.cpp | 33 + .../iterobjreachobj001/iterobjreachobj001.c | 550 --- .../iterobjreachobj001/iterobjreachobj001.cpp | 550 +++ .../libiterobjreachobj001.c | 33 - .../libiterobjreachobj001.cpp | 33 + ...bjreachobj002.c => iterobjreachobj002.cpp} | 0 .../libiterobjreachobj002.c | 33 - .../libiterobjreachobj002.cpp | 33 + ...bjreachobj003.c => iterobjreachobj003.cpp} | 0 .../libiterobjreachobj003.c | 33 - .../libiterobjreachobj003.cpp | 33 + ...bjreachobj004.c => iterobjreachobj004.cpp} | 0 .../libiterobjreachobj004.c | 33 - .../libiterobjreachobj004.cpp | 33 + ...bjreachobj005.c => iterobjreachobj005.cpp} | 0 .../libiterobjreachobj005.c | 33 - .../libiterobjreachobj005.cpp | 33 + .../iterreachobj001/iterreachobj001.c | 743 ---- .../iterreachobj001/iterreachobj001.cpp | 743 ++++ .../iterreachobj001/libiterreachobj001.c | 33 - .../iterreachobj001/libiterreachobj001.cpp | 33 + ...{iterreachobj002.c => iterreachobj002.cpp} | 0 .../iterreachobj002/libiterreachobj002.c | 33 - .../iterreachobj002/libiterreachobj002.cpp | 33 + ...{iterreachobj003.c => iterreachobj003.cpp} | 0 .../iterreachobj003/libiterreachobj003.c | 33 - .../iterreachobj003/libiterreachobj003.cpp | 33 + ...{iterreachobj004.c => iterreachobj004.cpp} | 0 .../iterreachobj004/libiterreachobj004.c | 33 - .../iterreachobj004/libiterreachobj004.cpp | 33 + ...{iterreachobj005.c => iterreachobj005.cpp} | 0 .../iterreachobj005/libiterreachobj005.c | 33 - .../iterreachobj005/libiterreachobj005.cpp | 33 + .../abort/{Abort.c => Abort.cpp} | 0 .../jvmti/IterateThroughHeap/abort/libAbort.c | 33 - .../IterateThroughHeap/abort/libAbort.cpp | 33 + .../IterateThroughHeap/callbacks/Callbacks.c | 644 --- .../callbacks/Callbacks.cpp | 644 +++ .../callbacks/libCallbacks.c | 33 - .../callbacks/libCallbacks.cpp | 33 + ...eKlassFilter.c => ConcreteKlassFilter.cpp} | 0 .../libConcreteKlassFilter.c | 33 - .../libConcreteKlassFilter.cpp | 33 + .../filter-tagged/HeapFilter.c | 612 --- .../filter-tagged/HeapFilter.cpp | 612 +++ .../filter-tagged/libHeapFilter.c | 33 - .../filter-tagged/libHeapFilter.cpp | 33 + ...assFilter.c => NonConcreteKlassFilter.cpp} | 0 .../libNonConcreteKlassFilter.c | 33 - .../libNonConcreteKlassFilter.cpp | 33 + .../MethodEntry/mentry001/libmentry001.c | 33 - .../MethodEntry/mentry001/libmentry001.cpp | 33 + .../jvmti/MethodEntry/mentry001/mentry001.c | 278 -- .../jvmti/MethodEntry/mentry001/mentry001.cpp | 284 ++ .../MethodEntry/mentry002/libmentry002.c | 33 - .../MethodEntry/mentry002/libmentry002.cpp | 33 + .../jvmti/MethodEntry/mentry002/mentry002.c | 203 - .../jvmti/MethodEntry/mentry002/mentry002.cpp | 203 + .../jvmti/MethodExit/mexit001/libmexit001.c | 33 - .../jvmti/MethodExit/mexit001/libmexit001.cpp | 33 + .../nsk/jvmti/MethodExit/mexit001/mexit001.c | 294 -- .../jvmti/MethodExit/mexit001/mexit001.cpp | 294 ++ .../jvmti/MethodExit/mexit002/libmexit002.c | 33 - .../jvmti/MethodExit/mexit002/libmexit002.cpp | 33 + .../nsk/jvmti/MethodExit/mexit002/mexit002.c | 284 -- .../jvmti/MethodExit/mexit002/mexit002.cpp | 284 ++ .../mcontenter001/libmcontenter001.c | 33 - .../mcontenter001/libmcontenter001.cpp | 33 + .../{mcontenter001.c => mcontenter001.cpp} | 0 .../mcontentered001/libmcontentered001.c | 33 - .../mcontentered001/libmcontentered001.cpp | 33 + ...{mcontentered001.c => mcontentered001.cpp} | 0 .../monitorwait001/libmonitorwait001.c | 33 - .../monitorwait001/libmonitorwait001.cpp | 33 + .../{monitorwait001.c => monitorwait001.cpp} | 0 .../monitorwaited001/libmonitorwaited001.c | 33 - .../monitorwaited001/libmonitorwaited001.cpp | 33 + ...onitorwaited001.c => monitorwaited001.cpp} | 0 .../nativemethbind001/libnativemethbind001.c | 33 - .../libnativemethbind001.cpp | 33 + ...ivemethbind001.c => nativemethbind001.cpp} | 0 .../nativemethbind002/libnativemethbind002.c | 33 - .../libnativemethbind002.cpp | 33 + ...ivemethbind002.c => nativemethbind002.cpp} | 0 .../nativemethbind003/libnativemethbind003.c | 33 - .../libnativemethbind003.cpp | 33 + ...ivemethbind003.c => nativemethbind003.cpp} | 0 .../nativemethbind004/libnativemethbind004.c | 33 - .../libnativemethbind004.cpp | 33 + ...ivemethbind004.c => nativemethbind004.cpp} | 0 .../nframepop001/libnframepop001.c | 33 - .../nframepop001/libnframepop001.cpp | 33 + .../nframepop001/nframepop001.c | 357 -- .../nframepop001/nframepop001.cpp | 357 ++ .../nframepop002/libnframepop002.c | 33 - .../nframepop002/libnframepop002.cpp | 33 + .../nframepop002/nframepop002.c | 128 - .../nframepop002/nframepop002.cpp | 128 + .../nframepop003/libnframepop003.c | 33 - .../nframepop003/libnframepop003.cpp | 33 + .../nframepop003/nframepop003.c | 138 - .../nframepop003/nframepop003.cpp | 138 + .../ObjectFree/objfree001/libobjfree001.c | 33 - .../ObjectFree/objfree001/libobjfree001.cpp | 33 + .../{objfree001.c => objfree001.cpp} | 0 .../ObjectFree/objfree002/libobjfree002.c | 33 - .../ObjectFree/objfree002/libobjfree002.cpp | 33 + .../{objfree002.c => objfree002.cpp} | 0 .../PopFrame/popframe001/libpopframe001.c | 33 - .../PopFrame/popframe001/libpopframe001.cpp | 33 + .../jvmti/PopFrame/popframe001/popframe001.c | 262 -- .../PopFrame/popframe001/popframe001.cpp | 262 ++ .../PopFrame/popframe002/libpopframe002.c | 33 - .../PopFrame/popframe002/libpopframe002.cpp | 33 + .../jvmti/PopFrame/popframe002/popframe002.c | 273 -- .../PopFrame/popframe002/popframe002.cpp | 273 ++ .../PopFrame/popframe003/libpopframe003.c | 33 - .../PopFrame/popframe003/libpopframe003.cpp | 33 + .../jvmti/PopFrame/popframe003/popframe003.c | 263 -- .../PopFrame/popframe003/popframe003.cpp | 263 ++ .../PopFrame/popframe004/libpopframe004.c | 33 - .../PopFrame/popframe004/libpopframe004.cpp | 33 + .../jvmti/PopFrame/popframe004/popframe004.c | 321 -- .../PopFrame/popframe004/popframe004.cpp | 321 ++ .../PopFrame/popframe005/libpopframe005.c | 33 - .../PopFrame/popframe005/libpopframe005.cpp | 33 + .../jvmti/PopFrame/popframe005/popframe005.c | 388 -- .../PopFrame/popframe005/popframe005.cpp | 396 ++ .../PopFrame/popframe006/libpopframe006.c | 33 - .../PopFrame/popframe006/libpopframe006.cpp | 33 + .../jvmti/PopFrame/popframe006/popframe006.c | 533 --- .../PopFrame/popframe006/popframe006.cpp | 534 +++ .../PopFrame/popframe007/libpopframe007.c | 33 - .../PopFrame/popframe007/libpopframe007.cpp | 33 + .../jvmti/PopFrame/popframe007/popframe007.c | 215 - .../PopFrame/popframe007/popframe007.cpp | 215 + .../PopFrame/popframe008/libpopframe008.c | 33 - .../PopFrame/popframe008/libpopframe008.cpp | 33 + .../jvmti/PopFrame/popframe008/popframe008.c | 333 -- .../PopFrame/popframe008/popframe008.cpp | 333 ++ .../PopFrame/popframe009/libpopframe009.c | 33 - .../PopFrame/popframe009/libpopframe009.cpp | 33 + .../jvmti/PopFrame/popframe009/popframe009.c | 613 --- .../PopFrame/popframe009/popframe009.cpp | 613 +++ .../PopFrame/popframe010/libpopframe010.c | 33 - .../PopFrame/popframe010/libpopframe010.cpp | 33 + .../jvmti/PopFrame/popframe010/popframe010.c | 364 -- .../PopFrame/popframe010/popframe010.cpp | 364 ++ .../PopFrame/popframe011/libpopframe011.c | 33 - .../PopFrame/popframe011/libpopframe011.cpp | 33 + .../jvmti/PopFrame/popframe011/popframe011.c | 319 -- .../PopFrame/popframe011/popframe011.cpp | 319 ++ .../rawmonenter001/librawmonenter001.c | 33 - .../rawmonenter001/librawmonenter001.cpp | 33 + .../rawmonenter001/rawmonenter001.c | 199 - .../rawmonenter001/rawmonenter001.cpp | 199 + .../rawmonenter002/librawmonenter002.c | 33 - .../rawmonenter002/librawmonenter002.cpp | 33 + .../rawmonenter002/rawmonenter002.c | 110 - .../rawmonenter002/rawmonenter002.cpp | 110 + .../rawmonenter003/librawmonenter003.c | 33 - .../rawmonenter003/librawmonenter003.cpp | 33 + .../rawmonenter003/rawmonenter003.c | 112 - .../rawmonenter003/rawmonenter003.cpp | 112 + .../rawmonenter004/librawmonenter004.c | 33 - .../rawmonenter004/librawmonenter004.cpp | 33 + .../rawmonenter004/rawmonenter004.c | 197 - .../rawmonenter004/rawmonenter004.cpp | 197 + .../rawmonexit001/librawmonexit001.c | 33 - .../rawmonexit001/librawmonexit001.cpp | 33 + .../rawmonexit001/rawmonexit001.c | 225 -- .../rawmonexit001/rawmonexit001.cpp | 225 ++ .../rawmonexit002/librawmonexit002.c | 33 - .../rawmonexit002/librawmonexit002.cpp | 33 + .../rawmonexit002/rawmonexit002.c | 110 - .../rawmonexit002/rawmonexit002.cpp | 110 + .../rawmonexit003/librawmonexit003.c | 33 - .../rawmonexit003/librawmonexit003.cpp | 33 + .../rawmonexit003/rawmonexit003.c | 112 - .../rawmonexit003/rawmonexit003.cpp | 112 + .../rawmonexit005/librawmonexit005.c | 33 - .../rawmonexit005/librawmonexit005.cpp | 33 + .../rawmonexit005/rawmonexit005.c | 119 - .../rawmonexit005/rawmonexit005.cpp | 119 + .../rawmnntfy001/librawmnntfy001.c | 33 - .../rawmnntfy001/librawmnntfy001.cpp | 33 + .../rawmnntfy001/rawmnntfy001.c | 251 -- .../rawmnntfy001/rawmnntfy001.cpp | 251 ++ .../rawmnntfy002/librawmnntfy002.c | 33 - .../rawmnntfy002/librawmnntfy002.cpp | 33 + .../rawmnntfy002/rawmnntfy002.c | 110 - .../rawmnntfy002/rawmnntfy002.cpp | 110 + .../rawmnntfy003/librawmnntfy003.c | 33 - .../rawmnntfy003/librawmnntfy003.cpp | 33 + .../rawmnntfy003/rawmnntfy003.c | 112 - .../rawmnntfy003/rawmnntfy003.cpp | 112 + .../rawmnntfy004/librawmnntfy004.c | 33 - .../rawmnntfy004/librawmnntfy004.cpp | 33 + .../rawmnntfy004/rawmnntfy004.c | 118 - .../rawmnntfy004/rawmnntfy004.cpp | 118 + .../rawmnntfyall001/librawmnntfyall001.c | 33 - .../rawmnntfyall001/librawmnntfyall001.cpp | 33 + .../rawmnntfyall001/rawmnntfyall001.c | 251 -- .../rawmnntfyall001/rawmnntfyall001.cpp | 251 ++ .../rawmnntfyall002/librawmnntfyall002.c | 33 - .../rawmnntfyall002/librawmnntfyall002.cpp | 33 + .../rawmnntfyall002/rawmnntfyall002.c | 110 - .../rawmnntfyall002/rawmnntfyall002.cpp | 110 + .../rawmnntfyall003/librawmnntfyall003.c | 33 - .../rawmnntfyall003/librawmnntfyall003.cpp | 33 + .../rawmnntfyall003/rawmnntfyall003.c | 112 - .../rawmnntfyall003/rawmnntfyall003.cpp | 112 + .../rawmnntfyall004/librawmnntfyall004.c | 33 - .../rawmnntfyall004/librawmnntfyall004.cpp | 33 + .../rawmnntfyall004/rawmnntfyall004.c | 118 - .../rawmnntfyall004/rawmnntfyall004.cpp | 118 + .../rawmnwait001/librawmnwait001.c | 33 - .../rawmnwait001/librawmnwait001.cpp | 33 + .../rawmnwait001/rawmnwait001.c | 252 -- .../rawmnwait001/rawmnwait001.cpp | 252 ++ .../rawmnwait002/librawmnwait002.c | 33 - .../rawmnwait002/librawmnwait002.cpp | 33 + .../rawmnwait002/rawmnwait002.c | 111 - .../rawmnwait002/rawmnwait002.cpp | 111 + .../rawmnwait003/librawmnwait003.c | 33 - .../rawmnwait003/librawmnwait003.cpp | 33 + .../rawmnwait003/rawmnwait003.c | 113 - .../rawmnwait003/rawmnwait003.cpp | 113 + .../rawmnwait004/librawmnwait004.c | 33 - .../rawmnwait004/librawmnwait004.cpp | 33 + .../rawmnwait004/rawmnwait004.c | 119 - .../rawmnwait004/rawmnwait004.cpp | 119 + .../rawmnwait005/librawmnwait005.c | 33 - .../rawmnwait005/librawmnwait005.cpp | 33 + .../rawmnwait005/rawmnwait005.c | 305 -- .../rawmnwait005/rawmnwait005.cpp | 305 ++ .../StressRedefine/libstressRedefine.c | 33 - .../StressRedefine/libstressRedefine.cpp | 33 + .../StressRedefine/stressRedefine.c | 133 - .../StressRedefine/stressRedefine.cpp | 133 + .../redefclass001/libredefclass001.c | 33 - .../redefclass001/libredefclass001.cpp | 33 + .../redefclass001/redefclass001.c | 144 - .../redefclass001/redefclass001.cpp | 144 + .../redefclass002/libredefclass002.c | 33 - .../redefclass002/libredefclass002.cpp | 33 + .../redefclass002/redefclass002.c | 180 - .../redefclass002/redefclass002.cpp | 180 + .../redefclass003/libredefclass003.c | 33 - .../redefclass003/libredefclass003.cpp | 33 + .../redefclass003/redefclass003.c | 189 - .../redefclass003/redefclass003.cpp | 189 + .../redefclass004/libredefclass004.c | 33 - .../redefclass004/libredefclass004.cpp | 33 + .../redefclass004/redefclass004.c | 221 -- .../redefclass004/redefclass004.cpp | 221 ++ .../redefclass005/libredefclass005.c | 33 - .../redefclass005/libredefclass005.cpp | 33 + .../redefclass005/redefclass005.c | 255 -- .../redefclass005/redefclass005.cpp | 255 ++ .../redefclass006/libredefclass006.c | 33 - .../redefclass006/libredefclass006.cpp | 33 + .../redefclass006/redefclass006.c | 155 - .../redefclass006/redefclass006.cpp | 155 + .../redefclass008/libredefclass008.c | 33 - .../redefclass008/libredefclass008.cpp | 33 + .../redefclass008/redefclass008.c | 308 -- .../redefclass008/redefclass008.cpp | 308 ++ .../redefclass009/libredefclass009.c | 33 - .../redefclass009/libredefclass009.cpp | 33 + .../redefclass009/redefclass009.c | 307 -- .../redefclass009/redefclass009.cpp | 307 ++ .../redefclass010/libredefclass010.c | 33 - .../redefclass010/libredefclass010.cpp | 33 + .../redefclass010/redefclass010.c | 285 -- .../redefclass010/redefclass010.cpp | 285 ++ .../redefclass011/libredefclass011.c | 33 - .../redefclass011/libredefclass011.cpp | 33 + .../redefclass011/redefclass011.c | 147 - .../redefclass011/redefclass011.cpp | 147 + .../redefclass012/libredefclass012.c | 33 - .../redefclass012/libredefclass012.cpp | 33 + .../redefclass012/redefclass012.c | 156 - .../redefclass012/redefclass012.cpp | 156 + .../redefclass013/libredefclass013.c | 33 - .../redefclass013/libredefclass013.cpp | 33 + .../redefclass013/redefclass013.c | 156 - .../redefclass013/redefclass013.cpp | 156 + .../redefclass014/libredefclass014.c | 33 - .../redefclass014/libredefclass014.cpp | 33 + .../redefclass014/redefclass014.c | 155 - .../redefclass014/redefclass014.cpp | 155 + .../redefclass015/libredefclass015.c | 33 - .../redefclass015/libredefclass015.cpp | 33 + .../redefclass015/redefclass015.c | 147 - .../redefclass015/redefclass015.cpp | 147 + .../redefclass016/libredefclass016.c | 33 - .../redefclass016/libredefclass016.cpp | 33 + .../redefclass016/redefclass016.c | 358 -- .../redefclass016/redefclass016.cpp | 358 ++ .../redefclass017/libredefclass017.c | 33 - .../redefclass017/libredefclass017.cpp | 33 + .../redefclass017/redefclass017.c | 210 - .../redefclass017/redefclass017.cpp | 210 + .../redefclass018/libredefclass018.c | 33 - .../redefclass018/libredefclass018.cpp | 33 + .../redefclass018/redefclass018.c | 204 - .../redefclass018/redefclass018.cpp | 204 + .../redefclass019/libredefclass019.c | 33 - .../redefclass019/libredefclass019.cpp | 33 + .../redefclass019/redefclass019.c | 516 --- .../redefclass019/redefclass019.cpp | 516 +++ .../redefclass020/libredefclass020.c | 33 - .../redefclass020/libredefclass020.cpp | 33 + .../redefclass020/redefclass020.c | 150 - .../redefclass020/redefclass020.cpp | 150 + .../redefclass021/libredefclass021.c | 33 - .../redefclass021/libredefclass021.cpp | 33 + .../redefclass021/redefclass021.c | 149 - .../redefclass021/redefclass021.cpp | 149 + .../redefclass022/libredefclass022.c | 33 - .../redefclass022/libredefclass022.cpp | 33 + .../redefclass022/redefclass022.c | 150 - .../redefclass022/redefclass022.cpp | 150 + .../redefclass023/libredefclass023.c | 33 - .../redefclass023/libredefclass023.cpp | 33 + .../redefclass023/redefclass023.c | 150 - .../redefclass023/redefclass023.cpp | 150 + .../redefclass024/libredefclass024.c | 33 - .../redefclass024/libredefclass024.cpp | 33 + .../redefclass024/redefclass024.c | 150 - .../redefclass024/redefclass024.cpp | 150 + .../redefclass025/libredefclass025.c | 33 - .../redefclass025/libredefclass025.cpp | 33 + .../redefclass025/redefclass025.c | 150 - .../redefclass025/redefclass025.cpp | 150 + .../redefclass026/libredefclass026.c | 33 - .../redefclass026/libredefclass026.cpp | 33 + .../redefclass026/redefclass026.c | 147 - .../redefclass026/redefclass026.cpp | 147 + .../redefclass027/libredefclass027.c | 33 - .../redefclass027/libredefclass027.cpp | 33 + .../redefclass027/redefclass027.c | 853 ---- .../redefclass027/redefclass027.cpp | 853 ++++ .../redefclass028/libredefclass028.c | 33 - .../redefclass028/libredefclass028.cpp | 33 + .../redefclass028/redefclass028.c | 294 -- .../redefclass028/redefclass028.cpp | 294 ++ .../redefclass029/libredefclass029.c | 33 - .../redefclass029/libredefclass029.cpp | 33 + .../redefclass029/redefclass029.c | 293 -- .../redefclass029/redefclass029.cpp | 293 ++ .../redefclass030/libredefclass030.c | 33 - .../redefclass030/libredefclass030.cpp | 33 + .../redefclass030/redefclass030.c | 294 -- .../redefclass030/redefclass030.cpp | 294 ++ .../redefclass031/libredefclass031.c | 33 - .../redefclass031/libredefclass031.cpp | 33 + .../redefclass031/redefclass031.c | 206 - .../redefclass031/redefclass031.cpp | 206 + .../relcaps001/librelcaps001.c | 33 - .../relcaps001/librelcaps001.cpp | 33 + .../{relcaps001.c => relcaps001.cpp} | 0 .../relcaps002/librelcaps002.c | 33 - .../relcaps002/librelcaps002.cpp | 33 + .../{relcaps002.c => relcaps002.cpp} | 0 .../jvmti/ResourceExhausted/libresexhausted.c | 33 - .../ResourceExhausted/libresexhausted.cpp | 33 + .../{resexhausted.c => resexhausted.cpp} | 0 .../resumethrd001/libresumethrd001.c | 33 - .../resumethrd001/libresumethrd001.cpp | 33 + .../{resumethrd001.c => resumethrd001.cpp} | 0 .../resumethrd002/libresumethrd002.c | 33 - .../resumethrd002/libresumethrd002.cpp | 33 + .../{resumethrd002.c => resumethrd002.cpp} | 0 .../resumethrdlst001/libresumethrdlst001.c | 33 - .../resumethrdlst001/libresumethrdlst001.cpp | 33 + ...esumethrdlst001.c => resumethrdlst001.cpp} | 0 .../resumethrdlst002/libresumethrdlst002.c | 33 - .../resumethrdlst002/libresumethrdlst002.cpp | 33 + ...esumethrdlst002.c => resumethrdlst002.cpp} | 0 .../retransform002/libretransform002.c | 33 - .../retransform002/libretransform002.cpp | 33 + .../retransform002/retransform002.c | 167 - .../retransform002/retransform002.cpp | 175 + .../retransform003/libretransform003.c | 33 - .../retransform003/libretransform003.cpp | 33 + .../retransform003/retransform003.c | 283 -- .../retransform003/retransform003.cpp | 291 ++ .../retransform004/libretransform004.c | 33 - .../retransform004/libretransform004.cpp | 33 + .../retransform004/retransform004.c | 180 - .../retransform004/retransform004.cpp | 188 + .../RunAgentThread/agentthr001/agentthr001.c | 342 -- .../agentthr001/agentthr001.cpp | 342 ++ .../agentthr001/libagentthr001.c | 33 - .../agentthr001/libagentthr001.cpp | 33 + .../RunAgentThread/agentthr002/agentthr002.c | 177 - .../agentthr002/agentthr002.cpp | 177 + .../agentthr002/libagentthr002.c | 33 - .../agentthr002/libagentthr002.cpp | 33 + .../RunAgentThread/agentthr003/agentthr003.c | 150 - .../agentthr003/agentthr003.cpp | 150 + .../agentthr003/libagentthr003.c | 33 - .../agentthr003/libagentthr003.cpp | 33 + .../SetBreakpoint/setbrk002/libsetbrk002.c | 33 - .../SetBreakpoint/setbrk002/libsetbrk002.cpp | 33 + .../jvmti/SetBreakpoint/setbrk002/setbrk002.c | 162 - .../SetBreakpoint/setbrk002/setbrk002.cpp | 162 + .../SetBreakpoint/setbrk003/libsetbrk003.c | 33 - .../SetBreakpoint/setbrk003/libsetbrk003.cpp | 33 + .../jvmti/SetBreakpoint/setbrk003/setbrk003.c | 144 - .../SetBreakpoint/setbrk003/setbrk003.cpp | 144 + .../SetBreakpoint/setbrk005/libsetbrk005.c | 33 - .../SetBreakpoint/setbrk005/libsetbrk005.cpp | 33 + .../jvmti/SetBreakpoint/setbrk005/setbrk005.c | 151 - .../SetBreakpoint/setbrk005/setbrk005.cpp | 151 + .../SetBreakpoint/setbrk007/libsetbrk007.c | 33 - .../SetBreakpoint/setbrk007/libsetbrk007.cpp | 33 + .../jvmti/SetBreakpoint/setbrk007/setbrk007.c | 148 - .../SetBreakpoint/setbrk007/setbrk007.cpp | 148 + .../SetBreakpoint/setbrk008/libsetbrk008.c | 33 - .../SetBreakpoint/setbrk008/libsetbrk008.cpp | 33 + .../jvmti/SetBreakpoint/setbrk008/setbrk008.c | 239 -- .../SetBreakpoint/setbrk008/setbrk008.cpp | 239 ++ .../setenvstor001/libsetenvstor001.c | 33 - .../setenvstor001/libsetenvstor001.cpp | 33 + .../{setenvstor001.c => setenvstor001.cpp} | 0 .../setenvstor002/libsetenvstor002.c | 33 - .../setenvstor002/libsetenvstor002.cpp | 33 + .../{setenvstor002.c => setenvstor002.cpp} | 0 .../setenvstor003/libsetenvstor003.c | 33 - .../setenvstor003/libsetenvstor003.cpp | 33 + .../{setenvstor003.c => setenvstor003.cpp} | 0 .../setevntcallb001/libsetevntcallb001.c | 33 - .../setevntcallb001/libsetevntcallb001.cpp | 33 + ...{setevntcallb001.c => setevntcallb001.cpp} | 0 .../setevntcallb002/libsetevntcallb002.c | 33 - .../setevntcallb002/libsetevntcallb002.cpp | 33 + ...{setevntcallb002.c => setevntcallb002.cpp} | 0 .../setevntcallb003/libsetevntcallb003.c | 33 - .../setevntcallb003/libsetevntcallb003.cpp | 33 + ...{setevntcallb003.c => setevntcallb003.cpp} | 0 .../setnotif001/libsetnotif001.c | 33 - .../setnotif001/libsetnotif001.cpp | 33 + .../setnotif001/setnotif001.c | 433 -- .../setnotif001/setnotif001.cpp | 434 +++ .../setextevent001/libsetextevent001.c | 33 - .../setextevent001/libsetextevent001.cpp | 33 + .../{setextevent001.c => setextevent001.cpp} | 0 .../setfldw001/libsetfldw001.c | 33 - .../setfldw001/libsetfldw001.cpp | 33 + .../setfldw001/setfldw001.c | 241 -- .../setfldw001/setfldw001.cpp | 241 ++ .../setfldw002/libsetfldw002.c | 33 - .../setfldw002/libsetfldw002.cpp | 33 + .../setfldw002/setfldw002.c | 175 - .../setfldw002/setfldw002.cpp | 175 + .../setfldw003/libsetfldw003.c | 33 - .../setfldw003/libsetfldw003.cpp | 33 + .../setfldw003/setfldw003.c | 190 - .../setfldw003/setfldw003.cpp | 190 + .../setfldw004/libsetfldw004.c | 33 - .../setfldw004/libsetfldw004.cpp | 33 + .../setfldw004/setfldw004.c | 196 - .../setfldw004/setfldw004.cpp | 196 + .../setfldw005/libsetfldw005.c | 33 - .../setfldw005/libsetfldw005.cpp | 33 + .../setfldw005/setfldw005.c | 225 -- .../setfldw005/setfldw005.cpp | 225 ++ .../setfldw006/libsetfldw006.c | 33 - .../setfldw006/libsetfldw006.cpp | 33 + .../setfldw006/setfldw006.c | 248 -- .../setfldw006/setfldw006.cpp | 248 ++ .../setfmodw001/libsetfmodw001.c | 33 - .../setfmodw001/libsetfmodw001.cpp | 33 + .../setfmodw001/setfmodw001.c | 236 -- .../setfmodw001/setfmodw001.cpp | 236 ++ .../setfmodw002/libsetfmodw002.c | 33 - .../setfmodw002/libsetfmodw002.cpp | 33 + .../setfmodw002/setfmodw002.c | 176 - .../setfmodw002/setfmodw002.cpp | 176 + .../setfmodw003/libsetfmodw003.c | 33 - .../setfmodw003/libsetfmodw003.cpp | 33 + .../setfmodw003/setfmodw003.c | 229 -- .../setfmodw003/setfmodw003.cpp | 229 ++ .../setfmodw004/libsetfmodw004.c | 33 - .../setfmodw004/libsetfmodw004.cpp | 33 + .../setfmodw004/setfmodw004.c | 227 -- .../setfmodw004/setfmodw004.cpp | 227 ++ .../setfmodw005/libsetfmodw005.c | 33 - .../setfmodw005/libsetfmodw005.cpp | 33 + .../setfmodw005/setfmodw005.c | 403 -- .../setfmodw005/setfmodw005.cpp | 403 ++ .../setfmodw006/libsetfmodw006.c | 33 - .../setfmodw006/libsetfmodw006.cpp | 33 + .../setfmodw006/setfmodw006.c | 245 -- .../setfmodw006/setfmodw006.cpp | 245 ++ .../setjniftab001/libsetjniftab001.c | 33 - .../setjniftab001/libsetjniftab001.cpp | 33 + .../setjniftab001/setjniftab001.c | 473 --- .../setjniftab001/setjniftab001.cpp | 472 +++ .../setjniftab002/libsetjniftab002.c | 33 - .../setjniftab002/libsetjniftab002.cpp | 33 + .../setjniftab002/setjniftab002.c | 158 - .../setjniftab002/setjniftab002.cpp | 158 + .../setlocal001/libsetlocal001.c | 33 - .../setlocal001/libsetlocal001.cpp | 33 + .../setlocal001/setlocal001.c | 374 -- .../setlocal001/setlocal001.cpp | 374 ++ .../setlocal002/libsetlocal002.c | 33 - .../setlocal002/libsetlocal002.cpp | 33 + .../setlocal002/setlocal002.c | 304 -- .../setlocal002/setlocal002.cpp | 304 ++ .../setlocal003/libsetlocal003.c | 33 - .../setlocal003/libsetlocal003.cpp | 33 + .../setlocal003/setlocal003.c | 249 -- .../setlocal003/setlocal003.cpp | 249 ++ .../setlocal004/libsetlocal004.c | 33 - .../setlocal004/libsetlocal004.cpp | 33 + .../setlocal004/setlocal004.c | 254 -- .../setlocal004/setlocal004.cpp | 254 ++ .../SetNativeMethodPrefix001.c | 364 -- .../SetNativeMethodPrefix001.cpp | 372 ++ .../libSetNativeMethodPrefix001.c | 33 - .../libSetNativeMethodPrefix001.cpp | 33 + .../SetNativeMethodPrefix002.c | 145 - .../SetNativeMethodPrefix002.cpp | 153 + .../SetNativeMethodPrefix002Main.c | 46 - .../SetNativeMethodPrefix002Main.cpp | 54 + .../libSetNativeMethodPrefix002.c | 33 - .../libSetNativeMethodPrefix002.cpp | 33 + .../libSetNativeMethodPrefix002Main.c | 32 - .../libSetNativeMethodPrefix002Main.cpp | 32 + .../setsysprop002/libsetsysprop002.c | 33 - .../setsysprop002/libsetsysprop002.cpp | 33 + .../{setsysprop002.c => setsysprop002.cpp} | 0 .../setsysprop003/libsetsysprop003.c | 33 - .../setsysprop003/libsetsysprop003.cpp | 33 + .../{setsysprop003.c => setsysprop003.cpp} | 0 .../nsk/jvmti/SetTag/settag001/libsettag001.c | 33 - .../jvmti/SetTag/settag001/libsettag001.cpp | 33 + .../nsk/jvmti/SetTag/settag001/settag001.c | 227 -- .../nsk/jvmti/SetTag/settag001/settag001.cpp | 227 ++ .../setthrdstor001/libsetthrdstor001.c | 33 - .../setthrdstor001/libsetthrdstor001.cpp | 33 + .../{setthrdstor001.c => setthrdstor001.cpp} | 0 .../setthrdstor002/libsetthrdstor002.c | 33 - .../setthrdstor002/libsetthrdstor002.cpp | 33 + .../{setthrdstor002.c => setthrdstor002.cpp} | 0 .../setthrdstor003/libsetthrdstor003.c | 33 - .../setthrdstor003/libsetthrdstor003.cpp | 33 + .../{setthrdstor003.c => setthrdstor003.cpp} | 0 .../setvrbflag001/libsetvrbflag001.c | 33 - .../setvrbflag001/libsetvrbflag001.cpp | 33 + .../{setvrbflag001.c => setvrbflag001.cpp} | 0 .../setvrbflag002/libsetvrbflag002.c | 33 - .../setvrbflag002/libsetvrbflag002.cpp | 33 + .../{setvrbflag002.c => setvrbflag002.cpp} | 0 .../singlestep001/libsinglestep001.c | 33 - .../singlestep001/libsinglestep001.cpp | 33 + .../SingleStep/singlestep001/singlestep001.c | 305 -- .../singlestep001/singlestep001.cpp | 305 ++ .../singlestep002/libsinglestep002.c | 33 - .../singlestep002/libsinglestep002.cpp | 33 + .../{singlestep002.c => singlestep002.cpp} | 0 .../singlestep003/libsinglestep003.c | 33 - .../singlestep003/libsinglestep003.cpp | 33 + .../{singlestep003.c => singlestep003.cpp} | 0 .../StopThread/stopthrd006/libstopthrd006.c | 33 - .../StopThread/stopthrd006/libstopthrd006.cpp | 33 + .../StopThread/stopthrd006/stopthrd006.c | 149 - .../StopThread/stopthrd006/stopthrd006.cpp | 149 + .../StopThread/stopthrd007/libstopthrd007.c | 33 - .../StopThread/stopthrd007/libstopthrd007.cpp | 33 + .../{stopthrd007.c => stopthrd007.cpp} | 0 .../suspendthrd001/libsuspendthrd001.c | 33 - .../suspendthrd001/libsuspendthrd001.cpp | 33 + .../{suspendthrd001.c => suspendthrd001.cpp} | 0 .../suspendthrd002/libsuspendthrd002.c | 33 - .../suspendthrd002/libsuspendthrd002.cpp | 33 + .../{suspendthrd002.c => suspendthrd002.cpp} | 0 .../suspendthrd003/libsuspendthrd003.c | 33 - .../suspendthrd003/libsuspendthrd003.cpp | 33 + .../{suspendthrd003.c => suspendthrd003.cpp} | 0 .../suspendthrdlst001/libsuspendthrdlst001.c | 33 - .../libsuspendthrdlst001.cpp | 33 + ...pendthrdlst001.c => suspendthrdlst001.cpp} | 0 .../suspendthrdlst002/libsuspendthrdlst002.c | 33 - .../libsuspendthrdlst002.cpp | 33 + ...pendthrdlst002.c => suspendthrdlst002.cpp} | 0 .../ThreadEnd/threadend001/libthreadend001.c | 33 - .../threadend001/libthreadend001.cpp | 33 + .../ThreadEnd/threadend001/threadend001.c | 175 - .../ThreadEnd/threadend001/threadend001.cpp | 175 + .../ThreadEnd/threadend002/libthreadend002.c | 33 - .../threadend002/libthreadend002.cpp | 33 + .../{threadend002.c => threadend002.cpp} | 0 .../threadstart001/libthreadstart001.c | 33 - .../threadstart001/libthreadstart001.cpp | 33 + .../threadstart001/threadstart001.c | 175 - .../threadstart001/threadstart001.cpp | 175 + .../threadstart002/libthreadstart002.c | 33 - .../threadstart002/libthreadstart002.cpp | 33 + .../threadstart002/threadstart002.c | 547 --- .../threadstart002/threadstart002.cpp | 547 +++ .../threadstart003/libthreadstart003.c | 33 - .../threadstart003/libthreadstart003.cpp | 33 + .../threadstart003/threadstart003.c | 293 -- .../threadstart003/threadstart003.cpp | 293 ++ .../jvmti/VMDeath/vmdeath001/libvmdeath001.c | 33 - .../VMDeath/vmdeath001/libvmdeath001.cpp | 33 + .../{vmdeath001.c => vmdeath001.cpp} | 0 .../nsk/jvmti/VMInit/vminit001/libvminit001.c | 33 - .../jvmti/VMInit/vminit001/libvminit001.cpp | 33 + .../nsk/jvmti/VMInit/vminit001/vminit001.c | 202 - .../nsk/jvmti/VMInit/vminit001/vminit001.cpp | 202 + .../vmobjalloc001/libvmobjalloc001.c | 33 - .../vmobjalloc001/libvmobjalloc001.cpp | 33 + .../{vmobjalloc001.c => vmobjalloc001.cpp} | 0 .../ap01t001/{ap01t001.c => ap01t001.cpp} | 0 .../allocation/AP01/ap01t001/libap01t001.c | 33 - .../allocation/AP01/ap01t001/libap01t001.cpp | 33 + .../allocation/AP02/ap02t001/ap02t001.c | 261 -- .../allocation/AP02/ap02t001/ap02t001.cpp | 261 ++ .../allocation/AP02/ap02t001/libap02t001.c | 33 - .../allocation/AP02/ap02t001/libap02t001.cpp | 33 + .../ap03t001/{ap03t001.c => ap03t001.cpp} | 0 .../allocation/AP03/ap03t001/libap03t001.c | 33 - .../allocation/AP03/ap03t001/libap03t001.cpp | 33 + .../allocation/AP04/ap04t001/ap04t001.c | 535 --- .../allocation/AP04/ap04t001/ap04t001.cpp | 535 +++ .../allocation/AP04/ap04t001/libap04t001.c | 33 - .../allocation/AP04/ap04t001/libap04t001.cpp | 33 + .../allocation/AP04/ap04t002/ap04t002.c | 519 --- .../allocation/AP04/ap04t002/ap04t002.cpp | 519 +++ .../allocation/AP04/ap04t002/libap04t002.c | 33 - .../allocation/AP04/ap04t002/libap04t002.cpp | 33 + .../allocation/AP04/ap04t003/ap04t003.c | 709 ---- .../allocation/AP04/ap04t003/ap04t003.cpp | 709 ++++ .../allocation/AP04/ap04t003/libap04t003.c | 33 - .../allocation/AP04/ap04t003/libap04t003.cpp | 33 + .../ap05t001/{ap05t001.c => ap05t001.cpp} | 0 .../allocation/AP05/ap05t001/libap05t001.c | 33 - .../allocation/AP05/ap05t001/libap05t001.cpp | 33 + .../ap05t002/{ap05t002.c => ap05t002.cpp} | 0 .../allocation/AP05/ap05t002/libap05t002.c | 33 - .../allocation/AP05/ap05t002/libap05t002.cpp | 33 + .../ap06t001/{ap06t001.c => ap06t001.cpp} | 0 .../allocation/AP06/ap06t001/libap06t001.c | 33 - .../allocation/AP06/ap06t001/libap06t001.cpp | 33 + .../ap07t001/{ap07t001.c => ap07t001.cpp} | 0 .../allocation/AP07/ap07t001/libap07t001.c | 33 - .../allocation/AP07/ap07t001/libap07t001.cpp | 33 + .../ap07t002/{ap07t002.c => ap07t002.cpp} | 0 .../allocation/AP07/ap07t002/libap07t002.c | 33 - .../allocation/AP07/ap07t002/libap07t002.cpp | 33 + .../ap09t001/{ap09t001.c => ap09t001.cpp} | 0 .../allocation/AP09/ap09t001/libap09t001.c | 33 - .../allocation/AP09/ap09t001/libap09t001.cpp | 33 + .../ap10t001/{ap10t001.c => ap10t001.cpp} | 0 .../allocation/AP10/ap10t001/libap10t001.c | 33 - .../allocation/AP10/ap10t001/libap10t001.cpp | 33 + .../allocation/AP11/ap11t001/ap11t001.c | 267 -- .../allocation/AP11/ap11t001/ap11t001.cpp | 267 ++ .../allocation/AP11/ap11t001/libap11t001.c | 33 - .../allocation/AP11/ap11t001/libap11t001.cpp | 33 + .../ap12t001/{ap12t001.c => ap12t001.cpp} | 0 .../allocation/AP12/ap12t001/libap12t001.c | 33 - .../allocation/AP12/ap12t001/libap12t001.cpp | 33 + .../bcinstr/BI01/bi01t001/bi01t001.c | 297 -- .../bcinstr/BI01/bi01t001/bi01t001.cpp | 297 ++ .../bcinstr/BI01/bi01t001/libbi01t001.c | 33 - .../bcinstr/BI01/bi01t001/libbi01t001.cpp | 33 + .../bcinstr/BI01/bi01t002/bi01t002.c | 311 -- .../bcinstr/BI01/bi01t002/bi01t002.cpp | 311 ++ .../bcinstr/BI01/bi01t002/libbi01t002.c | 33 - .../bcinstr/BI01/bi01t002/libbi01t002.cpp | 33 + .../bcinstr/BI02/bi02t001/bi02t001.c | 207 - .../bcinstr/BI02/bi02t001/bi02t001.cpp | 207 + .../bcinstr/BI02/bi02t001/libbi02t001.c | 33 - .../bcinstr/BI02/bi02t001/libbi02t001.cpp | 33 + .../bcinstr/BI02/bi02t002/bi02t002.c | 189 - .../bcinstr/BI02/bi02t002/bi02t002.cpp | 189 + .../bcinstr/BI02/bi02t002/libbi02t002.c | 33 - .../bcinstr/BI02/bi02t002/libbi02t002.cpp | 33 + .../bcinstr/BI03/bi03t001/bi03t001.c | 207 - .../bcinstr/BI03/bi03t001/bi03t001.cpp | 207 + .../bcinstr/BI03/bi03t001/libbi03t001.c | 33 - .../bcinstr/BI03/bi03t001/libbi03t001.cpp | 33 + .../bcinstr/BI03/bi03t002/bi03t002.c | 189 - .../bcinstr/BI03/bi03t002/bi03t002.cpp | 189 + .../bcinstr/BI03/bi03t002/libbi03t002.c | 33 - .../bcinstr/BI03/bi03t002/libbi03t002.cpp | 33 + .../bcinstr/BI04/bi04t002/bi04t002.c | 186 - .../bcinstr/BI04/bi04t002/bi04t002.cpp | 186 + .../bcinstr/BI04/bi04t002/libbi04t002.c | 33 - .../bcinstr/BI04/bi04t002/libbi04t002.cpp | 33 + .../cm01t001/{cm01t001.c => cm01t001.cpp} | 0 .../capability/CM01/cm01t001/libcm01t001.c | 33 - .../capability/CM01/cm01t001/libcm01t001.cpp | 33 + .../cm01t002/{cm01t002.c => cm01t002.cpp} | 0 .../capability/CM01/cm01t002/libcm01t002.c | 33 - .../capability/CM01/cm01t002/libcm01t002.cpp | 33 + .../cm01t003/{cm01t003.c => cm01t003.cpp} | 0 .../capability/CM01/cm01t003/libcm01t003.c | 33 - .../capability/CM01/cm01t003/libcm01t003.cpp | 33 + .../cm01t004/{cm01t004.c => cm01t004.cpp} | 0 .../capability/CM01/cm01t004/libcm01t004.c | 33 - .../capability/CM01/cm01t004/libcm01t004.cpp | 33 + .../cm01t005/{cm01t005.c => cm01t005.cpp} | 0 .../capability/CM01/cm01t005/libcm01t005.c | 33 - .../capability/CM01/cm01t005/libcm01t005.cpp | 33 + .../cm01t006/{cm01t006.c => cm01t006.cpp} | 0 .../capability/CM01/cm01t006/libcm01t006.c | 33 - .../capability/CM01/cm01t006/libcm01t006.cpp | 33 + .../cm01t007/{cm01t007.c => cm01t007.cpp} | 0 .../capability/CM01/cm01t007/libcm01t007.c | 33 - .../capability/CM01/cm01t007/libcm01t007.cpp | 33 + .../cm01t008/{cm01t008.c => cm01t008.cpp} | 0 .../capability/CM01/cm01t008/libcm01t008.c | 33 - .../capability/CM01/cm01t008/libcm01t008.cpp | 33 + .../cm01t009/{cm01t009.c => cm01t009.cpp} | 0 .../capability/CM01/cm01t009/libcm01t009.c | 33 - .../capability/CM01/cm01t009/libcm01t009.cpp | 33 + .../cm01t010/{cm01t010.c => cm01t010.cpp} | 0 .../capability/CM01/cm01t010/libcm01t010.c | 33 - .../capability/CM01/cm01t010/libcm01t010.cpp | 33 + .../cm01t011/{cm01t011.c => cm01t011.cpp} | 0 .../capability/CM01/cm01t011/libcm01t011.c | 33 - .../capability/CM01/cm01t011/libcm01t011.cpp | 33 + .../cm01t012/{cm01t012.c => cm01t012.cpp} | 0 .../capability/CM01/cm01t012/libcm01t012.c | 33 - .../capability/CM01/cm01t012/libcm01t012.cpp | 33 + .../cm01t013/{cm01t013.c => cm01t013.cpp} | 0 .../capability/CM01/cm01t013/libcm01t013.c | 33 - .../capability/CM01/cm01t013/libcm01t013.cpp | 33 + .../cm01t014/{cm01t014.c => cm01t014.cpp} | 0 .../capability/CM01/cm01t014/libcm01t014.c | 33 - .../capability/CM01/cm01t014/libcm01t014.cpp | 33 + .../cm01t015/{cm01t015.c => cm01t015.cpp} | 0 .../capability/CM01/cm01t015/libcm01t015.c | 33 - .../capability/CM01/cm01t015/libcm01t015.cpp | 33 + .../cm01t016/{cm01t016.c => cm01t016.cpp} | 0 .../capability/CM01/cm01t016/libcm01t016.c | 33 - .../capability/CM01/cm01t016/libcm01t016.cpp | 33 + .../cm01t017/{cm01t017.c => cm01t017.cpp} | 0 .../capability/CM01/cm01t017/libcm01t017.c | 33 - .../capability/CM01/cm01t017/libcm01t017.cpp | 33 + .../cm01t018/{cm01t018.c => cm01t018.cpp} | 0 .../capability/CM01/cm01t018/libcm01t018.c | 33 - .../capability/CM01/cm01t018/libcm01t018.cpp | 33 + .../cm01t019/{cm01t019.c => cm01t019.cpp} | 0 .../capability/CM01/cm01t019/libcm01t019.c | 33 - .../capability/CM01/cm01t019/libcm01t019.cpp | 33 + .../cm01t020/{cm01t020.c => cm01t020.cpp} | 0 .../capability/CM01/cm01t020/libcm01t020.c | 33 - .../capability/CM01/cm01t020/libcm01t020.cpp | 33 + .../cm01t021/{cm01t021.c => cm01t021.cpp} | 0 .../capability/CM01/cm01t021/libcm01t021.c | 33 - .../capability/CM01/cm01t021/libcm01t021.cpp | 33 + .../capability/CM02/cm02t001/cm02t001.c | 781 ---- .../capability/CM02/cm02t001/cm02t001.cpp | 781 ++++ .../capability/CM02/cm02t001/libcm02t001.c | 33 - .../capability/CM02/cm02t001/libcm02t001.cpp | 33 + .../cm03t001/{cm03t001.c => cm03t001.cpp} | 0 .../capability/CM03/cm03t001/libcm03t001.c | 33 - .../capability/CM03/cm03t001/libcm03t001.cpp | 33 + .../contention/TC01/tc01t001/libtc01t001.c | 33 - .../contention/TC01/tc01t001/libtc01t001.cpp | 33 + .../tc01t001/{tc01t001.c => tc01t001.cpp} | 0 .../contention/TC02/tc02t001/libtc02t001.c | 33 - .../contention/TC02/tc02t001/libtc02t001.cpp | 33 + .../tc02t001/{tc02t001.c => tc02t001.cpp} | 0 .../contention/TC03/tc03t001/libtc03t001.c | 33 - .../contention/TC03/tc03t001/libtc03t001.cpp | 33 + .../tc03t001/{tc03t001.c => tc03t001.cpp} | 0 .../contention/TC03/tc03t002/libtc03t002.c | 33 - .../contention/TC03/tc03t002/libtc03t002.cpp | 33 + .../tc03t002/{tc03t002.c => tc03t002.cpp} | 0 .../contention/TC04/tc04t001/libtc04t001.c | 33 - .../contention/TC04/tc04t001/libtc04t001.cpp | 33 + .../contention/TC04/tc04t001/tc04t001.c | 364 -- .../contention/TC04/tc04t001/tc04t001.cpp | 364 ++ .../contention/TC05/tc05t001/libtc05t001.c | 33 - .../contention/TC05/tc05t001/libtc05t001.cpp | 33 + .../contention/TC05/tc05t001/tc05t001.c | 369 -- .../contention/TC05/tc05t001/tc05t001.cpp | 369 ++ .../scenarios/events/EM01/em01t001/em01t001.c | 484 --- .../events/EM01/em01t001/em01t001.cpp | 484 +++ .../events/EM01/em01t001/libem01t001.c | 33 - .../events/EM01/em01t001/libem01t001.cpp | 33 + .../scenarios/events/EM01/em01t002/em01t002.c | 582 --- .../events/EM01/em01t002/em01t002.cpp | 582 +++ .../events/EM01/em01t002/libem01t002.c | 33 - .../events/EM01/em01t002/libem01t002.cpp | 33 + .../em02t001/{em02t001.c => em02t001.cpp} | 0 .../events/EM02/em02t001/libem02t001.c | 33 - .../events/EM02/em02t001/libem02t001.cpp | 33 + .../scenarios/events/EM02/em02t002/em02t002.c | 560 --- .../events/EM02/em02t002/em02t002.cpp | 560 +++ .../events/EM02/em02t002/libem02t002.c | 33 - .../events/EM02/em02t002/libem02t002.cpp | 33 + .../scenarios/events/EM02/em02t003/em02t003.c | 609 --- .../events/EM02/em02t003/em02t003.cpp | 609 +++ .../events/EM02/em02t003/libem02t003.c | 33 - .../events/EM02/em02t003/libem02t003.cpp | 33 + .../scenarios/events/EM02/em02t004/em02t004.c | 615 --- .../events/EM02/em02t004/em02t004.cpp | 615 +++ .../events/EM02/em02t004/libem02t004.c | 33 - .../events/EM02/em02t004/libem02t004.cpp | 33 + .../scenarios/events/EM02/em02t005/em02t005.c | 592 --- .../events/EM02/em02t005/em02t005.cpp | 592 +++ .../events/EM02/em02t005/libem02t005.c | 33 - .../events/EM02/em02t005/libem02t005.cpp | 33 + .../scenarios/events/EM02/em02t006/em02t006.c | 535 --- .../events/EM02/em02t006/em02t006.cpp | 535 +++ .../events/EM02/em02t006/libem02t006.c | 33 - .../events/EM02/em02t006/libem02t006.cpp | 33 + .../scenarios/events/EM02/em02t007/em02t007.c | 580 --- .../events/EM02/em02t007/em02t007.cpp | 580 +++ .../events/EM02/em02t007/libem02t007.c | 33 - .../events/EM02/em02t007/libem02t007.cpp | 33 + .../scenarios/events/EM02/em02t008/em02t008.c | 594 --- .../events/EM02/em02t008/em02t008.cpp | 594 +++ .../events/EM02/em02t008/libem02t008.c | 33 - .../events/EM02/em02t008/libem02t008.cpp | 33 + .../scenarios/events/EM02/em02t009/em02t009.c | 600 --- .../events/EM02/em02t009/em02t009.cpp | 600 +++ .../events/EM02/em02t009/libem02t009.c | 33 - .../events/EM02/em02t009/libem02t009.cpp | 33 + .../scenarios/events/EM02/em02t010/em02t010.c | 576 --- .../events/EM02/em02t010/em02t010.cpp | 576 +++ .../events/EM02/em02t010/libem02t010.c | 33 - .../events/EM02/em02t010/libem02t010.cpp | 33 + .../scenarios/events/EM02/em02t011/em02t011.c | 551 --- .../events/EM02/em02t011/em02t011.cpp | 551 +++ .../events/EM02/em02t011/libem02t011.c | 33 - .../events/EM02/em02t011/libem02t011.cpp | 33 + .../scenarios/events/EM02/em02t012/em02t012.c | 555 --- .../events/EM02/em02t012/em02t012.cpp | 555 +++ .../events/EM02/em02t012/libem02t012.c | 33 - .../events/EM02/em02t012/libem02t012.cpp | 33 + .../em04t001/{em04t001.c => em04t001.cpp} | 0 .../events/EM04/em04t001/libem04t001.c | 35 - .../events/EM04/em04t001/libem04t001.cpp | 35 + .../scenarios/events/EM05/em05t001/em05t001.c | 358 -- .../events/EM05/em05t001/em05t001.cpp | 358 ++ .../events/EM05/em05t001/libem05t001.c | 33 - .../events/EM05/em05t001/libem05t001.cpp | 33 + .../scenarios/events/EM05/em05t002/em05t002.c | 426 -- .../events/EM05/em05t002/em05t002.cpp | 426 ++ .../events/EM05/em05t002/libem05t002.c | 33 - .../events/EM05/em05t002/libem05t002.cpp | 33 + .../scenarios/events/EM06/em06t001/em06t001.c | 278 -- .../events/EM06/em06t001/em06t001.cpp | 278 ++ .../events/EM06/em06t001/libem06t001.c | 33 - .../events/EM06/em06t001/libem06t001.cpp | 33 + .../scenarios/events/EM07/em07t001/em07t001.c | 395 -- .../events/EM07/em07t001/em07t001.cpp | 395 ++ .../events/EM07/em07t001/libem07t001.c | 33 - .../events/EM07/em07t001/libem07t001.cpp | 33 + .../em07t002/{em07t002.c => em07t002.cpp} | 0 .../events/EM07/em07t002/libem07t002.c | 34 - .../events/EM07/em07t002/libem07t002.cpp | 34 + .../ex03t001/{ex03t001.c => ex03t001.cpp} | 0 .../extension/EX03/ex03t001/libex03t001.c | 33 - .../extension/EX03/ex03t001/libex03t001.cpp | 33 + .../gf01t001/{gf01t001.c => gf01t001.cpp} | 0 .../GF01/gf01t001/libgf01t001.c | 33 - .../GF01/gf01t001/libgf01t001.cpp | 33 + .../gf04t001/{gf04t001.c => gf04t001.cpp} | 0 .../GF04/gf04t001/libgf04t001.c | 33 - .../GF04/gf04t001/libgf04t001.cpp | 33 + .../gf06t001/{gf06t001.c => gf06t001.cpp} | 0 .../GF06/gf06t001/libgf06t001.c | 33 - .../GF06/gf06t001/libgf06t001.cpp | 33 + .../gf08t001/{gf08t001.c => gf08t001.cpp} | 0 .../GF08/gf08t001/libgf08t001.c | 33 - .../GF08/gf08t001/libgf08t001.cpp | 33 + .../gf08t002/{gf08t002.c => gf08t002.cpp} | 0 .../GF08/gf08t002/libgf08t002.c | 33 - .../GF08/gf08t002/libgf08t002.cpp | 33 + .../gf08t003/{gf08t003.c => gf08t003.cpp} | 0 .../GF08/gf08t003/libgf08t003.c | 33 - .../GF08/gf08t003/libgf08t003.cpp | 33 + .../hotswap/HS103/hs103t002/hs103t002.c | 183 - .../hotswap/HS103/hs103t002/hs103t002.cpp | 183 + .../hotswap/HS103/hs103t002/libhs103t002.c | 33 - .../hotswap/HS103/hs103t002/libhs103t002.cpp | 33 + .../hotswap/HS104/hs104t001/hs104t001.c | 113 - .../hotswap/HS104/hs104t001/hs104t001.cpp | 113 + .../hotswap/HS104/hs104t001/libhs104t001.c | 33 - .../hotswap/HS104/hs104t001/libhs104t001.cpp | 33 + .../hotswap/HS104/hs104t002/hs104t002.c | 99 - .../hotswap/HS104/hs104t002/hs104t002.cpp | 99 + .../hotswap/HS104/hs104t002/libhs104t002.c | 33 - .../hotswap/HS104/hs104t002/libhs104t002.cpp | 33 + .../hotswap/HS201/hs201t001/hs201t001.c | 737 ---- .../hotswap/HS201/hs201t001/hs201t001.cpp | 737 ++++ .../hotswap/HS201/hs201t001/libhs201t001.c | 33 - .../hotswap/HS201/hs201t001/libhs201t001.cpp | 33 + .../hotswap/HS201/hs201t002/hs201t002.c | 737 ---- .../hotswap/HS201/hs201t002/hs201t002.cpp | 737 ++++ .../hotswap/HS201/hs201t002/libhs201t002.c | 33 - .../hotswap/HS201/hs201t002/libhs201t002.cpp | 33 + .../hs201t003/{hs201t003.c => hs201t003.cpp} | 0 .../hotswap/HS201/hs201t003/libhs201t003.c | 33 - .../hotswap/HS201/hs201t003/libhs201t003.cpp | 33 + .../hotswap/HS202/hs202t001/hs202t001.c | 231 -- .../hotswap/HS202/hs202t001/hs202t001.cpp | 232 ++ .../hotswap/HS202/hs202t001/libhs202t001.c | 33 - .../hotswap/HS202/hs202t001/libhs202t001.cpp | 33 + .../hotswap/HS202/hs202t002/hs202t002.c | 205 - .../hotswap/HS202/hs202t002/hs202t002.cpp | 205 + .../hotswap/HS202/hs202t002/libhs202t002.c | 33 - .../hotswap/HS202/hs202t002/libhs202t002.cpp | 33 + .../hotswap/HS203/hs203t001/hs203t001.c | 239 -- .../hotswap/HS203/hs203t001/hs203t001.cpp | 239 ++ .../hotswap/HS203/hs203t001/libhs203t001.c | 33 - .../hotswap/HS203/hs203t001/libhs203t001.cpp | 33 + .../hotswap/HS203/hs203t002/hs203t002.c | 257 -- .../hotswap/HS203/hs203t002/hs203t002.cpp | 257 ++ .../hotswap/HS203/hs203t002/libhs203t002.c | 33 - .../hotswap/HS203/hs203t002/libhs203t002.cpp | 33 + .../hotswap/HS203/hs203t003/hs203t003.c | 232 -- .../hotswap/HS203/hs203t003/hs203t003.cpp | 232 ++ .../hotswap/HS203/hs203t003/libhs203t003.c | 33 - .../hotswap/HS203/hs203t003/libhs203t003.cpp | 33 + .../hotswap/HS203/hs203t004/hs203t004.c | 262 -- .../hotswap/HS203/hs203t004/hs203t004.cpp | 262 ++ .../hotswap/HS203/hs203t004/libhs203t004.c | 33 - .../hotswap/HS203/hs203t004/libhs203t004.cpp | 33 + .../hotswap/HS204/hs204t001/hs204t001.c | 310 -- .../hotswap/HS204/hs204t001/hs204t001.cpp | 310 ++ .../hotswap/HS204/hs204t001/libhs204t001.c | 33 - .../hotswap/HS204/hs204t001/libhs204t001.cpp | 33 + .../hotswap/HS204/hs204t002/hs204t002.c | 171 - .../hotswap/HS204/hs204t002/hs204t002.cpp | 171 + .../hotswap/HS204/hs204t002/libhs204t002.c | 33 - .../hotswap/HS204/hs204t002/libhs204t002.cpp | 33 + .../hotswap/HS204/hs204t003/hs204t003.c | 257 -- .../hotswap/HS204/hs204t003/hs204t003.cpp | 257 ++ .../hotswap/HS204/hs204t003/libhs204t003.c | 33 - .../hotswap/HS204/hs204t003/libhs204t003.cpp | 33 + .../hotswap/HS204/hs204t004/hs204t004.c | 205 - .../hotswap/HS204/hs204t004/hs204t004.cpp | 205 + .../hotswap/HS204/hs204t004/libhs204t004.c | 33 - .../hotswap/HS204/hs204t004/libhs204t004.cpp | 33 + .../hotswap/HS301/hs301t001/hs301t001.c | 109 - .../hotswap/HS301/hs301t001/hs301t001.cpp | 109 + .../hotswap/HS301/hs301t001/libhs301t001.c | 33 - .../hotswap/HS301/hs301t001/libhs301t001.cpp | 33 + .../hotswap/HS301/hs301t002/hs301t002.c | 107 - .../hotswap/HS301/hs301t002/hs301t002.cpp | 107 + .../hotswap/HS301/hs301t002/libhs301t002.c | 33 - .../hotswap/HS301/hs301t002/libhs301t002.cpp | 33 + .../hotswap/HS301/hs301t003/hs301t003.c | 111 - .../hotswap/HS301/hs301t003/hs301t003.cpp | 111 + .../hotswap/HS301/hs301t003/libhs301t003.c | 33 - .../hotswap/HS301/hs301t003/libhs301t003.cpp | 33 + .../hotswap/HS301/hs301t004/hs301t004.c | 113 - .../hotswap/HS301/hs301t004/hs301t004.cpp | 113 + .../hotswap/HS301/hs301t004/libhs301t004.c | 33 - .../hotswap/HS301/hs301t004/libhs301t004.cpp | 33 + .../hotswap/HS301/hs301t005/hs301t005.c | 104 - .../hotswap/HS301/hs301t005/hs301t005.cpp | 104 + .../hotswap/HS301/hs301t005/libhs301t005.c | 33 - .../hotswap/HS301/hs301t005/libhs301t005.cpp | 33 + .../hotswap/HS302/hs302t001/hs302t001.c | 104 - .../hotswap/HS302/hs302t001/hs302t001.cpp | 104 + .../hotswap/HS302/hs302t001/libhs302t001.c | 33 - .../hotswap/HS302/hs302t001/libhs302t001.cpp | 33 + .../hotswap/HS302/hs302t002/hs302t002.c | 111 - .../hotswap/HS302/hs302t002/hs302t002.cpp | 111 + .../hotswap/HS302/hs302t002/libhs302t002.c | 33 - .../hotswap/HS302/hs302t002/libhs302t002.cpp | 33 + .../hotswap/HS302/hs302t003/hs302t003.c | 110 - .../hotswap/HS302/hs302t003/hs302t003.cpp | 110 + .../hotswap/HS302/hs302t003/libhs302t003.c | 33 - .../hotswap/HS302/hs302t003/libhs302t003.cpp | 33 + .../hotswap/HS302/hs302t004/hs302t004.c | 103 - .../hotswap/HS302/hs302t004/hs302t004.cpp | 103 + .../hotswap/HS302/hs302t004/libhs302t004.c | 33 - .../hotswap/HS302/hs302t004/libhs302t004.cpp | 33 + .../hotswap/HS302/hs302t005/hs302t005.c | 107 - .../hotswap/HS302/hs302t005/hs302t005.cpp | 107 + .../hotswap/HS302/hs302t005/libhs302t005.c | 33 - .../hotswap/HS302/hs302t005/libhs302t005.cpp | 33 + .../hotswap/HS302/hs302t006/hs302t006.c | 105 - .../hotswap/HS302/hs302t006/hs302t006.cpp | 105 + .../hotswap/HS302/hs302t006/libhs302t006.c | 33 - .../hotswap/HS302/hs302t006/libhs302t006.cpp | 33 + .../hotswap/HS302/hs302t007/hs302t007.c | 101 - .../hotswap/HS302/hs302t007/hs302t007.cpp | 101 + .../hotswap/HS302/hs302t007/libhs302t007.c | 33 - .../hotswap/HS302/hs302t007/libhs302t007.cpp | 33 + .../hotswap/HS302/hs302t008/hs302t008.c | 104 - .../hotswap/HS302/hs302t008/hs302t008.cpp | 104 + .../hotswap/HS302/hs302t008/libhs302t008.c | 33 - .../hotswap/HS302/hs302t008/libhs302t008.cpp | 33 + .../hotswap/HS302/hs302t009/hs302t009.c | 105 - .../hotswap/HS302/hs302t009/hs302t009.cpp | 105 + .../hotswap/HS302/hs302t009/libhs302t009.c | 33 - .../hotswap/HS302/hs302t009/libhs302t009.cpp | 33 + .../hotswap/HS302/hs302t010/hs302t010.c | 103 - .../hotswap/HS302/hs302t010/hs302t010.cpp | 103 + .../hotswap/HS302/hs302t010/libhs302t010.c | 33 - .../hotswap/HS302/hs302t010/libhs302t010.cpp | 33 + .../hotswap/HS302/hs302t011/hs302t011.c | 104 - .../hotswap/HS302/hs302t011/hs302t011.cpp | 104 + .../hotswap/HS302/hs302t011/libhs302t011.c | 33 - .../hotswap/HS302/hs302t011/libhs302t011.cpp | 33 + .../hotswap/HS302/hs302t012/hs302t012.c | 107 - .../hotswap/HS302/hs302t012/hs302t012.cpp | 107 + .../hotswap/HS302/hs302t012/libhs302t012.c | 33 - .../hotswap/HS302/hs302t012/libhs302t012.cpp | 33 + .../jni_interception/JI01/ji01t001/ji01t001.c | 452 --- .../JI01/ji01t001/ji01t001.cpp | 460 +++ .../JI01/ji01t001/libji01t001.c | 33 - .../JI01/ji01t001/libji01t001.cpp | 33 + .../jni_interception/JI03/ji03t001/ji03t001.c | 228 -- .../JI03/ji03t001/ji03t001.cpp | 228 ++ .../JI03/ji03t001/libji03t001.c | 33 - .../JI03/ji03t001/libji03t001.cpp | 33 + .../jni_interception/JI03/ji03t002/ji03t002.c | 370 -- .../JI03/ji03t002/ji03t002.cpp | 360 ++ .../JI03/ji03t002/libji03t002.c | 33 - .../JI03/ji03t002/libji03t002.cpp | 33 + .../jni_interception/JI03/ji03t003/ji03t003.c | 367 -- .../JI03/ji03t003/ji03t003.cpp | 364 ++ .../JI03/ji03t003/libji03t003.c | 33 - .../JI03/ji03t003/libji03t003.cpp | 33 + .../jni_interception/JI03/ji03t004/ji03t004.c | 309 -- .../JI03/ji03t004/ji03t004.cpp | 307 ++ .../JI03/ji03t004/libji03t004.c | 33 - .../JI03/ji03t004/libji03t004.cpp | 33 + .../jni_interception/JI05/ji05t001/ji05t001.c | 477 --- .../JI05/ji05t001/ji05t001.cpp | 475 +++ .../JI05/ji05t001/libji05t001.c | 33 - .../JI05/ji05t001/libji05t001.cpp | 33 + .../jni_interception/JI06/ji06t001/ji06t001.c | 529 --- .../JI06/ji06t001/ji06t001.cpp | 528 +++ .../JI06/ji06t001/libji06t001.c | 33 - .../JI06/ji06t001/libji06t001.cpp | 33 + .../multienv/MA01/ma01t001/libma01t001.c | 33 - .../multienv/MA01/ma01t001/libma01t001.cpp | 33 + .../multienv/MA01/ma01t001/libma01t001a.c | 33 - .../multienv/MA01/ma01t001/libma01t001a.cpp | 33 + .../ma01t001/{ma01t001.c => ma01t001.cpp} | 0 .../ma01t001/{ma01t001a.c => ma01t001a.cpp} | 0 .../multienv/MA02/ma02t001/libma02t001.c | 33 - .../multienv/MA02/ma02t001/libma02t001.cpp | 33 + .../multienv/MA02/ma02t001/libma02t001a.c | 33 - .../multienv/MA02/ma02t001/libma02t001a.cpp | 33 + .../ma02t001/{ma02t001.c => ma02t001.cpp} | 0 .../ma02t001/{ma02t001a.c => ma02t001a.cpp} | 0 .../multienv/MA03/ma03t001/libma03t001.c | 33 - .../multienv/MA03/ma03t001/libma03t001.cpp | 33 + .../multienv/MA03/ma03t001/libma03t001a.c | 33 - .../multienv/MA03/ma03t001/libma03t001a.cpp | 33 + .../ma03t001/{ma03t001.c => ma03t001.cpp} | 0 .../ma03t001/{ma03t001a.c => ma03t001a.cpp} | 0 .../multienv/MA04/ma04t001/libma04t001.c | 33 - .../multienv/MA04/ma04t001/libma04t001.cpp | 33 + .../multienv/MA04/ma04t001/libma04t001a.c | 33 - .../multienv/MA04/ma04t001/libma04t001a.cpp | 33 + .../ma04t001/{ma04t001.c => ma04t001.cpp} | 0 .../ma04t001/{ma04t001a.c => ma04t001a.cpp} | 0 .../multienv/MA04/ma04t002/libma04t002.c | 33 - .../multienv/MA04/ma04t002/libma04t002.cpp | 33 + .../multienv/MA04/ma04t002/libma04t002a.c | 33 - .../multienv/MA04/ma04t002/libma04t002a.cpp | 33 + .../multienv/MA04/ma04t002/ma04t002.c | 353 -- .../multienv/MA04/ma04t002/ma04t002.cpp | 353 ++ .../multienv/MA04/ma04t002/ma04t002a.c | 353 -- .../multienv/MA04/ma04t002/ma04t002a.cpp | 353 ++ .../multienv/MA04/ma04t003/libma04t003.c | 33 - .../multienv/MA04/ma04t003/libma04t003.cpp | 33 + .../multienv/MA04/ma04t003/libma04t003a.c | 33 - .../multienv/MA04/ma04t003/libma04t003a.cpp | 33 + .../ma04t003/{ma04t003.c => ma04t003.cpp} | 0 .../ma04t003/{ma04t003a.c => ma04t003a.cpp} | 0 .../multienv/MA05/ma05t001/libma05t001.c | 33 - .../multienv/MA05/ma05t001/libma05t001.cpp | 33 + .../multienv/MA05/ma05t001/libma05t001a.c | 33 - .../multienv/MA05/ma05t001/libma05t001a.cpp | 33 + .../ma05t001/{ma05t001.c => ma05t001.cpp} | 0 .../ma05t001/{ma05t001a.c => ma05t001a.cpp} | 0 .../multienv/MA06/ma06t001/libma06t001.c | 33 - .../multienv/MA06/ma06t001/libma06t001.cpp | 33 + .../multienv/MA06/ma06t001/libma06t001a.c | 33 - .../multienv/MA06/ma06t001/libma06t001a.cpp | 33 + .../multienv/MA06/ma06t001/ma06t001.c | 250 -- .../multienv/MA06/ma06t001/ma06t001.cpp | 250 ++ .../multienv/MA06/ma06t001/ma06t001a.c | 250 -- .../multienv/MA06/ma06t001/ma06t001a.cpp | 250 ++ .../multienv/MA07/ma07t001/libma07t001.c | 33 - .../multienv/MA07/ma07t001/libma07t001.cpp | 33 + .../multienv/MA07/ma07t001/libma07t001a.c | 33 - .../multienv/MA07/ma07t001/libma07t001a.cpp | 33 + .../ma07t001/{ma07t001.c => ma07t001.cpp} | 0 .../ma07t001/{ma07t001a.c => ma07t001a.cpp} | 0 .../multienv/MA08/ma08t001/libma08t001.c | 33 - .../multienv/MA08/ma08t001/libma08t001.cpp | 33 + .../multienv/MA08/ma08t001/libma08t001a.c | 33 - .../multienv/MA08/ma08t001/libma08t001a.cpp | 33 + .../ma08t001/{ma08t001.c => ma08t001.cpp} | 0 .../ma08t001/{ma08t001a.c => ma08t001a.cpp} | 0 .../multienv/MA10/ma10t001/libma10t001.c | 33 - .../multienv/MA10/ma10t001/libma10t001.cpp | 33 + .../multienv/MA10/ma10t001/libma10t001a.c | 33 - .../multienv/MA10/ma10t001/libma10t001a.cpp | 33 + .../ma10t001/{ma10t001.c => ma10t001.cpp} | 0 .../ma10t001/{ma10t001a.c => ma10t001a.cpp} | 0 .../multienv/MA10/ma10t002/libma10t002.c | 33 - .../multienv/MA10/ma10t002/libma10t002.cpp | 33 + .../multienv/MA10/ma10t002/libma10t002a.c | 33 - .../multienv/MA10/ma10t002/libma10t002a.cpp | 33 + .../ma10t002/{ma10t002.c => ma10t002.cpp} | 0 .../ma10t002/{ma10t002a.c => ma10t002a.cpp} | 0 .../multienv/MA10/ma10t003/libma10t003.c | 33 - .../multienv/MA10/ma10t003/libma10t003.cpp | 33 + .../multienv/MA10/ma10t003/libma10t003a.c | 33 - .../multienv/MA10/ma10t003/libma10t003a.cpp | 33 + .../ma10t003/{ma10t003.c => ma10t003.cpp} | 0 .../ma10t003/{ma10t003a.c => ma10t003a.cpp} | 0 .../multienv/MA10/ma10t004/libma10t004.c | 33 - .../multienv/MA10/ma10t004/libma10t004.cpp | 33 + .../multienv/MA10/ma10t004/libma10t004a.c | 33 - .../multienv/MA10/ma10t004/libma10t004a.cpp | 33 + .../ma10t004/{ma10t004.c => ma10t004.cpp} | 0 .../ma10t004/{ma10t004a.c => ma10t004a.cpp} | 0 .../multienv/MA10/ma10t005/libma10t005.c | 33 - .../multienv/MA10/ma10t005/libma10t005.cpp | 33 + .../multienv/MA10/ma10t005/libma10t005a.c | 33 - .../multienv/MA10/ma10t005/libma10t005a.cpp | 33 + .../ma10t005/{ma10t005.c => ma10t005.cpp} | 0 .../ma10t005/{ma10t005a.c => ma10t005a.cpp} | 0 .../multienv/MA10/ma10t006/libma10t006.c | 33 - .../multienv/MA10/ma10t006/libma10t006.cpp | 33 + .../multienv/MA10/ma10t006/libma10t006a.c | 33 - .../multienv/MA10/ma10t006/libma10t006a.cpp | 33 + .../multienv/MA10/ma10t006/ma10t006.c | 177 - .../multienv/MA10/ma10t006/ma10t006.cpp | 177 + .../multienv/MA10/ma10t006/ma10t006a.c | 167 - .../multienv/MA10/ma10t006/ma10t006a.cpp | 167 + .../multienv/MA10/ma10t007/libma10t007.c | 33 - .../multienv/MA10/ma10t007/libma10t007.cpp | 33 + .../multienv/MA10/ma10t007/libma10t007a.c | 33 - .../multienv/MA10/ma10t007/libma10t007a.cpp | 33 + .../ma10t007/{ma10t007.c => ma10t007.cpp} | 0 .../ma10t007/{ma10t007a.c => ma10t007a.cpp} | 0 .../multienv/MA10/ma10t008/libma10t008.c | 33 - .../multienv/MA10/ma10t008/libma10t008.cpp | 33 + .../multienv/MA10/ma10t008/libma10t008a.c | 33 - .../multienv/MA10/ma10t008/libma10t008a.cpp | 33 + .../ma10t008/{ma10t008.c => ma10t008.cpp} | 0 .../ma10t008/{ma10t008a.c => ma10t008a.cpp} | 0 .../sampling/SP01/sp01t001/libsp01t001.c | 33 - .../sampling/SP01/sp01t001/libsp01t001.cpp | 33 + .../sampling/SP01/sp01t001/sp01t001.c | 282 -- .../sampling/SP01/sp01t001/sp01t001.cpp | 282 ++ .../sampling/SP01/sp01t002/libsp01t002.c | 33 - .../sampling/SP01/sp01t002/libsp01t002.cpp | 33 + .../sp01t002/{sp01t002.c => sp01t002.cpp} | 0 .../sampling/SP01/sp01t003/libsp01t003.c | 33 - .../sampling/SP01/sp01t003/libsp01t003.cpp | 33 + .../sp01t003/{sp01t003.c => sp01t003.cpp} | 0 .../sampling/SP02/sp02t001/libsp02t001.c | 33 - .../sampling/SP02/sp02t001/libsp02t001.cpp | 33 + .../sp02t001/{sp02t001.c => sp02t001.cpp} | 0 .../sampling/SP02/sp02t002/libsp02t002.c | 33 - .../sampling/SP02/sp02t002/libsp02t002.cpp | 33 + .../sp02t002/{sp02t002.c => sp02t002.cpp} | 0 .../sampling/SP02/sp02t003/libsp02t003.c | 33 - .../sampling/SP02/sp02t003/libsp02t003.cpp | 33 + .../sp02t003/{sp02t003.c => sp02t003.cpp} | 0 .../sampling/SP03/sp03t001/libsp03t001.c | 33 - .../sampling/SP03/sp03t001/libsp03t001.cpp | 33 + .../sp03t001/{sp03t001.c => sp03t001.cpp} | 0 .../sampling/SP03/sp03t002/libsp03t002.c | 33 - .../sampling/SP03/sp03t002/libsp03t002.cpp | 33 + .../sp03t002/{sp03t002.c => sp03t002.cpp} | 0 .../sampling/SP04/sp04t001/libsp04t001.c | 33 - .../sampling/SP04/sp04t001/libsp04t001.cpp | 33 + .../sp04t001/{sp04t001.c => sp04t001.cpp} | 0 .../sampling/SP04/sp04t002/libsp04t002.c | 33 - .../sampling/SP04/sp04t002/libsp04t002.cpp | 33 + .../sp04t002/{sp04t002.c => sp04t002.cpp} | 0 .../sampling/SP05/sp05t002/libsp05t002.c | 33 - .../sampling/SP05/sp05t002/libsp05t002.cpp | 33 + .../sampling/SP05/sp05t002/sp05t002.c | 425 -- .../sampling/SP05/sp05t002/sp05t002.cpp | 425 ++ .../sampling/SP05/sp05t003/libsp05t003.c | 33 - .../sampling/SP05/sp05t003/libsp05t003.cpp | 33 + .../sampling/SP05/sp05t003/sp05t003.c | 537 --- .../sampling/SP05/sp05t003/sp05t003.cpp | 537 +++ .../sampling/SP06/sp06t001/libsp06t001.c | 33 - .../sampling/SP06/sp06t001/libsp06t001.cpp | 33 + .../sp06t001/{sp06t001.c => sp06t001.cpp} | 0 .../sampling/SP06/sp06t002/libsp06t002.c | 33 - .../sampling/SP06/sp06t002/libsp06t002.cpp | 33 + .../sp06t002/{sp06t002.c => sp06t002.cpp} | 0 .../sampling/SP06/sp06t003/libsp06t003.c | 33 - .../sampling/SP06/sp06t003/libsp06t003.cpp | 33 + .../sp06t003/{sp06t003.c => sp06t003.cpp} | 0 .../sampling/SP07/sp07t001/libsp07t001.c | 33 - .../sampling/SP07/sp07t001/libsp07t001.cpp | 33 + .../sp07t001/{sp07t001.c => sp07t001.cpp} | 0 .../sampling/SP07/sp07t002/libsp07t002.c | 33 - .../sampling/SP07/sp07t002/libsp07t002.cpp | 33 + .../sp07t002/{sp07t002.c => sp07t002.cpp} | 0 .../followref001/followref001.c | 885 ----- .../followref001/followref001.cpp | 885 +++++ .../followref001/libfollowref001.c | 33 - .../followref001/libfollowref001.cpp | 33 + .../followref002/followref002.c | 778 ---- .../followref002/followref002.cpp | 778 ++++ .../followref002/libfollowref002.c | 33 - .../followref002/libfollowref002.cpp | 33 + .../followref003/followref003.c | 1113 ------ .../followref003/followref003.cpp | 1113 ++++++ .../followref003/libfollowref003.c | 33 - .../followref003/libfollowref003.cpp | 33 + .../{followref004.c => followref004.cpp} | 0 .../followref004/libfollowref004.c | 33 - .../followref004/libfollowref004.cpp | 33 + .../{followref005.c => followref005.cpp} | 0 .../followref005/libfollowref005.c | 33 - .../followref005/libfollowref005.cpp | 33 + .../{followref006.c => followref006.cpp} | 0 .../followref006/libfollowref006.c | 33 - .../followref006/libfollowref006.cpp | 33 + .../earlyretbase/earlyretbase.c | 293 -- .../earlyretbase/earlyretbase.cpp | 293 ++ .../earlyretbase/libearlyretbase.c | 33 - .../earlyretbase/libearlyretbase.cpp | 33 + .../ForceEarlyReturn/earlyretfp/earlyretfp.c | 478 --- .../earlyretfp/earlyretfp.cpp | 478 +++ .../earlyretfp/libearlyretfp.c | 33 - .../earlyretfp/libearlyretfp.cpp | 33 + .../earlyretint/earlyretint.c | 493 --- .../earlyretint/earlyretint.cpp | 493 +++ .../earlyretint/libearlyretint.c | 33 - .../earlyretint/libearlyretint.cpp | 33 + .../earlyretlong/earlyretlong.c | 449 --- .../earlyretlong/earlyretlong.cpp | 449 +++ .../earlyretlong/libearlyretlong.c | 33 - .../earlyretlong/libearlyretlong.cpp | 33 + .../earlyretobj/earlyretobj.c | 445 --- .../earlyretobj/earlyretobj.cpp | 445 +++ .../earlyretobj/libearlyretobj.c | 33 - .../earlyretobj/libearlyretobj.cpp | 33 + .../earlyretstr/earlyretstr.c | 435 --- .../earlyretstr/earlyretstr.cpp | 435 +++ .../earlyretstr/libearlyretstr.c | 33 - .../earlyretstr/libearlyretstr.cpp | 33 + .../earlyretvoid/earlyretvoid.c | 374 -- .../earlyretvoid/earlyretvoid.cpp | 374 ++ .../earlyretvoid/libearlyretvoid.c | 33 - .../earlyretvoid/libearlyretvoid.cpp | 33 + .../getallstktr001/getallstktr001.c | 405 -- .../getallstktr001/getallstktr001.cpp | 394 ++ .../getallstktr001/libgetallstktr001.c | 33 - .../getallstktr001/libgetallstktr001.cpp | 33 + .../GetConstantPool/getcpool001/getcpool001.c | 210 - .../getcpool001/getcpool001.cpp | 210 + .../getcpool001/libgetcpool001.c | 33 - .../getcpool001/libgetcpool001.cpp | 33 + .../linetab004/liblinetab004.c | 33 - .../linetab004/liblinetab004.cpp | 33 + .../linetab004/linetab004.c | 273 -- .../linetab004/linetab004.cpp | 273 ++ .../getlocal003/getlocal003.c | 329 -- .../getlocal003/getlocal003.cpp | 329 ++ .../getlocal003/libgetlocal003.c | 33 - .../getlocal003/libgetlocal003.cpp | 33 + .../getlocal004/getlocal004.c | 248 -- .../getlocal004/getlocal004.cpp | 248 ++ .../getlocal004/libgetlocal004.c | 33 - .../getlocal004/libgetlocal004.cpp | 33 + .../unit/IsSynthetic/issynth001/issynth001.c | 299 -- .../IsSynthetic/issynth001/issynth001.cpp | 299 ++ .../issynth001/libIsSyntheticIssynth001.c | 33 - .../issynth001/libIsSyntheticIssynth001.cpp | 33 + .../unit/MethodBind/JvmtiTest/JvmtiTest.c | 352 -- .../unit/MethodBind/JvmtiTest/JvmtiTest.cpp | 352 ++ .../unit/MethodBind/JvmtiTest/libMethodBind.c | 33 - .../MethodBind/JvmtiTest/libMethodBind.cpp | 33 + .../JvmtiTest/{JvmtiTest.c => JvmtiTest.cpp} | 0 .../unit/OnUnload/JvmtiTest/libOnUnload.c | 33 - .../unit/OnUnload/JvmtiTest/libOnUnload.cpp | 33 + .../unit/StackTrace/JvmtiTest/JvmtiTest.c | 351 -- .../unit/StackTrace/JvmtiTest/JvmtiTest.cpp | 351 ++ .../unit/StackTrace/JvmtiTest/libStackTrace.c | 33 - .../StackTrace/JvmtiTest/libStackTrace.cpp | 33 + .../nsk/jvmti/unit/agentthr/agentthr.c | 184 - .../nsk/jvmti/unit/agentthr/agentthr.cpp | 184 + .../nsk/jvmti/unit/agentthr/libagentthr.c | 33 - .../nsk/jvmti/unit/agentthr/libagentthr.cpp | 33 + .../jvmti/unit/clsldrclss00x/clsldrclss00x.c | 193 - .../unit/clsldrclss00x/clsldrclss00x.cpp | 193 + .../unit/clsldrclss00x/libclsldrclss00x.c | 33 - .../unit/clsldrclss00x/libclsldrclss00x.cpp | 33 + .../events/redefineCFLH/JvmtiTest/JvmtiTest.c | 231 -- .../redefineCFLH/JvmtiTest/JvmtiTest.cpp | 231 ++ .../redefineCFLH/JvmtiTest/libredefineCFLH.c | 33 - .../JvmtiTest/libredefineCFLH.cpp | 33 + .../nsk/jvmti/unit/extmech/extmech.c | 224 -- .../nsk/jvmti/unit/extmech/extmech.cpp | 232 ++ .../nsk/jvmti/unit/extmech/libextmech.c | 33 - .../nsk/jvmti/unit/extmech/libextmech.cpp | 33 + .../JvmtiTest/JvmtiTest.c | 274 -- .../JvmtiTest/JvmtiTest.cpp | 274 ++ .../libAddToBootstrapClassLoaderSearch.c | 33 - .../libAddToBootstrapClassLoaderSearch.cpp | 33 + .../functions/Dispose/JvmtiTest/JvmtiTest.c | 169 - .../functions/Dispose/JvmtiTest/JvmtiTest.cpp | 169 + .../functions/Dispose/JvmtiTest/libDispose.c | 33 - .../Dispose/JvmtiTest/libDispose.cpp | 33 + .../functions/ForceGarbageCollection/gc/gc.c | 212 - .../ForceGarbageCollection/gc/gc.cpp | 212 + .../ForceGarbageCollection/gc/libgc.c | 33 - .../ForceGarbageCollection/gc/libgc.cpp | 33 + .../environment/JvmtiTest/JvmtiTest.c | 147 - .../environment/JvmtiTest/JvmtiTest.cpp | 147 + .../environment/JvmtiTest/libenvironment.c | 33 - .../environment/JvmtiTest/libenvironment.cpp | 33 + .../JvmtiTest/JvmtiTest.c | 206 - .../JvmtiTest/JvmtiTest.cpp | 206 + .../JvmtiTest/libnosuspendMonitorInfo.c | 33 - .../JvmtiTest/libnosuspendMonitorInfo.cpp | 33 + .../nosuspendStackTrace/JvmtiTest/JvmtiTest.c | 332 -- .../JvmtiTest/JvmtiTest.cpp | 329 ++ .../JvmtiTest/libnosuspendStackTrace.c | 33 - .../JvmtiTest/libnosuspendStackTrace.cpp | 33 + .../unit/functions/rawmonitor/librawmonitor.c | 33 - .../functions/rawmonitor/librawmonitor.cpp | 33 + .../unit/functions/rawmonitor/rawmonitor.c | 367 -- .../unit/functions/rawmonitor/rawmonitor.cpp | 367 ++ .../nsk/jvmti/unit/heapref/heapref.c | 492 --- .../nsk/jvmti/unit/heapref/heapref.cpp | 492 +++ .../nsk/jvmti/unit/heapref/libheapref.c | 33 - .../nsk/jvmti/unit/heapref/libheapref.cpp | 33 + .../nsk/jvmti/unit/refignore/librefignore.c | 33 - .../nsk/jvmti/unit/refignore/librefignore.cpp | 33 + .../nsk/jvmti/unit/refignore/refignore.c | 490 --- .../nsk/jvmti/unit/refignore/refignore.cpp | 490 +++ .../unit/setNullVMInit/JvmtiTest/JvmtiTest.c | 206 - .../setNullVMInit/JvmtiTest/JvmtiTest.cpp | 206 + .../JvmtiTest/libsetNullVMInit.c | 33 - .../JvmtiTest/libsetNullVMInit.cpp | 33 + .../jvmti/unit/timers/JvmtiTest/JvmtiTest.c | 382 -- .../jvmti/unit/timers/JvmtiTest/JvmtiTest.cpp | 385 ++ .../jvmti/unit/timers/JvmtiTest/libtimers.c | 33 - .../jvmti/unit/timers/JvmtiTest/libtimers.cpp | 33 + ...eController.c => StackTraceController.cpp} | 0 .../nsk/monitoring/share/ThreadController.c | 531 --- .../nsk/monitoring/share/ThreadController.cpp | 531 +++ .../share/libStackTraceController.c | 26 - .../share/libStackTraceController.cpp | 26 + .../monitoring/share/libThreadController.c | 26 - .../monitoring/share/libThreadController.cpp | 26 + .../nsk/monitoring/share/thread/Deadlock.c | 104 - .../nsk/monitoring/share/thread/Deadlock.cpp | 112 + .../monitoring/share/thread/LockingThreads.c | 82 - .../share/thread/LockingThreads.cpp | 90 + .../share/thread/RecursiveMonitoringThread.c | 177 - .../thread/RecursiveMonitoringThread.cpp | 182 + .../nsk/monitoring/share/thread/libDeadlock.c | 26 - .../monitoring/share/thread/libDeadlock.cpp | 26 + .../share/thread/libLockingThreads.c | 26 - .../share/thread/libLockingThreads.cpp | 26 + .../share/thread/libNativeBlockedThread.c | 37 - .../share/thread/libNativeBlockedThread.cpp | 45 + .../thread/libRecursiveMonitoringThread.c | 26 - .../thread/libRecursiveMonitoringThread.cpp | 26 + .../share/{JVMDITools.c => JVMDITools.cpp} | 0 .../jtreg/vmTestbase/nsk/share/JVMTIagent.c | 1276 ------ .../jtreg/vmTestbase/nsk/share/JVMTIagent.cpp | 1276 ++++++ .../jtreg/vmTestbase/nsk/share/aod/aod.c | 288 -- .../jtreg/vmTestbase/nsk/share/aod/aod.cpp | 288 ++ .../gc/lock/jni/BooleanArrayCriticalLocker.c | 80 - .../lock/jni/BooleanArrayCriticalLocker.cpp | 88 + .../gc/lock/jni/ByteArrayCriticalLocker.c | 79 - .../gc/lock/jni/ByteArrayCriticalLocker.cpp | 87 + .../gc/lock/jni/CharArrayCriticalLocker.c | 80 - .../gc/lock/jni/CharArrayCriticalLocker.cpp | 88 + .../gc/lock/jni/DoubleArrayCriticalLocker.c | 80 - .../gc/lock/jni/DoubleArrayCriticalLocker.cpp | 88 + .../gc/lock/jni/FloatArrayCriticalLocker.c | 80 - .../gc/lock/jni/FloatArrayCriticalLocker.cpp | 88 + .../gc/lock/jni/IntArrayCriticalLocker.c | 80 - .../gc/lock/jni/IntArrayCriticalLocker.cpp | 88 + .../gc/lock/jni/LongArrayCriticalLocker.c | 80 - .../gc/lock/jni/LongArrayCriticalLocker.cpp | 88 + .../gc/lock/jni/ShortArrayCriticalLocker.c | 80 - .../gc/lock/jni/ShortArrayCriticalLocker.cpp | 88 + .../share/gc/lock/jni/StringCriticalLocker.c | 80 - .../gc/lock/jni/StringCriticalLocker.cpp | 88 + .../lock/jni/libBooleanArrayCriticalLocker.c | 26 - .../jni/libBooleanArrayCriticalLocker.cpp | 26 + .../gc/lock/jni/libByteArrayCriticalLocker.c | 26 - .../lock/jni/libByteArrayCriticalLocker.cpp | 26 + .../gc/lock/jni/libCharArrayCriticalLocker.c | 26 - .../lock/jni/libCharArrayCriticalLocker.cpp | 26 + .../lock/jni/libDoubleArrayCriticalLocker.c | 26 - .../lock/jni/libDoubleArrayCriticalLocker.cpp | 26 + .../gc/lock/jni/libFloatArrayCriticalLocker.c | 26 - .../lock/jni/libFloatArrayCriticalLocker.cpp | 26 + .../gc/lock/jni/libIntArrayCriticalLocker.c | 26 - .../gc/lock/jni/libIntArrayCriticalLocker.cpp | 26 + .../gc/lock/jni/libLongArrayCriticalLocker.c | 26 - .../lock/jni/libLongArrayCriticalLocker.cpp | 26 + .../gc/lock/jni/libShortArrayCriticalLocker.c | 26 - .../lock/jni/libShortArrayCriticalLocker.cpp | 26 + .../gc/lock/jni/libStringCriticalLocker.c | 26 - .../gc/lock/jni/libStringCriticalLocker.cpp | 26 + .../share/gc/lock/jniref/JNIGlobalRefLocker.c | 70 - .../gc/lock/jniref/JNIGlobalRefLocker.cpp | 78 + .../share/gc/lock/jniref/JNILocalRefLocker.c | 70 - .../gc/lock/jniref/JNILocalRefLocker.cpp | 78 + .../nsk/share/gc/lock/jniref/JNIRefLocker.c | 74 - .../nsk/share/gc/lock/jniref/JNIRefLocker.cpp | 82 + .../gc/lock/jniref/JNIWeakGlobalRefLocker.c | 70 - .../gc/lock/jniref/JNIWeakGlobalRefLocker.cpp | 78 + .../gc/lock/jniref/libJNIGlobalRefLocker.c | 26 - .../gc/lock/jniref/libJNIGlobalRefLocker.cpp | 26 + .../gc/lock/jniref/libJNILocalRefLocker.c | 26 - .../gc/lock/jniref/libJNILocalRefLocker.cpp | 26 + .../share/gc/lock/jniref/libJNIRefLocker.c | 26 - .../share/gc/lock/jniref/libJNIRefLocker.cpp | 26 + .../lock/jniref/libJNIWeakGlobalRefLocker.c | 26 - .../lock/jniref/libJNIWeakGlobalRefLocker.cpp | 26 + .../share/gc/lock/jvmti/JVMTIAllocLocker.c | 64 - .../share/gc/lock/jvmti/JVMTIAllocLocker.cpp | 72 + .../share/gc/lock/jvmti/libJVMTIAllocLocker.c | 26 - .../gc/lock/jvmti/libJVMTIAllocLocker.cpp | 26 + .../nsk/share/gc/lock/malloc/MallocLocker.c | 47 - .../nsk/share/gc/lock/malloc/MallocLocker.cpp | 55 + .../share/gc/lock/malloc/libMallocLocker.c | 26 - .../share/gc/lock/malloc/libMallocLocker.cpp | 26 + ...terExecutor.c => MonitorEnterExecutor.cpp} | 0 .../nsk/share/jdi/libMonitorEnterExecutor.c | 25 - .../nsk/share/jdi/libMonitorEnterExecutor.cpp | 25 + .../{JNIreferences.c => JNIreferences.cpp} | 0 .../share/jni/{jni_tools.c => jni_tools.cpp} | 0 .../nsk/share/jni/libJNIreferences.c | 25 - .../nsk/share/jni/libJNIreferences.cpp | 25 + ...hread.c => libNativeMethodsTestThread.cpp} | 0 ...search_agent.c => bootclssearch_agent.cpp} | 0 .../libbootclssearch_agent.c | 33 - .../libbootclssearch_agent.cpp | 33 + .../libsystemclssearch_agent.c | 33 - .../libsystemclssearch_agent.cpp | 33 + ...arch_agent.c => systemclssearch_agent.cpp} | 0 .../vmTestbase/nsk/share/jvmti/Injector.c | 1207 ------ .../vmTestbase/nsk/share/jvmti/Injector.cpp | 1207 ++++++ .../jvmti/{JVMTITools.c => JVMTITools.cpp} | 0 .../{agent_common.c => agent_common.cpp} | 0 .../vmTestbase/nsk/share/jvmti/agent_tools.c | 815 ---- .../nsk/share/jvmti/agent_tools.cpp | 815 ++++ .../nsk/share/jvmti/aod/jvmti_aod.c | 352 -- .../nsk/share/jvmti/aod/jvmti_aod.cpp | 352 ++ .../nsk/share/jvmti/aod/jvmti_aod.h | 2 +- .../nsk/share/jvmti/hotswap/HotSwap.c | 505 --- .../nsk/share/jvmti/hotswap/HotSwap.cpp | 505 +++ .../nsk/share/jvmti/hotswap/libHotSwap.c | 33 - .../nsk/share/jvmti/hotswap/libHotSwap.cpp | 33 + .../nsk/share/jvmti/jvmti_FollowRefObjects.c | 397 -- .../share/jvmti/jvmti_FollowRefObjects.cpp | 397 ++ .../vmTestbase/nsk/share/jvmti/jvmti_tools.c | 692 ---- .../nsk/share/jvmti/jvmti_tools.cpp | 692 ++++ .../vmTestbase/nsk/share/jvmti/unit/Heap.c | 467 --- .../vmTestbase/nsk/share/jvmti/unit/Heap.cpp | 475 +++ .../vmTestbase/nsk/share/jvmti/unit/libHeap.c | 33 - .../nsk/share/jvmti/unit/libHeap.cpp | 33 + .../nsk/share/locks/JNIMonitorLocker.c | 127 - .../nsk/share/locks/JNIMonitorLocker.cpp | 127 + .../{LockingThread.c => LockingThread.cpp} | 0 .../nsk/share/locks/libJNIMonitorLocker.c | 25 - .../nsk/share/locks/libJNIMonitorLocker.cpp | 25 + .../nsk/share/locks/libLockingThread.c | 25 - .../nsk/share/locks/libLockingThread.cpp | 25 + .../{native_thread.c => native_thread.cpp} | 0 .../{native_utils.c => native_utils.cpp} | 0 .../vmTestbase/nsk/share/native/nsk_list.c | 135 - .../vmTestbase/nsk/share/native/nsk_list.cpp | 143 + .../vmTestbase/nsk/share/native/nsk_list.h | 8 + .../vmTestbase/nsk/share/native/nsk_mutex.c | 89 - .../vmTestbase/nsk/share/native/nsk_mutex.cpp | 97 + .../native/{nsk_tools.c => nsk_tools.cpp} | 0 .../nsk/stress/jni/gclocker/libgcl001.c | 200 - .../nsk/stress/jni/gclocker/libgcl001.cpp | 208 + .../vmTestbase/nsk/stress/jni/jnihelper.h | 10 +- .../nsk/stress/jni/libjnistress001.c | 239 -- .../nsk/stress/jni/libjnistress001.cpp | 247 ++ .../nsk/stress/jni/libjnistress002.c | 102 - .../nsk/stress/jni/libjnistress002.cpp | 110 + .../nsk/stress/jni/libjnistress003.c | 260 -- .../nsk/stress/jni/libjnistress003.cpp | 268 ++ .../nsk/stress/jni/libjnistress004.c | 168 - .../nsk/stress/jni/libjnistress004.cpp | 176 + .../nsk/stress/jni/libjnistress005.c | 111 - .../nsk/stress/jni/libjnistress005.cpp | 119 + .../nsk/stress/jni/libjnistress006.c | 83 - .../nsk/stress/jni/libjnistress006.cpp | 91 + .../nsk/stress/jni/libjnistress007.c | 44 - .../nsk/stress/jni/libjnistress007.cpp | 52 + .../nsk/stress/strace/libstrace003.c | 26 - .../nsk/stress/strace/libstrace003.cpp | 26 + .../nsk/stress/strace/libstrace004.c | 26 - .../nsk/stress/strace/libstrace004.cpp | 26 + .../nsk/stress/strace/libstrace005.c | 26 - .../nsk/stress/strace/libstrace005.cpp | 26 + .../nsk/stress/strace/libstrace006.c | 26 - .../nsk/stress/strace/libstrace006.cpp | 26 + .../nsk/stress/strace/libstrace008.c | 26 - .../nsk/stress/strace/libstrace008.cpp | 26 + .../nsk/stress/strace/libstrace009.c | 26 - .../nsk/stress/strace/libstrace009.cpp | 26 + .../nsk/stress/strace/libstrace011.c | 26 - .../nsk/stress/strace/libstrace011.cpp | 26 + .../nsk/stress/strace/libstrace012.c | 26 - .../nsk/stress/strace/libstrace012.cpp | 26 + .../nsk/stress/strace/libstrace014.c | 26 - .../nsk/stress/strace/libstrace014.cpp | 26 + .../nsk/stress/strace/libstrace015.c | 26 - .../nsk/stress/strace/libstrace015.cpp | 26 + .../vmTestbase/nsk/stress/strace/nsk_strace.h | 4 +- .../strace/{strace003.c => strace003.cpp} | 0 .../strace/{strace004.c => strace004.cpp} | 0 .../vmTestbase/nsk/stress/strace/strace005.c | 107 - .../nsk/stress/strace/strace005.cpp | 107 + .../vmTestbase/nsk/stress/strace/strace006.c | 108 - .../nsk/stress/strace/strace006.cpp | 108 + .../strace/{strace008.c => strace008.cpp} | 0 .../strace/{strace009.c => strace009.cpp} | 0 .../strace/{strace011.c => strace011.cpp} | 0 .../strace/{strace012.c => strace012.cpp} | 0 .../strace/{strace014.c => strace014.cpp} | 0 .../strace/{strace015.c => strace015.cpp} | 0 .../vm/jit/LongTransitions/libLTTest.c | 3460 ---------------- .../vm/jit/LongTransitions/libLTTest.cpp | 3469 +++++++++++++++++ .../indy/func/jvmti/share/IndyRedefineClass.c | 218 -- .../func/jvmti/share/IndyRedefineClass.cpp | 226 ++ .../func/jvmti/share/libIndyRedefineClass.c | 32 - .../func/jvmti/share/libIndyRedefineClass.cpp | 32 + .../libstepBreakPopReturn.c | 32 - .../libstepBreakPopReturn.cpp | 32 + .../stepBreakPopReturn/stepBreakPopReturn.c | 203 - .../stepBreakPopReturn/stepBreakPopReturn.cpp | 210 + .../stress/jni/nativeAndMH/libnativeAndMH.c | 26 - .../stress/jni/nativeAndMH/libnativeAndMH.cpp | 26 + .../meth/stress/jni/nativeAndMH/nativeAndMH.c | 72 - .../stress/jni/nativeAndMH/nativeAndMH.cpp | 79 + .../vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.c | 124 - .../vm/mlvm/share/mlvmJvmtiUtils.cpp | 134 + .../vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.h | 7 + .../defmeth/shared/libredefineClasses.c | 31 - .../defmeth/shared/libredefineClasses.cpp | 31 + ...{redefineClasses.c => redefineClasses.cpp} | 0 .../jtreg/vmTestbase/vm/share/ProcessUtils.c | 258 -- .../vmTestbase/vm/share/ProcessUtils.cpp | 266 ++ .../vmTestbase/vm/share/libProcessUtils.c | 27 - .../vmTestbase/vm/share/libProcessUtils.cpp | 27 + 2523 files changed, 140737 insertions(+), 140214 deletions(-) delete mode 100644 test/hotspot/jtreg/vmTestbase/gc/g1/unloading/libdefine.c create mode 100644 test/hotspot/jtreg/vmTestbase/gc/g1/unloading/libdefine.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/libmallocWithGC1.c create mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/libmallocWithGC1.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/libmallocWithGC2.c create mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/libmallocWithGC2.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/libmallocWithGC3.c create mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/libmallocWithGC3.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/libnativeGC01.c create mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/libnativeGC01.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/libnativeGC02.c create mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/libnativeGC02.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/libnativeGC03.c create mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/libnativeGC03.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/libnativeGC05.c create mode 100644 test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/libnativeGC05.cpp rename test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/{agent00.c => agent00.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/{agent01.c => agent01.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/{agent02.c => agent02.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/{agent03.c => agent03.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent00.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent01.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent01.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent02.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent02.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent03.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent03.cpp rename test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/{agent00.c => agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/libVirtualMachine09agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/libVirtualMachine09agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn004/{libforceEarlyReturn004a.c => libforceEarlyReturn004a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn005/libforceEarlyReturn005a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn005/libforceEarlyReturn005a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/{libforceEarlyReturn002a.c => libforceEarlyReturn002a.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/{addcaps001.c => addcaps001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/libaddcaps001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/libaddcaps001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/{addcaps002.c => addcaps002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/libaddcaps002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/libaddcaps002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/{addcaps003.c => addcaps003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/libaddcaps003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/libaddcaps003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/{agentonload001.c => agentonload001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/libagentonload001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/libagentonload001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/{agentonload002.c => agentonload002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/libagentonload002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/libagentonload002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/{agentonload003.c => agentonload003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/libagentonload003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/libagentonload003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/{agentonunload001.c => agentonunload001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/libagentonunload001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/libagentonunload001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/alloc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/alloc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/liballoc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/liballoc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/attach002Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/attach002Agent00.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/libattach002Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/libattach002Agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/{attach002aAgent00.c => attach002aAgent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/libattach002aAgent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/libattach002aAgent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/{attach008Agent00.c => attach008Agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/libattach008Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/libattach008Agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/{attach009Agent00.c => attach009Agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/libattach009Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/libattach009Agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/{attach012Agent00.c => attach012Agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/libattach012Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/libattach012Agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/{attach014Agent00.c => attach014Agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/libattach014Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/libattach014Agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/{attach015Agent00.c => attach015Agent00.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/{attach015Agent01.c => attach015Agent01.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/{attach015Target.c => attach015Target.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent00.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent01.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent01.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Target.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Target.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/{attach020Agent00.c => attach020Agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/libattach020Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/libattach020Agent00.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/attach021Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/attach021Agent00.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/libattach021Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/libattach021Agent00.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/attach022Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/attach022Agent00.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/libattach022Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/libattach022Agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/{attach037Agent00.c => attach037Agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/libattach037Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/libattach037Agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/{attach038Agent00.c => attach038Agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/libattach038Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/libattach038Agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/{attach039Agent00.c => attach039Agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/libattach039Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/libattach039Agent00.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/attach040Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/attach040Agent00.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/libattach040Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/libattach040Agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/{attach041Agent00.c => attach041Agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/libattach041Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/libattach041Agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/{attach042Agent00.c => attach042Agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/libattach042Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/libattach042Agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/{attach045Agent00.c => attach045Agent00.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/{attach045Agent01.c => attach045Agent01.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent02.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent02.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/{attach045Agent03.c => attach045Agent03.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent00.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent01.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent01.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent02.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent02.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent03.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent03.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/{attach046Agent00.c => attach046Agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/libattach046Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/libattach046Agent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/{attach050Agent00.c => attach050Agent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/libattach050Agent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/libattach050Agent00.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/libsimpleAgent00.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/libsimpleAgent00.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/{simpleAgent00.c => simpleAgent00.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/breakpoint001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/breakpoint001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/libbreakpoint001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/libbreakpoint001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/{classfloadhk001.c => classfloadhk001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/libclassfloadhk001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/libclassfloadhk001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/classfloadhk002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/classfloadhk002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/libclassfloadhk002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/libclassfloadhk002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/classfloadhk003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/classfloadhk003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/libclassfloadhk003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/libclassfloadhk003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/classfloadhk004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/classfloadhk004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/libclassfloadhk004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/libclassfloadhk004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/classfloadhk005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/classfloadhk005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/libclassfloadhk005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/libclassfloadhk005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/classfloadhk006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/classfloadhk006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/libclassfloadhk006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/libclassfloadhk006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/classfloadhk007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/classfloadhk007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/libclassfloadhk007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/libclassfloadhk007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/classfloadhk008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/classfloadhk008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/libclassfloadhk008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/libclassfloadhk008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/classfloadhk009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/classfloadhk009.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/libclassfloadhk009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/libclassfloadhk009.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/{classload001.c => classload001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/libclassload001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/libclassload001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/classprep001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/classprep001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/libclassprep001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/libclassprep001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/clrbrk001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/clrbrk001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/libclrbrk001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/libclrbrk001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/clrbrk002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/clrbrk002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/libclrbrk002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/libclrbrk002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/clrbrk005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/clrbrk005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/libclrbrk005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/libclrbrk005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/clrfldw001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/clrfldw001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/libclrfldw001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/libclrfldw001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/clrfldw002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/clrfldw002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/libclrfldw002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/libclrfldw002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/clrfmodw001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/clrfmodw001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/libclrfmodw001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/libclrfmodw001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/clrfmodw002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/clrfmodw002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/libclrfmodw002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/libclrfmodw002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/{compmethload001.c => compmethload001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/libcompmethload001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/libcompmethload001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/compmethunload001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/compmethunload001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/libcompmethunload001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/libcompmethunload001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/crrawmon001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/crrawmon001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/libcrrawmon001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/libcrrawmon001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/crrawmon002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/crrawmon002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/libcrrawmon002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/libcrrawmon002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/{datadumpreq001.c => datadumpreq001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/libdatadumpreq001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/libdatadumpreq001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/dealloc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/dealloc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/libdealloc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/libdealloc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/drrawmon001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/drrawmon001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/libdrrawmon001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/libdrrawmon001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/drrawmon003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/drrawmon003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/libdrrawmon003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/libdrrawmon003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/drrawmon004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/drrawmon004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/libdrrawmon004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/libdrrawmon004.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/{disposeenv001.c => disposeenv001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/libdisposeenv001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/libdisposeenv001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/{disposeenv002.c => disposeenv002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/libdisposeenv002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/libdisposeenv002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/{dyncodgen001.c => dyncodgen001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/libdyncodgen001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/libdyncodgen001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/exception001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/exception001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/libexception001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/libexception001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/excatch001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/excatch001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/libexcatch001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/libexcatch001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/fieldacc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/fieldacc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/libfieldacc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/libfieldacc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/fieldacc002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/fieldacc002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/libfieldacc002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/libfieldacc002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/fieldacc003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/fieldacc003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/libfieldacc003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/libfieldacc003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/fieldacc004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/fieldacc004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/libfieldacc004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/libfieldacc004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/fieldmod001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/fieldmod001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/libfieldmod001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/libfieldmod001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/fieldmod002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/fieldmod002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/libfieldmod002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/libfieldmod002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/{ForceEarlyReturn001.c => ForceEarlyReturn001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/libForceEarlyReturn001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/libForceEarlyReturn001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/{forcegc001.c => forcegc001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/libforcegc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/libforcegc001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/{forcegc002.c => forcegc002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/libforcegc002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/libforcegc002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/framepop001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/framepop001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/libframepop001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/libframepop001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/framepop002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/framepop002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/libframepop002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/libframepop002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/{gcfinish001.c => gcfinish001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/libgcfinish001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/libgcfinish001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/{gcstart001.c => gcstart001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/libgcstart001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/libgcstart001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/{gcstart002.c => gcstart002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/libgcstart002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/libgcstart002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/{genevents001.c => genevents001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/libgenevents001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/libgenevents001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/allthr001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/allthr001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/liballthr001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/liballthr001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/allthr002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/allthr002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/liballthr002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/liballthr002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/argsize001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/argsize001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/libargsize001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/libargsize001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/argsize002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/argsize002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/libargsize002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/libargsize002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/{getavailproc001.c => getavailproc001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/libgetavailproc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/libgetavailproc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/bytecodes001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/bytecodes001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/libbytecodes001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/libbytecodes001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/bytecodes002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/bytecodes002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/libbytecodes002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/libbytecodes002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/bytecodes003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/bytecodes003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/libbytecodes003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/libbytecodes003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/getcaps001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/getcaps001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/libgetcaps001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/libgetcaps001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/{getcaps002.c => getcaps002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/libgetcaps002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/libgetcaps002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/getclfld005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/getclfld005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/libgetclfld005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/libgetclfld005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/getclfld006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/getclfld006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/libgetclfld006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/libgetclfld006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/getclfld007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/getclfld007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/libgetclfld007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/libgetclfld007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/getclsldr001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/getclsldr001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/libgetclsldr001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/libgetclsldr001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/getclsldr002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/getclsldr002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/libgetclsldr002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/libgetclsldr002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/getclsldr003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/getclsldr003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/libgetclsldr003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/libgetclsldr003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/clsldrclss001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/clsldrclss001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/libclsldrclss001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/libclsldrclss001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/clsldrclss002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/clsldrclss002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/libclsldrclss002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/libclsldrclss002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/getclmthd005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/getclmthd005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/libgetclmthd005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/libgetclmthd005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/getclmthd006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/getclmthd006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/libgetclmthd006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/libgetclmthd006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/getclmthd007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/getclmthd007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/libgetclmthd007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/libgetclmthd007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/getclmdf004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/getclmdf004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/libgetclmdf004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/libgetclmdf004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/getclmdf005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/getclmdf005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/libgetclmdf005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/libgetclmdf005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/getclmdf006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/getclmdf006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/libgetclmdf006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/libgetclmdf006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/getclmdf007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/getclmdf007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/libgetclmdf007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/libgetclmdf007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/getclsig004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/getclsig004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/libgetclsig004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/libgetclsig004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/getclsig005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/getclsig005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/libgetclsig005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/libgetclsig005.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/{getclsig006.c => getclsig006.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/libgetclsig006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/libgetclsig006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/getclstat005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/getclstat005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/libgetclstat005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/libgetclstat005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/getclstat006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/getclstat006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/libgetclstat006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/libgetclstat006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/getclstat007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/getclstat007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/libgetclstat007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/libgetclstat007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/contmon001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/contmon001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/libcontmon001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/libcontmon001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/contmon002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/contmon002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/libcontmon002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/libcontmon002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/contmon003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/contmon003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/libcontmon003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/libcontmon003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/{curthrcputime001.c => curthrcputime001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/libcurthrcputime001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/libcurthrcputime001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/{curthrtimerinfo001.c => curthrtimerinfo001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/libcurthrtimerinfo001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/libcurthrtimerinfo001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/GetEnv001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/GetEnv001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/libGetEnv001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/libGetEnv001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/{getenvstor001.c => getenvstor001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/libgetenvstor001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/libgetenvstor001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/{geterrname001.c => geterrname001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/libgeterrname001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/libgeterrname001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/{geterrname002.c => geterrname002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/libgeterrname002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/libgeterrname002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/{extevents001.c => extevents001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/libextevents001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/libextevents001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/{extfuncs001.c => extfuncs001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/libextfuncs001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/libextfuncs001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/getfldecl001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/getfldecl001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/libgetfldecl001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/libgetfldecl001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/getfldecl002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/getfldecl002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/libgetfldecl002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/libgetfldecl002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/getfldecl004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/getfldecl004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/libgetfldecl004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/libgetfldecl004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/getfldmdf003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/getfldmdf003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/libgetfldmdf003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/libgetfldmdf003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/getfldmdf004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/getfldmdf004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/libgetfldmdf004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/libgetfldmdf004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/getfldnm003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/getfldnm003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/libgetfldnm003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/libgetfldnm003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/getfldnm004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/getfldnm004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/libgetfldnm004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/libgetfldnm004.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/{getfldnm005.c => getfldnm005.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/libgetfldnm005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/libgetfldnm005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/framecnt001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/framecnt001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/libframecnt001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/libframecnt001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/framecnt002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/framecnt002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/libframecnt002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/libframecnt002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/framecnt003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/framecnt003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/libframecnt003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/libframecnt003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/frameloc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/frameloc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/libframeloc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/libframeloc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/frameloc002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/frameloc002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/libframeloc002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/libframeloc002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/frameloc003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/frameloc003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/libframeloc003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/libframeloc003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/getintrf005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/getintrf005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/libgetintrf005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/libgetintrf005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/getintrf006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/getintrf006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/libgetintrf006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/libgetintrf006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/getintrf007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/getintrf007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/libgetintrf007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/libgetintrf007.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/{getjlocfmt001.c => getjlocfmt001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/libgetjlocfmt001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/libgetjlocfmt001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/{getjlocfmt002.c => getjlocfmt002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/libgetjlocfmt002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/libgetjlocfmt002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/getjniftab001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/getjniftab001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/libgetjniftab001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/libgetjniftab001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/getjniftab002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/getjniftab002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/libgetjniftab002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/libgetjniftab002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/liblinetab001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/liblinetab001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/linetab001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/linetab001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/liblinetab002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/liblinetab002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/linetab002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/linetab002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/liblinetab003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/liblinetab003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/linetab003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/linetab003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/libloadedclss001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/libloadedclss001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/loadedclss001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/loadedclss001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/libloadedclss002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/libloadedclss002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/{loadedclss002.c => loadedclss002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/getlocal001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/getlocal001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/libgetlocal001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/libgetlocal001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/getlocal002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/getlocal002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/libgetlocal002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/libgetlocal002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/liblocaltab001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/liblocaltab001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/localtab001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/localtab001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/liblocaltab002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/liblocaltab002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/localtab002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/localtab002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/liblocaltab003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/liblocaltab003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/localtab003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/localtab003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/liblocaltab004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/liblocaltab004.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/{localtab004.c => localtab004.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/liblocaltab005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/liblocaltab005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/localtab005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/localtab005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc001/libmaxloc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc001/libmaxloc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc001/maxloc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc001/maxloc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/libmaxloc002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/libmaxloc002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/maxloc002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/maxloc002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/declcls001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/declcls001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/libdeclcls001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/libdeclcls001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/declcls002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/declcls002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/libdeclcls002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/libdeclcls002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/declcls003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/declcls003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/libdeclcls003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/libdeclcls003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/libmethloc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/libmethloc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/methloc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/methloc001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/libmethloc002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/libmethloc002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/methloc002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/methloc002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/libmethmod001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/libmethmod001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/methmod001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/methmod001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/libmethmod002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/libmethmod002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/methmod002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/methmod002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/libmethname001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/libmethname001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/methname001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/methname001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/libmethname002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/libmethname002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/methname002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/methname002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/libmethname003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/libmethname003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/{methname003.c => methname003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/libobjhashcode001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/libobjhashcode001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/objhashcode001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/objhashcode001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/libobjmonusage001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/libobjmonusage001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/objmonusage001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/objmonusage001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/libobjmonusage002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/libobjmonusage002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/objmonusage002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/objmonusage002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/libobjmonusage003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/libobjmonusage003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/objmonusage003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/objmonusage003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/libobjmonusage004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/libobjmonusage004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/objmonusage004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/objmonusage004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/libobjmonusage005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/libobjmonusage005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/objmonusage005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/objmonusage005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/libobjmonusage006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/libobjmonusage006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/objmonusage006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/objmonusage006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/libobjsize001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/libobjsize001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/objsize001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/objsize001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/libobjwithtags001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/libobjwithtags001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/objwithtags001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/objwithtags001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/libownmoninf001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/libownmoninf001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/ownmoninf001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/ownmoninf001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/libownmoninf002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/libownmoninf002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/ownmoninf002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/ownmoninf002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/libownmoninf003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/libownmoninf003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/ownmoninf003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/ownmoninf003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/{getphase001.c => getphase001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/libgetphase001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/libgetphase001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/{getphase002.c => getphase002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/libgetphase002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/libgetphase002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/{getpotcaps001.c => getpotcaps001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/libgetpotcaps001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/libgetpotcaps001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/libsrcdebugex001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/libsrcdebugex001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/srcdebugex001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/srcdebugex001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/libsrcdebugex002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/libsrcdebugex002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/srcdebugex002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/srcdebugex002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/libsrcdebugex003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/libsrcdebugex003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/srcdebugex003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/srcdebugex003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/getsrcfn004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/getsrcfn004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/libgetsrcfn004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/libgetsrcfn004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/getsrcfn005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/getsrcfn005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/libgetsrcfn005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/libgetsrcfn005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/getsrcfn006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/getsrcfn006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/libgetsrcfn006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/libgetsrcfn006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/getstacktr001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/getstacktr001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/libgetstacktr001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/libgetstacktr001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/getstacktr002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/getstacktr002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/libgetstacktr002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/libgetstacktr002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/getstacktr003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/getstacktr003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/libgetstacktr003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/libgetstacktr003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/getstacktr004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/getstacktr004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/libgetstacktr004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/libgetstacktr004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/getstacktr005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/getstacktr005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/libgetstacktr005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/libgetstacktr005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/getstacktr006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/getstacktr006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/libgetstacktr006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/libgetstacktr006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/getstacktr007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/getstacktr007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/libgetstacktr007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/libgetstacktr007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/getstacktr008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/getstacktr008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/libgetstacktr008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/libgetstacktr008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/getstacktr009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/getstacktr009.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/libgetstacktr009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/libgetstacktr009.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/{getsysprops001.c => getsysprops001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/libgetsysprops001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/libgetsysprops001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/{getsysprops002.c => getsysprops002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/libgetsysprops002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/libgetsysprops002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/{getsysprop001.c => getsysprop001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/libgetsysprop001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/libgetsysprop001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/{getsysprop002.c => getsysprop002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/libgetsysprop002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/libgetsysprop002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/gettag001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/gettag001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/libgettag001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/libgettag001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/libthrcputime001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/libthrcputime001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/{thrcputime001.c => thrcputime001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/libthrcputime002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/libthrcputime002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/{thrcputime002.c => thrcputime002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/libthrtimerinfo001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/libthrtimerinfo001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/{thrtimerinfo001.c => thrtimerinfo001.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/{getthrdgrpchld001.c => getthrdgrpchld001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/libgetthrdgrpchld001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/libgetthrdgrpchld001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/libthrgrpinfo001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/libthrgrpinfo001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/thrgrpinfo001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/thrgrpinfo001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/libthrgrpinfo002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/libthrgrpinfo002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/thrgrpinfo002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/thrgrpinfo002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/libthrinfo001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/libthrinfo001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/thrinfo001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/thrinfo001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/libthrinfo002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/libthrinfo002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/thrinfo002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/thrinfo002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/{getthrdstor001.c => getthrdstor001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/libgetthrdstor001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/libgetthrdstor001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/libthrstat001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/libthrstat001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/thrstat001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/thrstat001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/libthrstat002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/libthrstat002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/thrstat002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/thrstat002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/libthrstat003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/libthrstat003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/thrstat003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/thrstat003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/libthrstat004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/libthrstat004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/thrstat004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/thrstat004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/libthrstat005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/libthrstat005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/thrstat005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/thrstat005.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/{gettime001.c => gettime001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/libgettime001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/libgettime001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/libtimerinfo001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/libtimerinfo001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/{timerinfo001.c => timerinfo001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/libtopthrgrp001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/libtopthrgrp001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/topthrgrp001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/topthrgrp001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/libtopthrgrp002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/libtopthrgrp002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/topthrgrp002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/topthrgrp002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/getvern001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/getvern001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/libgetvern001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/libgetvern001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/{intrpthrd001.c => intrpthrd001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/libintrpthrd001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/libintrpthrd001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/intrpthrd002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/intrpthrd002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/libintrpthrd002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/libintrpthrd002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/intrpthrd003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/intrpthrd003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/libintrpthrd003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/libintrpthrd003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/isarray004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/isarray004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/libisarray004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/libisarray004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/isarray005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/isarray005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/libisarray005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/libisarray005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/isfldsin002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/isfldsin002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/libisfldsin002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/libisfldsin002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/isfldsin003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/isfldsin003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/libisfldsin003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/libisfldsin003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/isintrf004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/isintrf004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/libisintrf004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/libisintrf004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/isintrf005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/isintrf005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/libisintrf005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/libisintrf005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/isnative001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/isnative001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/libisnative001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/libisnative001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/isnative002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/isnative002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/libisnative002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/libisnative002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/isobsolete001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/isobsolete001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/libisobsolete001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/libisobsolete001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/issynth001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/issynth001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/libIsMethodSyntheticIssynth001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/libIsMethodSyntheticIssynth001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/issynth002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/issynth002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/libissynth002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/libissynth002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/iterheap001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/iterheap001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/libiterheap001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/libiterheap001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/iterheap002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/iterheap002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/libiterheap002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/libiterheap002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/iterheap003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/iterheap003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/libiterheap003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/libiterheap003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/{iterheap004.c => iterheap004.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/libiterheap004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/libiterheap004.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/{iterheap005.c => iterheap005.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/libiterheap005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/libiterheap005.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/{iterheap006.c => iterheap006.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/libiterheap006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/libiterheap006.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/{iterheap007.c => iterheap007.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/libiterheap007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/libiterheap007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/iterinstcls001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/iterinstcls001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/libiterinstcls001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/libiterinstcls001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/iterinstcls002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/iterinstcls002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/libiterinstcls002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/libiterinstcls002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/iterinstcls003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/iterinstcls003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/libiterinstcls003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/libiterinstcls003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/{iterinstcls004.c => iterinstcls004.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/libiterinstcls004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/libiterinstcls004.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/{iterinstcls005.c => iterinstcls005.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/libiterinstcls005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/libiterinstcls005.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/{iterinstcls006.c => iterinstcls006.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/libiterinstcls006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/libiterinstcls006.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/{iterinstcls007.c => iterinstcls007.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/libiterinstcls007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/libiterinstcls007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/iterobjreachobj001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/iterobjreachobj001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/libiterobjreachobj001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/libiterobjreachobj001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/{iterobjreachobj002.c => iterobjreachobj002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/libiterobjreachobj002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/libiterobjreachobj002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/{iterobjreachobj003.c => iterobjreachobj003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/libiterobjreachobj003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/libiterobjreachobj003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/{iterobjreachobj004.c => iterobjreachobj004.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/libiterobjreachobj004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/libiterobjreachobj004.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/{iterobjreachobj005.c => iterobjreachobj005.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/libiterobjreachobj005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/libiterobjreachobj005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/iterreachobj001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/iterreachobj001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/libiterreachobj001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/libiterreachobj001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/{iterreachobj002.c => iterreachobj002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/libiterreachobj002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/libiterreachobj002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/{iterreachobj003.c => iterreachobj003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/libiterreachobj003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/libiterreachobj003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/{iterreachobj004.c => iterreachobj004.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/libiterreachobj004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/libiterreachobj004.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/{iterreachobj005.c => iterreachobj005.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/libiterreachobj005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/libiterreachobj005.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/{Abort.c => Abort.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/libAbort.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/libAbort.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/callbacks/Callbacks.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/callbacks/Callbacks.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/callbacks/libCallbacks.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/callbacks/libCallbacks.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/concrete-klass-filter/{ConcreteKlassFilter.c => ConcreteKlassFilter.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/concrete-klass-filter/libConcreteKlassFilter.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/concrete-klass-filter/libConcreteKlassFilter.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/filter-tagged/HeapFilter.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/filter-tagged/HeapFilter.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/filter-tagged/libHeapFilter.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/filter-tagged/libHeapFilter.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/non-concrete-klass-filter/{NonConcreteKlassFilter.c => NonConcreteKlassFilter.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/non-concrete-klass-filter/libNonConcreteKlassFilter.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/non-concrete-klass-filter/libNonConcreteKlassFilter.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry001/libmentry001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry001/libmentry001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry001/mentry001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry001/mentry001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/libmentry002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/libmentry002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/mentry002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/mentry002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/libmexit001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/libmexit001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/mexit001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/mexit001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/libmexit002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/libmexit002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/mexit002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/mexit002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/libmcontenter001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/libmcontenter001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/{mcontenter001.c => mcontenter001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/libmcontentered001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/libmcontentered001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/{mcontentered001.c => mcontentered001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/libmonitorwait001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/libmonitorwait001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/{monitorwait001.c => monitorwait001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/libmonitorwaited001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/libmonitorwaited001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/{monitorwaited001.c => monitorwaited001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/libnativemethbind001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/libnativemethbind001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/{nativemethbind001.c => nativemethbind001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/libnativemethbind002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/libnativemethbind002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/{nativemethbind002.c => nativemethbind002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/libnativemethbind003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/libnativemethbind003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/{nativemethbind003.c => nativemethbind003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/libnativemethbind004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/libnativemethbind004.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/{nativemethbind004.c => nativemethbind004.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/libnframepop001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/libnframepop001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/nframepop001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/nframepop001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/libnframepop002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/libnframepop002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/nframepop002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/nframepop002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/libnframepop003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/libnframepop003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/nframepop003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/nframepop003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/libobjfree001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/libobjfree001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/{objfree001.c => objfree001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/libobjfree002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/libobjfree002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/{objfree002.c => objfree002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/libpopframe001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/libpopframe001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/popframe001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/popframe001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/libpopframe002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/libpopframe002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/popframe002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/popframe002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/libpopframe003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/libpopframe003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/popframe003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/popframe003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/libpopframe004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/libpopframe004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/popframe004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/popframe004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/libpopframe005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/libpopframe005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/popframe005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/popframe005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/libpopframe006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/libpopframe006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/popframe006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/popframe006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/libpopframe007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/libpopframe007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/popframe007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/popframe007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/libpopframe008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/libpopframe008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/popframe008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/popframe008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/libpopframe009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/libpopframe009.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/popframe009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/popframe009.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/libpopframe010.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/libpopframe010.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/popframe010.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/popframe010.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/libpopframe011.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/libpopframe011.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/popframe011.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/popframe011.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/librawmonenter001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/librawmonenter001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/rawmonenter001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/rawmonenter001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/librawmonenter002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/librawmonenter002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/rawmonenter002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/rawmonenter002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/librawmonenter003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/librawmonenter003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/rawmonenter003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/rawmonenter003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/librawmonenter004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/librawmonenter004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/rawmonenter004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/rawmonenter004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/librawmonexit001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/librawmonexit001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/rawmonexit001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/rawmonexit001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/librawmonexit002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/librawmonexit002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/rawmonexit002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/rawmonexit002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/librawmonexit003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/librawmonexit003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/rawmonexit003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/rawmonexit003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/librawmonexit005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/librawmonexit005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/rawmonexit005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/rawmonexit005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/librawmnntfy001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/librawmnntfy001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/rawmnntfy001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/rawmnntfy001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/librawmnntfy002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/librawmnntfy002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/rawmnntfy002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/rawmnntfy002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/librawmnntfy003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/librawmnntfy003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/rawmnntfy003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/rawmnntfy003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/librawmnntfy004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/librawmnntfy004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/rawmnntfy004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/rawmnntfy004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/librawmnntfyall001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/librawmnntfyall001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/rawmnntfyall001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/rawmnntfyall001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/librawmnntfyall002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/librawmnntfyall002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/rawmnntfyall002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/rawmnntfyall002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/librawmnntfyall003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/librawmnntfyall003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/rawmnntfyall003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/rawmnntfyall003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/librawmnntfyall004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/librawmnntfyall004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/rawmnntfyall004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/rawmnntfyall004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/librawmnwait001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/librawmnwait001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/rawmnwait001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/rawmnwait001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/librawmnwait002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/librawmnwait002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/rawmnwait002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/rawmnwait002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/librawmnwait003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/librawmnwait003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/rawmnwait003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/rawmnwait003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/librawmnwait004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/librawmnwait004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/rawmnwait004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/rawmnwait004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/librawmnwait005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/librawmnwait005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/rawmnwait005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/rawmnwait005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/libstressRedefine.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/libstressRedefine.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/stressRedefine.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/stressRedefine.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/libredefclass001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/libredefclass001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/redefclass001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/redefclass001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/libredefclass002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/libredefclass002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/redefclass002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/redefclass002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/libredefclass003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/libredefclass003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/redefclass003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/redefclass003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/libredefclass004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/libredefclass004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/redefclass004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/redefclass004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/libredefclass005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/libredefclass005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/redefclass005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/redefclass005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/libredefclass006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/libredefclass006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/redefclass006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/redefclass006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/libredefclass008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/libredefclass008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/redefclass008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/redefclass008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/libredefclass009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/libredefclass009.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/redefclass009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/redefclass009.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/libredefclass010.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/libredefclass010.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/redefclass010.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/redefclass010.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/libredefclass011.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/libredefclass011.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/redefclass011.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/redefclass011.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/libredefclass012.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/libredefclass012.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/redefclass012.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/redefclass012.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/libredefclass013.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/libredefclass013.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/redefclass013.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/redefclass013.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/libredefclass014.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/libredefclass014.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/redefclass014.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/redefclass014.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/libredefclass015.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/libredefclass015.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/redefclass015.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/redefclass015.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/libredefclass016.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/libredefclass016.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/redefclass016.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/redefclass016.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/libredefclass017.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/libredefclass017.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/redefclass017.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/redefclass017.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/libredefclass018.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/libredefclass018.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/redefclass018.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/redefclass018.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/libredefclass019.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/libredefclass019.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/redefclass019.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/redefclass019.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/libredefclass020.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/libredefclass020.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/redefclass020.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/redefclass020.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/libredefclass021.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/libredefclass021.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/redefclass021.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/redefclass021.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/libredefclass022.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/libredefclass022.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/redefclass022.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/redefclass022.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/libredefclass023.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/libredefclass023.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/redefclass023.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/redefclass023.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/libredefclass024.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/libredefclass024.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/redefclass024.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/redefclass024.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/libredefclass025.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/libredefclass025.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/redefclass025.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/redefclass025.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/libredefclass026.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/libredefclass026.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/redefclass026.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/redefclass026.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/libredefclass027.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/libredefclass027.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/redefclass027.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/redefclass027.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/libredefclass028.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/libredefclass028.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/redefclass028.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/redefclass028.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/libredefclass029.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/libredefclass029.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/redefclass029.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/redefclass029.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/libredefclass030.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/libredefclass030.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/redefclass030.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/redefclass030.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/libredefclass031.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/libredefclass031.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/redefclass031.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/redefclass031.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/librelcaps001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/librelcaps001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/{relcaps001.c => relcaps001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/librelcaps002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/librelcaps002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/{relcaps002.c => relcaps002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/libresexhausted.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/libresexhausted.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/{resexhausted.c => resexhausted.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/libresumethrd001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/libresumethrd001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/{resumethrd001.c => resumethrd001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/libresumethrd002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/libresumethrd002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/{resumethrd002.c => resumethrd002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/libresumethrdlst001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/libresumethrdlst001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/{resumethrdlst001.c => resumethrdlst001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/libresumethrdlst002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/libresumethrdlst002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/{resumethrdlst002.c => resumethrdlst002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/libretransform002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/libretransform002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/retransform002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/retransform002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/libretransform003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/libretransform003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/retransform003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/retransform003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/libretransform004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/libretransform004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/retransform004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/retransform004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/agentthr001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/agentthr001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/libagentthr001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/libagentthr001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/agentthr002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/agentthr002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/libagentthr002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/libagentthr002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/agentthr003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/agentthr003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/libagentthr003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/libagentthr003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/libsetbrk002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/libsetbrk002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/setbrk002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/setbrk002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/libsetbrk003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/libsetbrk003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/setbrk003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/setbrk003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/libsetbrk005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/libsetbrk005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/setbrk005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/setbrk005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/libsetbrk007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/libsetbrk007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/setbrk007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/setbrk007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/libsetbrk008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/libsetbrk008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/setbrk008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/setbrk008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/libsetenvstor001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/libsetenvstor001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/{setenvstor001.c => setenvstor001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/libsetenvstor002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/libsetenvstor002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/{setenvstor002.c => setenvstor002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/libsetenvstor003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/libsetenvstor003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/{setenvstor003.c => setenvstor003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/libsetevntcallb001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/libsetevntcallb001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/{setevntcallb001.c => setevntcallb001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/libsetevntcallb002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/libsetevntcallb002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/{setevntcallb002.c => setevntcallb002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/libsetevntcallb003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/libsetevntcallb003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/{setevntcallb003.c => setevntcallb003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/libsetnotif001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/libsetnotif001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/setnotif001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/setnotif001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/libsetextevent001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/libsetextevent001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/{setextevent001.c => setextevent001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/libsetfldw001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/libsetfldw001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/setfldw001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/setfldw001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/libsetfldw002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/libsetfldw002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/setfldw002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/setfldw002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/libsetfldw003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/libsetfldw003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/setfldw003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/setfldw003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/libsetfldw004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/libsetfldw004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/setfldw004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/setfldw004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/libsetfldw005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/libsetfldw005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/setfldw005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/setfldw005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/libsetfldw006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/libsetfldw006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/setfldw006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/setfldw006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/libsetfmodw001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/libsetfmodw001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/setfmodw001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/setfmodw001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/libsetfmodw002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/libsetfmodw002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/setfmodw002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/setfmodw002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/libsetfmodw003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/libsetfmodw003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/setfmodw003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/setfmodw003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/libsetfmodw004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/libsetfmodw004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/setfmodw004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/setfmodw004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/libsetfmodw005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/libsetfmodw005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/setfmodw005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/setfmodw005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/libsetfmodw006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/libsetfmodw006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/setfmodw006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/setfmodw006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/libsetjniftab001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/libsetjniftab001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/setjniftab001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/setjniftab001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/libsetjniftab002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/libsetjniftab002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/setjniftab002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/setjniftab002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/libsetlocal001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/libsetlocal001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/setlocal001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/setlocal001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/libsetlocal002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/libsetlocal002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/setlocal002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/setlocal002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/libsetlocal003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/libsetlocal003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/setlocal003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/setlocal003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/libsetlocal004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/libsetlocal004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/setlocal004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/setlocal004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/SetNativeMethodPrefix001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/SetNativeMethodPrefix001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/libSetNativeMethodPrefix001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/libSetNativeMethodPrefix001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002Main.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002Main.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002Main.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002Main.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/libsetsysprop002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/libsetsysprop002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/{setsysprop002.c => setsysprop002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/libsetsysprop003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/libsetsysprop003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/{setsysprop003.c => setsysprop003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/libsettag001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/libsettag001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/settag001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/settag001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/libsetthrdstor001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/libsetthrdstor001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/{setthrdstor001.c => setthrdstor001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/libsetthrdstor002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/libsetthrdstor002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/{setthrdstor002.c => setthrdstor002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/libsetthrdstor003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/libsetthrdstor003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/{setthrdstor003.c => setthrdstor003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/libsetvrbflag001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/libsetvrbflag001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/{setvrbflag001.c => setvrbflag001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/libsetvrbflag002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/libsetvrbflag002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/{setvrbflag002.c => setvrbflag002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/libsinglestep001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/libsinglestep001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/singlestep001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/singlestep001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep002/libsinglestep002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep002/libsinglestep002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep002/{singlestep002.c => singlestep002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep003/libsinglestep003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep003/libsinglestep003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep003/{singlestep003.c => singlestep003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd006/libstopthrd006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd006/libstopthrd006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd006/stopthrd006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd006/stopthrd006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/libstopthrd007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/libstopthrd007.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/{stopthrd007.c => stopthrd007.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/libsuspendthrd001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/libsuspendthrd001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/{suspendthrd001.c => suspendthrd001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/libsuspendthrd002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/libsuspendthrd002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/{suspendthrd002.c => suspendthrd002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/libsuspendthrd003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/libsuspendthrd003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/{suspendthrd003.c => suspendthrd003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/libsuspendthrdlst001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/libsuspendthrdlst001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/{suspendthrdlst001.c => suspendthrdlst001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/libsuspendthrdlst002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/libsuspendthrdlst002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/{suspendthrdlst002.c => suspendthrdlst002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/libthreadend001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/libthreadend001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/threadend001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/threadend001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/libthreadend002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/libthreadend002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/{threadend002.c => threadend002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/libthreadstart001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/libthreadstart001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/threadstart001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/threadstart001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/libthreadstart002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/libthreadstart002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/threadstart002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/threadstart002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/libthreadstart003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/libthreadstart003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/threadstart003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/threadstart003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/libvmdeath001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/libvmdeath001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/{vmdeath001.c => vmdeath001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/libvminit001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/libvminit001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/vminit001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/vminit001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/libvmobjalloc001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/libvmobjalloc001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/{vmobjalloc001.c => vmobjalloc001.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/{ap01t001.c => ap01t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/libap01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/libap01t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/ap02t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/ap02t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/libap02t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/libap02t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/{ap03t001.c => ap03t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/libap03t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/libap03t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/ap04t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/ap04t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/libap04t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/libap04t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/ap04t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/ap04t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/libap04t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/libap04t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/libap04t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/libap04t003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/{ap05t001.c => ap05t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/libap05t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/libap05t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/{ap05t002.c => ap05t002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/libap05t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/libap05t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/{ap06t001.c => ap06t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/libap06t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/libap06t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/{ap07t001.c => ap07t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/libap07t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/libap07t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/{ap07t002.c => ap07t002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/libap07t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/libap07t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/{ap09t001.c => ap09t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/libap09t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/libap09t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/{ap10t001.c => ap10t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/libap10t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/libap10t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/ap11t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/ap11t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/libap11t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/libap11t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/{ap12t001.c => ap12t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/libap12t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/libap12t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/bi01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/bi01t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/libbi01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/libbi01t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/bi01t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/bi01t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/libbi01t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/libbi01t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/bi02t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/bi02t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/libbi02t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/libbi02t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/bi02t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/bi02t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/libbi02t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/libbi02t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/bi03t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/bi03t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/libbi03t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/libbi03t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/bi03t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/bi03t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/libbi03t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/libbi03t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/bi04t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/bi04t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/libbi04t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/libbi04t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/{cm01t001.c => cm01t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/libcm01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/libcm01t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/{cm01t002.c => cm01t002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/libcm01t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/libcm01t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/{cm01t003.c => cm01t003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/libcm01t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/libcm01t003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/{cm01t004.c => cm01t004.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/libcm01t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/libcm01t004.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/{cm01t005.c => cm01t005.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/libcm01t005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/libcm01t005.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/{cm01t006.c => cm01t006.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/libcm01t006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/libcm01t006.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/{cm01t007.c => cm01t007.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/libcm01t007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/libcm01t007.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/{cm01t008.c => cm01t008.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/libcm01t008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/libcm01t008.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/{cm01t009.c => cm01t009.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/libcm01t009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/libcm01t009.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/{cm01t010.c => cm01t010.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/libcm01t010.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/libcm01t010.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/{cm01t011.c => cm01t011.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/libcm01t011.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/libcm01t011.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/{cm01t012.c => cm01t012.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/libcm01t012.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/libcm01t012.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/{cm01t013.c => cm01t013.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/libcm01t013.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/libcm01t013.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/{cm01t014.c => cm01t014.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/libcm01t014.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/libcm01t014.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/{cm01t015.c => cm01t015.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/libcm01t015.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/libcm01t015.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/{cm01t016.c => cm01t016.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/libcm01t016.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/libcm01t016.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/{cm01t017.c => cm01t017.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/libcm01t017.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/libcm01t017.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/{cm01t018.c => cm01t018.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/libcm01t018.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/libcm01t018.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/{cm01t019.c => cm01t019.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/libcm01t019.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/libcm01t019.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/{cm01t020.c => cm01t020.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/libcm01t020.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/libcm01t020.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/{cm01t021.c => cm01t021.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/libcm01t021.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/libcm01t021.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/cm02t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/cm02t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/libcm02t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/libcm02t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/{cm03t001.c => cm03t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/libcm03t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/libcm03t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/libtc01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/libtc01t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/{tc01t001.c => tc01t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/libtc02t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/libtc02t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/{tc02t001.c => tc02t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/libtc03t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/libtc03t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/{tc03t001.c => tc03t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/libtc03t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/libtc03t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/{tc03t002.c => tc03t002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/libtc04t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/libtc04t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/tc04t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/tc04t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/libtc05t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/libtc05t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/tc05t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/tc05t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/em01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/em01t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/libem01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/libem01t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/em01t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/em01t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/libem01t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/libem01t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/{em02t001.c => em02t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/libem02t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/libem02t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/em02t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/em02t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/libem02t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/libem02t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/em02t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/em02t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/libem02t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/libem02t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/em02t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/em02t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/libem02t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/libem02t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/em02t005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/em02t005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/libem02t005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/libem02t005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/em02t006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/em02t006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/libem02t006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/libem02t006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/em02t007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/em02t007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/libem02t007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/libem02t007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/em02t008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/em02t008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/libem02t008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/libem02t008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/em02t009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/em02t009.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/libem02t009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/libem02t009.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/em02t010.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/em02t010.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/libem02t010.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/libem02t010.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/em02t011.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/em02t011.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/libem02t011.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/libem02t011.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/em02t012.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/em02t012.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/libem02t012.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/libem02t012.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/{em04t001.c => em04t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/libem04t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/libem04t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/em05t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/em05t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/libem05t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/libem05t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/em05t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/em05t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/libem05t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/libem05t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/em06t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/em06t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/libem06t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/libem06t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/em07t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/em07t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/libem07t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/libem07t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/{em07t002.c => em07t002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/libem07t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/libem07t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/{ex03t001.c => ex03t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/libex03t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/libex03t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/{gf01t001.c => gf01t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/libgf01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/libgf01t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/{gf04t001.c => gf04t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/libgf04t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/libgf04t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/{gf06t001.c => gf06t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/libgf06t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/libgf06t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/{gf08t001.c => gf08t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/libgf08t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/libgf08t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/{gf08t002.c => gf08t002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/libgf08t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/libgf08t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/{gf08t003.c => gf08t003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/libgf08t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/libgf08t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/hs103t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/hs103t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/libhs103t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/libhs103t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/hs104t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/hs104t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/libhs104t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/libhs104t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/hs104t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/hs104t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/libhs104t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/libhs104t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/hs201t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/hs201t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/libhs201t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/libhs201t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/hs201t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/hs201t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/libhs201t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/libhs201t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/{hs201t003.c => hs201t003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/libhs201t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/libhs201t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/hs202t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/hs202t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/libhs202t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/libhs202t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/hs202t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/hs202t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/libhs202t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/libhs202t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/hs203t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/hs203t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/libhs203t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/libhs203t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/hs203t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/hs203t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/libhs203t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/libhs203t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/hs203t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/hs203t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/libhs203t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/libhs203t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/hs203t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/hs203t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/libhs203t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/libhs203t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/libhs204t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/libhs204t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/hs204t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/hs204t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/libhs204t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/libhs204t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/hs204t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/hs204t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/libhs204t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/libhs204t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/hs204t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/hs204t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/libhs204t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/libhs204t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/hs301t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/hs301t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/libhs301t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/libhs301t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/hs301t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/hs301t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/libhs301t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/libhs301t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/hs301t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/hs301t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/libhs301t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/libhs301t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/hs301t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/hs301t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/libhs301t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/libhs301t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/hs301t005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/hs301t005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/libhs301t005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/libhs301t005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/hs302t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/hs302t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/libhs302t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/libhs302t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/hs302t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/hs302t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/libhs302t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/libhs302t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/hs302t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/hs302t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/libhs302t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/libhs302t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/hs302t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/hs302t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/libhs302t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/libhs302t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/hs302t005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/hs302t005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/libhs302t005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/libhs302t005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/hs302t006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/hs302t006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/libhs302t006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/libhs302t006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/hs302t007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/hs302t007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/libhs302t007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/libhs302t007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/hs302t008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/hs302t008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/libhs302t008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/libhs302t008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/hs302t009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/hs302t009.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/libhs302t009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/libhs302t009.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/hs302t010.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/hs302t010.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/libhs302t010.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/libhs302t010.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/hs302t011.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/hs302t011.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/libhs302t011.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/libhs302t011.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/hs302t012.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/hs302t012.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/libhs302t012.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/libhs302t012.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/ji01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/ji01t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/libji01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/libji01t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/ji03t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/ji03t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/libji03t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/libji03t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/ji03t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/ji03t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/libji03t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/libji03t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/ji03t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/ji03t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/libji03t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/libji03t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/ji03t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/ji03t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/libji03t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/libji03t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI05/ji05t001/ji05t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI05/ji05t001/ji05t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI05/ji05t001/libji05t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI05/ji05t001/libji05t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/ji06t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/ji06t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/libji06t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/libji06t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/{ma01t001.c => ma01t001.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/{ma01t001a.c => ma01t001a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/{ma02t001.c => ma02t001.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/{ma02t001a.c => ma02t001a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/{ma03t001.c => ma03t001.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/{ma03t001a.c => ma03t001a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/{ma04t001.c => ma04t001.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/{ma04t001a.c => ma04t001a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002a.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002a.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/{ma04t003.c => ma04t003.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/{ma04t003a.c => ma04t003a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/{ma05t001.c => ma05t001.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/{ma05t001a.c => ma05t001a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001a.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001a.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/{ma07t001.c => ma07t001.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/{ma07t001a.c => ma07t001a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/{ma08t001.c => ma08t001.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/{ma08t001a.c => ma08t001a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/{ma10t001.c => ma10t001.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/{ma10t001a.c => ma10t001a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/{ma10t002.c => ma10t002.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/{ma10t002a.c => ma10t002a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/{ma10t003.c => ma10t003.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/{ma10t003a.c => ma10t003a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/{ma10t004.c => ma10t004.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/{ma10t004a.c => ma10t004a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/{ma10t005.c => ma10t005.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/{ma10t005a.c => ma10t005a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006a.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006a.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/{ma10t007.c => ma10t007.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/{ma10t007a.c => ma10t007a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008a.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008a.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/{ma10t008.c => ma10t008.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/{ma10t008a.c => ma10t008a.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/libsp01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/libsp01t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/sp01t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/sp01t001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/libsp01t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/libsp01t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/{sp01t002.c => sp01t002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/libsp01t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/libsp01t003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/{sp01t003.c => sp01t003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/libsp02t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/libsp02t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/{sp02t001.c => sp02t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/libsp02t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/libsp02t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/{sp02t002.c => sp02t002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/libsp02t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/libsp02t003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/{sp02t003.c => sp02t003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/libsp03t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/libsp03t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/{sp03t001.c => sp03t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/libsp03t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/libsp03t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/{sp03t002.c => sp03t002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/libsp04t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/libsp04t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/{sp04t001.c => sp04t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/libsp04t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/libsp04t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/{sp04t002.c => sp04t002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/libsp05t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/libsp05t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/sp05t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/sp05t002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/libsp05t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/libsp05t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/sp05t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/sp05t003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/libsp06t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/libsp06t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/{sp06t001.c => sp06t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/libsp06t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/libsp06t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/{sp06t002.c => sp06t002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/libsp06t003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/libsp06t003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/{sp06t003.c => sp06t003.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/libsp07t001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/libsp07t001.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/{sp07t001.c => sp07t001.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/libsp07t002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/libsp07t002.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/{sp07t002.c => sp07t002.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/followref001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/followref001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/libfollowref001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/libfollowref001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/followref002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/followref002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/libfollowref002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/libfollowref002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/followref003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/followref003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/libfollowref003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/libfollowref003.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/{followref004.c => followref004.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/libfollowref004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/libfollowref004.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/{followref005.c => followref005.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/libfollowref005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/libfollowref005.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/{followref006.c => followref006.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/libfollowref006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/libfollowref006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/earlyretbase.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/earlyretbase.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/libearlyretbase.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/libearlyretbase.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/earlyretfp.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/earlyretfp.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/libearlyretfp.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/libearlyretfp.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/earlyretint.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/earlyretint.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/libearlyretint.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/libearlyretint.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/earlyretlong.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/earlyretlong.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/libearlyretlong.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/libearlyretlong.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/earlyretobj.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/earlyretobj.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/libearlyretobj.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/libearlyretobj.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/earlyretstr.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/earlyretstr.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/libearlyretstr.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/libearlyretstr.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/earlyretvoid.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/earlyretvoid.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/libearlyretvoid.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/libearlyretvoid.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/getallstktr001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/getallstktr001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/libgetallstktr001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/libgetallstktr001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/getcpool001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/getcpool001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/libgetcpool001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/libgetcpool001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/liblinetab004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/liblinetab004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/linetab004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/linetab004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/getlocal003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/getlocal003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/libgetlocal003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/libgetlocal003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/getlocal004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/getlocal004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/libgetlocal004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/libgetlocal004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/issynth001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/issynth001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/libIsSyntheticIssynth001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/libIsSyntheticIssynth001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/JvmtiTest.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/JvmtiTest.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/libMethodBind.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/libMethodBind.cpp rename test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/{JvmtiTest.c => JvmtiTest.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/libOnUnload.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/libOnUnload.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/JvmtiTest.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/JvmtiTest.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/libStackTrace.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/libStackTrace.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/agentthr.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/agentthr.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/libagentthr.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/libagentthr.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/clsldrclss00x.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/clsldrclss00x.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/libclsldrclss00x.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/libclsldrclss00x.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/JvmtiTest.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/JvmtiTest.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/libredefineCFLH.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/libredefineCFLH.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/extmech.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/extmech.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/libextmech.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/libextmech.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/JvmtiTest.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/JvmtiTest.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/libAddToBootstrapClassLoaderSearch.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/libAddToBootstrapClassLoaderSearch.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/JvmtiTest.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/JvmtiTest.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/libDispose.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/libDispose.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/gc.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/gc.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/libgc.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/libgc.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/JvmtiTest.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/JvmtiTest.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/libenvironment.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/libenvironment.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/JvmtiTest.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/JvmtiTest.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/libnosuspendMonitorInfo.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/libnosuspendMonitorInfo.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/JvmtiTest.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/JvmtiTest.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/libnosuspendStackTrace.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/libnosuspendStackTrace.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/librawmonitor.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/librawmonitor.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/rawmonitor.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/rawmonitor.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/heapref.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/heapref.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/libheapref.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/libheapref.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/librefignore.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/librefignore.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/refignore.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/refignore.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/JvmtiTest.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/JvmtiTest.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/libsetNullVMInit.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/libsetNullVMInit.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/JvmtiTest.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/JvmtiTest.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/libtimers.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/libtimers.cpp rename test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/{StackTraceController.c => StackTraceController.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/ThreadController.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/ThreadController.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libStackTraceController.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libStackTraceController.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libThreadController.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libThreadController.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/Deadlock.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/Deadlock.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/LockingThreads.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/LockingThreads.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/RecursiveMonitoringThread.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/RecursiveMonitoringThread.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libDeadlock.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libDeadlock.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libLockingThreads.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libLockingThreads.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libNativeBlockedThread.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libNativeBlockedThread.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libRecursiveMonitoringThread.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libRecursiveMonitoringThread.cpp rename test/hotspot/jtreg/vmTestbase/nsk/share/{JVMDITools.c => JVMDITools.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/JVMTIagent.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/JVMTIagent.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/aod/aod.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/aod/aod.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libBooleanArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libBooleanArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libByteArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libByteArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libCharArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libCharArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libDoubleArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libDoubleArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libFloatArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libFloatArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libIntArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libIntArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libLongArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libLongArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libShortArrayCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libShortArrayCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libStringCriticalLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libStringCriticalLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIGlobalRefLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIGlobalRefLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNILocalRefLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNILocalRefLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIRefLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIRefLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIWeakGlobalRefLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIWeakGlobalRefLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/JVMTIAllocLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/JVMTIAllocLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/libJVMTIAllocLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/libJVMTIAllocLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/MallocLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/MallocLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/libMallocLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/libMallocLocker.cpp rename test/hotspot/jtreg/vmTestbase/nsk/share/jdi/{MonitorEnterExecutor.c => MonitorEnterExecutor.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jdi/libMonitorEnterExecutor.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jdi/libMonitorEnterExecutor.cpp rename test/hotspot/jtreg/vmTestbase/nsk/share/jni/{JNIreferences.c => JNIreferences.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/share/jni/{jni_tools.c => jni_tools.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jni/libJNIreferences.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jni/libJNIreferences.cpp rename test/hotspot/jtreg/vmTestbase/nsk/share/jpda/{libNativeMethodsTestThread.c => libNativeMethodsTestThread.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/{bootclssearch_agent.c => bootclssearch_agent.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/libbootclssearch_agent.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/libbootclssearch_agent.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/libsystemclssearch_agent.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/libsystemclssearch_agent.cpp rename test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/{systemclssearch_agent.c => systemclssearch_agent.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/Injector.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/Injector.cpp rename test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/{JVMTITools.c => JVMTITools.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_common/{agent_common.c => agent_common.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_tools.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_tools.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/aod/jvmti_aod.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/aod/jvmti_aod.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/HotSwap.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/HotSwap.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/libHotSwap.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/libHotSwap.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_FollowRefObjects.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_FollowRefObjects.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_tools.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_tools.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/Heap.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/Heap.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/libHeap.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/libHeap.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/locks/JNIMonitorLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/locks/JNIMonitorLocker.cpp rename test/hotspot/jtreg/vmTestbase/nsk/share/locks/{LockingThread.c => LockingThread.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/locks/libJNIMonitorLocker.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/locks/libJNIMonitorLocker.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/locks/libLockingThread.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/locks/libLockingThread.cpp rename test/hotspot/jtreg/vmTestbase/nsk/share/native/{native_thread.c => native_thread.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/share/native/{native_utils.c => native_utils.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_mutex.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_mutex.cpp rename test/hotspot/jtreg/vmTestbase/nsk/share/native/{nsk_tools.c => nsk_tools.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/gclocker/libgcl001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/gclocker/libgcl001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress001.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress001.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress002.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress002.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress007.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress007.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace003.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace003.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace004.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace004.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace006.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace008.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace008.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace009.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace009.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace011.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace011.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace012.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace012.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace014.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace014.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace015.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace015.cpp rename test/hotspot/jtreg/vmTestbase/nsk/stress/strace/{strace003.c => strace003.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/stress/strace/{strace004.c => strace004.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace006.c create mode 100644 test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace006.cpp rename test/hotspot/jtreg/vmTestbase/nsk/stress/strace/{strace008.c => strace008.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/stress/strace/{strace009.c => strace009.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/stress/strace/{strace011.c => strace011.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/stress/strace/{strace012.c => strace012.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/stress/strace/{strace014.c => strace014.cpp} (100%) rename test/hotspot/jtreg/vmTestbase/nsk/stress/strace/{strace015.c => strace015.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/vm/jit/LongTransitions/libLTTest.c create mode 100644 test/hotspot/jtreg/vmTestbase/vm/jit/LongTransitions/libLTTest.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/IndyRedefineClass.c create mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/IndyRedefineClass.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/libIndyRedefineClass.c create mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/libIndyRedefineClass.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/libstepBreakPopReturn.c create mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/libstepBreakPopReturn.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/stepBreakPopReturn.c create mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/stepBreakPopReturn.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/libnativeAndMH.c create mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/libnativeAndMH.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/nativeAndMH.c create mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/nativeAndMH.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.c create mode 100644 test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/libredefineClasses.c create mode 100644 test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/libredefineClasses.cpp rename test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/{redefineClasses.c => redefineClasses.cpp} (100%) delete mode 100644 test/hotspot/jtreg/vmTestbase/vm/share/ProcessUtils.c create mode 100644 test/hotspot/jtreg/vmTestbase/vm/share/ProcessUtils.cpp delete mode 100644 test/hotspot/jtreg/vmTestbase/vm/share/libProcessUtils.c create mode 100644 test/hotspot/jtreg/vmTestbase/vm/share/libProcessUtils.cpp diff --git a/make/common/TestFilesCompilation.gmk b/make/common/TestFilesCompilation.gmk index 72c722ca4db..74d20585b71 100644 --- a/make/common/TestFilesCompilation.gmk +++ b/make/common/TestFilesCompilation.gmk @@ -77,7 +77,7 @@ define SetupTestFilesCompilationBody # Locate all files with the matching prefix $1_FILE_LIST := \ - $$(call FindFiles, $$($1_SOURCE_DIRS), $$($1_PREFIX)*.c $$($1_PREFIX)*.m) + $$(call FindFiles, $$($1_SOURCE_DIRS), $$($1_PREFIX)*.c $$($1_PREFIX)*.cpp $$($1_PREFIX)*.m) $1_EXCLUDE_PATTERN := $$(addprefix %/, $$($1_EXCLUDE)) $1_FILTERED_FILE_LIST := $$(filter-out $$($1_EXCLUDE_PATTERN), $$($1_FILE_LIST)) @@ -99,6 +99,7 @@ define SetupTestFilesCompilationBody DISABLED_WARNINGS_CXX_solstudio := wvarhidenmem, \ DISABLED_WARNINGS_CXX_gcc := format, \ LIBS := $$($1_LIBS_$$(name)), \ + TOOLCHAIN := $(if $$(filter %.cpp, $$(file)), TOOLCHAIN_LINK_CXX, TOOLCHAIN_DEFAULT), \ OPTIMIZATION := $$(if $$($1_OPTIMIZATION_$$(name)),$$($1_OPTIMIZATION_$$(name)),LOW), \ COPY_DEBUG_SYMBOLS := false, \ STRIP_SYMBOLS := false, \ diff --git a/make/test/JtregNativeHotspot.gmk b/make/test/JtregNativeHotspot.gmk index bb6a0ec5b8b..58bd7bf940a 100644 --- a/make/test/JtregNativeHotspot.gmk +++ b/make/test/JtregNativeHotspot.gmk @@ -148,6 +148,9 @@ BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libNoFramePointer := $(NO_FRAMEPOINTER_CFLA # Optimization -O3 needed, HIGH == -O3 BUILD_HOTSPOT_JTREG_LIBRARIES_OPTIMIZATION_libNoFramePointer := HIGH +BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS := -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS +BUILD_HOTSPOT_JTREG_EXECUTABLES_CFLAGS := -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS + BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libProcessUtils := $(VM_SHARE_INCLUDES) BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libThreadController := $(NSK_MONITORING_INCLUDES) @@ -845,10 +848,6 @@ BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libVirtualMachine09agent00 := $(NSK_AOD_INC ################################################################################ -ifeq ($(TOOLCHAIN_TYPE), solstudio) - BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libji06t001 += -erroff=E_END_OF_LOOP_CODE_NOT_REACHED -endif - # Platform specific setup ifneq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU_ARCH), solaris-sparc) BUILD_HOTSPOT_JTREG_EXCLUDE += liboverflow.c exeThreadSignalMask.c diff --git a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/libdefine.c b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/libdefine.c deleted file mode 100644 index b15f1824aad..00000000000 --- a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/libdefine.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include - -#include -#include - -#define STATUS_FAILED 2 -#define STATUS_PASSED 0 - -#define REFERENCES_ARRAY_SIZE 10000000 - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) x -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x, y) x , y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#ifndef _Included_gc_g1_unloading_unloading_classloaders_JNIClassloader -#define _Included_gc_g1_unloading_unloading_classloaders_JNIClassloader - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Class: gc_g1_unloading_unloading_classloaders_JNIClassloader - * Method: loadThroughJNI0 - * Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;[B)Ljava/lang/Class; - */ -JNIEXPORT jclass JNICALL Java_gc_g1_unloading_classloaders_JNIClassloader_loadThroughJNI0 (JNIEnv * env, - jclass clazz, jstring className, jobject classLoader, jbyteArray bytecode) { - - const char * classNameChar = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, className), NULL); - jbyte * arrayContent = JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytecode), NULL); - jsize bytecodeLength = JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytecode)); - jclass returnValue = JNI_ENV_PTR(env)->DefineClass(JNI_ENV_ARG(env, classNameChar), classLoader, arrayContent, bytecodeLength); - if (!returnValue) { - printf("ERROR: DefineClass call returned NULL by some reason. Classloading failed.\n"); - } - - return returnValue; -} - - /* - * Class: gc_g1_unloading_unloading_loading_ClassLoadingThread - * Method: makeRedefinition0 - * Signature: (ILjava/lang/Class;[B)I - */ -JNIEXPORT jint JNICALL Java_gc_g1_unloading_loading_ClassLoadingThread_makeRedefinition0(JNIEnv *env, - jclass cls, jint fl, jclass redefCls, jbyteArray classBytes) { - JavaVM * jvm; - jvmtiEnv * jvmti; - jvmtiError err; - jvmtiCapabilities caps; - jvmtiClassDefinition classDef; - jint jint_err = JNI_ENV_PTR(env)->GetJavaVM(JNI_ENV_ARG(env, &jvm)); - if (jint_err) { - printf("GetJavaVM returned nonzero: %d", jint_err); - return STATUS_FAILED; - } - - jint_err = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **)&jvmti), JVMTI_VERSION_1_0); - if (jint_err) { - printf("GetEnv returned nonzero: %d", jint_err); - return STATUS_FAILED; - } - - err = JNI_ENV_PTR(jvmti)->GetPotentialCapabilities(JNI_ENV_ARG(jvmti, &caps)); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %d\n",err); - return JNI_ERR; - } - - err = JNI_ENV_PTR(jvmti)->AddCapabilities(JNI_ENV_ARG(jvmti, &caps)); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %d\n", err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("ERROR: Can't redefine classes. jvmtiCapabilities.can_redefine_classes isn't set up."); - return STATUS_FAILED; - } - - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), - NULL); - - if (fl == 2) { - printf(">>>>>>>> Invoke RedefineClasses():\n"); - printf("\tnew class byte count=%d\n", classDef.class_byte_count); - } - err = JNI_ENV_PTR(jvmti)->RedefineClasses(JNI_ENV_ARG(jvmti, 1), &classDef); - if (err != JVMTI_ERROR_NONE) { - printf("%s: Failed to call RedefineClasses():\n", __FILE__); - printf("\tthe function returned error %d\n", err); - printf("\tFor more info about this error see the JVMTI spec.\n"); - return STATUS_FAILED; - } - if (fl == 2) - printf("<<<<<<<< RedefineClasses() is successfully done\n"); - - return STATUS_PASSED; -} - -jobject referencesArray[REFERENCES_ARRAY_SIZE]; -int firstFreeIndex = 0; - -/* - * Class: gc_g1_unloading_unloading_keepref_JNIGlobalRefHolder - * Method: keepGlobalJNIReference - * Signature: (Ljava/lang/Object;)I - */ -JNIEXPORT jint JNICALL Java_gc_g1_unloading_keepref_JNIGlobalRefHolder_keepGlobalJNIReference - (JNIEnv * env, jclass clazz, jobject obj) { - int returnValue; - referencesArray[firstFreeIndex] = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, obj)); - printf("checkpoint1 %d \n", firstFreeIndex); - returnValue = firstFreeIndex; - firstFreeIndex++; - return returnValue; -} - -/* - * Class: gc_g1_unloading_unloading_keepref_JNIGlobalRefHolder - * Method: deleteGlobalJNIReference - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_gc_g1_unloading_keepref_JNIGlobalRefHolder_deleteGlobalJNIReference - (JNIEnv * env, jclass clazz, jint index) { - JNI_ENV_PTR(env)->DeleteGlobalRef(JNI_ENV_ARG(env, referencesArray[index])); -} - - -/* - * Class: gc_g1_unloading_unloading_keepref_JNILocalRefHolder - * Method: holdWithJNILocalReference - * Signature: (Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL Java_gc_g1_unloading_keepref_JNILocalRefHolder_holdWithJNILocalReference - (JNIEnv * env, jobject thisObject, jobject syncObject) { - jclass clazz, objectClazz; - jfieldID objectToKeepField; - jobject objectToKeep, localRef; - jmethodID waitMethod; - - clazz = (*env)->GetObjectClass(env, thisObject); - objectToKeepField = (*env)->GetFieldID(env, clazz, "objectToKeep", "Ljava/lang/Object;"); - objectToKeep = (*env)->GetObjectField(env, thisObject, objectToKeepField); - localRef = (*env)->NewLocalRef(env, objectToKeep); - (*env)->SetObjectField(env, thisObject, objectToKeepField, NULL); - - objectClazz = (*env)->FindClass(env, "Ljava/lang/Object;"); - waitMethod = (*env)->GetMethodID(env, objectClazz, "wait", "()V"); - (*env)->CallVoidMethod(env, syncObject, waitMethod); - printf("checkpoint2 \n"); - } - - -#ifdef __cplusplus -} -#endif -#endif diff --git a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/libdefine.cpp b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/libdefine.cpp new file mode 100644 index 00000000000..ff6edf5cd79 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/libdefine.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include + +#include +#include + +#define STATUS_FAILED 2 +#define STATUS_PASSED 0 + +#define REFERENCES_ARRAY_SIZE 10000000 + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x, y) x , y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#ifndef _Included_gc_g1_unloading_unloading_classloaders_JNIClassloader +#define _Included_gc_g1_unloading_unloading_classloaders_JNIClassloader + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: gc_g1_unloading_unloading_classloaders_JNIClassloader + * Method: loadThroughJNI0 + * Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;[B)Ljava/lang/Class; + */ +JNIEXPORT jclass JNICALL Java_gc_g1_unloading_classloaders_JNIClassloader_loadThroughJNI0 (JNIEnv * env, + jclass clazz, jstring className, jobject classLoader, jbyteArray bytecode) { + + const char * classNameChar = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, className), NULL); + jbyte * arrayContent = JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytecode), NULL); + jsize bytecodeLength = JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytecode)); + jclass returnValue = JNI_ENV_PTR(env)->DefineClass(JNI_ENV_ARG(env, classNameChar), classLoader, arrayContent, bytecodeLength); + if (!returnValue) { + printf("ERROR: DefineClass call returned NULL by some reason. Classloading failed.\n"); + } + + return returnValue; +} + + /* + * Class: gc_g1_unloading_unloading_loading_ClassLoadingThread + * Method: makeRedefinition0 + * Signature: (ILjava/lang/Class;[B)I + */ +JNIEXPORT jint JNICALL Java_gc_g1_unloading_loading_ClassLoadingThread_makeRedefinition0(JNIEnv *env, + jclass cls, jint fl, jclass redefCls, jbyteArray classBytes) { + JavaVM * jvm; + jvmtiEnv * jvmti; + jvmtiError err; + jvmtiCapabilities caps; + jvmtiClassDefinition classDef; + jint jint_err = JNI_ENV_PTR(env)->GetJavaVM(JNI_ENV_ARG(env, &jvm)); + if (jint_err) { + printf("GetJavaVM returned nonzero: %d", jint_err); + return STATUS_FAILED; + } + + jint_err = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **)&jvmti), JVMTI_VERSION_1_0); + if (jint_err) { + printf("GetEnv returned nonzero: %d", jint_err); + return STATUS_FAILED; + } + + err = JNI_ENV_PTR(jvmti)->GetPotentialCapabilities(JNI_ENV_ARG(jvmti, &caps)); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %d\n",err); + return JNI_ERR; + } + + err = JNI_ENV_PTR(jvmti)->AddCapabilities(JNI_ENV_ARG(jvmti, &caps)); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %d\n", err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("ERROR: Can't redefine classes. jvmtiCapabilities.can_redefine_classes isn't set up."); + return STATUS_FAILED; + } + + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), + NULL); + + if (fl == 2) { + printf(">>>>>>>> Invoke RedefineClasses():\n"); + printf("\tnew class byte count=%d\n", classDef.class_byte_count); + } + err = JNI_ENV_PTR(jvmti)->RedefineClasses(JNI_ENV_ARG(jvmti, 1), &classDef); + if (err != JVMTI_ERROR_NONE) { + printf("%s: Failed to call RedefineClasses():\n", __FILE__); + printf("\tthe function returned error %d\n", err); + printf("\tFor more info about this error see the JVMTI spec.\n"); + return STATUS_FAILED; + } + if (fl == 2) + printf("<<<<<<<< RedefineClasses() is successfully done\n"); + + return STATUS_PASSED; +} + +jobject referencesArray[REFERENCES_ARRAY_SIZE]; +int firstFreeIndex = 0; + +/* + * Class: gc_g1_unloading_unloading_keepref_JNIGlobalRefHolder + * Method: keepGlobalJNIReference + * Signature: (Ljava/lang/Object;)I + */ +JNIEXPORT jint JNICALL Java_gc_g1_unloading_keepref_JNIGlobalRefHolder_keepGlobalJNIReference + (JNIEnv * env, jclass clazz, jobject obj) { + int returnValue; + referencesArray[firstFreeIndex] = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, obj)); + printf("checkpoint1 %d \n", firstFreeIndex); + returnValue = firstFreeIndex; + firstFreeIndex++; + return returnValue; +} + +/* + * Class: gc_g1_unloading_unloading_keepref_JNIGlobalRefHolder + * Method: deleteGlobalJNIReference + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_gc_g1_unloading_keepref_JNIGlobalRefHolder_deleteGlobalJNIReference + (JNIEnv * env, jclass clazz, jint index) { + JNI_ENV_PTR(env)->DeleteGlobalRef(JNI_ENV_ARG(env, referencesArray[index])); +} + + +/* + * Class: gc_g1_unloading_unloading_keepref_JNILocalRefHolder + * Method: holdWithJNILocalReference + * Signature: (Ljava/lang/Object;)V + */ +JNIEXPORT void JNICALL Java_gc_g1_unloading_keepref_JNILocalRefHolder_holdWithJNILocalReference + (JNIEnv * env, jobject thisObject, jobject syncObject) { + jclass clazz, objectClazz; + jfieldID objectToKeepField; + jobject objectToKeep, localRef; + jmethodID waitMethod; + + clazz = env->GetObjectClass(thisObject); + objectToKeepField = env->GetFieldID(clazz, "objectToKeep", "Ljava/lang/Object;"); + objectToKeep = env->GetObjectField(thisObject, objectToKeepField); + localRef = env->NewLocalRef(objectToKeep); + env->SetObjectField(thisObject, objectToKeepField, NULL); + + objectClazz = env->FindClass("Ljava/lang/Object;"); + waitMethod = env->GetMethodID(objectClazz, "wait", "()V"); + env->CallVoidMethod(syncObject, waitMethod); + printf("checkpoint2 \n"); + } + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/libmallocWithGC1.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/libmallocWithGC1.c deleted file mode 100644 index 6d048475973..00000000000 --- a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/libmallocWithGC1.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include - -JNIEXPORT void JNICALL Java_gc_gctests_mallocWithGC1_mallocWithGC1_getMallocLock01 -(JNIEnv *env, jobject obj) { - char *c_ptr; - time_t current_time, old_time; - - old_time = time(NULL); - current_time = 0; - - while (current_time - old_time < 180) { - c_ptr = (char *) malloc(1); - free(c_ptr); - current_time = time(NULL); - } -} diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/libmallocWithGC1.cpp b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/libmallocWithGC1.cpp new file mode 100644 index 00000000000..004ed27f2c8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/libmallocWithGC1.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT void JNICALL Java_gc_gctests_mallocWithGC1_mallocWithGC1_getMallocLock01 +(JNIEnv *env, jobject obj) { + char *c_ptr; + time_t current_time, old_time; + + old_time = time(NULL); + current_time = 0; + + while (current_time - old_time < 180) { + c_ptr = (char *) malloc(1); + free(c_ptr); + current_time = time(NULL); + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/libmallocWithGC2.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/libmallocWithGC2.c deleted file mode 100644 index 63ae87558f6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/libmallocWithGC2.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include - -JNIEXPORT void JNICALL Java_gc_gctests_mallocWithGC2_mallocWithGC2_getMallocLock02 -(JNIEnv *env, jobject obj) { - char *c_ptr; - time_t current_time, old_time; - - old_time = time(NULL); - current_time = 0; - - while (current_time - old_time < 180) { - c_ptr = (char *) malloc(1); - free(c_ptr); - current_time = time(NULL); - } -} diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/libmallocWithGC2.cpp b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/libmallocWithGC2.cpp new file mode 100644 index 00000000000..ec387c62d2c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/libmallocWithGC2.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT void JNICALL Java_gc_gctests_mallocWithGC2_mallocWithGC2_getMallocLock02 +(JNIEnv *env, jobject obj) { + char *c_ptr; + time_t current_time, old_time; + + old_time = time(NULL); + current_time = 0; + + while (current_time - old_time < 180) { + c_ptr = (char *) malloc(1); + free(c_ptr); + current_time = time(NULL); + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/libmallocWithGC3.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/libmallocWithGC3.c deleted file mode 100644 index 49ae509b0ce..00000000000 --- a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/libmallocWithGC3.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include - -JNIEXPORT void JNICALL -Java_gc_gctests_mallocWithGC3_mallocWithGC3_getMallocLock03 -(JNIEnv *env, jobject obj) { - char *c_ptr; - time_t current_time, old_time; - - old_time = time(NULL); - current_time = 0; - - while (current_time - old_time < 180) { - c_ptr = (char *) malloc(1); - free(c_ptr); - current_time = time(NULL); - } -} diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/libmallocWithGC3.cpp b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/libmallocWithGC3.cpp new file mode 100644 index 00000000000..9f4cfc544ac --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/libmallocWithGC3.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT void JNICALL +Java_gc_gctests_mallocWithGC3_mallocWithGC3_getMallocLock03 +(JNIEnv *env, jobject obj) { + char *c_ptr; + time_t current_time, old_time; + + old_time = time(NULL); + current_time = 0; + + while (current_time - old_time < 180) { + c_ptr = (char *) malloc(1); + free(c_ptr); + current_time = time(NULL); + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/libnativeGC01.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/libnativeGC01.c deleted file mode 100644 index 045c5ab7523..00000000000 --- a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/libnativeGC01.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -/* - * A C function that takes a reference to java Object( a circular Linked list) - * and utilizes this reference to do a java method callback to determine the - * number of elements in the linked list - */ -JNIEXPORT jint JNICALL -Java_gc_gctests_nativeGC01_nativeGC01_nativeMethod01 -(JNIEnv *env, jobject obj, jobject linked_list) { - jclass cls, clss; - jmethodID mid, mid2; - int elementCount; - - /* Before doing anything force a GC by - invoking a callback where System.gc() is called - */ - cls = (*env)->GetObjectClass(env, obj); - mid = (*env)->GetMethodID(env, cls, "callbackGC", "()V"); - if (mid == 0) { - printf("couldnt locate method callbackGC()"); - return -1; - } - (*env)->CallVoidMethod(env,obj,mid); - - /* Now that a GC has been done, invoke the callback - that counts the number of elements in the - circular linked list - */ - - clss = (*env)->GetObjectClass(env, linked_list); - mid2 = (*env)->GetMethodID(env, clss, "getLength", "()I" ); - if (mid2 == 0) { - printf("couldnt locate method getLength()"); - return -1; - } - elementCount = (*env)->CallIntMethod(env, linked_list, mid2); - return elementCount; -} diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/libnativeGC01.cpp b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/libnativeGC01.cpp new file mode 100644 index 00000000000..d8c0c191ecf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/libnativeGC01.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * A C function that takes a reference to java Object( a circular Linked list) + * and utilizes this reference to do a java method callback to determine the + * number of elements in the linked list + */ +JNIEXPORT jint JNICALL +Java_gc_gctests_nativeGC01_nativeGC01_nativeMethod01 +(JNIEnv *env, jobject obj, jobject linked_list) { + jclass cls, clss; + jmethodID mid, mid2; + int elementCount; + + /* Before doing anything force a GC by + invoking a callback where System.gc() is called + */ + cls = env->GetObjectClass(obj); + mid = env->GetMethodID(cls, "callbackGC", "()V"); + if (mid == 0) { + printf("couldnt locate method callbackGC()"); + return -1; + } + env->CallVoidMethod(obj,mid); + + /* Now that a GC has been done, invoke the callback + that counts the number of elements in the + circular linked list + */ + + clss = env->GetObjectClass(linked_list); + mid2 = env->GetMethodID(clss, "getLength", "()I" ); + if (mid2 == 0) { + printf("couldnt locate method getLength()"); + return -1; + } + elementCount = env->CallIntMethod(linked_list, mid2); + return elementCount; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/libnativeGC02.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/libnativeGC02.c deleted file mode 100644 index a29ae701394..00000000000 --- a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/libnativeGC02.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include - -/* A C function that takes a reference to java Object( a circular Linked list) - and utilizes this reference to do a java method callback to determine the - number of elements in the linked list */ -JNIEXPORT jint JNICALL -Java_gc_gctests_nativeGC02_nativeGC02_nativeMethod02 -(JNIEnv *env, jobject obj, jobject linked_list) { - jclass cls, clss; - jmethodID mid, mid2; - jfieldID fid; - jobject llist; - int elementCount; - - /* Store a reference to the linked list in the C stack */ - - clss = (*env)->GetObjectClass(env, obj); - fid = (*env)->GetFieldID(env, clss, "cl", "Lnsk/share/gc/CircularLinkedList;"); - if (fid == 0) { - printf("could not locate field - cl\n"); - return -1; - } - - llist = (*env)->GetObjectField(env, obj, fid); - - /* force a GC by invoking a callback where System.gc() is called - */ - - cls = (*env)->GetObjectClass(env, obj); - mid = (*env)->GetMethodID(env, cls, "callbackGC", "()V"); - if (mid == 0){ - printf("couldnt locate method callbackGC()\n"); - return -1; - } - (*env)->CallVoidMethod(env,obj,mid); - - /* Now that a GC has been done, invoke the callback - that counts the number of elements in the - circular linked list - */ - - clss = (*env)->GetObjectClass(env, linked_list); - mid2 = (*env)->GetMethodID(env, clss, "getLength", "(Lnsk/share/gc/CircularLinkedList;)I" ); - if (mid2 == 0 ){ - printf("couldnt locate method getLength(CircularLinkedList)\n"); - return -1; - } - elementCount = (*env)->CallIntMethod(env, linked_list, mid2, llist); - return elementCount; -} diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/libnativeGC02.cpp b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/libnativeGC02.cpp new file mode 100644 index 00000000000..946a900a459 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/libnativeGC02.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* A C function that takes a reference to java Object( a circular Linked list) + and utilizes this reference to do a java method callback to determine the + number of elements in the linked list */ +JNIEXPORT jint JNICALL +Java_gc_gctests_nativeGC02_nativeGC02_nativeMethod02 +(JNIEnv *env, jobject obj, jobject linked_list) { + jclass cls, clss; + jmethodID mid, mid2; + jfieldID fid; + jobject llist; + int elementCount; + + /* Store a reference to the linked list in the C stack */ + + clss = env->GetObjectClass(obj); + fid = env->GetFieldID(clss, "cl", "Lnsk/share/gc/CircularLinkedList;"); + if (fid == 0) { + printf("could not locate field - cl\n"); + return -1; + } + + llist = env->GetObjectField(obj, fid); + + /* force a GC by invoking a callback where System.gc() is called + */ + + cls = env->GetObjectClass(obj); + mid = env->GetMethodID(cls, "callbackGC", "()V"); + if (mid == 0){ + printf("couldnt locate method callbackGC()\n"); + return -1; + } + env->CallVoidMethod(obj,mid); + + /* Now that a GC has been done, invoke the callback + that counts the number of elements in the + circular linked list + */ + + clss = env->GetObjectClass(linked_list); + mid2 = env->GetMethodID(clss, "getLength", "(Lnsk/share/gc/CircularLinkedList;)I" ); + if (mid2 == 0 ){ + printf("couldnt locate method getLength(CircularLinkedList)\n"); + return -1; + } + elementCount = env->CallIntMethod(linked_list, mid2, llist); + return elementCount; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/libnativeGC03.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/libnativeGC03.c deleted file mode 100644 index fbe41e3c146..00000000000 --- a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/libnativeGC03.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include - -JNIEXPORT void JNICALL -Java_gc_gctests_nativeGC03_nativeGC03_nativeMethod03 -(JNIEnv *env, jobject obj, jobjectArray listHolder) { - jsize len; - int i, count; - jmethodID mid; - jclass clss; - - len = (*env)->GetArrayLength(env, listHolder); - i = 0; - count = 0; - /*Trash all the linked lists */ - while (count < 10) { - while (i < len) { - (*env)->SetObjectArrayElement(env, listHolder, i, NULL); - i++; - } - - /* Invoke a callback that will refill the array */ - - clss = (*env)->GetObjectClass(env, obj); - mid = (*env)->GetMethodID(env, clss, "fillArray", "()V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, obj, mid); - count++; - } - -} diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/libnativeGC03.cpp b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/libnativeGC03.cpp new file mode 100644 index 00000000000..ce268924670 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/libnativeGC03.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT void JNICALL +Java_gc_gctests_nativeGC03_nativeGC03_nativeMethod03 +(JNIEnv *env, jobject obj, jobjectArray listHolder) { + jsize len; + int i, count; + jmethodID mid; + jclass clss; + + len = env->GetArrayLength(listHolder); + i = 0; + count = 0; + /*Trash all the linked lists */ + while (count < 10) { + while (i < len) { + env->SetObjectArrayElement(listHolder, i, NULL); + i++; + } + + /* Invoke a callback that will refill the array */ + + clss = env->GetObjectClass(obj); + mid = env->GetMethodID(clss, "fillArray", "()V"); + if (mid == 0) { + return; + } + env->CallVoidMethod(obj, mid); + count++; + } + +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/libnativeGC05.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/libnativeGC05.c deleted file mode 100644 index 59c53d4c947..00000000000 --- a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/libnativeGC05.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include - -JNIEXPORT void JNICALL -Java_gc_gctests_nativeGC05_nativeGC05_kickOffRefillers -(JNIEnv *env, jobject obj, jobject matrix, jobject stack) { - jclass matrixClass, stackClass, pairClass = 0; - jmethodID stack_pop_mid, stack_empty_mid, matrix_repopulate_mid, pair_geti_mid = 0, pair_getj_mid = 0; - jobject pair; - jint i, j; - jboolean b; - - /* Get class objects associated with the objects passed in */ - matrixClass = (*env)->GetObjectClass(env, matrix); - stackClass = (*env)->GetObjectClass(env, stack); - - /* GetMethodID's for the pop() and Repopulate() methods */ - stack_pop_mid = (*env)->GetMethodID(env, stackClass, "pop", "()Ljava/lang/Object;"); - if (stack_pop_mid == 0) { - printf("could not get a methodID for Stack::pop()\n"); - return; - } - stack_empty_mid = (*env)->GetMethodID(env, stackClass, "empty", "()Z"); - if (stack_empty_mid == 0) { - printf("could not get a methodID for Stack::empty()\n"); - return; - } - - matrix_repopulate_mid = (*env)->GetMethodID(env, matrixClass, "repopulate", "(II)V"); - if (matrix_repopulate_mid == 0) { - printf("could not get a methodID for Matrix::repopulate(int, int)\n"); - return; - } - - /** b = stack.empty(); */ - b = (*env)->CallBooleanMethod(env, stack, stack_empty_mid); - while (b == JNI_FALSE) { - /** pair = stack.pop() */ - pair = (*env)->CallObjectMethod(env, stack, stack_pop_mid); - - if (pairClass == 0) { - pairClass = (*env)->GetObjectClass(env, pair); - pair_geti_mid = (*env)->GetMethodID(env, pairClass, "getI", "()I"); - if (pair_geti_mid == 0) { - printf("could not get a methodID for IndexPair::getI()\n"); - return; - } - pair_getj_mid = (*env)->GetMethodID(env, pairClass, "getJ", "()I"); - if (pair_getj_mid == 0) { - printf("could not get a methodID for IndexPair::getJ()\n"); - return; - } - } - - /** i = pair.getI(); */ - i = (*env)->CallIntMethod(env, pair, pair_geti_mid); - /** j = pair.getJ(); */ - j = (*env)->CallIntMethod(env, pair, pair_getj_mid); - - /* matrix.repopulate(i, j); */ - (*env)->CallVoidMethod(env, matrix, matrix_repopulate_mid, i, j); - - /** b = stack.empty(); */ - b = (*env)->CallBooleanMethod(env, stack, stack_empty_mid); - } -} diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/libnativeGC05.cpp b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/libnativeGC05.cpp new file mode 100644 index 00000000000..b1bcf74e7a4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/libnativeGC05.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT void JNICALL +Java_gc_gctests_nativeGC05_nativeGC05_kickOffRefillers +(JNIEnv *env, jobject obj, jobject matrix, jobject stack) { + jclass matrixClass, stackClass, pairClass = 0; + jmethodID stack_pop_mid, stack_empty_mid, matrix_repopulate_mid, pair_geti_mid = 0, pair_getj_mid = 0; + jobject pair; + jint i, j; + jboolean b; + + /* Get class objects associated with the objects passed in */ + matrixClass = env->GetObjectClass(matrix); + stackClass = env->GetObjectClass(stack); + + /* GetMethodID's for the pop() and Repopulate() methods */ + stack_pop_mid = env->GetMethodID(stackClass, "pop", "()Ljava/lang/Object;"); + if (stack_pop_mid == 0) { + printf("could not get a methodID for Stack::pop()\n"); + return; + } + stack_empty_mid = env->GetMethodID(stackClass, "empty", "()Z"); + if (stack_empty_mid == 0) { + printf("could not get a methodID for Stack::empty()\n"); + return; + } + + matrix_repopulate_mid = env->GetMethodID(matrixClass, "repopulate", "(II)V"); + if (matrix_repopulate_mid == 0) { + printf("could not get a methodID for Matrix::repopulate(int, int)\n"); + return; + } + + /** b = stack.empty(); */ + b = env->CallBooleanMethod(stack, stack_empty_mid); + while (b == JNI_FALSE) { + /** pair = stack.pop() */ + pair = env->CallObjectMethod(stack, stack_pop_mid); + + if (pairClass == 0) { + pairClass = env->GetObjectClass(pair); + pair_geti_mid = env->GetMethodID(pairClass, "getI", "()I"); + if (pair_geti_mid == 0) { + printf("could not get a methodID for IndexPair::getI()\n"); + return; + } + pair_getj_mid = env->GetMethodID(pairClass, "getJ", "()I"); + if (pair_getj_mid == 0) { + printf("could not get a methodID for IndexPair::getJ()\n"); + return; + } + } + + /** i = pair.getI(); */ + i = env->CallIntMethod(pair, pair_geti_mid); + /** j = pair.getJ(); */ + j = env->CallIntMethod(pair, pair_getj_mid); + + /* matrix.repopulate(i, j); */ + env->CallVoidMethod(matrix, matrix_repopulate_mid, i, j); + + /** b = stack.empty(); */ + b = env->CallBooleanMethod(stack, stack_empty_mid); + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent01.c b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent01.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent01.c rename to test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent01.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent02.c b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent02.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent02.c rename to test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent02.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent03.c b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent03.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent03.c rename to test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/agent03.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent00.c deleted file mode 100644 index b08040b69bf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent00.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "aod.c" -#include "jni_tools.c" -#include "nsk_tools.c" -#include "agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent00.cpp new file mode 100644 index 00000000000..baddde5307f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent00.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "aod.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent01.c b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent01.c deleted file mode 100644 index f75f3e154cb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent01.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "aod.c" -#include "jni_tools.c" -#include "nsk_tools.c" -#include "agent01.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent01.cpp b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent01.cpp new file mode 100644 index 00000000000..c73f0344dbd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent01.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "aod.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "agent01.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent02.c b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent02.c deleted file mode 100644 index b44ef2443ff..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent02.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "aod.c" -#include "jni_tools.c" -#include "nsk_tools.c" -#include "agent02.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent02.cpp b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent02.cpp new file mode 100644 index 00000000000..203cd0b52b5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent02.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "aod.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "agent02.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent03.c b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent03.c deleted file mode 100644 index 8a7e2defbaa..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent03.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "aod.c" -#include "jni_tools.c" -#include "nsk_tools.c" -#include "agent03.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent03.cpp b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent03.cpp new file mode 100644 index 00000000000..c6598da732e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/libVirtualMachine07agent03.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "aod.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "agent03.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/libVirtualMachine09agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/libVirtualMachine09agent00.c deleted file mode 100644 index b08040b69bf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/libVirtualMachine09agent00.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "aod.c" -#include "jni_tools.c" -#include "nsk_tools.c" -#include "agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/libVirtualMachine09agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/libVirtualMachine09agent00.cpp new file mode 100644 index 00000000000..baddde5307f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/libVirtualMachine09agent00.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "aod.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn004/libforceEarlyReturn004a.c b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn004/libforceEarlyReturn004a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn004/libforceEarlyReturn004a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn004/libforceEarlyReturn004a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn005/libforceEarlyReturn005a.c b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn005/libforceEarlyReturn005a.c deleted file mode 100644 index da7a6469f29..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn005/libforceEarlyReturn005a.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni.h" -#include "nsk_tools.c" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_PTR - -#ifdef __cplusplus -#define JNI_ENV_ARG_2(x, y) y -#define JNI_ENV_ARG_3(x,y,z) y, z -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG_2(x,y) x, y -#define JNI_ENV_ARG_3(x,y,z) x, y, z -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -JNIEXPORT void JNICALL -Java_nsk_jdi_ThreadReference_forceEarlyReturn_forceEarlyReturn005_forceEarlyReturn005a_nativeJNIMonitorEnter(JNIEnv *env, jobject classObject, jobject object) -{ - jint success = JNI_ENV_PTR(env)->MonitorEnter(JNI_ENV_ARG_2(env, object)); - - if(success != 0) - { - NSK_COMPLAIN1("MonitorEnter return non-zero: %d\n", success); - - JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG_3(env, JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG_2(env, "nsk/share/TestJNIError")), "MonitorEnter return non-zero")); - } -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn005/libforceEarlyReturn005a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn005/libforceEarlyReturn005a.cpp new file mode 100644 index 00000000000..5771b777a73 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn005/libforceEarlyReturn005a.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni.h" +#include "nsk_tools.cpp" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_PTR + +#ifdef __cplusplus +#define JNI_ENV_ARG_2(x, y) y +#define JNI_ENV_ARG_3(x,y,z) y, z +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG_2(x,y) x, y +#define JNI_ENV_ARG_3(x,y,z) x, y, z +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +JNIEXPORT void JNICALL +Java_nsk_jdi_ThreadReference_forceEarlyReturn_forceEarlyReturn005_forceEarlyReturn005a_nativeJNIMonitorEnter(JNIEnv *env, jobject classObject, jobject object) +{ + jint success = JNI_ENV_PTR(env)->MonitorEnter(JNI_ENV_ARG_2(env, object)); + + if(success != 0) + { + NSK_COMPLAIN1("MonitorEnter return non-zero: %d\n", success); + + JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG_3(env, JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG_2(env, "nsk/share/TestJNIError")), "MonitorEnter return non-zero")); + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/libforceEarlyReturn002a.c b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/libforceEarlyReturn002a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/libforceEarlyReturn002a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/libforceEarlyReturn002a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/addcaps001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/addcaps001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/addcaps001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/addcaps001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/libaddcaps001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/libaddcaps001.c deleted file mode 100644 index 3bf868c1944..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/libaddcaps001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "addcaps001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/libaddcaps001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/libaddcaps001.cpp new file mode 100644 index 00000000000..b81f04e78fc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps001/libaddcaps001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "addcaps001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/addcaps002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/addcaps002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/addcaps002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/addcaps002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/libaddcaps002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/libaddcaps002.c deleted file mode 100644 index 599bda7f05b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/libaddcaps002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "addcaps002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/libaddcaps002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/libaddcaps002.cpp new file mode 100644 index 00000000000..9498f0da19d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps002/libaddcaps002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "addcaps002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/addcaps003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/addcaps003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/addcaps003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/addcaps003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/libaddcaps003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/libaddcaps003.c deleted file mode 100644 index d0970fa632b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/libaddcaps003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "addcaps003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/libaddcaps003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/libaddcaps003.cpp new file mode 100644 index 00000000000..0aced31abd4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AddCapabilities/addcaps003/libaddcaps003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "addcaps003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/agentonload001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/agentonload001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/agentonload001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/agentonload001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/libagentonload001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/libagentonload001.c deleted file mode 100644 index 38b3c84b77f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/libagentonload001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "agentonload001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/libagentonload001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/libagentonload001.cpp new file mode 100644 index 00000000000..9410b38efa1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload001/libagentonload001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "agentonload001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/agentonload002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/agentonload002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/agentonload002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/agentonload002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/libagentonload002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/libagentonload002.c deleted file mode 100644 index dfd880c0061..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/libagentonload002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "agentonload002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/libagentonload002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/libagentonload002.cpp new file mode 100644 index 00000000000..379b8a2ac45 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/libagentonload002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "agentonload002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/agentonload003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/agentonload003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/agentonload003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/agentonload003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/libagentonload003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/libagentonload003.c deleted file mode 100644 index 1cb0ec80a14..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/libagentonload003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "agentonload003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/libagentonload003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/libagentonload003.cpp new file mode 100644 index 00000000000..7b87d57b7da --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/libagentonload003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "agentonload003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/agentonunload001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/agentonunload001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/agentonunload001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/agentonunload001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/libagentonunload001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/libagentonunload001.c deleted file mode 100644 index 309b724a75b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/libagentonunload001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "agentonunload001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/libagentonunload001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/libagentonunload001.cpp new file mode 100644 index 00000000000..bc402483465 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/libagentonunload001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "agentonunload001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/alloc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/alloc001.c deleted file mode 100644 index 8801ab0f823..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/alloc001.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define FAILED_NO_OOM 3 -#define MAX_CHUNK 1024*1024 - -// Limit total allocations to 8Gb. -// Without this check we will loop forever if the OS does not -// limit virtual memory (this usually happens on mac). -#define MAX_CHUNK_COUNT 8*1024 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_alloc001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_alloc001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_alloc001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_Allocate_alloc001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - size_t size; - void *prev = NULL; - void **mem; - int memCount = 1; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> Null pointer check ...\n"); - } - err = (*jvmti)->Allocate(jvmti, (jlong)1, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s\n", - TranslateError(err)); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - if (printdump == JNI_TRUE) { - printf(">>> Accessibility check ...\n"); - } - for (size = sizeof(mem); size <= MAX_CHUNK; size <<= 1) { - err = (*jvmti)->Allocate(jvmti, size, (unsigned char **)&mem); - if (err == JVMTI_ERROR_NONE) { - memset(mem, 0, size); - *mem = prev; - prev = mem; - } else if (err == JVMTI_ERROR_OUT_OF_MEMORY) { - break; - } else { - printf("(Allocate) Error expected: JVMTI_ERROR_NONE, got: %s\n", - TranslateError(err)); - result = STATUS_FAILED; - break; - } - } - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - if (printdump == JNI_TRUE) { - printf(">>> Out of memory check ...\n"); - } - while (err != JVMTI_ERROR_OUT_OF_MEMORY) { - err = (*jvmti)->Allocate(jvmti, (jlong)MAX_CHUNK, (unsigned char **)&mem); - if (err == JVMTI_ERROR_NONE) { - *mem = prev; - prev = mem; - memCount++; - if (memCount > MAX_CHUNK_COUNT) { - printf("Allocated %dMb. Virtual memory limit too high. Quit to avoid timeout.\n", memCount); - result = FAILED_NO_OOM; - break; - } - } else if (err == JVMTI_ERROR_OUT_OF_MEMORY) { - break; - } else { - printf("Error expected: JVMTI_ERROR_OUT_OF_MEMORY, got: %s\n", - TranslateError(err)); - result = STATUS_FAILED; - break; - } - - if (printdump == JNI_TRUE && (memCount % 50 == 0) ) { - printf(">>> ... done (%dMb)\n", memCount); - } - } - if (printdump == JNI_TRUE) { - printf(">>> ... done (%dMb)\n", memCount); - } - - if (printdump == JNI_TRUE) { - printf(">>> Deallocation ...\n"); - } - while (prev != NULL) { - mem = prev; - prev = *mem; - err = (*jvmti)->Deallocate(jvmti, (unsigned char *)mem); - if (err != JVMTI_ERROR_NONE) { - printf("(Deallocate) Error expected: JVMTI_ERROR_NONE, got: %s\n", - TranslateError(err)); - result = STATUS_FAILED; - break; - } - } - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/alloc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/alloc001.cpp new file mode 100644 index 00000000000..b85f85e1048 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/alloc001.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define FAILED_NO_OOM 3 +#define MAX_CHUNK 1024*1024 + +// Limit total allocations to 8Gb. +// Without this check we will loop forever if the OS does not +// limit virtual memory (this usually happens on mac). +#define MAX_CHUNK_COUNT 8*1024 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_alloc001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_alloc001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_alloc001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_Allocate_alloc001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + size_t size; + void *prev = NULL; + void **mem; + int memCount = 1; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> Null pointer check ...\n"); + } + err = jvmti->Allocate((jlong)1, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s\n", + TranslateError(err)); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + if (printdump == JNI_TRUE) { + printf(">>> Accessibility check ...\n"); + } + for (size = sizeof(mem); size <= MAX_CHUNK; size <<= 1) { + err = jvmti->Allocate(size, (unsigned char **)&mem); + if (err == JVMTI_ERROR_NONE) { + memset(mem, 0, size); + *mem = prev; + prev = mem; + } else if (err == JVMTI_ERROR_OUT_OF_MEMORY) { + break; + } else { + printf("(Allocate) Error expected: JVMTI_ERROR_NONE, got: %s\n", + TranslateError(err)); + result = STATUS_FAILED; + break; + } + } + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + if (printdump == JNI_TRUE) { + printf(">>> Out of memory check ...\n"); + } + while (err != JVMTI_ERROR_OUT_OF_MEMORY) { + err = jvmti->Allocate((jlong)MAX_CHUNK, (unsigned char **)&mem); + if (err == JVMTI_ERROR_NONE) { + *mem = prev; + prev = mem; + memCount++; + if (memCount > MAX_CHUNK_COUNT) { + printf("Allocated %dMb. Virtual memory limit too high. Quit to avoid timeout.\n", memCount); + result = FAILED_NO_OOM; + break; + } + } else if (err == JVMTI_ERROR_OUT_OF_MEMORY) { + break; + } else { + printf("Error expected: JVMTI_ERROR_OUT_OF_MEMORY, got: %s\n", + TranslateError(err)); + result = STATUS_FAILED; + break; + } + + if (printdump == JNI_TRUE && (memCount % 50 == 0) ) { + printf(">>> ... done (%dMb)\n", memCount); + } + } + if (printdump == JNI_TRUE) { + printf(">>> ... done (%dMb)\n", memCount); + } + + if (printdump == JNI_TRUE) { + printf(">>> Deallocation ...\n"); + } + while (prev != NULL) { + mem = (void**) prev; + prev = *mem; + err = jvmti->Deallocate((unsigned char *)mem); + if (err != JVMTI_ERROR_NONE) { + printf("(Deallocate) Error expected: JVMTI_ERROR_NONE, got: %s\n", + TranslateError(err)); + result = STATUS_FAILED; + break; + } + } + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/liballoc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/liballoc001.c deleted file mode 100644 index d4ae6b52fdd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/liballoc001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "alloc001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/liballoc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/liballoc001.cpp new file mode 100644 index 00000000000..6e8e48cbea4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/liballoc001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "alloc001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/attach002Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/attach002Agent00.c deleted file mode 100644 index d9a1e777c27..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/attach002Agent00.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Expected agent work scenario: - * - receive ClassFileLoadHook event for class 'ClassToRedefine' - * - receive ClassLoad event for class 'ClassToRedefine' and redefine class from ClassLoad event handler - * - receive one more ClassFileLoadHook event for class 'ClassToRedefine' - * - receive ClassPrepare event for class 'ClassToRedefine' and finish work - */ - -#define REDEFINED_CLASS_NAME "Lnsk/jvmti/AttachOnDemand/attach002/ClassToRedefine;" -#define REDEFINED_CLASS_FILE_NAME "nsk/jvmti/AttachOnDemand/attach002/ClassToRedefine" - -// class name in the ClassFileLoadHook callback -#define REDEFINED_CLASS_NAME_INTERNAL "nsk/jvmti/AttachOnDemand/attach002/ClassToRedefine" - -static Options* options = NULL; -static const char* agentName; - -static volatile jboolean agentGotCapabilities = JNI_FALSE; - -static jvmtiEvent testEvents[] = { - JVMTI_EVENT_CLASS_LOAD, - JVMTI_EVENT_CLASS_PREPARE, - JVMTI_EVENT_CLASS_FILE_LOAD_HOOK}; - -static const int testEventsNumber = 3; - -static volatile int classLoadReceived = 0; -static volatile int classFileLoadHookReceived = 0; - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_AttachOnDemand_attach002_attach002Target_agentGotCapabilities(JNIEnv * jni, - jclass klass, jobject obj) { - return agentGotCapabilities; -} - -#define ATTACH002_TARGET_APP_CLASS_NAME "nsk/jvmti/AttachOnDemand/attach002/attach002Target" - -int registerNativeMethods(JNIEnv* jni) { - jclass appClass; - JNINativeMethod nativeMethods[] = { - {"agentGotCapabilities", "()Z", (void*) Java_nsk_jvmti_AttachOnDemand_attach002_attach002Target_agentGotCapabilities}}; - jint nativeMethodsNumber = 1; - - if (!NSK_JNI_VERIFY(jni, (appClass = - NSK_CPP_STUB2(FindClass, jni, ATTACH002_TARGET_APP_CLASS_NAME)) != NULL)) { - return NSK_FALSE; - } - - if (!NSK_JNI_VERIFY(jni, - (NSK_CPP_STUB4(RegisterNatives, jni, appClass, nativeMethods, nativeMethodsNumber) == 0))) { - return NSK_FALSE; - } - - return NSK_TRUE; -} - -void JNICALL classLoadHandler( - jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread, - jclass klass) { - char className[MAX_STRING_LENGTH]; - - if (!nsk_jvmti_aod_getClassName(jvmti, klass, className)) { - nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni); - return; - } - - NSK_DISPLAY2("%s: ClassLoad event was received for class '%s'\n", agentName, className); - - if (!strcmp(className, REDEFINED_CLASS_NAME)) { - - classLoadReceived = 1; - - NSK_DISPLAY1("%s: redefining class\n", agentName); - - if (!NSK_VERIFY(nsk_jvmti_aod_redefineClass(options, jvmti, klass, REDEFINED_CLASS_FILE_NAME))) { - NSK_COMPLAIN1("%s: failed to redefine class\n", agentName); - nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni); - } - } -} - -void JNICALL classPrepareHandler( - jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread, - jclass klass) { - char className[MAX_STRING_LENGTH]; - - if (!nsk_jvmti_aod_getClassName(jvmti, klass, className)) { - nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni); - return; - } - - NSK_DISPLAY2("%s: ClassPrepare event received for class '%s'\n", agentName, REDEFINED_CLASS_NAME); - - if (!strcmp(className, REDEFINED_CLASS_NAME)) { - int success = 1; - - if (!classLoadReceived) { - success = 0; - NSK_COMPLAIN2("%s: expected ClassLoad event wasn't received for class '%s'\n", agentName, REDEFINED_CLASS_NAME); - } - - /* - * ClassFileLoadHook event should be received twice - when class is loaded and when class is redefined - */ - if (classFileLoadHookReceived != 2) { - success = 0; - NSK_COMPLAIN2("%s: expected ClassFileLoadHook event wasn't received for class '%s'\n", agentName, REDEFINED_CLASS_NAME); - } - - nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, success, jvmti, jni); - } -} - -void JNICALL classFileLoadHoockHandler( - jvmtiEnv * jvmti, - JNIEnv * jni, - jclass class_beeing_redefined, - jobject loader, - const char * name, - jobject protection_domain, - jint class_data_len, - const unsigned char * class_data, - jint * new_class_data_len, - unsigned char** new_class_data) { - - if (name != NULL) { - NSK_DISPLAY2("%s: ClassFileLoadHook event received for class '%s'\n", agentName, name); - if (!strcmp(name, REDEFINED_CLASS_NAME_INTERNAL)) { - classFileLoadHookReceived++; - } - } else { - NSK_DISPLAY1("%s: ClassFileLoadHook event received for class with NULL name\n", agentName); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNI_OnLoad_attach002Agent00(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif - -JNIEXPORT jint JNICALL -#ifdef STATIC_BUILD -Agent_OnAttach_attach002Agent00(JavaVM *vm, char *optionsString, void *reserved) -#else -Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) -#endif -{ - jvmtiEventCallbacks eventCallbacks; - jvmtiCapabilities caps; - jvmtiEnv* jvmti = NULL; - JNIEnv* jni = NULL; - - if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL)) - return JNI_ERR; - - agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION); - - if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL) - return NSK_FALSE; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_VERIFY(registerNativeMethods(jni))) { - return JNI_ERR; - } - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_all_class_hook_events = 1; - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)) ) { - /* - * If VM is run with -Xshare:on agent can't get required capabilities (see 6718407) - */ - NSK_DISPLAY1("%s: warning: agent failed to get required capabilities, agent finishing\n", agentName); - - if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) - return JNI_ERR; - - nsk_aod_agentFinished(jni, agentName, 1); - } else { - agentGotCapabilities = JNI_TRUE; - - memset(&eventCallbacks,0, sizeof(eventCallbacks)); - eventCallbacks.ClassLoad = classLoadHandler; - eventCallbacks.ClassPrepare = classPrepareHandler; - eventCallbacks.ClassFileLoadHook = classFileLoadHoockHandler; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &eventCallbacks, sizeof(eventCallbacks))) ) { - return JNI_ERR; - } - - if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) { - return JNI_ERR; - } - - NSK_DISPLAY1("%s: initialization was done\n", agentName); - - if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) - return JNI_ERR; - } - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/attach002Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/attach002Agent00.cpp new file mode 100644 index 00000000000..f5b24864de6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/attach002Agent00.cpp @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Expected agent work scenario: + * - receive ClassFileLoadHook event for class 'ClassToRedefine' + * - receive ClassLoad event for class 'ClassToRedefine' and redefine class from ClassLoad event handler + * - receive one more ClassFileLoadHook event for class 'ClassToRedefine' + * - receive ClassPrepare event for class 'ClassToRedefine' and finish work + */ + +#define REDEFINED_CLASS_NAME "Lnsk/jvmti/AttachOnDemand/attach002/ClassToRedefine;" +#define REDEFINED_CLASS_FILE_NAME "nsk/jvmti/AttachOnDemand/attach002/ClassToRedefine" + +// class name in the ClassFileLoadHook callback +#define REDEFINED_CLASS_NAME_INTERNAL "nsk/jvmti/AttachOnDemand/attach002/ClassToRedefine" + +static Options* options = NULL; +static const char* agentName; + +static volatile jboolean agentGotCapabilities = JNI_FALSE; + +static jvmtiEvent testEvents[] = { + JVMTI_EVENT_CLASS_LOAD, + JVMTI_EVENT_CLASS_PREPARE, + JVMTI_EVENT_CLASS_FILE_LOAD_HOOK}; + +static const int testEventsNumber = 3; + +static volatile int classLoadReceived = 0; +static volatile int classFileLoadHookReceived = 0; + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_AttachOnDemand_attach002_attach002Target_agentGotCapabilities(JNIEnv * jni, + jclass klass, jobject obj) { + return agentGotCapabilities; +} + +#define ATTACH002_TARGET_APP_CLASS_NAME "nsk/jvmti/AttachOnDemand/attach002/attach002Target" + +int registerNativeMethods(JNIEnv* jni) { + jclass appClass; + JNINativeMethod nativeMethods[] = { + {(char*) "agentGotCapabilities", (char*) "()Z", (void*) Java_nsk_jvmti_AttachOnDemand_attach002_attach002Target_agentGotCapabilities}}; + jint nativeMethodsNumber = 1; + + if (!NSK_JNI_VERIFY(jni, (appClass = + NSK_CPP_STUB2(FindClass, jni, ATTACH002_TARGET_APP_CLASS_NAME)) != NULL)) { + return NSK_FALSE; + } + + if (!NSK_JNI_VERIFY(jni, + (NSK_CPP_STUB4(RegisterNatives, jni, appClass, nativeMethods, nativeMethodsNumber) == 0))) { + return NSK_FALSE; + } + + return NSK_TRUE; +} + +void JNICALL classLoadHandler( + jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread, + jclass klass) { + char className[MAX_STRING_LENGTH]; + + if (!nsk_jvmti_aod_getClassName(jvmti, klass, className)) { + nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni); + return; + } + + NSK_DISPLAY2("%s: ClassLoad event was received for class '%s'\n", agentName, className); + + if (!strcmp(className, REDEFINED_CLASS_NAME)) { + + classLoadReceived = 1; + + NSK_DISPLAY1("%s: redefining class\n", agentName); + + if (!NSK_VERIFY(nsk_jvmti_aod_redefineClass(options, jvmti, klass, REDEFINED_CLASS_FILE_NAME))) { + NSK_COMPLAIN1("%s: failed to redefine class\n", agentName); + nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni); + } + } +} + +void JNICALL classPrepareHandler( + jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread, + jclass klass) { + char className[MAX_STRING_LENGTH]; + + if (!nsk_jvmti_aod_getClassName(jvmti, klass, className)) { + nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni); + return; + } + + NSK_DISPLAY2("%s: ClassPrepare event received for class '%s'\n", agentName, REDEFINED_CLASS_NAME); + + if (!strcmp(className, REDEFINED_CLASS_NAME)) { + int success = 1; + + if (!classLoadReceived) { + success = 0; + NSK_COMPLAIN2("%s: expected ClassLoad event wasn't received for class '%s'\n", agentName, REDEFINED_CLASS_NAME); + } + + /* + * ClassFileLoadHook event should be received twice - when class is loaded and when class is redefined + */ + if (classFileLoadHookReceived != 2) { + success = 0; + NSK_COMPLAIN2("%s: expected ClassFileLoadHook event wasn't received for class '%s'\n", agentName, REDEFINED_CLASS_NAME); + } + + nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, success, jvmti, jni); + } +} + +void JNICALL classFileLoadHoockHandler( + jvmtiEnv * jvmti, + JNIEnv * jni, + jclass class_beeing_redefined, + jobject loader, + const char * name, + jobject protection_domain, + jint class_data_len, + const unsigned char * class_data, + jint * new_class_data_len, + unsigned char** new_class_data) { + + if (name != NULL) { + NSK_DISPLAY2("%s: ClassFileLoadHook event received for class '%s'\n", agentName, name); + if (!strcmp(name, REDEFINED_CLASS_NAME_INTERNAL)) { + classFileLoadHookReceived++; + } + } else { + NSK_DISPLAY1("%s: ClassFileLoadHook event received for class with NULL name\n", agentName); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNI_OnLoad_attach002Agent00(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif + +JNIEXPORT jint JNICALL +#ifdef STATIC_BUILD +Agent_OnAttach_attach002Agent00(JavaVM *vm, char *optionsString, void *reserved) +#else +Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) +#endif +{ + jvmtiEventCallbacks eventCallbacks; + jvmtiCapabilities caps; + jvmtiEnv* jvmti = NULL; + JNIEnv* jni = NULL; + + if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL)) + return JNI_ERR; + + agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION); + + if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL) + return NSK_FALSE; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_VERIFY(registerNativeMethods(jni))) { + return JNI_ERR; + } + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_all_class_hook_events = 1; + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)) ) { + /* + * If VM is run with -Xshare:on agent can't get required capabilities (see 6718407) + */ + NSK_DISPLAY1("%s: warning: agent failed to get required capabilities, agent finishing\n", agentName); + + if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) + return JNI_ERR; + + nsk_aod_agentFinished(jni, agentName, 1); + } else { + agentGotCapabilities = JNI_TRUE; + + memset(&eventCallbacks,0, sizeof(eventCallbacks)); + eventCallbacks.ClassLoad = classLoadHandler; + eventCallbacks.ClassPrepare = classPrepareHandler; + eventCallbacks.ClassFileLoadHook = classFileLoadHoockHandler; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &eventCallbacks, sizeof(eventCallbacks))) ) { + return JNI_ERR; + } + + if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) { + return JNI_ERR; + } + + NSK_DISPLAY1("%s: initialization was done\n", agentName); + + if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/libattach002Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/libattach002Agent00.c deleted file mode 100644 index f5ab80a80ec..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/libattach002Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach002Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/libattach002Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/libattach002Agent00.cpp new file mode 100644 index 00000000000..ccd04677a3d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/libattach002Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach002Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/attach002aAgent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/attach002aAgent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/attach002aAgent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/attach002aAgent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/libattach002aAgent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/libattach002aAgent00.c deleted file mode 100644 index f3f1eeff04b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/libattach002aAgent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach002aAgent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/libattach002aAgent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/libattach002aAgent00.cpp new file mode 100644 index 00000000000..40cccb23efc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/libattach002aAgent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach002aAgent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/attach008Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/attach008Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/attach008Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/attach008Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/libattach008Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/libattach008Agent00.c deleted file mode 100644 index 3ab75360c1a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/libattach008Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach008Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/libattach008Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/libattach008Agent00.cpp new file mode 100644 index 00000000000..914edfc60a9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach008/libattach008Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach008Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/attach009Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/attach009Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/attach009Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/attach009Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/libattach009Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/libattach009Agent00.c deleted file mode 100644 index ae3e90ecb2a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/libattach009Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach009Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/libattach009Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/libattach009Agent00.cpp new file mode 100644 index 00000000000..4f911d5e2ff --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/libattach009Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach009Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/attach012Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/attach012Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/attach012Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/attach012Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/libattach012Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/libattach012Agent00.c deleted file mode 100644 index 52d10445c7e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/libattach012Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach012Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/libattach012Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/libattach012Agent00.cpp new file mode 100644 index 00000000000..12a9b48a8a7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/libattach012Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach012Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/attach014Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/attach014Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/attach014Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/attach014Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/libattach014Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/libattach014Agent00.c deleted file mode 100644 index 87affcfa800..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/libattach014Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach014Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/libattach014Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/libattach014Agent00.cpp new file mode 100644 index 00000000000..8b2c25f0a78 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach014/libattach014Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach014Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/attach015Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/attach015Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/attach015Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/attach015Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/attach015Agent01.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/attach015Agent01.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/attach015Agent01.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/attach015Agent01.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/attach015Target.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/attach015Target.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/attach015Target.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/attach015Target.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent00.c deleted file mode 100644 index bc77c492a4c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach015Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent00.cpp new file mode 100644 index 00000000000..4def9706d85 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach015Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent01.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent01.c deleted file mode 100644 index 0cd7df3bfbd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent01.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach015Agent01.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent01.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent01.cpp new file mode 100644 index 00000000000..ee8a77b0790 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Agent01.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach015Agent01.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Target.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Target.c deleted file mode 100644 index 549c5b04791..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Target.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach015Target.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Target.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Target.cpp new file mode 100644 index 00000000000..4b7eba8c58a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach015/libattach015Target.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach015Target.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/attach020Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/attach020Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/attach020Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/attach020Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/libattach020Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/libattach020Agent00.c deleted file mode 100644 index 610482ccbcd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/libattach020Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach020Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/libattach020Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/libattach020Agent00.cpp new file mode 100644 index 00000000000..c50bacfa6d8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/libattach020Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach020Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/attach021Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/attach021Agent00.c deleted file mode 100644 index f66ebf2174e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/attach021Agent00.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Expected agent work scenario: - * - during initialization agent registers native methods used be target application and enables ObjectFree events - * - target application using native method and agent's jvmti environment tags object and provokes collection - * of this object - * - agent receives ObjectFree event for tagged object - * - target application using native method calls nsk_aod_agentFinished and agent finishes work - * (agent can't call nsk_aod_agentFinished from ObjectFree handler, nsk_aod_agentFinished calls - * JNI functions and it is prohibited in ObjectFree handler) - * - */ - -#define TAG_VALUE (jlong)777 -#define ATTACH021_TARGET_APP_CLASS_NAME "nsk/jvmti/AttachOnDemand/attach021/attach021Target" - -static jvmtiEnv* jvmti; - -static Options* options = NULL; -static const char* agentName; - -// agent should set success status from objectFreeHandler -volatile int success = 0; - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_AttachOnDemand_attach021_attach021Target_setTagFor(JNIEnv * jni, - jclass klass, jobject obj) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, obj, TAG_VALUE))) { - return JNI_FALSE; - } - - NSK_DISPLAY2("%s: object is tagged (tag: %ld)\n", agentName, TAG_VALUE); - - return JNI_TRUE; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_AttachOnDemand_attach021_attach021Target_shutdownAgent(JNIEnv * jni, - jclass klass) { - nsk_jvmti_aod_disableEventAndFinish(agentName, JVMTI_EVENT_OBJECT_FREE, success, jvmti, jni); -} - -void JNICALL objectFreeHandler(jvmtiEnv *jvmti, jlong tag) { - NSK_DISPLAY2("%s: object free event for object %ld\n", agentName, tag); - - if (tag != TAG_VALUE) { - success = 0; - NSK_COMPLAIN2("%s: unexpected tag value, expected is %ld\n", agentName, TAG_VALUE); - } else { - success = 1; - } - - /* - * Can't use JNI functions from ObjectFree event handler, in this test target application calls - * function nsk_aod_agentFinished - */ -} - -int registerNativeMethods(JNIEnv* jni) { - jclass appClass; - JNINativeMethod nativeMethods[] = { - {"setTagFor", "(Ljava/lang/Object;)Z", (void*) Java_nsk_jvmti_AttachOnDemand_attach021_attach021Target_setTagFor}, - {"shutdownAgent", "()V", (void*) Java_nsk_jvmti_AttachOnDemand_attach021_attach021Target_shutdownAgent}}; - jint nativeMethodsNumber = 2; - - if (!NSK_JNI_VERIFY(jni, (appClass = - NSK_CPP_STUB2(FindClass, jni, ATTACH021_TARGET_APP_CLASS_NAME)) != NULL)) { - return NSK_FALSE; - } - - if (!NSK_JNI_VERIFY(jni, - (NSK_CPP_STUB4(RegisterNatives, jni, appClass, nativeMethods, nativeMethodsNumber) == 0))) { - return NSK_FALSE; - } - - return NSK_TRUE; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNI_OnLoad_attach021Agent00(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif - -JNIEXPORT jint JNICALL -#ifdef STATIC_BUILD -Agent_OnAttach_attach021Agent00(JavaVM *vm, char *optionsString, void *reserved) -#else -Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) -#endif -{ - jvmtiEventCallbacks eventCallbacks; - jvmtiCapabilities caps; - JNIEnv* jni; - - if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL)) - return JNI_ERR; - - agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION); - - if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_VERIFY(registerNativeMethods(jni))) { - return JNI_ERR; - } - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - caps.can_generate_object_free_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)) ) { - return JNI_ERR; - } - - memset(&eventCallbacks,0, sizeof(eventCallbacks)); - eventCallbacks.ObjectFree = objectFreeHandler; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &eventCallbacks, sizeof(eventCallbacks))) ) { - return JNI_ERR; - } - - if (!(nsk_jvmti_aod_enableEvent(jvmti, JVMTI_EVENT_OBJECT_FREE))) { - return JNI_ERR; - } - - NSK_DISPLAY1("%s: initialization was done\n", agentName); - - if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) - return JNI_ERR; - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/attach021Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/attach021Agent00.cpp new file mode 100644 index 00000000000..203c06c55c0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/attach021Agent00.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Expected agent work scenario: + * - during initialization agent registers native methods used be target application and enables ObjectFree events + * - target application using native method and agent's jvmti environment tags object and provokes collection + * of this object + * - agent receives ObjectFree event for tagged object + * - target application using native method calls nsk_aod_agentFinished and agent finishes work + * (agent can't call nsk_aod_agentFinished from ObjectFree handler, nsk_aod_agentFinished calls + * JNI functions and it is prohibited in ObjectFree handler) + * + */ + +#define TAG_VALUE (jlong)777 +#define ATTACH021_TARGET_APP_CLASS_NAME "nsk/jvmti/AttachOnDemand/attach021/attach021Target" + +static jvmtiEnv* jvmti; + +static Options* options = NULL; +static const char* agentName; + +// agent should set success status from objectFreeHandler +volatile int success = 0; + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_AttachOnDemand_attach021_attach021Target_setTagFor(JNIEnv * jni, + jclass klass, jobject obj) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, obj, TAG_VALUE))) { + return JNI_FALSE; + } + + NSK_DISPLAY2("%s: object is tagged (tag: %ld)\n", agentName, TAG_VALUE); + + return JNI_TRUE; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_AttachOnDemand_attach021_attach021Target_shutdownAgent(JNIEnv * jni, + jclass klass) { + nsk_jvmti_aod_disableEventAndFinish(agentName, JVMTI_EVENT_OBJECT_FREE, success, jvmti, jni); +} + +void JNICALL objectFreeHandler(jvmtiEnv *jvmti, jlong tag) { + NSK_DISPLAY2("%s: object free event for object %ld\n", agentName, tag); + + if (tag != TAG_VALUE) { + success = 0; + NSK_COMPLAIN2("%s: unexpected tag value, expected is %ld\n", agentName, TAG_VALUE); + } else { + success = 1; + } + + /* + * Can't use JNI functions from ObjectFree event handler, in this test target application calls + * function nsk_aod_agentFinished + */ +} + +int registerNativeMethods(JNIEnv* jni) { + jclass appClass; + JNINativeMethod nativeMethods[] = { + {(char*) "setTagFor", (char*) "(Ljava/lang/Object;)Z", (void*) Java_nsk_jvmti_AttachOnDemand_attach021_attach021Target_setTagFor}, + {(char*) "shutdownAgent", (char*) "()V", (void*) Java_nsk_jvmti_AttachOnDemand_attach021_attach021Target_shutdownAgent}}; + jint nativeMethodsNumber = 2; + + if (!NSK_JNI_VERIFY(jni, (appClass = + NSK_CPP_STUB2(FindClass, jni, ATTACH021_TARGET_APP_CLASS_NAME)) != NULL)) { + return NSK_FALSE; + } + + if (!NSK_JNI_VERIFY(jni, + (NSK_CPP_STUB4(RegisterNatives, jni, appClass, nativeMethods, nativeMethodsNumber) == 0))) { + return NSK_FALSE; + } + + return NSK_TRUE; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNI_OnLoad_attach021Agent00(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif + +JNIEXPORT jint JNICALL +#ifdef STATIC_BUILD +Agent_OnAttach_attach021Agent00(JavaVM *vm, char *optionsString, void *reserved) +#else +Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) +#endif +{ + jvmtiEventCallbacks eventCallbacks; + jvmtiCapabilities caps; + JNIEnv* jni; + + if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL)) + return JNI_ERR; + + agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION); + + if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_VERIFY(registerNativeMethods(jni))) { + return JNI_ERR; + } + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + caps.can_generate_object_free_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)) ) { + return JNI_ERR; + } + + memset(&eventCallbacks,0, sizeof(eventCallbacks)); + eventCallbacks.ObjectFree = objectFreeHandler; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &eventCallbacks, sizeof(eventCallbacks))) ) { + return JNI_ERR; + } + + if (!(nsk_jvmti_aod_enableEvent(jvmti, JVMTI_EVENT_OBJECT_FREE))) { + return JNI_ERR; + } + + NSK_DISPLAY1("%s: initialization was done\n", agentName); + + if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/libattach021Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/libattach021Agent00.c deleted file mode 100644 index 5ffc70a0baf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/libattach021Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach021Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/libattach021Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/libattach021Agent00.cpp new file mode 100644 index 00000000000..07358b0fea9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/libattach021Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach021Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/attach022Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/attach022Agent00.c deleted file mode 100644 index e057dd1c4a2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/attach022Agent00.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define OBJECTS_FOR_ALLOCATION_TEST_CLASS_NAME "Lnsk/jvmti/AttachOnDemand/attach022/ClassForAllocationEventsTest;" - -static jvmtiEnv* jvmti; -static Options* options = NULL; -static const char* agentName; - -static jvmtiEvent testEvents[] = {JVMTI_EVENT_OBJECT_FREE, JVMTI_EVENT_VM_OBJECT_ALLOC}; -static const int testEventsNumber = 2; - -static volatile int taggedObjectsCounter = 0; -static volatile int freedObjectsCounter = 0; - -static jrawMonitorID objectTagMonitor; -static jrawMonitorID objectFreeMonitor; - -volatile int success = 1; - -volatile int agentFinished; - -void shutdownAgent(JNIEnv* jni) { - if (agentFinished) - return; - - if (!nsk_jvmti_aod_disableEvents(jvmti, testEvents, testEventsNumber)) - success = 0; - - nsk_aod_agentFinished(jni, agentName, success); - - agentFinished = 1; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_AttachOnDemand_attach022_attach022Target_shutdownAgent(JNIEnv * jni, - jclass klass, jint expectedTaggedObjectsCounter) { - - if (taggedObjectsCounter != expectedTaggedObjectsCounter) { - success = 0; - NSK_COMPLAIN2("ERROR: unexpected taggedObjectsCounter: %d (expected value is %d)\n", taggedObjectsCounter, expectedTaggedObjectsCounter); - } - - if (taggedObjectsCounter != freedObjectsCounter) { - success = 0; - NSK_COMPLAIN2("ERROR: taggedObjectsCounter != freedObjectsCounter (taggedObjectsCounter: %d, freedObjectsCounter: %d)\n", - taggedObjectsCounter, freedObjectsCounter); - } - - shutdownAgent(jni); - - return success ? JNI_TRUE : JNI_FALSE; -} - -void JNICALL objectFreeHandler(jvmtiEnv *jvmti, jlong tag) { - NSK_DISPLAY2("%s: ObjectFree event received (object tag: %ld)\n", agentName, tag); - - if (NSK_JVMTI_VERIFY(NSK_CPP_STUB2( - RawMonitorEnter, jvmti, objectFreeMonitor))) { - - freedObjectsCounter++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, objectFreeMonitor))) { - success = 0; - } - } else { - success = 0; - } -} - -#define ATTACH022_TARGET_APP_CLASS_NAME "nsk/jvmti/AttachOnDemand/attach022/attach022Target" - -int registerNativeMethods(JNIEnv* jni) { - jclass appClass; - JNINativeMethod nativeMethods[] = { - {"shutdownAgent", "(I)Z", (void*) Java_nsk_jvmti_AttachOnDemand_attach022_attach022Target_shutdownAgent}}; - jint nativeMethodsNumber = 1; - - if (!NSK_JNI_VERIFY(jni, (appClass = - NSK_CPP_STUB2(FindClass, jni, ATTACH022_TARGET_APP_CLASS_NAME)) != NULL)) { - return NSK_FALSE; - } - - if (!NSK_JNI_VERIFY(jni, - (NSK_CPP_STUB4(RegisterNatives, jni, appClass, nativeMethods, nativeMethodsNumber) == 0))) { - return NSK_FALSE; - } - - return NSK_TRUE; -} - -void JNICALL vmObjectAllocHandler(jvmtiEnv * jvmti, - JNIEnv * jni, - jthread thread, - jobject object, - jclass object_class, - jlong size) { - char className[MAX_STRING_LENGTH]; - - if (!nsk_jvmti_aod_getClassName(jvmti, object_class, className)) { - success = 0; - shutdownAgent(jni); - return; - } - - NSK_DISPLAY2("%s: ObjectAlloc event received (object class: %s)\n", agentName, className); - - if (!strcmp(className, OBJECTS_FOR_ALLOCATION_TEST_CLASS_NAME)) { - if (NSK_JVMTI_VERIFY(NSK_CPP_STUB2( - RawMonitorEnter, jvmti, objectTagMonitor))) { - jlong tagValue = taggedObjectsCounter + 1; - - - if (!NSK_JVMTI_VERIFY( NSK_CPP_STUB3(SetTag, jvmti, object, tagValue))) { - NSK_COMPLAIN1("%s: failed to set tag\n", agentName); - success = 0; - } else { - NSK_DISPLAY2("%s: object was tagged (tag value: %ld)\n", agentName, tagValue); - taggedObjectsCounter++; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, objectTagMonitor))) { - success = 0; - } - } else { - success = 0; - } - } - - if (!success) { - NSK_COMPLAIN1("%s: error happened during agent work, stop agent\n", agentName); - shutdownAgent(jni); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNI_OnLoad_attach022Agent00(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif - -JNIEXPORT jint JNICALL -#ifdef STATIC_BUILD -Agent_OnAttach_attach022Agent00(JavaVM *vm, char *optionsString, void *reserved) -#else -Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) -#endif -{ - jvmtiEventCallbacks eventCallbacks; - jvmtiCapabilities caps; - JNIEnv* jni; - - if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL)) - return JNI_ERR; - - agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION); - - if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_VERIFY(registerNativeMethods(jni))) { - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "ObjectTagMonitor", &objectTagMonitor))) { - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "ObjectFreeMonitor", &objectFreeMonitor))) { - return JNI_ERR; - } - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - caps.can_generate_object_free_events = 1; - caps.can_generate_vm_object_alloc_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)) ) { - return JNI_ERR; - } - - memset(&eventCallbacks,0, sizeof(eventCallbacks)); - eventCallbacks.ObjectFree = objectFreeHandler; - eventCallbacks.VMObjectAlloc = vmObjectAllocHandler; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &eventCallbacks, sizeof(eventCallbacks))) ) { - return JNI_ERR; - } - - if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) { - return JNI_ERR; - } - - NSK_DISPLAY1("%s: initialization was done\n", agentName); - - if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) - return JNI_ERR; - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/attach022Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/attach022Agent00.cpp new file mode 100644 index 00000000000..e29da3ef132 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/attach022Agent00.cpp @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define OBJECTS_FOR_ALLOCATION_TEST_CLASS_NAME "Lnsk/jvmti/AttachOnDemand/attach022/ClassForAllocationEventsTest;" + +static jvmtiEnv* jvmti; +static Options* options = NULL; +static const char* agentName; + +static jvmtiEvent testEvents[] = {JVMTI_EVENT_OBJECT_FREE, JVMTI_EVENT_VM_OBJECT_ALLOC}; +static const int testEventsNumber = 2; + +static volatile int taggedObjectsCounter = 0; +static volatile int freedObjectsCounter = 0; + +static jrawMonitorID objectTagMonitor; +static jrawMonitorID objectFreeMonitor; + +volatile int success = 1; + +volatile int agentFinished; + +void shutdownAgent(JNIEnv* jni) { + if (agentFinished) + return; + + if (!nsk_jvmti_aod_disableEvents(jvmti, testEvents, testEventsNumber)) + success = 0; + + nsk_aod_agentFinished(jni, agentName, success); + + agentFinished = 1; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_AttachOnDemand_attach022_attach022Target_shutdownAgent(JNIEnv * jni, + jclass klass, jint expectedTaggedObjectsCounter) { + + if (taggedObjectsCounter != expectedTaggedObjectsCounter) { + success = 0; + NSK_COMPLAIN2("ERROR: unexpected taggedObjectsCounter: %d (expected value is %d)\n", taggedObjectsCounter, expectedTaggedObjectsCounter); + } + + if (taggedObjectsCounter != freedObjectsCounter) { + success = 0; + NSK_COMPLAIN2("ERROR: taggedObjectsCounter != freedObjectsCounter (taggedObjectsCounter: %d, freedObjectsCounter: %d)\n", + taggedObjectsCounter, freedObjectsCounter); + } + + shutdownAgent(jni); + + return success ? JNI_TRUE : JNI_FALSE; +} + +void JNICALL objectFreeHandler(jvmtiEnv *jvmti, jlong tag) { + NSK_DISPLAY2("%s: ObjectFree event received (object tag: %ld)\n", agentName, tag); + + if (NSK_JVMTI_VERIFY(NSK_CPP_STUB2( + RawMonitorEnter, jvmti, objectFreeMonitor))) { + + freedObjectsCounter++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, objectFreeMonitor))) { + success = 0; + } + } else { + success = 0; + } +} + +#define ATTACH022_TARGET_APP_CLASS_NAME "nsk/jvmti/AttachOnDemand/attach022/attach022Target" + +int registerNativeMethods(JNIEnv* jni) { + jclass appClass; + JNINativeMethod nativeMethods[] = { + {(char*)"shutdownAgent", (char*)"(I)Z", + (void*) Java_nsk_jvmti_AttachOnDemand_attach022_attach022Target_shutdownAgent}}; + jint nativeMethodsNumber = 1; + + if (!NSK_JNI_VERIFY(jni, (appClass = + NSK_CPP_STUB2(FindClass, jni, ATTACH022_TARGET_APP_CLASS_NAME)) != NULL)) { + return NSK_FALSE; + } + + if (!NSK_JNI_VERIFY(jni, + (NSK_CPP_STUB4(RegisterNatives, jni, appClass, nativeMethods, nativeMethodsNumber) == 0))) { + return NSK_FALSE; + } + + return NSK_TRUE; +} + +void JNICALL vmObjectAllocHandler(jvmtiEnv * jvmti, + JNIEnv * jni, + jthread thread, + jobject object, + jclass object_class, + jlong size) { + char className[MAX_STRING_LENGTH]; + + if (!nsk_jvmti_aod_getClassName(jvmti, object_class, className)) { + success = 0; + shutdownAgent(jni); + return; + } + + NSK_DISPLAY2("%s: ObjectAlloc event received (object class: %s)\n", agentName, className); + + if (!strcmp(className, OBJECTS_FOR_ALLOCATION_TEST_CLASS_NAME)) { + if (NSK_JVMTI_VERIFY(NSK_CPP_STUB2( + RawMonitorEnter, jvmti, objectTagMonitor))) { + jlong tagValue = taggedObjectsCounter + 1; + + + if (!NSK_JVMTI_VERIFY( NSK_CPP_STUB3(SetTag, jvmti, object, tagValue))) { + NSK_COMPLAIN1("%s: failed to set tag\n", agentName); + success = 0; + } else { + NSK_DISPLAY2("%s: object was tagged (tag value: %ld)\n", agentName, tagValue); + taggedObjectsCounter++; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, objectTagMonitor))) { + success = 0; + } + } else { + success = 0; + } + } + + if (!success) { + NSK_COMPLAIN1("%s: error happened during agent work, stop agent\n", agentName); + shutdownAgent(jni); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNI_OnLoad_attach022Agent00(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif + +JNIEXPORT jint JNICALL +#ifdef STATIC_BUILD +Agent_OnAttach_attach022Agent00(JavaVM *vm, char *optionsString, void *reserved) +#else +Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) +#endif +{ + jvmtiEventCallbacks eventCallbacks; + jvmtiCapabilities caps; + JNIEnv* jni; + + if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL)) + return JNI_ERR; + + agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION); + + if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_VERIFY(registerNativeMethods(jni))) { + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "ObjectTagMonitor", &objectTagMonitor))) { + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "ObjectFreeMonitor", &objectFreeMonitor))) { + return JNI_ERR; + } + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + caps.can_generate_object_free_events = 1; + caps.can_generate_vm_object_alloc_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)) ) { + return JNI_ERR; + } + + memset(&eventCallbacks,0, sizeof(eventCallbacks)); + eventCallbacks.ObjectFree = objectFreeHandler; + eventCallbacks.VMObjectAlloc = vmObjectAllocHandler; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &eventCallbacks, sizeof(eventCallbacks))) ) { + return JNI_ERR; + } + + if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) { + return JNI_ERR; + } + + NSK_DISPLAY1("%s: initialization was done\n", agentName); + + if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/libattach022Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/libattach022Agent00.c deleted file mode 100644 index 1cb8dce1426..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/libattach022Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach022Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/libattach022Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/libattach022Agent00.cpp new file mode 100644 index 00000000000..f918b76ca1b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/libattach022Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach022Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/attach037Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/attach037Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/attach037Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/attach037Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/libattach037Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/libattach037Agent00.c deleted file mode 100644 index a04d33a56fa..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/libattach037Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach037Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/libattach037Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/libattach037Agent00.cpp new file mode 100644 index 00000000000..89419e5aa24 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach037/libattach037Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach037Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/attach038Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/attach038Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/attach038Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/attach038Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/libattach038Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/libattach038Agent00.c deleted file mode 100644 index baba57b9894..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/libattach038Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach038Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/libattach038Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/libattach038Agent00.cpp new file mode 100644 index 00000000000..e62773f7a34 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach038/libattach038Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach038Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/attach039Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/attach039Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/attach039Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/attach039Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/libattach039Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/libattach039Agent00.c deleted file mode 100644 index 0ccd5606a63..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/libattach039Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach039Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/libattach039Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/libattach039Agent00.cpp new file mode 100644 index 00000000000..9c638c81aa3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach039/libattach039Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach039Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/attach040Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/attach040Agent00.c deleted file mode 100644 index ff0d29f1259..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/attach040Agent00.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Expected agent work scenario: - * - during initialization agent enables ThreadStart events - * - target application starts several threads - * - agent receives ThreadStart events and tries to find thread provoked this event in the array returned - * by JVMTI function GetAllThreads - * - when expected number of ThreadStart events is received agent finishes work - */ - -#define TEST_THREADS_NUMBER 5 - -#define TEST_THREAD_NAME_PREFIX "attach040-TestThread-" - -static jrawMonitorID threadsCounterMonitor; - -static volatile int testThreadsCounter = 0; - -static Options* options = NULL; -static const char* agentName; - -void JNICALL threadStartHandler(jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread) { - int success = 1; - int threadsCount = 0; - jthread * threads; - int i; - char startedThreadName[MAX_STRING_LENGTH]; - - if (!nsk_jvmti_aod_getThreadName(jvmti, thread, startedThreadName)) { - nsk_jvmti_aod_disableEventAndFinish(agentName, JVMTI_EVENT_THREAD_START, success, jvmti, jni); - return; - } - - NSK_DISPLAY2("%s: ThreadStart event was received for thread '%s'\n", agentName, startedThreadName); - - if (NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetAllThreads, jvmti, &threadsCount, &threads))) { - int startedThreadWasFound = 0; - - for (i = 0; i < threadsCount; i++) { - char threadName[MAX_STRING_LENGTH]; - - if (!nsk_jvmti_aod_getThreadName(jvmti, thread, threadName)) { - nsk_jvmti_aod_disableEventAndFinish(agentName, JVMTI_EVENT_THREAD_START, success, jvmti, jni); - return; - } - - if (!strcmp(threadName, startedThreadName)) { - startedThreadWasFound = 1; - break; - } - } - - if (!startedThreadWasFound) { - NSK_COMPLAIN2("%s: GetAllThreads didn't return information about thread '%s'\n", agentName, startedThreadName); - success = 0; - } - - nsk_jvmti_aod_deallocate(jvmti, (unsigned char*)threads); - } else { - success = 0; - } - - if (strstr(startedThreadName, TEST_THREAD_NAME_PREFIX)) { - if (NSK_JVMTI_VERIFY(NSK_CPP_STUB2( - RawMonitorEnter, jvmti, threadsCounterMonitor))) { - - testThreadsCounter++; - - if (testThreadsCounter == TEST_THREADS_NUMBER) { - nsk_jvmti_aod_disableEventAndFinish(agentName, JVMTI_EVENT_THREAD_START, success, jvmti, jni); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, threadsCounterMonitor))) { - success = 0; - } - } else { - success = 0; - } - } - - if (!success) { - NSK_COMPLAIN1("%s: unexpected error during agent work, stop agent\n", agentName); - nsk_jvmti_aod_disableEventAndFinish(agentName, JVMTI_EVENT_THREAD_START, 0, jvmti, jni); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNI_OnLoad_attach040Agent00(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif - -JNIEXPORT jint JNICALL -#ifdef STATIC_BUILD -Agent_OnAttach_attach040Agent00(JavaVM *vm, char *optionsString, void *reserved) -#else -Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) -#endif -{ - jvmtiEventCallbacks eventCallbacks; - jvmtiEnv* jvmti; - JNIEnv* jni; - - if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL)) - return JNI_ERR; - - agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION); - - if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "threadsCounterMonitor", &threadsCounterMonitor))) { - return JNI_ERR; - } - - memset(&eventCallbacks,0, sizeof(eventCallbacks)); - eventCallbacks.ThreadStart = threadStartHandler; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &eventCallbacks, sizeof(eventCallbacks))) ) { - return JNI_ERR; - } - - if (!(nsk_jvmti_aod_enableEvent(jvmti, JVMTI_EVENT_THREAD_START))) { - return JNI_ERR; - } - - NSK_DISPLAY1("%s: initialization was done\n", agentName); - - if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) - return JNI_ERR; - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/attach040Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/attach040Agent00.cpp new file mode 100644 index 00000000000..f5bb5bd1e7a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/attach040Agent00.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Expected agent work scenario: + * - during initialization agent enables ThreadStart events + * - target application starts several threads + * - agent receives ThreadStart events and tries to find thread provoked this event in the array returned + * by JVMTI function GetAllThreads + * - when expected number of ThreadStart events is received agent finishes work + */ + +#define TEST_THREADS_NUMBER 5 + +#define TEST_THREAD_NAME_PREFIX "attach040-TestThread-" + +static jrawMonitorID threadsCounterMonitor; + +static volatile int testThreadsCounter = 0; + +static Options* options = NULL; +static const char* agentName; + +void JNICALL threadStartHandler(jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread) { + int success = 1; + jint threadsCount = 0; + jthread * threads; + jint i; + char startedThreadName[MAX_STRING_LENGTH]; + + if (!nsk_jvmti_aod_getThreadName(jvmti, thread, startedThreadName)) { + nsk_jvmti_aod_disableEventAndFinish(agentName, JVMTI_EVENT_THREAD_START, success, jvmti, jni); + return; + } + + NSK_DISPLAY2("%s: ThreadStart event was received for thread '%s'\n", agentName, startedThreadName); + + if (NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetAllThreads, jvmti, &threadsCount, &threads))) { + int startedThreadWasFound = 0; + + for (i = 0; i < threadsCount; i++) { + char threadName[MAX_STRING_LENGTH]; + + if (!nsk_jvmti_aod_getThreadName(jvmti, thread, threadName)) { + nsk_jvmti_aod_disableEventAndFinish(agentName, JVMTI_EVENT_THREAD_START, success, jvmti, jni); + return; + } + + if (!strcmp(threadName, startedThreadName)) { + startedThreadWasFound = 1; + break; + } + } + + if (!startedThreadWasFound) { + NSK_COMPLAIN2("%s: GetAllThreads didn't return information about thread '%s'\n", agentName, startedThreadName); + success = 0; + } + + nsk_jvmti_aod_deallocate(jvmti, (unsigned char*)threads); + } else { + success = 0; + } + + if (strstr(startedThreadName, TEST_THREAD_NAME_PREFIX)) { + if (NSK_JVMTI_VERIFY(NSK_CPP_STUB2( + RawMonitorEnter, jvmti, threadsCounterMonitor))) { + + testThreadsCounter++; + + if (testThreadsCounter == TEST_THREADS_NUMBER) { + nsk_jvmti_aod_disableEventAndFinish(agentName, JVMTI_EVENT_THREAD_START, success, jvmti, jni); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, threadsCounterMonitor))) { + success = 0; + } + } else { + success = 0; + } + } + + if (!success) { + NSK_COMPLAIN1("%s: unexpected error during agent work, stop agent\n", agentName); + nsk_jvmti_aod_disableEventAndFinish(agentName, JVMTI_EVENT_THREAD_START, 0, jvmti, jni); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNI_OnLoad_attach040Agent00(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif + +JNIEXPORT jint JNICALL +#ifdef STATIC_BUILD +Agent_OnAttach_attach040Agent00(JavaVM *vm, char *optionsString, void *reserved) +#else +Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) +#endif +{ + jvmtiEventCallbacks eventCallbacks; + jvmtiEnv* jvmti; + JNIEnv* jni; + + if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL)) + return JNI_ERR; + + agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION); + + if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "threadsCounterMonitor", &threadsCounterMonitor))) { + return JNI_ERR; + } + + memset(&eventCallbacks,0, sizeof(eventCallbacks)); + eventCallbacks.ThreadStart = threadStartHandler; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &eventCallbacks, sizeof(eventCallbacks))) ) { + return JNI_ERR; + } + + if (!(nsk_jvmti_aod_enableEvent(jvmti, JVMTI_EVENT_THREAD_START))) { + return JNI_ERR; + } + + NSK_DISPLAY1("%s: initialization was done\n", agentName); + + if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/libattach040Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/libattach040Agent00.c deleted file mode 100644 index e76e800540e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/libattach040Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach040Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/libattach040Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/libattach040Agent00.cpp new file mode 100644 index 00000000000..f486c13fbfd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach040/libattach040Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach040Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/attach041Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/attach041Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/attach041Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/attach041Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/libattach041Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/libattach041Agent00.c deleted file mode 100644 index 7a0e5770ca1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/libattach041Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach041Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/libattach041Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/libattach041Agent00.cpp new file mode 100644 index 00000000000..0dcd60fbcb9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach041/libattach041Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach041Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/attach042Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/attach042Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/attach042Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/attach042Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/libattach042Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/libattach042Agent00.c deleted file mode 100644 index b36c93a51ae..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/libattach042Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach042Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/libattach042Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/libattach042Agent00.cpp new file mode 100644 index 00000000000..e89a330627c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach042/libattach042Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach042Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent01.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent01.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent01.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent01.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent02.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent02.c deleted file mode 100644 index e26d2d0cf2d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent02.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Agent receives expected number of ThreadStart/ThreadEnd events and finishes work - * (events should be provoked by target application) - */ - - -#define EXPECTED_EVENTS_NUMBER 200 - -static Options* options = NULL; -static const char* agentName; - -static jvmtiEvent testEvents[] = {JVMTI_EVENT_THREAD_START, JVMTI_EVENT_THREAD_END}; -static const int testEventsNumber = 2; - -static jrawMonitorID eventsCounterMonitor; - -static volatile int eventsCounter = 0; - -void eventHandler(jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread, - int threadStartEvent) { - char threadName[MAX_STRING_LENGTH]; - int success = 1; - int threadsCount = 0; - jthread * threads; - - if (!nsk_jvmti_aod_getThreadName(jvmti, thread, threadName)) { - nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni); - return; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetAllThreads, jvmti, &threadsCount, &threads))) { - NSK_COMPLAIN1("%s: failed to get all threads\n", agentName); - nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni); - return; - } - - nsk_jvmti_aod_deallocate(jvmti, (unsigned char*)threads); - - if (NSK_JVMTI_VERIFY(NSK_CPP_STUB2( - RawMonitorEnter, jvmti, eventsCounterMonitor))) { - - eventsCounter++; - - if (threadStartEvent) - NSK_DISPLAY3("%s: ThreadStart event received for thread '%s' (eventsCounter: %d)\n", agentName, threadName, eventsCounter); - else - NSK_DISPLAY3("%s: ThreadEnd event received for thread '%s' (eventsCounter: %d)\n", agentName, threadName, eventsCounter); - - if (eventsCounter == EXPECTED_EVENTS_NUMBER) { - NSK_DISPLAY2("%s: all expected events were received (eventsCounter: %d)\n", agentName, eventsCounter); - - nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, success, jvmti, jni); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, eventsCounterMonitor))) { - success = 0; - } - } else { - success = 0; - } - - if (!success) { - nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni); - } -} - -void JNICALL threadStartHandler( - jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread) { - eventHandler(jvmti, jni, thread, 1); -} - -void JNICALL threadEndHandler( - jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread) { - eventHandler(jvmti, jni, thread, 0); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNI_OnLoad_attach045Agent02(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif - -JNIEXPORT jint JNICALL -#ifdef STATIC_BUILD -Agent_OnAttach_attach045Agent02(JavaVM *vm, char *optionsString, void *reserved) -#else -Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) -#endif -{ - jvmtiEventCallbacks eventCallbacks; - jvmtiEnv* jvmti; - JNIEnv* jni; - - if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL)) - return JNI_ERR; - - agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION); - - if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "attach045-agent02-eventsCounterMonitor", &eventsCounterMonitor))) { - return JNI_ERR; - } - - memset(&eventCallbacks,0, sizeof(eventCallbacks)); - eventCallbacks.ThreadStart = threadStartHandler; - eventCallbacks.ThreadEnd = threadEndHandler; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &eventCallbacks, sizeof(eventCallbacks))) ) { - return JNI_ERR; - } - - if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) { - return JNI_ERR; - } - - NSK_DISPLAY1("%s: initialization was done\n", agentName); - - if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) - return JNI_ERR; - - return JNI_OK; -} - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent02.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent02.cpp new file mode 100644 index 00000000000..aae000956a0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent02.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Agent receives expected number of ThreadStart/ThreadEnd events and finishes work + * (events should be provoked by target application) + */ + + +#define EXPECTED_EVENTS_NUMBER 200 + +static Options* options = NULL; +static const char* agentName; + +static jvmtiEvent testEvents[] = {JVMTI_EVENT_THREAD_START, JVMTI_EVENT_THREAD_END}; +static const int testEventsNumber = 2; + +static jrawMonitorID eventsCounterMonitor; + +static volatile int eventsCounter = 0; + +void eventHandler(jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread, + int threadStartEvent) { + char threadName[MAX_STRING_LENGTH]; + int success = 1; + jint threadsCount = 0; + jthread * threads; + + if (!nsk_jvmti_aod_getThreadName(jvmti, thread, threadName)) { + nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni); + return; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetAllThreads, jvmti, &threadsCount, &threads))) { + NSK_COMPLAIN1("%s: failed to get all threads\n", agentName); + nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni); + return; + } + + nsk_jvmti_aod_deallocate(jvmti, (unsigned char*)threads); + + if (NSK_JVMTI_VERIFY(NSK_CPP_STUB2( + RawMonitorEnter, jvmti, eventsCounterMonitor))) { + + eventsCounter++; + + if (threadStartEvent) + NSK_DISPLAY3("%s: ThreadStart event received for thread '%s' (eventsCounter: %d)\n", agentName, threadName, eventsCounter); + else + NSK_DISPLAY3("%s: ThreadEnd event received for thread '%s' (eventsCounter: %d)\n", agentName, threadName, eventsCounter); + + if (eventsCounter == EXPECTED_EVENTS_NUMBER) { + NSK_DISPLAY2("%s: all expected events were received (eventsCounter: %d)\n", agentName, eventsCounter); + + nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, success, jvmti, jni); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, eventsCounterMonitor))) { + success = 0; + } + } else { + success = 0; + } + + if (!success) { + nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni); + } +} + +void JNICALL threadStartHandler( + jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread) { + eventHandler(jvmti, jni, thread, 1); +} + +void JNICALL threadEndHandler( + jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread) { + eventHandler(jvmti, jni, thread, 0); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNI_OnLoad_attach045Agent02(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif + +JNIEXPORT jint JNICALL +#ifdef STATIC_BUILD +Agent_OnAttach_attach045Agent02(JavaVM *vm, char *optionsString, void *reserved) +#else +Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) +#endif +{ + jvmtiEventCallbacks eventCallbacks; + jvmtiEnv* jvmti; + JNIEnv* jni; + + if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL)) + return JNI_ERR; + + agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION); + + if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "attach045-agent02-eventsCounterMonitor", &eventsCounterMonitor))) { + return JNI_ERR; + } + + memset(&eventCallbacks,0, sizeof(eventCallbacks)); + eventCallbacks.ThreadStart = threadStartHandler; + eventCallbacks.ThreadEnd = threadEndHandler; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &eventCallbacks, sizeof(eventCallbacks))) ) { + return JNI_ERR; + } + + if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) { + return JNI_ERR; + } + + NSK_DISPLAY1("%s: initialization was done\n", agentName); + + if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) + return JNI_ERR; + + return JNI_OK; +} + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent03.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent03.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent03.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent03.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent00.c deleted file mode 100644 index c7900f423e8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach045Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent00.cpp new file mode 100644 index 00000000000..32ad9bbac55 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach045Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent01.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent01.c deleted file mode 100644 index 6793f00e48e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent01.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach045Agent01.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent01.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent01.cpp new file mode 100644 index 00000000000..7e209feee73 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent01.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach045Agent01.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent02.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent02.c deleted file mode 100644 index 7b00eaaf10a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent02.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach045Agent02.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent02.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent02.cpp new file mode 100644 index 00000000000..3fec1ae4bf1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent02.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach045Agent02.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent03.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent03.c deleted file mode 100644 index 9fe8b9bcbed..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent03.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach045Agent03.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent03.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent03.cpp new file mode 100644 index 00000000000..fffca8e8437 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/libattach045Agent03.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach045Agent03.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/attach046Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/attach046Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/attach046Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/attach046Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/libattach046Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/libattach046Agent00.c deleted file mode 100644 index 9300f2f37fe..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/libattach046Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach046Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/libattach046Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/libattach046Agent00.cpp new file mode 100644 index 00000000000..e46ce9a85ce --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach046/libattach046Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach046Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/attach050Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/attach050Agent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/attach050Agent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/attach050Agent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/libattach050Agent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/libattach050Agent00.c deleted file mode 100644 index cb548f4265e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/libattach050Agent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "attach050Agent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/libattach050Agent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/libattach050Agent00.cpp new file mode 100644 index 00000000000..035884b0cea --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/libattach050Agent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "attach050Agent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/libsimpleAgent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/libsimpleAgent00.c deleted file mode 100644 index 48fb355538f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/libsimpleAgent00.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "aod.c" -#include "jvmti_aod.c" -#include "simpleAgent00.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/libsimpleAgent00.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/libsimpleAgent00.cpp new file mode 100644 index 00000000000..bf99cdad182 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/libsimpleAgent00.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "aod.cpp" +#include "jvmti_aod.cpp" +#include "simpleAgent00.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/simpleAgent00.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/simpleAgent00.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/simpleAgent00.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/simpleAgent00.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/breakpoint001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/breakpoint001.c deleted file mode 100644 index 42c019fe513..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/breakpoint001.c +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" -#include "jni_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -#define METH_NUM 2 -static const char *METHODS[][2] = { - {"bpMethod", "()V"}, - {"bpMethod2", "()I"} -}; - -static const char *CLASS_SIG = - "Lnsk/jvmti/Breakpoint/breakpoint001;"; - -static const char *THREAD_NAME = "breakpoint001Thr"; - -static volatile int bpEvents[METH_NUM]; -static volatile jint result = PASSED; -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; - -static int vm_started = 0; -static jrawMonitorID agent_lock; - -static void initCounters() { - int i; - - for(i=0; iRawMonitorEnter(jvmti, agent_lock); - - if (vm_started) { - // GetClassSignature may be called only during the start or the live phase - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, - jvmti_env, klass, &sig, &generic))) - NSK_CPP_STUB2(FatalError, env, - "failed to obtain a class signature\n"); - - if (sig != NULL && (strcmp(sig, CLASS_SIG) == 0)) { - NSK_DISPLAY1("ClassLoad event received for the class \"%s\"\n\ -\tsetting breakpoints ...\n", - sig); - setBP(jvmti_env, env, klass); - } - } - - (*jvmti)->RawMonitorExit(jvmti, agent_lock); -} - -void JNICALL -Breakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - jclass klass; - char *clsSig, *generic, *methNam, *methSig; - jvmtiThreadInfo thr_info; - int checkStatus = PASSED; - int i; - - NSK_DISPLAY0(">>>> Breakpoint event received\n"); - - /* checking thread info */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, - jvmti_env, thread, &thr_info))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: unable to get thread info during Breakpoint callback\n\n"); - return; - } - if (thr_info.name == NULL || - strcmp(thr_info.name,THREAD_NAME) != 0 || - thr_info.is_daemon==JNI_TRUE) { - result = checkStatus = STATUS_FAILED; - NSK_COMPLAIN2("TEST FAILED: Breakpoint event with unexpected thread info:\n\ -\tname: \"%s\"\ttype: %s thread\n\n", - (thr_info.name == NULL)?"NULL":thr_info.name, - (thr_info.is_daemon==JNI_TRUE)?"deamon":"user"); - } - else - NSK_DISPLAY2("CHECK PASSED: thread name: \"%s\"\ttype: %s thread\n", - thr_info.name, (thr_info.is_daemon==JNI_TRUE)?"deamon":"user"); - - /* checking location */ - if (location != 0) { - result = checkStatus = STATUS_FAILED; - NSK_COMPLAIN1("TEST FAILED: Breakpoint event with unexpected location %ld:\n\n", - (long) location); - } - else - NSK_DISPLAY1("CHECK PASSED: location: %ld as expected\n", - (long) location); - - /* checking method info */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, method, &klass))) { - result = checkStatus = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: unable to get method declaring class during Breakpoint callback\n\n"); - return; - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, - jvmti_env, klass, &clsSig, &generic))) { - result = checkStatus = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: unable to obtain a class signature during Breakpoint callback\n\n"); - return; - } - if (clsSig == NULL || - strcmp(clsSig,CLASS_SIG) != 0) { - result = checkStatus = STATUS_FAILED; - NSK_COMPLAIN1("TEST FAILED: Breakpoint event with unexpected class signature:\n\ -\t\"%s\"\n\n", - (clsSig == NULL)?"NULL":clsSig); - } - else - NSK_DISPLAY1("CHECK PASSED: class signature: \"%s\"\n", - clsSig); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &methNam, &methSig, NULL))) { - result = checkStatus = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); - return; - } - - for (i=0; iRawMonitorEnter(jvmti, agent_lock); - - vm_started = 1; - - (*jvmti)->RawMonitorExit(jvmti, agent_lock); -} - -/************************/ - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_Breakpoint_breakpoint001_check( - JNIEnv *env, jobject obj) { - int i; - - for (i=0; iCreateRawMonitor(jvmti, "agent_lock", &agent_lock) != JVMTI_ERROR_NONE) { - return JNI_ERR; - } - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/breakpoint001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/breakpoint001.cpp new file mode 100644 index 00000000000..bd57ddaca1c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/breakpoint001.cpp @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +#define METH_NUM 2 +static const char *METHODS[][2] = { + {"bpMethod", "()V"}, + {"bpMethod2", "()I"} +}; + +static const char *CLASS_SIG = + "Lnsk/jvmti/Breakpoint/breakpoint001;"; + +static const char *THREAD_NAME = "breakpoint001Thr"; + +static volatile int bpEvents[METH_NUM]; +static volatile jint result = PASSED; +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; + +static int vm_started = 0; +static jrawMonitorID agent_lock; + +static void initCounters() { + int i; + + for(i=0; iRawMonitorEnter(agent_lock); + + if (vm_started) { + // GetClassSignature may be called only during the start or the live phase + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, + jvmti_env, klass, &sig, &generic))) + NSK_CPP_STUB2(FatalError, env, + "failed to obtain a class signature\n"); + + if (sig != NULL && (strcmp(sig, CLASS_SIG) == 0)) { + NSK_DISPLAY1("ClassLoad event received for the class \"%s\"\n\ +\tsetting breakpoints ...\n", + sig); + setBP(jvmti_env, env, klass); + } + } + + jvmti->RawMonitorExit(agent_lock); +} + +void JNICALL +Breakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + jclass klass; + char *clsSig, *generic, *methNam, *methSig; + jvmtiThreadInfo thr_info; + int checkStatus = PASSED; + int i; + + NSK_DISPLAY0(">>>> Breakpoint event received\n"); + + /* checking thread info */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, + jvmti_env, thread, &thr_info))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: unable to get thread info during Breakpoint callback\n\n"); + return; + } + if (thr_info.name == NULL || + strcmp(thr_info.name,THREAD_NAME) != 0 || + thr_info.is_daemon==JNI_TRUE) { + result = checkStatus = STATUS_FAILED; + NSK_COMPLAIN2("TEST FAILED: Breakpoint event with unexpected thread info:\n\ +\tname: \"%s\"\ttype: %s thread\n\n", + (thr_info.name == NULL)?"NULL":thr_info.name, + (thr_info.is_daemon==JNI_TRUE)?"deamon":"user"); + } + else + NSK_DISPLAY2("CHECK PASSED: thread name: \"%s\"\ttype: %s thread\n", + thr_info.name, (thr_info.is_daemon==JNI_TRUE)?"deamon":"user"); + + /* checking location */ + if (location != 0) { + result = checkStatus = STATUS_FAILED; + NSK_COMPLAIN1("TEST FAILED: Breakpoint event with unexpected location %ld:\n\n", + (long) location); + } + else + NSK_DISPLAY1("CHECK PASSED: location: %ld as expected\n", + (long) location); + + /* checking method info */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, method, &klass))) { + result = checkStatus = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: unable to get method declaring class during Breakpoint callback\n\n"); + return; + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, + jvmti_env, klass, &clsSig, &generic))) { + result = checkStatus = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: unable to obtain a class signature during Breakpoint callback\n\n"); + return; + } + if (clsSig == NULL || + strcmp(clsSig,CLASS_SIG) != 0) { + result = checkStatus = STATUS_FAILED; + NSK_COMPLAIN1("TEST FAILED: Breakpoint event with unexpected class signature:\n\ +\t\"%s\"\n\n", + (clsSig == NULL)?"NULL":clsSig); + } + else + NSK_DISPLAY1("CHECK PASSED: class signature: \"%s\"\n", + clsSig); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &methNam, &methSig, NULL))) { + result = checkStatus = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); + return; + } + + for (i=0; iRawMonitorEnter(agent_lock); + + vm_started = 1; + + jvmti->RawMonitorExit(agent_lock); +} + +/************************/ + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_Breakpoint_breakpoint001_check( + JNIEnv *env, jobject obj) { + int i; + + for (i=0; iCreateRawMonitor("agent_lock", &agent_lock) != JVMTI_ERROR_NONE) { + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/libbreakpoint001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/libbreakpoint001.c deleted file mode 100644 index 63ca4c0c708..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/libbreakpoint001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "breakpoint001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/libbreakpoint001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/libbreakpoint001.cpp new file mode 100644 index 00000000000..4b09ac95a77 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/libbreakpoint001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "breakpoint001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/classfloadhk001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/classfloadhk001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/classfloadhk001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/classfloadhk001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/libclassfloadhk001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/libclassfloadhk001.c deleted file mode 100644 index 41ce29c4100..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/libclassfloadhk001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "classfloadhk001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/libclassfloadhk001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/libclassfloadhk001.cpp new file mode 100644 index 00000000000..3d832bc53a4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/libclassfloadhk001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "classfloadhk001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/classfloadhk002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/classfloadhk002.c deleted file mode 100644 index f83400f934a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/classfloadhk002.c +++ /dev/null @@ -1,355 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk002" -#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk002r" -#define TESTED_CLASS_SIG "L"TESTED_CLASS_NAME";" -#define BYTECODE_FIELD_SIG "[B" -#define ORIG_BYTECODE_FIELD_NAME "origClassBytes" - -static unsigned char* origClassBytes = NULL; -static jint origClassSize = 0; - -static volatile int eventsCount = 0; - -/* ============================================================================= */ - -/** Check (strictly or not) if bytecode has expected size and bytes or complain an error. */ -static int checkBytecode(const char kind[], jint size, const unsigned char bytes[], - jint expectedSize, const unsigned char expectedBytes[], - int strict) { - int success = NSK_TRUE; - - NSK_DISPLAY3("Check %s bytecode: 0x%p:%d\n", kind, (void*)bytes, (int)size); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, size, bytes); - } - - if (bytes == NULL) { - NSK_COMPLAIN2("Unexpected NULL pointer to %s bytecode in CLASS_FILE_LOAD_HOOK: 0x%p\n", - kind, (void*)bytes); - return NSK_FALSE; - } - - if (size <= 0) { - NSK_COMPLAIN2("Unexpected zero size of %s bytecode in CLASS_FILE_LOAD_HOOK: %d\n", - kind, (int)size); - return NSK_FALSE; - } - - if (strict) { - if (size != expectedSize) { - NSK_COMPLAIN3("Unexpected size of %s bytecode in CLASS_FILE_LOAD_HOOK:\n" - "# got size: %d\n" - "# expected: %d\n", - kind, (int)size, (int)expectedSize); - success = NSK_FALSE; - } else { - jint different = 0; - jint i; - - for (i = 0; i < size; i++) { - if (bytes[i] != expectedBytes[i]) { - different++; - } - } - if (different > 0) { - NSK_COMPLAIN2("Unexpected bytes in %s bytecode in CLASS_FILE_LOAD_HOOK:\n" - "# different bytes: %d\n" - "# total bytes: %d\n", - (int)different, (int)size); - success = NSK_FALSE; - } - } - - if (!success) { - NSK_COMPLAIN2("Got %s bytecode is not equal to expected bytecode: %d bytes\n", - kind, expectedSize); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, expectedSize, expectedBytes); - } - } else { - NSK_DISPLAY1("All %s bytecode is equal to expected one\n", kind); - } - } - - return success; -} - -/** Get classfile bytecode from a static field of given class. */ -static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[], - jint* size, unsigned char* *bytes) { - - jfieldID fieldID = NULL; - jbyteArray array = NULL; - jbyte* elements; - int i; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); - - if (!NSK_JNI_VERIFY(jni, (*size = - NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); - - { - jboolean isCopy; - if (!NSK_JNI_VERIFY(jni, (elements = - NSK_CPP_STUB3(GetByteArrayElements, jni, array, - &isCopy)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); - - for (i = 0; i < *size; i++) { - (*bytes)[i] = (unsigned char)elements[i]; - } - NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); - - NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); - NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); - NSK_DISPLAY0(" ... released\n"); - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for debuggee to become ready\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - NSK_DISPLAY0(">>> Obtain original bytecode of tested class\n"); - { - jclass debugeeClass = NULL; - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, - ORIG_BYTECODE_FIELD_NAME, - BYTECODE_FIELD_SIG, - &origClassSize, &origClassBytes))) - return; - } - - NSK_DISPLAY0(">>> Testcase #1: Load tested class and check CLASS_FILE_LOAD_HOOK event\n"); - { - jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; - - NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - NSK_DISPLAY0(" ... event enabled\n"); - - NSK_DISPLAY0("Let debugee to load tested class\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - NSK_DISPLAY0("Wait for tested class to be loaded\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { - NSK_DISPLAY0(" ... event disabled\n"); - } - - NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (eventsCount != 1) { - NSK_COMPLAIN3("Unexpected number of %s events for tested class:\n" - "# got events: %d\n" - "# expected: %d\n", - "CLASS_FILE_LOAD_HOOK", - eventsCount, 1); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY1(" ... received: %d events\n", eventsCount); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - NSK_DISPLAY1("Deallocate bytecode array: 0x%p\n", (void*)origClassBytes); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, origClassBytes))) { - nsk_jvmti_setFailStatus(); - } - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Callback for CLASS_FILE_LOAD_HOOK event **/ -static void JNICALL -callbackClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *env, - jclass class_being_redefined, - jobject loader, const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", - nsk_null_string(name), (void*)loader, (void*)class_being_redefined, - (void*)class_data, (int)class_data_len); - - if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { - NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); - eventsCount++; - - NSK_DISPLAY1("Check class_being_redefined: 0x%p\n", (void*)class_being_redefined); - if (class_being_redefined != NULL) { - NSK_COMPLAIN1("Unexpected not NULL class_being_redefined in CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)class_being_redefined); - nsk_jvmti_setFailStatus(); - } - - if (!checkBytecode("original", class_data_len, class_data, - origClassSize, origClassBytes, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_classfloadhk002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - NSK_DISPLAY1("Add required capability: %s\n", "can_generate_eraly_class_hook_events"); - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_all_class_hook_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... added\n"); - - NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); - { - jvmtiEventCallbacks callbacks; - jint size = (jint)sizeof(callbacks); - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = callbackClassFileLoadHook; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... set\n"); - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/classfloadhk002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/classfloadhk002.cpp new file mode 100644 index 00000000000..02d299d3afb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/classfloadhk002.cpp @@ -0,0 +1,355 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk002" +#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk002r" +#define TESTED_CLASS_SIG "L" TESTED_CLASS_NAME ";" +#define BYTECODE_FIELD_SIG "[B" +#define ORIG_BYTECODE_FIELD_NAME "origClassBytes" + +static unsigned char* origClassBytes = NULL; +static jint origClassSize = 0; + +static volatile int eventsCount = 0; + +/* ============================================================================= */ + +/** Check (strictly or not) if bytecode has expected size and bytes or complain an error. */ +static int checkBytecode(const char kind[], jint size, const unsigned char bytes[], + jint expectedSize, const unsigned char expectedBytes[], + int strict) { + int success = NSK_TRUE; + + NSK_DISPLAY3("Check %s bytecode: 0x%p:%d\n", kind, (void*)bytes, (int)size); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, size, bytes); + } + + if (bytes == NULL) { + NSK_COMPLAIN2("Unexpected NULL pointer to %s bytecode in CLASS_FILE_LOAD_HOOK: 0x%p\n", + kind, (void*)bytes); + return NSK_FALSE; + } + + if (size <= 0) { + NSK_COMPLAIN2("Unexpected zero size of %s bytecode in CLASS_FILE_LOAD_HOOK: %d\n", + kind, (int)size); + return NSK_FALSE; + } + + if (strict) { + if (size != expectedSize) { + NSK_COMPLAIN3("Unexpected size of %s bytecode in CLASS_FILE_LOAD_HOOK:\n" + "# got size: %d\n" + "# expected: %d\n", + kind, (int)size, (int)expectedSize); + success = NSK_FALSE; + } else { + jint different = 0; + jint i; + + for (i = 0; i < size; i++) { + if (bytes[i] != expectedBytes[i]) { + different++; + } + } + if (different > 0) { + NSK_COMPLAIN2("Unexpected bytes in %s bytecode in CLASS_FILE_LOAD_HOOK:\n" + "# different bytes: %d\n" + "# total bytes: %d\n", + (int)different, (int)size); + success = NSK_FALSE; + } + } + + if (!success) { + NSK_COMPLAIN2("Got %s bytecode is not equal to expected bytecode: %d bytes\n", + kind, expectedSize); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, expectedSize, expectedBytes); + } + } else { + NSK_DISPLAY1("All %s bytecode is equal to expected one\n", kind); + } + } + + return success; +} + +/** Get classfile bytecode from a static field of given class. */ +static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[], + jint* size, unsigned char* *bytes) { + + jfieldID fieldID = NULL; + jbyteArray array = NULL; + jbyte* elements; + int i; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); + + if (!NSK_JNI_VERIFY(jni, (*size = + NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); + + { + jboolean isCopy; + if (!NSK_JNI_VERIFY(jni, (elements = + NSK_CPP_STUB3(GetByteArrayElements, jni, array, + &isCopy)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); + + for (i = 0; i < *size; i++) { + (*bytes)[i] = (unsigned char)elements[i]; + } + NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); + + NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); + NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); + NSK_DISPLAY0(" ... released\n"); + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for debuggee to become ready\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + NSK_DISPLAY0(">>> Obtain original bytecode of tested class\n"); + { + jclass debugeeClass = NULL; + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, + ORIG_BYTECODE_FIELD_NAME, + BYTECODE_FIELD_SIG, + &origClassSize, &origClassBytes))) + return; + } + + NSK_DISPLAY0(">>> Testcase #1: Load tested class and check CLASS_FILE_LOAD_HOOK event\n"); + { + jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; + + NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + NSK_DISPLAY0(" ... event enabled\n"); + + NSK_DISPLAY0("Let debugee to load tested class\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + NSK_DISPLAY0("Wait for tested class to be loaded\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { + NSK_DISPLAY0(" ... event disabled\n"); + } + + NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (eventsCount != 1) { + NSK_COMPLAIN3("Unexpected number of %s events for tested class:\n" + "# got events: %d\n" + "# expected: %d\n", + "CLASS_FILE_LOAD_HOOK", + eventsCount, 1); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY1(" ... received: %d events\n", eventsCount); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + NSK_DISPLAY1("Deallocate bytecode array: 0x%p\n", (void*)origClassBytes); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, origClassBytes))) { + nsk_jvmti_setFailStatus(); + } + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Callback for CLASS_FILE_LOAD_HOOK event **/ +static void JNICALL +callbackClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *env, + jclass class_being_redefined, + jobject loader, const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", + nsk_null_string(name), (void*)loader, (void*)class_being_redefined, + (void*)class_data, (int)class_data_len); + + if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { + NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); + eventsCount++; + + NSK_DISPLAY1("Check class_being_redefined: 0x%p\n", (void*)class_being_redefined); + if (class_being_redefined != NULL) { + NSK_COMPLAIN1("Unexpected not NULL class_being_redefined in CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)class_being_redefined); + nsk_jvmti_setFailStatus(); + } + + if (!checkBytecode("original", class_data_len, class_data, + origClassSize, origClassBytes, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_classfloadhk002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + NSK_DISPLAY1("Add required capability: %s\n", "can_generate_eraly_class_hook_events"); + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_all_class_hook_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... added\n"); + + NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); + { + jvmtiEventCallbacks callbacks; + jint size = (jint)sizeof(callbacks); + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = callbackClassFileLoadHook; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... set\n"); + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/libclassfloadhk002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/libclassfloadhk002.c deleted file mode 100644 index df01e31f569..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/libclassfloadhk002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "classfloadhk002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/libclassfloadhk002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/libclassfloadhk002.cpp new file mode 100644 index 00000000000..7c0f8ec3ea5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/libclassfloadhk002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "classfloadhk002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/classfloadhk003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/classfloadhk003.c deleted file mode 100644 index 556d5bb728a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/classfloadhk003.c +++ /dev/null @@ -1,417 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk003" -#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk003r" -#define TESTED_CLASS_SIG "L"TESTED_CLASS_NAME";" -#define TESTED_CLASSLOADER_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk003ClassLoader" -#define TESTED_CLASSLOADER_SIG "L"TESTED_CLASSLOADER_NAME";" - -#define CLASSLOADER_FIELD_NAME "classLoader" -#define BYTECODE_FIELD_SIG "[B" -#define ORIG_BYTECODE_FIELD_NAME "origClassBytes" - -static jobject classLoader = NULL; -static jint origClassSize = 0; -static unsigned char* origClassBytes = NULL; - -static volatile int eventsCount = 0; - -/* ============================================================================= */ - -/** Check (strictly or not) if bytecode has expected size and bytes or complain an error. */ -static int checkBytecode(const char kind[], jint size, const unsigned char bytes[], - jint expectedSize, const unsigned char expectedBytes[], - int strict) { - int success = NSK_TRUE; - - NSK_DISPLAY3("Check %s bytecode: 0x%p:%d\n", kind, (void*)bytes, (int)size); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, size, bytes); - } - - if (bytes == NULL) { - NSK_COMPLAIN2("Unexpected NULL pointer to %s bytecode in CLASS_FILE_LOAD_HOOK: 0x%p\n", - kind, (void*)bytes); - return NSK_FALSE; - } - - if (size <= 0) { - NSK_COMPLAIN2("Unexpected zero size of %s bytecode in CLASS_FILE_LOAD_HOOK: %d\n", - kind, (int)size); - return NSK_FALSE; - } - - if (strict) { - if (size != expectedSize) { - NSK_COMPLAIN3("Unexpected size of %s bytecode in CLASS_FILE_LOAD_HOOK:\n" - "# got size: %d\n" - "# expected: %d\n", - kind, (int)size, (int)expectedSize); - success = NSK_FALSE; - } else { - jint different = 0; - jint i; - - for (i = 0; i < size; i++) { - if (bytes[i] != expectedBytes[i]) { - different++; - } - } - if (different > 0) { - NSK_COMPLAIN2("Unexpected bytes in %s bytecode in CLASS_FILE_LOAD_HOOK:\n" - "# different bytes: %d\n" - "# total bytes: %d\n", - (int)different, (int)size); - success = NSK_FALSE; - } - } - - if (!success) { - NSK_COMPLAIN2("Got %s bytecode is not equal to expected bytecode: %d bytes\n", - kind, expectedSize); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, expectedSize, expectedBytes); - } - } else { - NSK_DISPLAY1("All %s bytecode is equal to expected one\n", kind); - } - } - - return success; -} - -/** Get classfile bytecode from a static field of given class. */ -static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[], - jint* size, unsigned char* *bytes) { - - jfieldID fieldID = NULL; - jbyteArray array = NULL; - jbyte* elements; - int i; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); - - if (!NSK_JNI_VERIFY(jni, (*size = - NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); - - { - jboolean isCopy; - if (!NSK_JNI_VERIFY(jni, (elements = - NSK_CPP_STUB3(GetByteArrayElements, jni, array, - &isCopy)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); - - for (i = 0; i < *size; i++) { - (*bytes)[i] = (unsigned char)elements[i]; - } - NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); - - NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); - NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); - NSK_DISPLAY0(" ... released\n"); - - return NSK_TRUE; -} - -/** Get global reference to object from a static field of given class. */ -static jobject getObject(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[]) { - - jfieldID fieldID = NULL; - jobject obj = NULL; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get object from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)obj); - - NSK_DISPLAY1("Make global reference to object: 0x%p\n", obj); - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB2(NewGlobalRef, jni, obj)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got global ref: 0x%p\n", (void*)obj); - - return obj; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for debuggee to become ready\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - { - jclass debugeeClass = NULL; - - NSK_DISPLAY0(">>> Obtain debuggee class\n"); - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY0(">>> Obtain classloader of tested class\n"); - if (!NSK_VERIFY((classLoader = - getObject(jvmti, jni, debugeeClass, CLASSLOADER_FIELD_NAME, - TESTED_CLASSLOADER_SIG)) != NULL)) - return; - - NSK_DISPLAY0(">>> Obtain original bytecode of tested class\n"); - if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, - ORIG_BYTECODE_FIELD_NAME, - BYTECODE_FIELD_SIG, - &origClassSize, &origClassBytes))) - return; - } - - NSK_DISPLAY0(">>> Testcase #1: Load tested class and check CLASS_FILE_LOAD_HOOK event\n"); - { - jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; - - NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - NSK_DISPLAY0(" ... event enabled\n"); - - NSK_DISPLAY0("Let debugee to load tested class\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - NSK_DISPLAY0("Wait for tested class to be loaded\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { - NSK_DISPLAY0(" ... event disabled\n"); - } - - NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (eventsCount != 1) { - NSK_COMPLAIN3("Unexpected number of %s events for tested class:\n" - "# got events: %d\n" - "# expected: %d\n", - "CLASS_FILE_LOAD_HOOK", - eventsCount, 1); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY1(" ... received: %d events\n", eventsCount); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - NSK_DISPLAY1("Delete global reference to classloader object: 0x%p\n", (void*)classLoader); - NSK_CPP_STUB2(DeleteGlobalRef, jni, classLoader); - - NSK_DISPLAY1("Deallocate classfile bytes array: 0x%p\n", (void*)origClassBytes); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, origClassBytes))) { - nsk_jvmti_setFailStatus(); - } - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Callback for CLASS_FILE_LOAD_HOOK event **/ -static void JNICALL -callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, - jclass class_being_redefined, - jobject loader, const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", - nsk_null_string(name), (void*)loader, (void*)class_being_redefined, - (void*)class_data, (int)class_data_len); - - if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { - NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); - eventsCount++; - - NSK_DISPLAY1("Check class_being_redefined: 0x%p\n", (void*)class_being_redefined); - if (class_being_redefined != NULL) { - NSK_COMPLAIN1("Unexpected not NULL class_being_redefined in CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)class_being_redefined); - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY1("Check classloader: 0x%p\n", (void*)loader); - if (loader == NULL) { - NSK_COMPLAIN1("Unexpected NULL classloader in CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)loader); - nsk_jvmti_setFailStatus(); - } else if (!NSK_CPP_STUB3(IsSameObject, jni, loader, classLoader)) { - NSK_COMPLAIN2("Unexpected classloader in CLASS_FILE_LOAD_HOOK for tested class:\n" - "# got classloder: 0x%p\n" - "# expected same as: 0x%p\n", - (void*)loader, (void*)classLoader); - nsk_jvmti_setFailStatus(); - } - - if (!checkBytecode("original", class_data_len, class_data, - origClassSize, origClassBytes, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_classfloadhk003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - NSK_DISPLAY1("Add required capability: %s\n", "can_generate_eraly_class_hook_events"); - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_all_class_hook_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... added\n"); - - NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); - { - jvmtiEventCallbacks callbacks; - jint size = (jint)sizeof(callbacks); - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = callbackClassFileLoadHook; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... set\n"); - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/classfloadhk003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/classfloadhk003.cpp new file mode 100644 index 00000000000..15c6fa01a58 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/classfloadhk003.cpp @@ -0,0 +1,417 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk003" +#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk003r" +#define TESTED_CLASS_SIG "L" TESTED_CLASS_NAME ";" +#define TESTED_CLASSLOADER_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk003ClassLoader" +#define TESTED_CLASSLOADER_SIG "L" TESTED_CLASSLOADER_NAME ";" + +#define CLASSLOADER_FIELD_NAME "classLoader" +#define BYTECODE_FIELD_SIG "[B" +#define ORIG_BYTECODE_FIELD_NAME "origClassBytes" + +static jobject classLoader = NULL; +static jint origClassSize = 0; +static unsigned char* origClassBytes = NULL; + +static volatile int eventsCount = 0; + +/* ============================================================================= */ + +/** Check (strictly or not) if bytecode has expected size and bytes or complain an error. */ +static int checkBytecode(const char kind[], jint size, const unsigned char bytes[], + jint expectedSize, const unsigned char expectedBytes[], + int strict) { + int success = NSK_TRUE; + + NSK_DISPLAY3("Check %s bytecode: 0x%p:%d\n", kind, (void*)bytes, (int)size); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, size, bytes); + } + + if (bytes == NULL) { + NSK_COMPLAIN2("Unexpected NULL pointer to %s bytecode in CLASS_FILE_LOAD_HOOK: 0x%p\n", + kind, (void*)bytes); + return NSK_FALSE; + } + + if (size <= 0) { + NSK_COMPLAIN2("Unexpected zero size of %s bytecode in CLASS_FILE_LOAD_HOOK: %d\n", + kind, (int)size); + return NSK_FALSE; + } + + if (strict) { + if (size != expectedSize) { + NSK_COMPLAIN3("Unexpected size of %s bytecode in CLASS_FILE_LOAD_HOOK:\n" + "# got size: %d\n" + "# expected: %d\n", + kind, (int)size, (int)expectedSize); + success = NSK_FALSE; + } else { + jint different = 0; + jint i; + + for (i = 0; i < size; i++) { + if (bytes[i] != expectedBytes[i]) { + different++; + } + } + if (different > 0) { + NSK_COMPLAIN2("Unexpected bytes in %s bytecode in CLASS_FILE_LOAD_HOOK:\n" + "# different bytes: %d\n" + "# total bytes: %d\n", + (int)different, (int)size); + success = NSK_FALSE; + } + } + + if (!success) { + NSK_COMPLAIN2("Got %s bytecode is not equal to expected bytecode: %d bytes\n", + kind, expectedSize); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, expectedSize, expectedBytes); + } + } else { + NSK_DISPLAY1("All %s bytecode is equal to expected one\n", kind); + } + } + + return success; +} + +/** Get classfile bytecode from a static field of given class. */ +static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[], + jint* size, unsigned char* *bytes) { + + jfieldID fieldID = NULL; + jbyteArray array = NULL; + jbyte* elements; + int i; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); + + if (!NSK_JNI_VERIFY(jni, (*size = + NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); + + { + jboolean isCopy; + if (!NSK_JNI_VERIFY(jni, (elements = + NSK_CPP_STUB3(GetByteArrayElements, jni, array, + &isCopy)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); + + for (i = 0; i < *size; i++) { + (*bytes)[i] = (unsigned char)elements[i]; + } + NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); + + NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); + NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); + NSK_DISPLAY0(" ... released\n"); + + return NSK_TRUE; +} + +/** Get global reference to object from a static field of given class. */ +static jobject getObject(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[]) { + + jfieldID fieldID = NULL; + jobject obj = NULL; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get object from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)obj); + + NSK_DISPLAY1("Make global reference to object: 0x%p\n", obj); + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB2(NewGlobalRef, jni, obj)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got global ref: 0x%p\n", (void*)obj); + + return obj; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for debuggee to become ready\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + { + jclass debugeeClass = NULL; + + NSK_DISPLAY0(">>> Obtain debuggee class\n"); + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY0(">>> Obtain classloader of tested class\n"); + if (!NSK_VERIFY((classLoader = + getObject(jvmti, jni, debugeeClass, CLASSLOADER_FIELD_NAME, + TESTED_CLASSLOADER_SIG)) != NULL)) + return; + + NSK_DISPLAY0(">>> Obtain original bytecode of tested class\n"); + if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, + ORIG_BYTECODE_FIELD_NAME, + BYTECODE_FIELD_SIG, + &origClassSize, &origClassBytes))) + return; + } + + NSK_DISPLAY0(">>> Testcase #1: Load tested class and check CLASS_FILE_LOAD_HOOK event\n"); + { + jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; + + NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + NSK_DISPLAY0(" ... event enabled\n"); + + NSK_DISPLAY0("Let debugee to load tested class\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + NSK_DISPLAY0("Wait for tested class to be loaded\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { + NSK_DISPLAY0(" ... event disabled\n"); + } + + NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (eventsCount != 1) { + NSK_COMPLAIN3("Unexpected number of %s events for tested class:\n" + "# got events: %d\n" + "# expected: %d\n", + "CLASS_FILE_LOAD_HOOK", + eventsCount, 1); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY1(" ... received: %d events\n", eventsCount); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + NSK_DISPLAY1("Delete global reference to classloader object: 0x%p\n", (void*)classLoader); + NSK_CPP_STUB2(DeleteGlobalRef, jni, classLoader); + + NSK_DISPLAY1("Deallocate classfile bytes array: 0x%p\n", (void*)origClassBytes); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, origClassBytes))) { + nsk_jvmti_setFailStatus(); + } + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Callback for CLASS_FILE_LOAD_HOOK event **/ +static void JNICALL +callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, + jclass class_being_redefined, + jobject loader, const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", + nsk_null_string(name), (void*)loader, (void*)class_being_redefined, + (void*)class_data, (int)class_data_len); + + if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { + NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); + eventsCount++; + + NSK_DISPLAY1("Check class_being_redefined: 0x%p\n", (void*)class_being_redefined); + if (class_being_redefined != NULL) { + NSK_COMPLAIN1("Unexpected not NULL class_being_redefined in CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)class_being_redefined); + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY1("Check classloader: 0x%p\n", (void*)loader); + if (loader == NULL) { + NSK_COMPLAIN1("Unexpected NULL classloader in CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)loader); + nsk_jvmti_setFailStatus(); + } else if (!NSK_CPP_STUB3(IsSameObject, jni, loader, classLoader)) { + NSK_COMPLAIN2("Unexpected classloader in CLASS_FILE_LOAD_HOOK for tested class:\n" + "# got classloder: 0x%p\n" + "# expected same as: 0x%p\n", + (void*)loader, (void*)classLoader); + nsk_jvmti_setFailStatus(); + } + + if (!checkBytecode("original", class_data_len, class_data, + origClassSize, origClassBytes, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_classfloadhk003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + NSK_DISPLAY1("Add required capability: %s\n", "can_generate_eraly_class_hook_events"); + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_all_class_hook_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... added\n"); + + NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); + { + jvmtiEventCallbacks callbacks; + jint size = (jint)sizeof(callbacks); + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = callbackClassFileLoadHook; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... set\n"); + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/libclassfloadhk003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/libclassfloadhk003.c deleted file mode 100644 index 4bc200f6e15..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/libclassfloadhk003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "classfloadhk003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/libclassfloadhk003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/libclassfloadhk003.cpp new file mode 100644 index 00000000000..c5c4db35694 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/libclassfloadhk003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "classfloadhk003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/classfloadhk004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/classfloadhk004.c deleted file mode 100644 index dd41600a361..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/classfloadhk004.c +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk004" -#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk004r" -#define TESTED_CLASS_SIG "L"TESTED_CLASS_NAME";" - -#define BYTECODE_FIELD_SIG "[B" -#define NEW_BYTECODE_FIELD_NAME "newClassBytes" - -static jint newClassSize = 0; -static unsigned char* newClassBytes = NULL; - -static volatile int eventsCount = 0; - -/* ============================================================================= */ - -/** Get classfile bytecode from a static field of given class. */ -static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[], - jint* size, unsigned char* *bytes) { - - jfieldID fieldID = NULL; - jbyteArray array = NULL; - jbyte* elements; - int i; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); - - if (!NSK_JNI_VERIFY(jni, (*size = - NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); - - { - jboolean isCopy; - if (!NSK_JNI_VERIFY(jni, (elements = - NSK_CPP_STUB3(GetByteArrayElements, jni, array, - &isCopy)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); - - for (i = 0; i < *size; i++) { - (*bytes)[i] = (unsigned char)elements[i]; - } - NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); - - NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); - NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); - NSK_DISPLAY0(" ... released\n"); - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for debuggee to become ready\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - NSK_DISPLAY0(">>> Obtain classloader and instrumented bytecode of tested class\n"); - { - jclass debugeeClass = NULL; - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, - NEW_BYTECODE_FIELD_NAME, - BYTECODE_FIELD_SIG, - &newClassSize, &newClassBytes))) - return; - } - - NSK_DISPLAY0(">>> Testcase #1: Load tested class and replace bytecode in CLASS_FILE_LOAD_HOOK event\n"); - { - jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; - - NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - NSK_DISPLAY0(" ... event enabled\n"); - - NSK_DISPLAY0("Let debugee to load tested class\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - NSK_DISPLAY0("Wait for tested class to be loaded\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { - NSK_DISPLAY0(" ... event disabled\n"); - } - - NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (eventsCount != 1) { - NSK_COMPLAIN3("Unexpected number of %s events for tested class:\n" - "# got events: %d\n" - "# expected: %d\n", - "CLASS_FILE_LOAD_HOOK", - eventsCount, 1); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY1(" ... received: %d events\n", eventsCount); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Callback for CLASS_FILE_LOAD_HOOK event **/ -static void JNICALL -callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, - jclass class_being_redefined, - jobject loader, const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", - nsk_null_string(name), (void*)loader, (void*)class_being_redefined, - (void*)class_data, (int)class_data_len); - - if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { - NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); - eventsCount++; - - NSK_DISPLAY2("Received bytecode of loaded class: 0x%p:%d\n", - (void*)class_data, (int)class_data_len); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, class_data_len, class_data); - } - - NSK_DISPLAY1("Check pointer to new_class_data_len: 0x%p\n", (void*)new_class_data_len); - if (new_class_data_len == NULL) { - NSK_COMPLAIN1("NULL new_class_data_len pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)new_class_data_len); - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY1("Check pointer to new_class_data: 0x%p\n", (void*)new_class_data); - if (new_class_data == NULL) { - NSK_COMPLAIN1("NULL new_class_data pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)new_class_data); - nsk_jvmti_setFailStatus(); - } - - if (new_class_data_len != NULL && new_class_data != NULL) { - NSK_DISPLAY2("Replace with new bytecode: 0x%p:%d\n", - (void*)newClassBytes, (int)newClassSize); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, newClassSize, newClassBytes); - } - - *new_class_data_len = newClassSize; - *new_class_data = newClassBytes; - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_classfloadhk004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - NSK_DISPLAY1("Add required capability: %s\n", "can_generate_eraly_class_hook_events"); - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_all_class_hook_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... added\n"); - - NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); - { - jvmtiEventCallbacks callbacks; - jint size = (jint)sizeof(callbacks); - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = callbackClassFileLoadHook; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... set\n"); - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/classfloadhk004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/classfloadhk004.cpp new file mode 100644 index 00000000000..1609f63fb25 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/classfloadhk004.cpp @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk004" +#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk004r" +#define TESTED_CLASS_SIG "L" TESTED_CLASS_NAME ";" + +#define BYTECODE_FIELD_SIG "[B" +#define NEW_BYTECODE_FIELD_NAME "newClassBytes" + +static jint newClassSize = 0; +static unsigned char* newClassBytes = NULL; + +static volatile int eventsCount = 0; + +/* ============================================================================= */ + +/** Get classfile bytecode from a static field of given class. */ +static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[], + jint* size, unsigned char* *bytes) { + + jfieldID fieldID = NULL; + jbyteArray array = NULL; + jbyte* elements; + int i; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); + + if (!NSK_JNI_VERIFY(jni, (*size = + NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); + + { + jboolean isCopy; + if (!NSK_JNI_VERIFY(jni, (elements = + NSK_CPP_STUB3(GetByteArrayElements, jni, array, + &isCopy)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); + + for (i = 0; i < *size; i++) { + (*bytes)[i] = (unsigned char)elements[i]; + } + NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); + + NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); + NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); + NSK_DISPLAY0(" ... released\n"); + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for debuggee to become ready\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + NSK_DISPLAY0(">>> Obtain classloader and instrumented bytecode of tested class\n"); + { + jclass debugeeClass = NULL; + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, + NEW_BYTECODE_FIELD_NAME, + BYTECODE_FIELD_SIG, + &newClassSize, &newClassBytes))) + return; + } + + NSK_DISPLAY0(">>> Testcase #1: Load tested class and replace bytecode in CLASS_FILE_LOAD_HOOK event\n"); + { + jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; + + NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + NSK_DISPLAY0(" ... event enabled\n"); + + NSK_DISPLAY0("Let debugee to load tested class\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + NSK_DISPLAY0("Wait for tested class to be loaded\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { + NSK_DISPLAY0(" ... event disabled\n"); + } + + NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (eventsCount != 1) { + NSK_COMPLAIN3("Unexpected number of %s events for tested class:\n" + "# got events: %d\n" + "# expected: %d\n", + "CLASS_FILE_LOAD_HOOK", + eventsCount, 1); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY1(" ... received: %d events\n", eventsCount); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Callback for CLASS_FILE_LOAD_HOOK event **/ +static void JNICALL +callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, + jclass class_being_redefined, + jobject loader, const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", + nsk_null_string(name), (void*)loader, (void*)class_being_redefined, + (void*)class_data, (int)class_data_len); + + if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { + NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); + eventsCount++; + + NSK_DISPLAY2("Received bytecode of loaded class: 0x%p:%d\n", + (void*)class_data, (int)class_data_len); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, class_data_len, class_data); + } + + NSK_DISPLAY1("Check pointer to new_class_data_len: 0x%p\n", (void*)new_class_data_len); + if (new_class_data_len == NULL) { + NSK_COMPLAIN1("NULL new_class_data_len pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)new_class_data_len); + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY1("Check pointer to new_class_data: 0x%p\n", (void*)new_class_data); + if (new_class_data == NULL) { + NSK_COMPLAIN1("NULL new_class_data pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)new_class_data); + nsk_jvmti_setFailStatus(); + } + + if (new_class_data_len != NULL && new_class_data != NULL) { + NSK_DISPLAY2("Replace with new bytecode: 0x%p:%d\n", + (void*)newClassBytes, (int)newClassSize); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, newClassSize, newClassBytes); + } + + *new_class_data_len = newClassSize; + *new_class_data = newClassBytes; + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_classfloadhk004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + NSK_DISPLAY1("Add required capability: %s\n", "can_generate_eraly_class_hook_events"); + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_all_class_hook_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... added\n"); + + NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); + { + jvmtiEventCallbacks callbacks; + jint size = (jint)sizeof(callbacks); + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = callbackClassFileLoadHook; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... set\n"); + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/libclassfloadhk004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/libclassfloadhk004.c deleted file mode 100644 index c1298d45084..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/libclassfloadhk004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "classfloadhk004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/libclassfloadhk004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/libclassfloadhk004.cpp new file mode 100644 index 00000000000..bd970474377 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk004/libclassfloadhk004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "classfloadhk004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/classfloadhk005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/classfloadhk005.c deleted file mode 100644 index aaa2297e5b3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/classfloadhk005.c +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk005" -#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk005r" -#define TESTED_CLASS_SIG "L"TESTED_CLASS_NAME";" - -#define BYTECODE_FIELD_SIG "[B" -#define NEW_BYTECODE_FIELD_NAME "newClassBytes" - -static jint newClassSize = 0; -static unsigned char* newClassBytes = NULL; - -static volatile int eventsCount = 0; - -/* ============================================================================= */ - -/** Check (strictly or not) if bytecode has expected size and bytes or complain an error. */ -static int checkBytecode(const char kind[], jint size, const unsigned char bytes[], - jint expectedSize, const unsigned char expectedBytes[], - int strict) { - int success = NSK_TRUE; - - NSK_DISPLAY3("Check %s bytecode: 0x%p:%d\n", kind, (void*)bytes, (int)size); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, size, bytes); - } - - if (bytes == NULL) { - NSK_COMPLAIN2("Unexpected NULL pointer to %s bytecode in CLASS_FILE_LOAD_HOOK: 0x%p\n", - kind, (void*)bytes); - return NSK_FALSE; - } - - if (size <= 0) { - NSK_COMPLAIN2("Unexpected zero size of %s bytecode in CLASS_FILE_LOAD_HOOK: %d\n", - kind, (int)size); - return NSK_FALSE; - } - - if (strict) { - if (size != expectedSize) { - NSK_COMPLAIN3("Unexpected size of %s bytecode in CLASS_FILE_LOAD_HOOK:\n" - "# got size: %d\n" - "# expected: %d\n", - kind, (int)size, (int)expectedSize); - success = NSK_FALSE; - } else { - jint different = 0; - jint i; - - for (i = 0; i < size; i++) { - if (bytes[i] != expectedBytes[i]) { - different++; - } - } - if (different > 0) { - NSK_COMPLAIN2("Unexpected bytes in %s bytecode in CLASS_FILE_LOAD_HOOK:\n" - "# different bytes: %d\n" - "# total bytes: %d\n", - (int)different, (int)size); - success = NSK_FALSE; - } - } - - if (!success) { - NSK_COMPLAIN2("Got %s bytecode is not equal to expected bytecode: %d bytes\n", - kind, expectedSize); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, expectedSize, expectedBytes); - } - } else { - NSK_DISPLAY1("All %s bytecode is equal to expected one\n", kind); - } - } - - return success; -} - -/** Get classfile bytecode from a static field of given class. */ -static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[], - jint* size, unsigned char* *bytes) { - - jfieldID fieldID = NULL; - jbyteArray array = NULL; - jbyte* elements; - int i; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); - - if (!NSK_JNI_VERIFY(jni, (*size = - NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); - - { - jboolean isCopy; - if (!NSK_JNI_VERIFY(jni, (elements = - NSK_CPP_STUB3(GetByteArrayElements, jni, array, - &isCopy)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); - - for (i = 0; i < *size; i++) { - (*bytes)[i] = (unsigned char)elements[i]; - } - NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); - - NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); - NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); - NSK_DISPLAY0(" ... released\n"); - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for debuggee to become ready\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - NSK_DISPLAY0(">>> Obtain classloader and instrumented bytecode of tested class\n"); - { - jclass debugeeClass = NULL; - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, - NEW_BYTECODE_FIELD_NAME, - BYTECODE_FIELD_SIG, - &newClassSize, &newClassBytes))) - return; - } - - NSK_DISPLAY0(">>> Testcase #1: Load tested class and replace bytecode in CLASS_FILE_LOAD_HOOK event\n"); - { - jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; - - NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - NSK_DISPLAY0(" ... event enabled\n"); - - NSK_DISPLAY0("Let debugee to load tested class\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - NSK_DISPLAY0("Wait for tested class to be loaded\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { - NSK_DISPLAY0(" ... event disabled\n"); - } - - NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (eventsCount != 1) { - NSK_COMPLAIN3("Unexpected number of %s events for tested class:\n" - "# got events: %d\n" - "# expected: %d\n", - "CLASS_FILE_LOAD_HOOK", - eventsCount, 1); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY1(" ... received: %d events\n", eventsCount); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Callback for CLASS_FILE_LOAD_HOOK event **/ -static void JNICALL -callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, - jclass class_being_redefined, - jobject loader, const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", - nsk_null_string(name), (void*)loader, (void*)class_being_redefined, - (void*)class_data, (int)class_data_len); - - if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { - NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); - eventsCount++; - - NSK_DISPLAY2("Received original bytecode of tested class: 0x%p:%d\n", - (void*)class_data, (int)class_data_len); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, class_data_len, class_data); - } - - NSK_DISPLAY1("Check pointer to new_class_data_len: 0x%p\n", (void*)new_class_data_len); - if (new_class_data_len == NULL) { - NSK_COMPLAIN1("NULL new_class_data_len pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)new_class_data_len); - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY1("Check pointer to new_class_data: 0x%p\n", (void*)new_class_data); - if (new_class_data == NULL) { - NSK_COMPLAIN1("NULL new_class_data pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)new_class_data); - nsk_jvmti_setFailStatus(); - } - - if (new_class_data_len != NULL && new_class_data != NULL) { - NSK_DISPLAY2("Replace with instrumented bytecode: 0x%p:%d\n", - (void*)newClassBytes, (int)newClassSize); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, newClassSize, newClassBytes); - } - - *new_class_data_len = newClassSize; - *new_class_data = newClassBytes; - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_classfloadhk005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - NSK_DISPLAY1("Add required capability: %s\n", "can_generate_eraly_class_hook_events"); - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_all_class_hook_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... added\n"); - - NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); - { - jvmtiEventCallbacks callbacks; - jint size = (jint)sizeof(callbacks); - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = callbackClassFileLoadHook; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... set\n"); - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/classfloadhk005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/classfloadhk005.cpp new file mode 100644 index 00000000000..736b8667137 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/classfloadhk005.cpp @@ -0,0 +1,370 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk005" +#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk005r" +#define TESTED_CLASS_SIG "L" TESTED_CLASS_NAME ";" + +#define BYTECODE_FIELD_SIG "[B" +#define NEW_BYTECODE_FIELD_NAME "newClassBytes" + +static jint newClassSize = 0; +static unsigned char* newClassBytes = NULL; + +static volatile int eventsCount = 0; + +/* ============================================================================= */ + +/** Check (strictly or not) if bytecode has expected size and bytes or complain an error. */ +static int checkBytecode(const char kind[], jint size, const unsigned char bytes[], + jint expectedSize, const unsigned char expectedBytes[], + int strict) { + int success = NSK_TRUE; + + NSK_DISPLAY3("Check %s bytecode: 0x%p:%d\n", kind, (void*)bytes, (int)size); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, size, bytes); + } + + if (bytes == NULL) { + NSK_COMPLAIN2("Unexpected NULL pointer to %s bytecode in CLASS_FILE_LOAD_HOOK: 0x%p\n", + kind, (void*)bytes); + return NSK_FALSE; + } + + if (size <= 0) { + NSK_COMPLAIN2("Unexpected zero size of %s bytecode in CLASS_FILE_LOAD_HOOK: %d\n", + kind, (int)size); + return NSK_FALSE; + } + + if (strict) { + if (size != expectedSize) { + NSK_COMPLAIN3("Unexpected size of %s bytecode in CLASS_FILE_LOAD_HOOK:\n" + "# got size: %d\n" + "# expected: %d\n", + kind, (int)size, (int)expectedSize); + success = NSK_FALSE; + } else { + jint different = 0; + jint i; + + for (i = 0; i < size; i++) { + if (bytes[i] != expectedBytes[i]) { + different++; + } + } + if (different > 0) { + NSK_COMPLAIN2("Unexpected bytes in %s bytecode in CLASS_FILE_LOAD_HOOK:\n" + "# different bytes: %d\n" + "# total bytes: %d\n", + (int)different, (int)size); + success = NSK_FALSE; + } + } + + if (!success) { + NSK_COMPLAIN2("Got %s bytecode is not equal to expected bytecode: %d bytes\n", + kind, expectedSize); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, expectedSize, expectedBytes); + } + } else { + NSK_DISPLAY1("All %s bytecode is equal to expected one\n", kind); + } + } + + return success; +} + +/** Get classfile bytecode from a static field of given class. */ +static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[], + jint* size, unsigned char* *bytes) { + + jfieldID fieldID = NULL; + jbyteArray array = NULL; + jbyte* elements; + int i; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); + + if (!NSK_JNI_VERIFY(jni, (*size = + NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); + + { + jboolean isCopy; + if (!NSK_JNI_VERIFY(jni, (elements = + NSK_CPP_STUB3(GetByteArrayElements, jni, array, + &isCopy)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); + + for (i = 0; i < *size; i++) { + (*bytes)[i] = (unsigned char)elements[i]; + } + NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); + + NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); + NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); + NSK_DISPLAY0(" ... released\n"); + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for debuggee to become ready\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + NSK_DISPLAY0(">>> Obtain classloader and instrumented bytecode of tested class\n"); + { + jclass debugeeClass = NULL; + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, + NEW_BYTECODE_FIELD_NAME, + BYTECODE_FIELD_SIG, + &newClassSize, &newClassBytes))) + return; + } + + NSK_DISPLAY0(">>> Testcase #1: Load tested class and replace bytecode in CLASS_FILE_LOAD_HOOK event\n"); + { + jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; + + NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + NSK_DISPLAY0(" ... event enabled\n"); + + NSK_DISPLAY0("Let debugee to load tested class\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + NSK_DISPLAY0("Wait for tested class to be loaded\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { + NSK_DISPLAY0(" ... event disabled\n"); + } + + NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (eventsCount != 1) { + NSK_COMPLAIN3("Unexpected number of %s events for tested class:\n" + "# got events: %d\n" + "# expected: %d\n", + "CLASS_FILE_LOAD_HOOK", + eventsCount, 1); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY1(" ... received: %d events\n", eventsCount); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Callback for CLASS_FILE_LOAD_HOOK event **/ +static void JNICALL +callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, + jclass class_being_redefined, + jobject loader, const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", + nsk_null_string(name), (void*)loader, (void*)class_being_redefined, + (void*)class_data, (int)class_data_len); + + if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { + NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); + eventsCount++; + + NSK_DISPLAY2("Received original bytecode of tested class: 0x%p:%d\n", + (void*)class_data, (int)class_data_len); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, class_data_len, class_data); + } + + NSK_DISPLAY1("Check pointer to new_class_data_len: 0x%p\n", (void*)new_class_data_len); + if (new_class_data_len == NULL) { + NSK_COMPLAIN1("NULL new_class_data_len pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)new_class_data_len); + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY1("Check pointer to new_class_data: 0x%p\n", (void*)new_class_data); + if (new_class_data == NULL) { + NSK_COMPLAIN1("NULL new_class_data pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)new_class_data); + nsk_jvmti_setFailStatus(); + } + + if (new_class_data_len != NULL && new_class_data != NULL) { + NSK_DISPLAY2("Replace with instrumented bytecode: 0x%p:%d\n", + (void*)newClassBytes, (int)newClassSize); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, newClassSize, newClassBytes); + } + + *new_class_data_len = newClassSize; + *new_class_data = newClassBytes; + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_classfloadhk005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + NSK_DISPLAY1("Add required capability: %s\n", "can_generate_eraly_class_hook_events"); + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_all_class_hook_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... added\n"); + + NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); + { + jvmtiEventCallbacks callbacks; + jint size = (jint)sizeof(callbacks); + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = callbackClassFileLoadHook; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... set\n"); + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/libclassfloadhk005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/libclassfloadhk005.c deleted file mode 100644 index c341e71283a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/libclassfloadhk005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "classfloadhk005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/libclassfloadhk005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/libclassfloadhk005.cpp new file mode 100644 index 00000000000..04a1c051d9a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk005/libclassfloadhk005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "classfloadhk005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/classfloadhk006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/classfloadhk006.c deleted file mode 100644 index aa28756490d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/classfloadhk006.c +++ /dev/null @@ -1,434 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk006" -#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk006r" -#define TESTED_CLASS_SIG "L"TESTED_CLASS_NAME";" - -#define BYTECODE_FIELD_SIG "[B" -#define REDEF_BYTECODE_FIELD_NAME "redefClassBytes" - -#define TESTED_CLASS_FIELD_NAME "testedClass" -#define TESTED_CLASS_FIELD_SIG "Ljava/lang/Class;" - -static jclass testedClass = NULL; - -static jint redefClassSize = 0; -static unsigned char* redefClassBytes = NULL; - -static volatile int eventsCount = 0; - -/* ============================================================================= */ - -/** Check (strictly or not) if bytecode has expected size and bytes or complain an error. */ -static int checkBytecode(const char kind[], jint size, const unsigned char bytes[], - jint expectedSize, const unsigned char expectedBytes[], - int strict) { - int success = NSK_TRUE; - - NSK_DISPLAY3("Check %s bytecode: 0x%p:%d\n", kind, (void*)bytes, (int)size); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, size, bytes); - } - - if (bytes == NULL) { - NSK_COMPLAIN2("Unexpected NULL pointer to %s bytecode in CLASS_FILE_LOAD_HOOK: 0x%p\n", - kind, (void*)bytes); - return NSK_FALSE; - } - - if (size <= 0) { - NSK_COMPLAIN2("Unexpected zero size of %s bytecode in CLASS_FILE_LOAD_HOOK: %d\n", - kind, (int)size); - return NSK_FALSE; - } - - if (strict) { - if (size != expectedSize) { - NSK_COMPLAIN3("Unexpected size of %s bytecode in CLASS_FILE_LOAD_HOOK:\n" - "# got size: %d\n" - "# expected: %d\n", - kind, (int)size, (int)expectedSize); - success = NSK_FALSE; - } else { - jint different = 0; - jint i; - - for (i = 0; i < size; i++) { - if (bytes[i] != expectedBytes[i]) { - different++; - } - } - if (different > 0) { - NSK_COMPLAIN2("Unexpected bytes in %s bytecode in CLASS_FILE_LOAD_HOOK:\n" - "# different bytes: %d\n" - "# total bytes: %d\n", - (int)different, (int)size); - success = NSK_FALSE; - } - } - - if (!success) { - NSK_COMPLAIN2("Got %s bytecode is not equal to expected bytecode: %d bytes\n", - kind, expectedSize); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, expectedSize, expectedBytes); - } - } else { - NSK_DISPLAY1("All %s bytecode is equal to expected one\n", kind); - } - } - - return success; -} - -/** Get classfile bytecode from a static field of given class. */ -static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[], - jint* size, unsigned char* *bytes) { - - jfieldID fieldID = NULL; - jbyteArray array = NULL; - jbyte* elements; - int i; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); - - if (!NSK_JNI_VERIFY(jni, (*size = - NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); - - { - jboolean isCopy; - if (!NSK_JNI_VERIFY(jni, (elements = - NSK_CPP_STUB3(GetByteArrayElements, jni, array, - &isCopy)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); - - for (i = 0; i < *size; i++) { - (*bytes)[i] = (unsigned char)elements[i]; - } - NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); - - NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); - NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); - NSK_DISPLAY0(" ... released\n"); - - return NSK_TRUE; -} - -/** Get global reference to object from a static field of given class. */ -static jobject getObject(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[]) { - - jfieldID fieldID = NULL; - jobject obj = NULL; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get object from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)obj); - - NSK_DISPLAY1("Make global reference to object: 0x%p\n", obj); - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB2(NewGlobalRef, jni, obj)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got global ref: 0x%p\n", (void*)obj); - - return obj; -} - -/** Redefine given class with new bytecode. */ -static int redefineClass(jvmtiEnv* jvmti, jclass klass, const char className[], - jint size, unsigned char bytes[]) { - jvmtiClassDefinition classDef; - - classDef.klass = klass; - classDef.class_byte_count = size; - classDef.class_bytes = bytes; - - NSK_DISPLAY1("Redefine class: %s\n", className); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &classDef))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... redefined with bytecode: %d bytes\n", (int)size); - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for debuggee to load original class\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - { - jclass debugeeClass = NULL; - - NSK_DISPLAY0(">>> Obtain debuggee class\n"); - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY0(">>> Obtain tested class object\n"); - if (!NSK_VERIFY((testedClass = (jclass) - getObject(jvmti, jni, debugeeClass, TESTED_CLASS_FIELD_NAME, - TESTED_CLASS_FIELD_SIG)) != NULL)) - return; - - NSK_DISPLAY0(">>> Obtain redefined bytecode of tested class\n"); - if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, - REDEF_BYTECODE_FIELD_NAME, - BYTECODE_FIELD_SIG, - &redefClassSize, &redefClassBytes))) - return; - } - - NSK_DISPLAY0(">>> Redefine tested class\n"); - { - if (!NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, - redefClassSize, redefClassBytes))) - return; - } - - NSK_DISPLAY0(">>> Testcase #1: Redefine class and check CLASS_FILE_LOAD_HOOK event\n"); - { - jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; - - NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - NSK_DISPLAY0(" ... event enabled\n"); - - NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, - redefClassSize, redefClassBytes)); - - NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { - NSK_DISPLAY0(" ... event disabled\n"); - } - - NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (eventsCount != 1) { - NSK_COMPLAIN3("Unexpected number of %s events received for tested class:\n" - "# received: %d events\n" - "# expected: %d events\n", - "CLASS_FILE_LOAD_HOOK", eventsCount, 1); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY1(" ... received: %d events\n", eventsCount); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - NSK_DISPLAY1("Delete global reference to tested class object: 0x%p\n", (void*)testedClass); - NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass); - - NSK_DISPLAY1("Deallocate redefined bytecode array: 0x%p\n", (void*)redefClassBytes); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, redefClassBytes))) { - nsk_jvmti_setFailStatus(); - } - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Callback for CLASS_FILE_LOAD_HOOK event **/ -static void JNICALL -callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, - jclass class_being_redefined, - jobject loader, const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", - nsk_null_string(name), (void*)loader, (void*)class_being_redefined, - (void*)class_data, (int)class_data_len); - - if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { - NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); - eventsCount++; - - NSK_DISPLAY1("Check class_being_redefined: 0x%p\n", (void*)class_being_redefined); - if (class_being_redefined == NULL) { - NSK_COMPLAIN1("Unexpected NULL class_being_redefined in CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)class_being_redefined); - nsk_jvmti_setFailStatus(); - } else if (!NSK_CPP_STUB3(IsSameObject, jni, class_being_redefined, testedClass)) { - NSK_COMPLAIN2("Unexpected class_being_redefined in CLASS_FILE_LOAD_HOOK:\n" - "# got class: 0x%p\n" - "# expected same as: 0x%p\n", - (void*)class_being_redefined, (void*)testedClass); - nsk_jvmti_setFailStatus(); - } - - if (!checkBytecode("redefined", class_data_len, class_data, - redefClassSize, redefClassBytes, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_classfloadhk006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - NSK_DISPLAY1("Add required capabilities: %s\n", "can_generate_eraly_class_hook_events, can_redefine_classes"); - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_all_class_hook_events = 1; - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... added\n"); - - NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); - { - jvmtiEventCallbacks callbacks; - jint size = (jint)sizeof(callbacks); - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = callbackClassFileLoadHook; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... set\n"); - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/classfloadhk006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/classfloadhk006.cpp new file mode 100644 index 00000000000..260c6d0ea76 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/classfloadhk006.cpp @@ -0,0 +1,434 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk006" +#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk006r" +#define TESTED_CLASS_SIG "L" TESTED_CLASS_NAME ";" + +#define BYTECODE_FIELD_SIG "[B" +#define REDEF_BYTECODE_FIELD_NAME "redefClassBytes" + +#define TESTED_CLASS_FIELD_NAME "testedClass" +#define TESTED_CLASS_FIELD_SIG "Ljava/lang/Class;" + +static jclass testedClass = NULL; + +static jint redefClassSize = 0; +static unsigned char* redefClassBytes = NULL; + +static volatile int eventsCount = 0; + +/* ============================================================================= */ + +/** Check (strictly or not) if bytecode has expected size and bytes or complain an error. */ +static int checkBytecode(const char kind[], jint size, const unsigned char bytes[], + jint expectedSize, const unsigned char expectedBytes[], + int strict) { + int success = NSK_TRUE; + + NSK_DISPLAY3("Check %s bytecode: 0x%p:%d\n", kind, (void*)bytes, (int)size); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, size, bytes); + } + + if (bytes == NULL) { + NSK_COMPLAIN2("Unexpected NULL pointer to %s bytecode in CLASS_FILE_LOAD_HOOK: 0x%p\n", + kind, (void*)bytes); + return NSK_FALSE; + } + + if (size <= 0) { + NSK_COMPLAIN2("Unexpected zero size of %s bytecode in CLASS_FILE_LOAD_HOOK: %d\n", + kind, (int)size); + return NSK_FALSE; + } + + if (strict) { + if (size != expectedSize) { + NSK_COMPLAIN3("Unexpected size of %s bytecode in CLASS_FILE_LOAD_HOOK:\n" + "# got size: %d\n" + "# expected: %d\n", + kind, (int)size, (int)expectedSize); + success = NSK_FALSE; + } else { + jint different = 0; + jint i; + + for (i = 0; i < size; i++) { + if (bytes[i] != expectedBytes[i]) { + different++; + } + } + if (different > 0) { + NSK_COMPLAIN2("Unexpected bytes in %s bytecode in CLASS_FILE_LOAD_HOOK:\n" + "# different bytes: %d\n" + "# total bytes: %d\n", + (int)different, (int)size); + success = NSK_FALSE; + } + } + + if (!success) { + NSK_COMPLAIN2("Got %s bytecode is not equal to expected bytecode: %d bytes\n", + kind, expectedSize); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, expectedSize, expectedBytes); + } + } else { + NSK_DISPLAY1("All %s bytecode is equal to expected one\n", kind); + } + } + + return success; +} + +/** Get classfile bytecode from a static field of given class. */ +static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[], + jint* size, unsigned char* *bytes) { + + jfieldID fieldID = NULL; + jbyteArray array = NULL; + jbyte* elements; + int i; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); + + if (!NSK_JNI_VERIFY(jni, (*size = + NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); + + { + jboolean isCopy; + if (!NSK_JNI_VERIFY(jni, (elements = + NSK_CPP_STUB3(GetByteArrayElements, jni, array, + &isCopy)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); + + for (i = 0; i < *size; i++) { + (*bytes)[i] = (unsigned char)elements[i]; + } + NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); + + NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); + NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); + NSK_DISPLAY0(" ... released\n"); + + return NSK_TRUE; +} + +/** Get global reference to object from a static field of given class. */ +static jobject getObject(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[]) { + + jfieldID fieldID = NULL; + jobject obj = NULL; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get object from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)obj); + + NSK_DISPLAY1("Make global reference to object: 0x%p\n", obj); + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB2(NewGlobalRef, jni, obj)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got global ref: 0x%p\n", (void*)obj); + + return obj; +} + +/** Redefine given class with new bytecode. */ +static int redefineClass(jvmtiEnv* jvmti, jclass klass, const char className[], + jint size, unsigned char bytes[]) { + jvmtiClassDefinition classDef; + + classDef.klass = klass; + classDef.class_byte_count = size; + classDef.class_bytes = bytes; + + NSK_DISPLAY1("Redefine class: %s\n", className); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &classDef))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... redefined with bytecode: %d bytes\n", (int)size); + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for debuggee to load original class\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + { + jclass debugeeClass = NULL; + + NSK_DISPLAY0(">>> Obtain debuggee class\n"); + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY0(">>> Obtain tested class object\n"); + if (!NSK_VERIFY((testedClass = (jclass) + getObject(jvmti, jni, debugeeClass, TESTED_CLASS_FIELD_NAME, + TESTED_CLASS_FIELD_SIG)) != NULL)) + return; + + NSK_DISPLAY0(">>> Obtain redefined bytecode of tested class\n"); + if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, + REDEF_BYTECODE_FIELD_NAME, + BYTECODE_FIELD_SIG, + &redefClassSize, &redefClassBytes))) + return; + } + + NSK_DISPLAY0(">>> Redefine tested class\n"); + { + if (!NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, + redefClassSize, redefClassBytes))) + return; + } + + NSK_DISPLAY0(">>> Testcase #1: Redefine class and check CLASS_FILE_LOAD_HOOK event\n"); + { + jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; + + NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + NSK_DISPLAY0(" ... event enabled\n"); + + NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, + redefClassSize, redefClassBytes)); + + NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { + NSK_DISPLAY0(" ... event disabled\n"); + } + + NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (eventsCount != 1) { + NSK_COMPLAIN3("Unexpected number of %s events received for tested class:\n" + "# received: %d events\n" + "# expected: %d events\n", + "CLASS_FILE_LOAD_HOOK", eventsCount, 1); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY1(" ... received: %d events\n", eventsCount); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + NSK_DISPLAY1("Delete global reference to tested class object: 0x%p\n", (void*)testedClass); + NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass); + + NSK_DISPLAY1("Deallocate redefined bytecode array: 0x%p\n", (void*)redefClassBytes); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, redefClassBytes))) { + nsk_jvmti_setFailStatus(); + } + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Callback for CLASS_FILE_LOAD_HOOK event **/ +static void JNICALL +callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, + jclass class_being_redefined, + jobject loader, const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", + nsk_null_string(name), (void*)loader, (void*)class_being_redefined, + (void*)class_data, (int)class_data_len); + + if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { + NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); + eventsCount++; + + NSK_DISPLAY1("Check class_being_redefined: 0x%p\n", (void*)class_being_redefined); + if (class_being_redefined == NULL) { + NSK_COMPLAIN1("Unexpected NULL class_being_redefined in CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)class_being_redefined); + nsk_jvmti_setFailStatus(); + } else if (!NSK_CPP_STUB3(IsSameObject, jni, class_being_redefined, testedClass)) { + NSK_COMPLAIN2("Unexpected class_being_redefined in CLASS_FILE_LOAD_HOOK:\n" + "# got class: 0x%p\n" + "# expected same as: 0x%p\n", + (void*)class_being_redefined, (void*)testedClass); + nsk_jvmti_setFailStatus(); + } + + if (!checkBytecode("redefined", class_data_len, class_data, + redefClassSize, redefClassBytes, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_classfloadhk006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + NSK_DISPLAY1("Add required capabilities: %s\n", "can_generate_eraly_class_hook_events, can_redefine_classes"); + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_all_class_hook_events = 1; + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... added\n"); + + NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); + { + jvmtiEventCallbacks callbacks; + jint size = (jint)sizeof(callbacks); + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = callbackClassFileLoadHook; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... set\n"); + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/libclassfloadhk006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/libclassfloadhk006.c deleted file mode 100644 index 4c050acbe64..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/libclassfloadhk006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "classfloadhk006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/libclassfloadhk006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/libclassfloadhk006.cpp new file mode 100644 index 00000000000..9e7024382e7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk006/libclassfloadhk006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "classfloadhk006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/classfloadhk007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/classfloadhk007.c deleted file mode 100644 index 5b5ff1a0b19..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/classfloadhk007.c +++ /dev/null @@ -1,460 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk007" -#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk007r" -#define TESTED_CLASS_SIG "L"TESTED_CLASS_NAME";" -#define TESTED_CLASSLOADER_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk007ClassLoader" -#define TESTED_CLASSLOADER_SIG "L"TESTED_CLASSLOADER_NAME";" - -#define BYTECODE_FIELD_SIG "[B" -#define REDEF_BYTECODE_FIELD_NAME "redefClassBytes" - -#define CLASSLOADER_FIELD_NAME "classLoader" -#define TESTED_CLASS_FIELD_NAME "testedClass" -#define TESTED_CLASS_FIELD_SIG "Ljava/lang/Class;" - -static jobject classLoader = NULL; -static jclass testedClass = NULL; - -static jint redefClassSize = 0; -static unsigned char* redefClassBytes = NULL; - -static volatile int eventsCount = 0; - -/* ============================================================================= */ - -/** Check (strictly or not) if bytecode has expected size and bytes or complain an error. */ -static int checkBytecode(const char kind[], jint size, const unsigned char bytes[], - jint expectedSize, const unsigned char expectedBytes[], - int strict) { - int success = NSK_TRUE; - - NSK_DISPLAY3("Check %s bytecode: 0x%p:%d\n", kind, (void*)bytes, (int)size); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, size, bytes); - } - - if (bytes == NULL) { - NSK_COMPLAIN2("Unexpected NULL pointer to %s bytecode in CLASS_FILE_LOAD_HOOK: 0x%p\n", - kind, (void*)bytes); - return NSK_FALSE; - } - - if (size <= 0) { - NSK_COMPLAIN2("Unexpected zero size of %s bytecode in CLASS_FILE_LOAD_HOOK: %d\n", - kind, (int)size); - return NSK_FALSE; - } - - if (strict) { - if (size != expectedSize) { - NSK_COMPLAIN3("Unexpected size of %s bytecode in CLASS_FILE_LOAD_HOOK:\n" - "# got size: %d\n" - "# expected: %d\n", - kind, (int)size, (int)expectedSize); - success = NSK_FALSE; - } else { - jint different = 0; - jint i; - - for (i = 0; i < size; i++) { - if (bytes[i] != expectedBytes[i]) { - different++; - } - } - if (different > 0) { - NSK_COMPLAIN2("Unexpected bytes in %s bytecode in CLASS_FILE_LOAD_HOOK:\n" - "# different bytes: %d\n" - "# total bytes: %d\n", - (int)different, (int)size); - success = NSK_FALSE; - } - } - - if (!success) { - NSK_COMPLAIN2("Got %s bytecode is not equal to expected bytecode: %d bytes\n", - kind, expectedSize); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, expectedSize, expectedBytes); - } - } else { - NSK_DISPLAY1("All %s bytecode is equal to expected one\n", kind); - } - } - - return success; -} - -/** Get classfile bytecode from a static field of given class. */ -static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[], - jint* size, unsigned char* *bytes) { - - jfieldID fieldID = NULL; - jbyteArray array = NULL; - jbyte* elements; - int i; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); - - if (!NSK_JNI_VERIFY(jni, (*size = - NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); - - { - jboolean isCopy; - if (!NSK_JNI_VERIFY(jni, (elements = - NSK_CPP_STUB3(GetByteArrayElements, jni, array, - &isCopy)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); - - for (i = 0; i < *size; i++) { - (*bytes)[i] = (unsigned char)elements[i]; - } - NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); - - NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); - NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); - NSK_DISPLAY0(" ... released\n"); - - return NSK_TRUE; -} - -/** Get global reference to object from a static field of given class. */ -static jobject getObject(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[]) { - - jfieldID fieldID = NULL; - jobject obj = NULL; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get object from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)obj); - - NSK_DISPLAY1("Make global reference to object: 0x%p\n", obj); - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB2(NewGlobalRef, jni, obj)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got global ref: 0x%p\n", (void*)obj); - - return obj; -} - -/** Redefine given class with new bytecode. */ -static int redefineClass(jvmtiEnv* jvmti, jclass klass, const char className[], - jint size, unsigned char bytes[]) { - jvmtiClassDefinition classDef; - - classDef.klass = klass; - classDef.class_byte_count = size; - classDef.class_bytes = bytes; - - NSK_DISPLAY1("Redefine class: %s\n", className); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &classDef))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... redefined with bytecode: %d bytes\n", (int)size); - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for debuggee to load original class\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - { - jclass debugeeClass = NULL; - - NSK_DISPLAY0(">>> Obtain debuggee class\n"); - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY0(">>> Obtain tested class object\n"); - if (!NSK_VERIFY((testedClass = (jclass) - getObject(jvmti, jni, debugeeClass, TESTED_CLASS_FIELD_NAME, - TESTED_CLASS_FIELD_SIG)) != NULL)) - return; - - NSK_DISPLAY0(">>> Obtain classloader object\n"); - if (!NSK_VERIFY((classLoader = - getObject(jvmti, jni, debugeeClass, CLASSLOADER_FIELD_NAME, - TESTED_CLASSLOADER_SIG)) != NULL)) - return; - - NSK_DISPLAY0(">>> Obtain redefined bytecode of tested class\n"); - if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, - REDEF_BYTECODE_FIELD_NAME, - BYTECODE_FIELD_SIG, - &redefClassSize, &redefClassBytes))) - return; - } - - NSK_DISPLAY0(">>> Redefine tested class\n"); - { - if (!NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, - redefClassSize, redefClassBytes))) - return; - } - - NSK_DISPLAY0(">>> Testcase #1: Redefine class and check CLASS_FILE_LOAD_HOOK event\n"); - { - jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; - - NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - NSK_DISPLAY0(" ... event enabled\n"); - - NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, - redefClassSize, redefClassBytes)); - - NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { - NSK_DISPLAY0(" ... event disabled\n"); - } - - NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (eventsCount != 1) { - NSK_COMPLAIN3("Unexpected number of %s events received for tested class:\n" - "# received: %d events\n" - "# expected: %d events\n", - "CLASS_FILE_LOAD_HOOK", eventsCount, 1); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY1(" ... received: %d events\n", eventsCount); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - NSK_DISPLAY1("Delete global reference to classloader object: 0x%p\n", (void*)classLoader); - NSK_CPP_STUB2(DeleteGlobalRef, jni, classLoader); - - NSK_DISPLAY1("Delete global reference to tested class object: 0x%p\n", (void*)testedClass); - NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass); - - NSK_DISPLAY1("Deallocate redefined bytecode array: 0x%p\n", (void*)redefClassBytes); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, redefClassBytes))) { - nsk_jvmti_setFailStatus(); - } - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Callback for CLASS_FILE_LOAD_HOOK event **/ -static void JNICALL -callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, - jclass class_being_redefined, - jobject loader, const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", - nsk_null_string(name), (void*)loader, (void*)class_being_redefined, - (void*)class_data, (int)class_data_len); - - if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { - NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); - eventsCount++; - - NSK_DISPLAY1("Check classloader: 0x%p\n", (void*)loader); - if (loader == NULL) { - NSK_COMPLAIN1("Unexpected NULL classloader in CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)loader); - nsk_jvmti_setFailStatus(); - } else if (!NSK_CPP_STUB3(IsSameObject, jni, loader, classLoader)) { - NSK_COMPLAIN2("Unexpected classloader in CLASS_FILE_LOAD_HOOK:\n" - "# got classloder: 0x%p\n" - "# expected same as: 0x%p\n", - (void*)loader, (void*)classLoader); - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY1("Check class_being_redefined: 0x%p\n", (void*)class_being_redefined); - if (class_being_redefined == NULL) { - NSK_COMPLAIN1("Unexpected NULL class_being_redefined in CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)class_being_redefined); - nsk_jvmti_setFailStatus(); - } else if (!NSK_CPP_STUB3(IsSameObject, jni, class_being_redefined, testedClass)) { - NSK_COMPLAIN2("Unexpected class_being_redefined in CLASS_FILE_LOAD_HOOK:\n" - "# got class: 0x%p\n" - "# expected same as: 0x%p\n", - (void*)class_being_redefined, (void*)testedClass); - nsk_jvmti_setFailStatus(); - } - - if (!checkBytecode("redefined", class_data_len, class_data, - redefClassSize, redefClassBytes, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_classfloadhk007(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - NSK_DISPLAY1("Add required capabilities: %s\n", "can_generate_eraly_class_hook_events, can_redefine_classes"); - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_all_class_hook_events = 1; - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... added\n"); - - NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); - { - jvmtiEventCallbacks callbacks; - jint size = (jint)sizeof(callbacks); - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = callbackClassFileLoadHook; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... set\n"); - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/classfloadhk007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/classfloadhk007.cpp new file mode 100644 index 00000000000..b533ee86dd7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/classfloadhk007.cpp @@ -0,0 +1,460 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk007" +#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk007r" +#define TESTED_CLASS_SIG "L" TESTED_CLASS_NAME ";" +#define TESTED_CLASSLOADER_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk007ClassLoader" +#define TESTED_CLASSLOADER_SIG "L" TESTED_CLASSLOADER_NAME ";" + +#define BYTECODE_FIELD_SIG "[B" +#define REDEF_BYTECODE_FIELD_NAME "redefClassBytes" + +#define CLASSLOADER_FIELD_NAME "classLoader" +#define TESTED_CLASS_FIELD_NAME "testedClass" +#define TESTED_CLASS_FIELD_SIG "Ljava/lang/Class;" + +static jobject classLoader = NULL; +static jclass testedClass = NULL; + +static jint redefClassSize = 0; +static unsigned char* redefClassBytes = NULL; + +static volatile int eventsCount = 0; + +/* ============================================================================= */ + +/** Check (strictly or not) if bytecode has expected size and bytes or complain an error. */ +static int checkBytecode(const char kind[], jint size, const unsigned char bytes[], + jint expectedSize, const unsigned char expectedBytes[], + int strict) { + int success = NSK_TRUE; + + NSK_DISPLAY3("Check %s bytecode: 0x%p:%d\n", kind, (void*)bytes, (int)size); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, size, bytes); + } + + if (bytes == NULL) { + NSK_COMPLAIN2("Unexpected NULL pointer to %s bytecode in CLASS_FILE_LOAD_HOOK: 0x%p\n", + kind, (void*)bytes); + return NSK_FALSE; + } + + if (size <= 0) { + NSK_COMPLAIN2("Unexpected zero size of %s bytecode in CLASS_FILE_LOAD_HOOK: %d\n", + kind, (int)size); + return NSK_FALSE; + } + + if (strict) { + if (size != expectedSize) { + NSK_COMPLAIN3("Unexpected size of %s bytecode in CLASS_FILE_LOAD_HOOK:\n" + "# got size: %d\n" + "# expected: %d\n", + kind, (int)size, (int)expectedSize); + success = NSK_FALSE; + } else { + jint different = 0; + jint i; + + for (i = 0; i < size; i++) { + if (bytes[i] != expectedBytes[i]) { + different++; + } + } + if (different > 0) { + NSK_COMPLAIN2("Unexpected bytes in %s bytecode in CLASS_FILE_LOAD_HOOK:\n" + "# different bytes: %d\n" + "# total bytes: %d\n", + (int)different, (int)size); + success = NSK_FALSE; + } + } + + if (!success) { + NSK_COMPLAIN2("Got %s bytecode is not equal to expected bytecode: %d bytes\n", + kind, expectedSize); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, expectedSize, expectedBytes); + } + } else { + NSK_DISPLAY1("All %s bytecode is equal to expected one\n", kind); + } + } + + return success; +} + +/** Get classfile bytecode from a static field of given class. */ +static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[], + jint* size, unsigned char* *bytes) { + + jfieldID fieldID = NULL; + jbyteArray array = NULL; + jbyte* elements; + int i; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); + + if (!NSK_JNI_VERIFY(jni, (*size = + NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); + + { + jboolean isCopy; + if (!NSK_JNI_VERIFY(jni, (elements = + NSK_CPP_STUB3(GetByteArrayElements, jni, array, + &isCopy)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); + + for (i = 0; i < *size; i++) { + (*bytes)[i] = (unsigned char)elements[i]; + } + NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); + + NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); + NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); + NSK_DISPLAY0(" ... released\n"); + + return NSK_TRUE; +} + +/** Get global reference to object from a static field of given class. */ +static jobject getObject(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[]) { + + jfieldID fieldID = NULL; + jobject obj = NULL; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get object from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)obj); + + NSK_DISPLAY1("Make global reference to object: 0x%p\n", obj); + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB2(NewGlobalRef, jni, obj)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got global ref: 0x%p\n", (void*)obj); + + return obj; +} + +/** Redefine given class with new bytecode. */ +static int redefineClass(jvmtiEnv* jvmti, jclass klass, const char className[], + jint size, unsigned char bytes[]) { + jvmtiClassDefinition classDef; + + classDef.klass = klass; + classDef.class_byte_count = size; + classDef.class_bytes = bytes; + + NSK_DISPLAY1("Redefine class: %s\n", className); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &classDef))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... redefined with bytecode: %d bytes\n", (int)size); + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for debuggee to load original class\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + { + jclass debugeeClass = NULL; + + NSK_DISPLAY0(">>> Obtain debuggee class\n"); + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY0(">>> Obtain tested class object\n"); + if (!NSK_VERIFY((testedClass = (jclass) + getObject(jvmti, jni, debugeeClass, TESTED_CLASS_FIELD_NAME, + TESTED_CLASS_FIELD_SIG)) != NULL)) + return; + + NSK_DISPLAY0(">>> Obtain classloader object\n"); + if (!NSK_VERIFY((classLoader = + getObject(jvmti, jni, debugeeClass, CLASSLOADER_FIELD_NAME, + TESTED_CLASSLOADER_SIG)) != NULL)) + return; + + NSK_DISPLAY0(">>> Obtain redefined bytecode of tested class\n"); + if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, + REDEF_BYTECODE_FIELD_NAME, + BYTECODE_FIELD_SIG, + &redefClassSize, &redefClassBytes))) + return; + } + + NSK_DISPLAY0(">>> Redefine tested class\n"); + { + if (!NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, + redefClassSize, redefClassBytes))) + return; + } + + NSK_DISPLAY0(">>> Testcase #1: Redefine class and check CLASS_FILE_LOAD_HOOK event\n"); + { + jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; + + NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + NSK_DISPLAY0(" ... event enabled\n"); + + NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, + redefClassSize, redefClassBytes)); + + NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { + NSK_DISPLAY0(" ... event disabled\n"); + } + + NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (eventsCount != 1) { + NSK_COMPLAIN3("Unexpected number of %s events received for tested class:\n" + "# received: %d events\n" + "# expected: %d events\n", + "CLASS_FILE_LOAD_HOOK", eventsCount, 1); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY1(" ... received: %d events\n", eventsCount); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + NSK_DISPLAY1("Delete global reference to classloader object: 0x%p\n", (void*)classLoader); + NSK_CPP_STUB2(DeleteGlobalRef, jni, classLoader); + + NSK_DISPLAY1("Delete global reference to tested class object: 0x%p\n", (void*)testedClass); + NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass); + + NSK_DISPLAY1("Deallocate redefined bytecode array: 0x%p\n", (void*)redefClassBytes); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, redefClassBytes))) { + nsk_jvmti_setFailStatus(); + } + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Callback for CLASS_FILE_LOAD_HOOK event **/ +static void JNICALL +callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, + jclass class_being_redefined, + jobject loader, const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", + nsk_null_string(name), (void*)loader, (void*)class_being_redefined, + (void*)class_data, (int)class_data_len); + + if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { + NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); + eventsCount++; + + NSK_DISPLAY1("Check classloader: 0x%p\n", (void*)loader); + if (loader == NULL) { + NSK_COMPLAIN1("Unexpected NULL classloader in CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)loader); + nsk_jvmti_setFailStatus(); + } else if (!NSK_CPP_STUB3(IsSameObject, jni, loader, classLoader)) { + NSK_COMPLAIN2("Unexpected classloader in CLASS_FILE_LOAD_HOOK:\n" + "# got classloder: 0x%p\n" + "# expected same as: 0x%p\n", + (void*)loader, (void*)classLoader); + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY1("Check class_being_redefined: 0x%p\n", (void*)class_being_redefined); + if (class_being_redefined == NULL) { + NSK_COMPLAIN1("Unexpected NULL class_being_redefined in CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)class_being_redefined); + nsk_jvmti_setFailStatus(); + } else if (!NSK_CPP_STUB3(IsSameObject, jni, class_being_redefined, testedClass)) { + NSK_COMPLAIN2("Unexpected class_being_redefined in CLASS_FILE_LOAD_HOOK:\n" + "# got class: 0x%p\n" + "# expected same as: 0x%p\n", + (void*)class_being_redefined, (void*)testedClass); + nsk_jvmti_setFailStatus(); + } + + if (!checkBytecode("redefined", class_data_len, class_data, + redefClassSize, redefClassBytes, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_classfloadhk007(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + NSK_DISPLAY1("Add required capabilities: %s\n", "can_generate_eraly_class_hook_events, can_redefine_classes"); + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_all_class_hook_events = 1; + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... added\n"); + + NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); + { + jvmtiEventCallbacks callbacks; + jint size = (jint)sizeof(callbacks); + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = callbackClassFileLoadHook; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... set\n"); + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/libclassfloadhk007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/libclassfloadhk007.c deleted file mode 100644 index 41c0efdc563..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/libclassfloadhk007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "classfloadhk007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/libclassfloadhk007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/libclassfloadhk007.cpp new file mode 100644 index 00000000000..f7933b5b951 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/libclassfloadhk007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "classfloadhk007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/classfloadhk008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/classfloadhk008.c deleted file mode 100644 index 3384bcc0bf7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/classfloadhk008.c +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk008" -#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk008r" -#define TESTED_CLASS_SIG "L"TESTED_CLASS_NAME";" - -#define BYTECODE_FIELD_SIG "[B" -#define REDEF_BYTECODE_FIELD_NAME "redefClassBytes" -#define NEW_BYTECODE_FIELD_NAME "newClassBytes" - -#define TESTED_CLASS_FIELD_NAME "testedClass" -#define TESTED_CLASS_FIELD_SIG "Ljava/lang/Class;" - -static jclass testedClass = NULL; - -static jint redefClassSize = 0; -static unsigned char* redefClassBytes = NULL; - -static jint newClassSize = 0; -static unsigned char* newClassBytes = NULL; - -static volatile int eventsCount = 0; - -/* ============================================================================= */ - -/** Get classfile bytecode from a static field of given class. */ -static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[], - jint* size, unsigned char* *bytes) { - - jfieldID fieldID = NULL; - jbyteArray array = NULL; - jbyte* elements; - int i; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); - - if (!NSK_JNI_VERIFY(jni, (*size = - NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); - - { - jboolean isCopy; - if (!NSK_JNI_VERIFY(jni, (elements = - NSK_CPP_STUB3(GetByteArrayElements, jni, array, - &isCopy)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); - - for (i = 0; i < *size; i++) { - (*bytes)[i] = (unsigned char)elements[i]; - } - NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); - - NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); - NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); - NSK_DISPLAY0(" ... released\n"); - - return NSK_TRUE; -} - -/** Get global reference to object from a static field of given class. */ -static jobject getObject(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[]) { - - jfieldID fieldID = NULL; - jobject obj = NULL; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get object from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)obj); - - NSK_DISPLAY1("Make global reference to object: 0x%p\n", obj); - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB2(NewGlobalRef, jni, obj)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got global ref: 0x%p\n", (void*)obj); - - return obj; -} - -/** Redefine given class with new bytecode. */ -static int redefineClass(jvmtiEnv* jvmti, jclass klass, const char className[], - jint size, unsigned char bytes[]) { - jvmtiClassDefinition classDef; - - classDef.klass = klass; - classDef.class_byte_count = size; - classDef.class_bytes = bytes; - - NSK_DISPLAY1("Redefine class: %s\n", className); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &classDef))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... redefined with bytecode: %d bytes\n", (int)size); - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for debuggee to load original class\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - { - jclass debugeeClass = NULL; - - NSK_DISPLAY0(">>> Obtain debuggee class\n"); - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY0(">>> Obtain tested class object\n"); - if (!NSK_VERIFY((testedClass = (jclass) - getObject(jvmti, jni, debugeeClass, TESTED_CLASS_FIELD_NAME, - TESTED_CLASS_FIELD_SIG)) != NULL)) - return; - - NSK_DISPLAY0(">>> Obtain redefined bytecode of tested class\n"); - if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, - REDEF_BYTECODE_FIELD_NAME, - BYTECODE_FIELD_SIG, - &redefClassSize, &redefClassBytes))) - return; - - NSK_DISPLAY0(">>> Obtain new instrumented bytecode of tested class\n"); - if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, - NEW_BYTECODE_FIELD_NAME, - BYTECODE_FIELD_SIG, - &newClassSize, &newClassBytes))) - return; - } - - NSK_DISPLAY0(">>> Redefine tested class\n"); - { - if (!NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, - redefClassSize, redefClassBytes))) - return; - } - - NSK_DISPLAY0(">>> Testcase #1: Redefine class and check CLASS_FILE_LOAD_HOOK event\n"); - { - jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; - - NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - NSK_DISPLAY0(" ... event enabled\n"); - - NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, - redefClassSize, redefClassBytes)); - - NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { - NSK_DISPLAY0(" ... event disabled\n"); - } - - NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (eventsCount != 1) { - NSK_COMPLAIN3("Unexpected number of %s events received for tested class:\n" - "# received: %d events\n" - "# expected: %d events\n", - "CLASS_FILE_LOAD_HOOK", eventsCount, 1); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY1(" ... received: %d events\n", eventsCount); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - NSK_DISPLAY1("Delete global reference to tested class object: 0x%p\n", (void*)testedClass); - NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass); - - NSK_DISPLAY1("Deallocate redefined bytecode array: 0x%p\n", (void*)redefClassBytes); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, redefClassBytes))) { - nsk_jvmti_setFailStatus(); - } - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Callback for CLASS_FILE_LOAD_HOOK event **/ -static void JNICALL -callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, - jclass class_being_redefined, - jobject loader, const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", - nsk_null_string(name), (void*)loader, (void*)class_being_redefined, - (void*)class_data, (int)class_data_len); - - if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { - NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); - eventsCount++; - - NSK_DISPLAY2("Received redefined bytecode of redefined class: 0x%p:%d\n", - (void*)class_data, (int)class_data_len); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, class_data_len, class_data); - } - - NSK_DISPLAY1("Check pointer to new_class_data_len: 0x%p\n", (void*)new_class_data_len); - if (new_class_data_len == NULL) { - NSK_COMPLAIN1("NULL new_class_data_len pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)new_class_data_len); - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY1("Check pointer to new_class_data: 0x%p\n", (void*)new_class_data); - if (new_class_data == NULL) { - NSK_COMPLAIN1("NULL new_class_data pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)new_class_data); - nsk_jvmti_setFailStatus(); - } - - if (new_class_data_len != NULL && new_class_data != NULL) { - NSK_DISPLAY2("Replace with new instrumented bytecode: 0x%p:%d\n", - (void*)newClassBytes, (int)newClassSize); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, newClassSize, newClassBytes); - } - - *new_class_data_len = newClassSize; - *new_class_data = newClassBytes; - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_classfloadhk008(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - NSK_DISPLAY1("Add required capabilities: %s\n", "can_generate_eraly_class_hook_events, can_redefine_classes"); - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_all_class_hook_events = 1; - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... added\n"); - - NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); - { - jvmtiEventCallbacks callbacks; - jint size = (jint)sizeof(callbacks); - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = callbackClassFileLoadHook; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... set\n"); - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/classfloadhk008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/classfloadhk008.cpp new file mode 100644 index 00000000000..54281a37ca2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/classfloadhk008.cpp @@ -0,0 +1,396 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk008" +#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk008r" +#define TESTED_CLASS_SIG "L" TESTED_CLASS_NAME ";" + +#define BYTECODE_FIELD_SIG "[B" +#define REDEF_BYTECODE_FIELD_NAME "redefClassBytes" +#define NEW_BYTECODE_FIELD_NAME "newClassBytes" + +#define TESTED_CLASS_FIELD_NAME "testedClass" +#define TESTED_CLASS_FIELD_SIG "Ljava/lang/Class;" + +static jclass testedClass = NULL; + +static jint redefClassSize = 0; +static unsigned char* redefClassBytes = NULL; + +static jint newClassSize = 0; +static unsigned char* newClassBytes = NULL; + +static volatile int eventsCount = 0; + +/* ============================================================================= */ + +/** Get classfile bytecode from a static field of given class. */ +static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[], + jint* size, unsigned char* *bytes) { + + jfieldID fieldID = NULL; + jbyteArray array = NULL; + jbyte* elements; + int i; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); + + if (!NSK_JNI_VERIFY(jni, (*size = + NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); + + { + jboolean isCopy; + if (!NSK_JNI_VERIFY(jni, (elements = + NSK_CPP_STUB3(GetByteArrayElements, jni, array, + &isCopy)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); + + for (i = 0; i < *size; i++) { + (*bytes)[i] = (unsigned char)elements[i]; + } + NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); + + NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); + NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); + NSK_DISPLAY0(" ... released\n"); + + return NSK_TRUE; +} + +/** Get global reference to object from a static field of given class. */ +static jobject getObject(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[]) { + + jfieldID fieldID = NULL; + jobject obj = NULL; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get object from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)obj); + + NSK_DISPLAY1("Make global reference to object: 0x%p\n", obj); + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB2(NewGlobalRef, jni, obj)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got global ref: 0x%p\n", (void*)obj); + + return obj; +} + +/** Redefine given class with new bytecode. */ +static int redefineClass(jvmtiEnv* jvmti, jclass klass, const char className[], + jint size, unsigned char bytes[]) { + jvmtiClassDefinition classDef; + + classDef.klass = klass; + classDef.class_byte_count = size; + classDef.class_bytes = bytes; + + NSK_DISPLAY1("Redefine class: %s\n", className); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &classDef))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... redefined with bytecode: %d bytes\n", (int)size); + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for debuggee to load original class\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + { + jclass debugeeClass = NULL; + + NSK_DISPLAY0(">>> Obtain debuggee class\n"); + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY0(">>> Obtain tested class object\n"); + if (!NSK_VERIFY((testedClass = (jclass) + getObject(jvmti, jni, debugeeClass, TESTED_CLASS_FIELD_NAME, + TESTED_CLASS_FIELD_SIG)) != NULL)) + return; + + NSK_DISPLAY0(">>> Obtain redefined bytecode of tested class\n"); + if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, + REDEF_BYTECODE_FIELD_NAME, + BYTECODE_FIELD_SIG, + &redefClassSize, &redefClassBytes))) + return; + + NSK_DISPLAY0(">>> Obtain new instrumented bytecode of tested class\n"); + if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, + NEW_BYTECODE_FIELD_NAME, + BYTECODE_FIELD_SIG, + &newClassSize, &newClassBytes))) + return; + } + + NSK_DISPLAY0(">>> Redefine tested class\n"); + { + if (!NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, + redefClassSize, redefClassBytes))) + return; + } + + NSK_DISPLAY0(">>> Testcase #1: Redefine class and check CLASS_FILE_LOAD_HOOK event\n"); + { + jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; + + NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + NSK_DISPLAY0(" ... event enabled\n"); + + NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, + redefClassSize, redefClassBytes)); + + NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { + NSK_DISPLAY0(" ... event disabled\n"); + } + + NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (eventsCount != 1) { + NSK_COMPLAIN3("Unexpected number of %s events received for tested class:\n" + "# received: %d events\n" + "# expected: %d events\n", + "CLASS_FILE_LOAD_HOOK", eventsCount, 1); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY1(" ... received: %d events\n", eventsCount); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + NSK_DISPLAY1("Delete global reference to tested class object: 0x%p\n", (void*)testedClass); + NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass); + + NSK_DISPLAY1("Deallocate redefined bytecode array: 0x%p\n", (void*)redefClassBytes); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, redefClassBytes))) { + nsk_jvmti_setFailStatus(); + } + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Callback for CLASS_FILE_LOAD_HOOK event **/ +static void JNICALL +callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, + jclass class_being_redefined, + jobject loader, const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", + nsk_null_string(name), (void*)loader, (void*)class_being_redefined, + (void*)class_data, (int)class_data_len); + + if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { + NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); + eventsCount++; + + NSK_DISPLAY2("Received redefined bytecode of redefined class: 0x%p:%d\n", + (void*)class_data, (int)class_data_len); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, class_data_len, class_data); + } + + NSK_DISPLAY1("Check pointer to new_class_data_len: 0x%p\n", (void*)new_class_data_len); + if (new_class_data_len == NULL) { + NSK_COMPLAIN1("NULL new_class_data_len pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)new_class_data_len); + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY1("Check pointer to new_class_data: 0x%p\n", (void*)new_class_data); + if (new_class_data == NULL) { + NSK_COMPLAIN1("NULL new_class_data pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)new_class_data); + nsk_jvmti_setFailStatus(); + } + + if (new_class_data_len != NULL && new_class_data != NULL) { + NSK_DISPLAY2("Replace with new instrumented bytecode: 0x%p:%d\n", + (void*)newClassBytes, (int)newClassSize); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, newClassSize, newClassBytes); + } + + *new_class_data_len = newClassSize; + *new_class_data = newClassBytes; + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_classfloadhk008(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + NSK_DISPLAY1("Add required capabilities: %s\n", "can_generate_eraly_class_hook_events, can_redefine_classes"); + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_all_class_hook_events = 1; + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... added\n"); + + NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); + { + jvmtiEventCallbacks callbacks; + jint size = (jint)sizeof(callbacks); + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = callbackClassFileLoadHook; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... set\n"); + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/libclassfloadhk008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/libclassfloadhk008.c deleted file mode 100644 index 950cad5ed49..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/libclassfloadhk008.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "classfloadhk008.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/libclassfloadhk008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/libclassfloadhk008.cpp new file mode 100644 index 00000000000..500b68094d7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/libclassfloadhk008.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "classfloadhk008.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/classfloadhk009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/classfloadhk009.c deleted file mode 100644 index 7f4e8f967e3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/classfloadhk009.c +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk009" -#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk009r" -#define TESTED_CLASS_SIG "L"TESTED_CLASS_NAME";" - -#define BYTECODE_FIELD_SIG "[B" -#define REDEF_BYTECODE_FIELD_NAME "redefClassBytes" -#define NEW_BYTECODE_FIELD_NAME "newClassBytes" - -#define TESTED_CLASS_FIELD_NAME "testedClass" -#define TESTED_CLASS_FIELD_SIG "Ljava/lang/Class;" - -static jclass testedClass = NULL; - -static jint redefClassSize = 0; -static unsigned char* redefClassBytes = NULL; - -static jint newClassSize = 0; -static unsigned char* newClassBytes = NULL; - -static volatile int eventsCount = 0; - -/* ============================================================================= */ - -/** Get classfile bytecode from a static field of given class. */ -static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[], - jint* size, unsigned char* *bytes) { - - jfieldID fieldID = NULL; - jbyteArray array = NULL; - jbyte* elements; - int i; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); - - if (!NSK_JNI_VERIFY(jni, (*size = - NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); - - { - jboolean isCopy; - if (!NSK_JNI_VERIFY(jni, (elements = - NSK_CPP_STUB3(GetByteArrayElements, jni, array, - &isCopy)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); - - for (i = 0; i < *size; i++) { - (*bytes)[i] = (unsigned char)elements[i]; - } - NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); - - NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); - NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); - NSK_DISPLAY0(" ... released\n"); - - return NSK_TRUE; -} - -/** Get global reference to object from a static field of given class. */ -static jobject getObject(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, - const char fieldName[], const char fieldSig[]) { - - jfieldID fieldID = NULL; - jobject obj = NULL; - - NSK_DISPLAY1("Find static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); - - NSK_DISPLAY1("Get object from static field: %s\n", fieldName); - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)obj); - - NSK_DISPLAY1("Make global reference to object: 0x%p\n", obj); - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB2(NewGlobalRef, jni, obj)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - NSK_DISPLAY1(" ... got global ref: 0x%p\n", (void*)obj); - - return obj; -} - -/** Redefine given class with new bytecode. */ -static int redefineClass(jvmtiEnv* jvmti, jclass klass, const char className[], - jint size, unsigned char bytes[]) { - jvmtiClassDefinition classDef; - - classDef.klass = klass; - classDef.class_byte_count = size; - classDef.class_bytes = bytes; - - NSK_DISPLAY1("Redefine class: %s\n", className); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &classDef))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... redefined with bytecode: %d bytes\n", (int)size); - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for debuggee to load original class\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - { - jclass debugeeClass = NULL; - - NSK_DISPLAY0(">>> Obtain debuggee class\n"); - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY0(">>> Obtain tested class object\n"); - if (!NSK_VERIFY((testedClass = (jclass) - getObject(jvmti, jni, debugeeClass, TESTED_CLASS_FIELD_NAME, - TESTED_CLASS_FIELD_SIG)) != NULL)) - return; - - NSK_DISPLAY0(">>> Obtain redefined bytecode of tested class\n"); - if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, - REDEF_BYTECODE_FIELD_NAME, - BYTECODE_FIELD_SIG, - &redefClassSize, &redefClassBytes))) - return; - - NSK_DISPLAY0(">>> Obtain new instrumented bytecode of tested class\n"); - if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, - NEW_BYTECODE_FIELD_NAME, - BYTECODE_FIELD_SIG, - &newClassSize, &newClassBytes))) - return; - } - - NSK_DISPLAY0(">>> Redefine tested class\n"); - { - if (!NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, - redefClassSize, redefClassBytes))) - return; - } - - NSK_DISPLAY0(">>> Testcase #1: Redefine class and check CLASS_FILE_LOAD_HOOK event\n"); - { - jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; - - NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - NSK_DISPLAY0(" ... event enabled\n"); - - NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, - redefClassSize, redefClassBytes)); - - NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { - NSK_DISPLAY0(" ... event disabled\n"); - } - - NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); - if (eventsCount != 1) { - NSK_COMPLAIN3("Unexpected number of %s events received for tested class:\n" - "# received: %d events\n" - "# expected: %d events\n", - "CLASS_FILE_LOAD_HOOK", eventsCount, 1); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY1(" ... received: %d events\n", eventsCount); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - NSK_DISPLAY1("Delete global reference to tested class object: 0x%p\n", (void*)testedClass); - NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass); - - NSK_DISPLAY1("Deallocate redefined bytecode array: 0x%p\n", (void*)redefClassBytes); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, redefClassBytes))) { - nsk_jvmti_setFailStatus(); - } - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Callback for CLASS_FILE_LOAD_HOOK event **/ -static void JNICALL -callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, - jclass class_being_redefined, - jobject loader, const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", - nsk_null_string(name), (void*)loader, (void*)class_being_redefined, - (void*)class_data, (int)class_data_len); - - if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { - NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); - eventsCount++; - - NSK_DISPLAY2("Received redefined bytecode of redefined class: 0x%p:%d\n", - (void*)class_data, (int)class_data_len); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, class_data_len, class_data); - } - - NSK_DISPLAY1("Check pointer to new_class_data_len: 0x%p\n", (void*)new_class_data_len); - if (new_class_data_len == NULL) { - NSK_COMPLAIN1("NULL new_class_data_len pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)new_class_data_len); - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY1("Check pointer to new_class_data: 0x%p\n", (void*)new_class_data); - if (new_class_data == NULL) { - NSK_COMPLAIN1("NULL new_class_data pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", - (void*)new_class_data); - nsk_jvmti_setFailStatus(); - } - - if (new_class_data_len != NULL && new_class_data != NULL) { - NSK_DISPLAY2("Replace with new instrumented bytecode: 0x%p:%d\n", - (void*)newClassBytes, (int)newClassSize); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, newClassSize, newClassBytes); - } - - *new_class_data_len = newClassSize; - *new_class_data = newClassBytes; - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk009(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk009(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_classfloadhk009(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - NSK_DISPLAY1("Add required capabilities: %s\n", "can_generate_eraly_class_hook_events, can_redefine_classes"); - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_all_class_hook_events = 1; - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... added\n"); - - NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); - { - jvmtiEventCallbacks callbacks; - jint size = (jint)sizeof(callbacks); - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = callbackClassFileLoadHook; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { - return JNI_ERR; - } - } - NSK_DISPLAY0(" ... set\n"); - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/classfloadhk009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/classfloadhk009.cpp new file mode 100644 index 00000000000..5cbd5b58b8c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/classfloadhk009.cpp @@ -0,0 +1,396 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk009" +#define TESTED_CLASS_NAME "nsk/jvmti/ClassFileLoadHook/classfloadhk009r" +#define TESTED_CLASS_SIG "L" TESTED_CLASS_NAME ";" + +#define BYTECODE_FIELD_SIG "[B" +#define REDEF_BYTECODE_FIELD_NAME "redefClassBytes" +#define NEW_BYTECODE_FIELD_NAME "newClassBytes" + +#define TESTED_CLASS_FIELD_NAME "testedClass" +#define TESTED_CLASS_FIELD_SIG "Ljava/lang/Class;" + +static jclass testedClass = NULL; + +static jint redefClassSize = 0; +static unsigned char* redefClassBytes = NULL; + +static jint newClassSize = 0; +static unsigned char* newClassBytes = NULL; + +static volatile int eventsCount = 0; + +/* ============================================================================= */ + +/** Get classfile bytecode from a static field of given class. */ +static int getBytecode(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[], + jint* size, unsigned char* *bytes) { + + jfieldID fieldID = NULL; + jbyteArray array = NULL; + jbyte* elements; + int i; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)array); + + if (!NSK_JNI_VERIFY(jni, (*size = + NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); + + { + jboolean isCopy; + if (!NSK_JNI_VERIFY(jni, (elements = + NSK_CPP_STUB3(GetByteArrayElements, jni, array, + &isCopy)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + NSK_DISPLAY1(" ... got elements list: 0x%p\n", (void*)elements); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... created bytes array: 0x%p\n", (void*)*bytes); + + for (i = 0; i < *size; i++) { + (*bytes)[i] = (unsigned char)elements[i]; + } + NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); + + NSK_DISPLAY1("Release elements list: 0x%p\n", (void*)elements); + NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); + NSK_DISPLAY0(" ... released\n"); + + return NSK_TRUE; +} + +/** Get global reference to object from a static field of given class. */ +static jobject getObject(jvmtiEnv* jvmti, JNIEnv* jni, jclass cls, + const char fieldName[], const char fieldSig[]) { + + jfieldID fieldID = NULL; + jobject obj = NULL; + + NSK_DISPLAY1("Find static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, cls, fieldName, fieldSig)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)fieldID); + + NSK_DISPLAY1("Get object from static field: %s\n", fieldName); + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetStaticObjectField, jni, cls, fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)obj); + + NSK_DISPLAY1("Make global reference to object: 0x%p\n", obj); + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB2(NewGlobalRef, jni, obj)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + NSK_DISPLAY1(" ... got global ref: 0x%p\n", (void*)obj); + + return obj; +} + +/** Redefine given class with new bytecode. */ +static int redefineClass(jvmtiEnv* jvmti, jclass klass, const char className[], + jint size, unsigned char bytes[]) { + jvmtiClassDefinition classDef; + + classDef.klass = klass; + classDef.class_byte_count = size; + classDef.class_bytes = bytes; + + NSK_DISPLAY1("Redefine class: %s\n", className); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &classDef))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... redefined with bytecode: %d bytes\n", (int)size); + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for debuggee to load original class\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + { + jclass debugeeClass = NULL; + + NSK_DISPLAY0(">>> Obtain debuggee class\n"); + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY0(">>> Obtain tested class object\n"); + if (!NSK_VERIFY((testedClass = (jclass) + getObject(jvmti, jni, debugeeClass, TESTED_CLASS_FIELD_NAME, + TESTED_CLASS_FIELD_SIG)) != NULL)) + return; + + NSK_DISPLAY0(">>> Obtain redefined bytecode of tested class\n"); + if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, + REDEF_BYTECODE_FIELD_NAME, + BYTECODE_FIELD_SIG, + &redefClassSize, &redefClassBytes))) + return; + + NSK_DISPLAY0(">>> Obtain new instrumented bytecode of tested class\n"); + if (!NSK_VERIFY(getBytecode(jvmti, jni, debugeeClass, + NEW_BYTECODE_FIELD_NAME, + BYTECODE_FIELD_SIG, + &newClassSize, &newClassBytes))) + return; + } + + NSK_DISPLAY0(">>> Redefine tested class\n"); + { + if (!NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, + redefClassSize, redefClassBytes))) + return; + } + + NSK_DISPLAY0(">>> Testcase #1: Redefine class and check CLASS_FILE_LOAD_HOOK event\n"); + { + jvmtiEvent event = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; + + NSK_DISPLAY1("Enable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + NSK_DISPLAY0(" ... event enabled\n"); + + NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, + redefClassSize, redefClassBytes)); + + NSK_DISPLAY1("Disable event: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) { + NSK_DISPLAY0(" ... event disabled\n"); + } + + NSK_DISPLAY1("Check if event was received: %s\n", "CLASS_FILE_LOAD_HOOK"); + if (eventsCount != 1) { + NSK_COMPLAIN3("Unexpected number of %s events received for tested class:\n" + "# received: %d events\n" + "# expected: %d events\n", + "CLASS_FILE_LOAD_HOOK", eventsCount, 1); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY1(" ... received: %d events\n", eventsCount); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + NSK_DISPLAY1("Delete global reference to tested class object: 0x%p\n", (void*)testedClass); + NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass); + + NSK_DISPLAY1("Deallocate redefined bytecode array: 0x%p\n", (void*)redefClassBytes); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, redefClassBytes))) { + nsk_jvmti_setFailStatus(); + } + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Callback for CLASS_FILE_LOAD_HOOK event **/ +static void JNICALL +callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni, + jclass class_being_redefined, + jobject loader, const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + NSK_DISPLAY5(" : name: %s, loader: 0x%p, redefined: 0x%p, bytecode: 0x%p:%d\n", + nsk_null_string(name), (void*)loader, (void*)class_being_redefined, + (void*)class_data, (int)class_data_len); + + if (name != NULL && (strcmp(name, TESTED_CLASS_NAME) == 0)) { + NSK_DISPLAY1("SUCCESS! CLASS_FILE_LOAD_HOOK for tested class: %s\n", TESTED_CLASS_NAME); + eventsCount++; + + NSK_DISPLAY2("Received redefined bytecode of redefined class: 0x%p:%d\n", + (void*)class_data, (int)class_data_len); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, class_data_len, class_data); + } + + NSK_DISPLAY1("Check pointer to new_class_data_len: 0x%p\n", (void*)new_class_data_len); + if (new_class_data_len == NULL) { + NSK_COMPLAIN1("NULL new_class_data_len pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)new_class_data_len); + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY1("Check pointer to new_class_data: 0x%p\n", (void*)new_class_data); + if (new_class_data == NULL) { + NSK_COMPLAIN1("NULL new_class_data pointer passed to CLASS_FILE_LOAD_HOOK: 0x%p\n", + (void*)new_class_data); + nsk_jvmti_setFailStatus(); + } + + if (new_class_data_len != NULL && new_class_data != NULL) { + NSK_DISPLAY2("Replace with new instrumented bytecode: 0x%p:%d\n", + (void*)newClassBytes, (int)newClassSize); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, newClassSize, newClassBytes); + } + + *new_class_data_len = newClassSize; + *new_class_data = newClassBytes; + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_classfloadhk009(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_classfloadhk009(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_classfloadhk009(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + NSK_DISPLAY1("Add required capabilities: %s\n", "can_generate_eraly_class_hook_events, can_redefine_classes"); + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_all_class_hook_events = 1; + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... added\n"); + + NSK_DISPLAY1("Set callback for event: %s\n", "CLASS_FILE_LOAD_HOOK"); + { + jvmtiEventCallbacks callbacks; + jint size = (jint)sizeof(callbacks); + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = callbackClassFileLoadHook; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { + return JNI_ERR; + } + } + NSK_DISPLAY0(" ... set\n"); + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/libclassfloadhk009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/libclassfloadhk009.c deleted file mode 100644 index 6333f0ac800..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/libclassfloadhk009.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "classfloadhk009.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/libclassfloadhk009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/libclassfloadhk009.cpp new file mode 100644 index 00000000000..de864ca7092 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/libclassfloadhk009.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "classfloadhk009.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/classload001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/classload001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/classload001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/classload001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/libclassload001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/libclassload001.c deleted file mode 100644 index eff60a74fb0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/libclassload001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "classload001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/libclassload001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/libclassload001.cpp new file mode 100644 index 00000000000..9bfd821f8cf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/libclassload001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "classload001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/classprep001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/classprep001.c deleted file mode 100644 index 42aa4e0e62e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/classprep001.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define EXP_STATUS (JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED) - -typedef struct { - char *sig; - jint status; - jint mcount; - jint fcount; - jint icount; -} class_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static size_t eventsCount = 0; -static size_t eventsExpected = 0; -static class_info classes[] = { - {"Lnsk/jvmti/ClassPrepare/classprep001$TestInterface;", EXP_STATUS, 2, 1, 0}, - {"Lnsk/jvmti/ClassPrepare/classprep001$TestClass;", EXP_STATUS, 3, 2, 1} -}; - -void printStatus(jint status) { - int flags = 0; - if ((status & JVMTI_CLASS_STATUS_VERIFIED) != 0) { - printf("JVMTI_CLASS_STATUS_VERIFIED"); - flags++; - } - if ((status & JVMTI_CLASS_STATUS_PREPARED) != 0) { - if (flags > 0) printf(" | "); - printf("JVMTI_CLASS_STATUS_PREPARED"); - flags++; - } - if ((status & JVMTI_CLASS_STATUS_INITIALIZED) != 0) { - if (flags > 0) printf(" | "); - printf("JVMTI_CLASS_STATUS_INITIALIZED"); - flags++; - } - if ((status & JVMTI_CLASS_STATUS_ERROR) != 0) { - if (flags > 0) printf(" | "); - printf("JVMTI_CLASS_STATUS_ERROR"); - flags++; - } - printf(" (0x%x)\n", status); -} - -void JNICALL ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jclass cls) { - jvmtiError err; - class_info inf; - jmethodID *methods; - jfieldID *fields; - jclass *interfaces; - char *name, *sig, *generic; - int i; - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &inf.sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%" PRIuPTR ") unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassStatus(jvmti_env, cls, &inf.status); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassStatus#%" PRIuPTR ") unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassMethods(jvmti_env, cls, &inf.mcount, &methods); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassMethods#%" PRIuPTR ") unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassFields(jvmti_env, cls, &inf.fcount, &fields); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassMethods#%" PRIuPTR ") unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetImplementedInterfaces(jvmti_env, cls, - &inf.icount, &interfaces); - if (err != JVMTI_ERROR_NONE) { - printf("(GetImplementedInterfaces#%" PRIuPTR ") unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> [class prepare event #%" PRIuPTR "]", eventsCount); - printf(" \"%s\"\n", inf.sig); - printf(">>> status: "); - printStatus(inf.status); - printf(">>> %d methods:", inf.mcount); - for (i = 0; i < inf.mcount; i++) { - if (i > 0) printf(","); - if (methods[i] == NULL) { - printf(" null"); - } else { - err = (*jvmti_env)->GetMethodName(jvmti_env, methods[i], - &name, &sig, &generic); - if (err == JVMTI_ERROR_NONE) { - printf(" \"%s%s\"", name, sig); - } else { - printf(" ???"); - } - } - } - printf("\n"); - printf(">>> %d fields:", inf.fcount); - for (i = 0; i < inf.fcount; i++) { - if (i > 0) printf(","); - if (fields[i] == NULL) { - printf(" null"); - } else { - err = (*jvmti_env)->GetFieldName(jvmti_env, cls, fields[i], - &name, &sig, &generic); - if (err == JVMTI_ERROR_NONE) { - printf(" \"%s, %s\"", name, sig); - } else { - printf(" ???"); - } - } - } - printf("\n"); - printf(">>> %d interfaces:", inf.icount); - for (i = 0; i < inf.icount; i++) { - if (i > 0) printf(","); - if (interfaces[i] == NULL) { - printf(" null"); - } else { - err = (*jvmti_env)->GetClassSignature(jvmti_env, - interfaces[i], &sig, &generic); - if (err == JVMTI_ERROR_NONE) { - printf(" \"%s\"", sig); - } else { - printf(" ???"); - } - } - } - printf("\n"); - } - - if (eventsCount >= eventsExpected) { - printf("(#%" PRIuPTR ") too many events: %" PRIuPTR ", expected: %" PRIuPTR "\n", - eventsCount, eventsCount + 1, eventsExpected); - result = STATUS_FAILED; - return; - } - - if (inf.sig == NULL || strcmp(inf.sig, classes[eventsCount].sig) != 0) { - printf("(#%" PRIuPTR ") wrong class: \"%s\"", - eventsCount, inf.sig); - printf(", expected: \"%s\"\n", classes[eventsCount].sig); - result = STATUS_FAILED; - } - if (inf.status != classes[eventsCount].status) { - printf("(#%" PRIuPTR ") wrong status: ", eventsCount); - printStatus(inf.status); - printf(" expected: "); - printStatus(classes[eventsCount].status); - result = STATUS_FAILED; - } - if (inf.mcount != classes[eventsCount].mcount) { - printf("(#%" PRIuPTR ") wrong number of methods: 0x%x", - eventsCount, inf.mcount); - printf(", expected: 0x%x\n", classes[eventsCount].mcount); - result = STATUS_FAILED; - } - if (inf.fcount != classes[eventsCount].fcount) { - printf("(#%" PRIuPTR ") wrong number of fields: 0x%x", - eventsCount, inf.fcount); - printf(", expected: 0x%x\n", classes[eventsCount].fcount); - result = STATUS_FAILED; - } - if (inf.icount != classes[eventsCount].icount) { - printf("(#%" PRIuPTR ") wrong number of interfaces: 0x%x", - eventsCount, inf.icount); - printf(", expected: 0x%x\n", classes[eventsCount].icount); - result = STATUS_FAILED; - } - eventsCount++; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_classprep001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_classprep001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_classprep001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.ClassPrepare = &ClassPrepare; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ClassPrepare_classprep001_getReady(JNIEnv *env, jclass cls) { - jvmtiError err; - jthread prep_thread; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return; - } - - if ((err = ((*jvmti)->GetCurrentThread(jvmti, &prep_thread))) != JVMTI_ERROR_NONE) { - printf("Failed to get current thread: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_CLASS_PREPARE, prep_thread); - if (err == JVMTI_ERROR_NONE) { - eventsExpected = sizeof(classes)/sizeof(class_info); - } else { - printf("Failed to enable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_ClassPrepare_classprep001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jthread prep_thread; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if ((err = ((*jvmti)->GetCurrentThread(jvmti, &prep_thread))) != JVMTI_ERROR_NONE) { - printf("Failed to get current thread: %s (%d)\n", TranslateError(err), err); - return STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_CLASS_PREPARE, prep_thread); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (eventsCount != eventsExpected) { - printf("Wrong number of class prepare events: %" PRIuPTR ", expected: %" PRIuPTR "\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/classprep001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/classprep001.cpp new file mode 100644 index 00000000000..0fb92b5882b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/classprep001.cpp @@ -0,0 +1,338 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define EXP_STATUS (JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED) + +typedef struct { + char *sig; + jint status; + jint mcount; + jint fcount; + jint icount; +} writable_class_info; + +typedef struct { + const char *sig; + jint status; + jint mcount; + jint fcount; + jint icount; +} class_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static size_t eventsCount = 0; +static size_t eventsExpected = 0; +static class_info classes[] = { + {"Lnsk/jvmti/ClassPrepare/classprep001$TestInterface;", EXP_STATUS, 2, 1, 0}, + {"Lnsk/jvmti/ClassPrepare/classprep001$TestClass;", EXP_STATUS, 3, 2, 1} +}; + +void printStatus(jint status) { + int flags = 0; + if ((status & JVMTI_CLASS_STATUS_VERIFIED) != 0) { + printf("JVMTI_CLASS_STATUS_VERIFIED"); + flags++; + } + if ((status & JVMTI_CLASS_STATUS_PREPARED) != 0) { + if (flags > 0) printf(" | "); + printf("JVMTI_CLASS_STATUS_PREPARED"); + flags++; + } + if ((status & JVMTI_CLASS_STATUS_INITIALIZED) != 0) { + if (flags > 0) printf(" | "); + printf("JVMTI_CLASS_STATUS_INITIALIZED"); + flags++; + } + if ((status & JVMTI_CLASS_STATUS_ERROR) != 0) { + if (flags > 0) printf(" | "); + printf("JVMTI_CLASS_STATUS_ERROR"); + flags++; + } + printf(" (0x%x)\n", status); +} + +void JNICALL ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jclass cls) { + jvmtiError err; + writable_class_info inf; + jmethodID *methods; + jfieldID *fields; + jclass *interfaces; + char *name, *sig, *generic; + int i; + + err = jvmti_env->GetClassSignature(cls, &inf.sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%" PRIuPTR ") unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassStatus(cls, &inf.status); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassStatus#%" PRIuPTR ") unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassMethods(cls, &inf.mcount, &methods); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassMethods#%" PRIuPTR ") unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassFields(cls, &inf.fcount, &fields); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassMethods#%" PRIuPTR ") unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetImplementedInterfaces(cls, + &inf.icount, &interfaces); + if (err != JVMTI_ERROR_NONE) { + printf("(GetImplementedInterfaces#%" PRIuPTR ") unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> [class prepare event #%" PRIuPTR "]", eventsCount); + printf(" \"%s\"\n", inf.sig); + printf(">>> status: "); + printStatus(inf.status); + printf(">>> %d methods:", inf.mcount); + for (i = 0; i < inf.mcount; i++) { + if (i > 0) printf(","); + if (methods[i] == NULL) { + printf(" null"); + } else { + err = jvmti_env->GetMethodName(methods[i], + &name, &sig, &generic); + if (err == JVMTI_ERROR_NONE) { + printf(" \"%s%s\"", name, sig); + } else { + printf(" ???"); + } + } + } + printf("\n"); + printf(">>> %d fields:", inf.fcount); + for (i = 0; i < inf.fcount; i++) { + if (i > 0) printf(","); + if (fields[i] == NULL) { + printf(" null"); + } else { + err = jvmti_env->GetFieldName(cls, fields[i], + &name, &sig, &generic); + if (err == JVMTI_ERROR_NONE) { + printf(" \"%s, %s\"", name, sig); + } else { + printf(" ???"); + } + } + } + printf("\n"); + printf(">>> %d interfaces:", inf.icount); + for (i = 0; i < inf.icount; i++) { + if (i > 0) printf(","); + if (interfaces[i] == NULL) { + printf(" null"); + } else { + err = jvmti_env->GetClassSignature( + interfaces[i], &sig, &generic); + if (err == JVMTI_ERROR_NONE) { + printf(" \"%s\"", sig); + } else { + printf(" ???"); + } + } + } + printf("\n"); + } + + if (eventsCount >= eventsExpected) { + printf("(#%" PRIuPTR ") too many events: %" PRIuPTR ", expected: %" PRIuPTR "\n", + eventsCount, eventsCount + 1, eventsExpected); + result = STATUS_FAILED; + return; + } + + if (inf.sig == NULL || strcmp(inf.sig, classes[eventsCount].sig) != 0) { + printf("(#%" PRIuPTR ") wrong class: \"%s\"", + eventsCount, inf.sig); + printf(", expected: \"%s\"\n", classes[eventsCount].sig); + result = STATUS_FAILED; + } + if (inf.status != classes[eventsCount].status) { + printf("(#%" PRIuPTR ") wrong status: ", eventsCount); + printStatus(inf.status); + printf(" expected: "); + printStatus(classes[eventsCount].status); + result = STATUS_FAILED; + } + if (inf.mcount != classes[eventsCount].mcount) { + printf("(#%" PRIuPTR ") wrong number of methods: 0x%x", + eventsCount, inf.mcount); + printf(", expected: 0x%x\n", classes[eventsCount].mcount); + result = STATUS_FAILED; + } + if (inf.fcount != classes[eventsCount].fcount) { + printf("(#%" PRIuPTR ") wrong number of fields: 0x%x", + eventsCount, inf.fcount); + printf(", expected: 0x%x\n", classes[eventsCount].fcount); + result = STATUS_FAILED; + } + if (inf.icount != classes[eventsCount].icount) { + printf("(#%" PRIuPTR ") wrong number of interfaces: 0x%x", + eventsCount, inf.icount); + printf(", expected: 0x%x\n", classes[eventsCount].icount); + result = STATUS_FAILED; + } + eventsCount++; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_classprep001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_classprep001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_classprep001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.ClassPrepare = &ClassPrepare; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ClassPrepare_classprep001_getReady(JNIEnv *env, jclass cls) { + jvmtiError err; + jthread prep_thread; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return; + } + + if ((err = (jvmti->GetCurrentThread(&prep_thread))) != JVMTI_ERROR_NONE) { + printf("Failed to get current thread: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_CLASS_PREPARE, prep_thread); + if (err == JVMTI_ERROR_NONE) { + eventsExpected = sizeof(classes)/sizeof(class_info); + } else { + printf("Failed to enable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_ClassPrepare_classprep001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jthread prep_thread; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if ((err = (jvmti->GetCurrentThread(&prep_thread))) != JVMTI_ERROR_NONE) { + printf("Failed to get current thread: %s (%d)\n", TranslateError(err), err); + return STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_CLASS_PREPARE, prep_thread); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (eventsCount != eventsExpected) { + printf("Wrong number of class prepare events: %" PRIuPTR ", expected: %" PRIuPTR "\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/libclassprep001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/libclassprep001.c deleted file mode 100644 index cb3d45e4831..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/libclassprep001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "classprep001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/libclassprep001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/libclassprep001.cpp new file mode 100644 index 00000000000..2dcd1658057 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassPrepare/classprep001/libclassprep001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "classprep001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/clrbrk001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/clrbrk001.c deleted file mode 100644 index a80d43a4172..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/clrbrk001.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID mid; -static int breakpointsExpected = 0; -static int breakpointsCount = 0; - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - breakpointsCount++; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_clrbrk001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_clrbrk001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_clrbrk001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ClearBreakpoint_clrbrk001_getReady(JNIEnv *env, jclass cls, jint i) { - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "trial", "(I)I"); - if (mid == NULL) { - printf("Cannot find method \"trial(I)I\"\n"); - result = STATUS_FAILED; - } else { - breakpointsExpected = i; - } -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_ClearBreakpoint_clrbrk001_setBP(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return; - } - - if (!caps.can_generate_breakpoint_events) { - return; - } - - if (mid == NULL) { - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to SetBreakpoint: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_ClearBreakpoint_clrbrk001_clearBP(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return; - } - - if (!caps.can_generate_breakpoint_events) { - return; - } - - if (mid == NULL) { - return; - } - - err = (*jvmti)->ClearBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to ClearBreakpoint: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_ClearBreakpoint_clrbrk001_check(JNIEnv *env, jclass cls) { - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_generate_breakpoint_events) { - return result; - } - - if (printdump == JNI_TRUE) { - printf("Total number of Breakpoint events: %d\n", breakpointsCount); - } - - if (breakpointsCount != breakpointsExpected) { - printf("Wrong number of Breakpoint events: %d, expected: %d\n", - breakpointsCount, breakpointsExpected); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/clrbrk001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/clrbrk001.cpp new file mode 100644 index 00000000000..7f622ddc990 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/clrbrk001.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID mid; +static int breakpointsExpected = 0; +static int breakpointsCount = 0; + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + breakpointsCount++; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_clrbrk001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_clrbrk001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_clrbrk001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ClearBreakpoint_clrbrk001_getReady(JNIEnv *env, jclass cls, jint i) { + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "trial", "(I)I"); + if (mid == NULL) { + printf("Cannot find method \"trial(I)I\"\n"); + result = STATUS_FAILED; + } else { + breakpointsExpected = i; + } +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_ClearBreakpoint_clrbrk001_setBP(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return; + } + + if (!caps.can_generate_breakpoint_events) { + return; + } + + if (mid == NULL) { + return; + } + + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to SetBreakpoint: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_ClearBreakpoint_clrbrk001_clearBP(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return; + } + + if (!caps.can_generate_breakpoint_events) { + return; + } + + if (mid == NULL) { + return; + } + + err = jvmti->ClearBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to ClearBreakpoint: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_ClearBreakpoint_clrbrk001_check(JNIEnv *env, jclass cls) { + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_generate_breakpoint_events) { + return result; + } + + if (printdump == JNI_TRUE) { + printf("Total number of Breakpoint events: %d\n", breakpointsCount); + } + + if (breakpointsCount != breakpointsExpected) { + printf("Wrong number of Breakpoint events: %d, expected: %d\n", + breakpointsCount, breakpointsExpected); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/libclrbrk001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/libclrbrk001.c deleted file mode 100644 index 5ac471ef024..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/libclrbrk001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "clrbrk001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/libclrbrk001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/libclrbrk001.cpp new file mode 100644 index 00000000000..93f4d78fdcf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/libclrbrk001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "clrbrk001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/clrbrk002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/clrbrk002.c deleted file mode 100644 index f7cbcf9919e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/clrbrk002.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_clrbrk002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_clrbrk002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_clrbrk002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_generate_breakpoint_events) { - printf("Warning: Breakpoint is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_ClearBreakpoint_clrbrk002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jlocation start; - jlocation end; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_generate_breakpoint_events) { - return result; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I"); - if (mid == NULL) { - printf("Cannot find method run\n"); - return STATUS_FAILED; - } - - err=(*jvmti)->GetMethodLocation(jvmti, mid, &start, &end); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> location less then starting location check ...\n"); - } - err = (*jvmti)->ClearBreakpoint(jvmti, mid, start - 1); - if (err != JVMTI_ERROR_INVALID_LOCATION) { - printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> location greater then ending location check ...\n"); - } - err = (*jvmti)->ClearBreakpoint(jvmti, mid, end + 1); - if (err != JVMTI_ERROR_INVALID_LOCATION) { - printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/clrbrk002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/clrbrk002.cpp new file mode 100644 index 00000000000..d12d874ecf1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/clrbrk002.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_clrbrk002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_clrbrk002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_clrbrk002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_generate_breakpoint_events) { + printf("Warning: Breakpoint is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_ClearBreakpoint_clrbrk002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jlocation start; + jlocation end; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_generate_breakpoint_events) { + return result; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I"); + if (mid == NULL) { + printf("Cannot find method run\n"); + return STATUS_FAILED; + } + + err=jvmti->GetMethodLocation(mid, &start, &end); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> location less then starting location check ...\n"); + } + err = jvmti->ClearBreakpoint(mid, start - 1); + if (err != JVMTI_ERROR_INVALID_LOCATION) { + printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> location greater then ending location check ...\n"); + } + err = jvmti->ClearBreakpoint(mid, end + 1); + if (err != JVMTI_ERROR_INVALID_LOCATION) { + printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/libclrbrk002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/libclrbrk002.c deleted file mode 100644 index 531a2173fd1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/libclrbrk002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "clrbrk002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/libclrbrk002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/libclrbrk002.cpp new file mode 100644 index 00000000000..8d969518fe2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/libclrbrk002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "clrbrk002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/clrbrk005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/clrbrk005.c deleted file mode 100644 index f6c0b99c3a0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/clrbrk005.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_clrbrk005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_clrbrk005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_clrbrk005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_generate_breakpoint_events) { - printf("Warning: Breakpoint is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_ClearBreakpoint_clrbrk005_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_generate_breakpoint_events) { - return result; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (mid == 0) { - printf("Cannot find Method ID for method checkPoint\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->ClearBreakpoint(jvmti, NULL, 0); - if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> not found check ...\n"); - } - err = (*jvmti)->ClearBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NOT_FOUND) { - printf("Error expected: JVMTI_ERROR_NOT_FOUND,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/clrbrk005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/clrbrk005.cpp new file mode 100644 index 00000000000..224507edd68 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/clrbrk005.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_clrbrk005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_clrbrk005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_clrbrk005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_generate_breakpoint_events) { + printf("Warning: Breakpoint is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_ClearBreakpoint_clrbrk005_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_generate_breakpoint_events) { + return result; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (mid == 0) { + printf("Cannot find Method ID for method checkPoint\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->ClearBreakpoint(NULL, 0); + if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> not found check ...\n"); + } + err = jvmti->ClearBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NOT_FOUND) { + printf("Error expected: JVMTI_ERROR_NOT_FOUND,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/libclrbrk005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/libclrbrk005.c deleted file mode 100644 index f5dd78dc2ae..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/libclrbrk005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "clrbrk005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/libclrbrk005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/libclrbrk005.cpp new file mode 100644 index 00000000000..7c4ca02b35f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/libclrbrk005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "clrbrk005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/clrfldw001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/clrfldw001.c deleted file mode 100644 index 01bb2f687ec..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/clrfldw001.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *class; - char *name; - char *sig; - int stat; - jfieldID fid; -} field; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jfieldID thrown_fid = NULL; -static field fields[] = { - {"nsk/jvmti/ClearFieldAccessWatch/clrfldw001", "fld0", "I", 0, NULL}, - {"nsk/jvmti/ClearFieldAccessWatch/clrfldw001", "fld1", "I", 1, NULL}, - {"nsk/jvmti/ClearFieldAccessWatch/clrfldw001", "fld2", - "Lnsk/jvmti/ClearFieldAccessWatch/clrfldw001a;", 0, NULL}, - {"nsk/jvmti/ClearFieldAccessWatch/clrfldw001a", "fld3", "[I", 0, NULL}, - {"nsk/jvmti/ClearFieldAccessWatch/clrfldw001b", "fld4", "F", 0, NULL}, -}; - -void switchWatch(JNIEnv *env, jint ind, jboolean on) { - jvmtiError err; - jclass cls; - field fld = fields[ind]; - char *msg; - - cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, fld.class)); - if (fld.fid == NULL) { - if (fld.stat) { - fields[ind].fid = JNI_ENV_PTR(env)-> - GetStaticFieldID(JNI_ENV_ARG(env, cls), fld.name, fld.sig); - } else { - fields[ind].fid = JNI_ENV_PTR(env)-> - GetFieldID(JNI_ENV_ARG(env, cls), fld.name, fld.sig); - } - } - - if (on == JNI_TRUE) { - msg = "Set"; - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, fields[ind].fid); - } else { - msg = "Clear"; - err = (*jvmti)->ClearFieldAccessWatch(jvmti, cls, fields[ind].fid); - } - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_generate_field_access_events) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(%sFieldAccessWatch#%d) unexpected error: %s (%d)\n", - msg, ind, TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thd, jmethodID mid, jlocation loc, - jclass field_klass, jobject obj, jfieldID field) { - thrown_fid = field; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_clrfldw001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_clrfldw001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_clrfldw001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldAccess watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw001_setWatch(JNIEnv *env, - jclass cls, jint fld_ind) { - switchWatch(env, fld_ind, JNI_TRUE); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw001_clearWatch(JNIEnv *env, - jclass cls, jint fld_ind) { - switchWatch(env, fld_ind, JNI_FALSE); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw001_touchfld0(JNIEnv *env, - jobject obj) { - jint val; - - val = JNI_ENV_PTR(env)->GetIntField(JNI_ENV_ARG(env, obj), fields[0].fid); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw001_check(JNIEnv *env, - jclass cls, jint fld_ind, jboolean flag) { - if (caps.can_generate_field_access_events) { - if (flag == JNI_FALSE && thrown_fid != NULL) { - result = STATUS_FAILED; - printf("(Field %d) FIELD_ACCESS event without access watch set\n", - fld_ind); - } else if (flag == JNI_TRUE && thrown_fid != fields[fld_ind].fid) { - result = STATUS_FAILED; - printf("(Field %d) thrown field ID expected: 0x%p, got: 0x%p\n", - fld_ind, fields[fld_ind].fid, thrown_fid); - } - thrown_fid = NULL; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/clrfldw001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/clrfldw001.cpp new file mode 100644 index 00000000000..88df6a5998e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/clrfldw001.cpp @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *klass; + const char *name; + const char *sig; + int stat; + jfieldID fid; +} field; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jfieldID thrown_fid = NULL; +static field fields[] = { + {"nsk/jvmti/ClearFieldAccessWatch/clrfldw001", "fld0", "I", 0, NULL}, + {"nsk/jvmti/ClearFieldAccessWatch/clrfldw001", "fld1", "I", 1, NULL}, + {"nsk/jvmti/ClearFieldAccessWatch/clrfldw001", "fld2", + "Lnsk/jvmti/ClearFieldAccessWatch/clrfldw001a;", 0, NULL}, + {"nsk/jvmti/ClearFieldAccessWatch/clrfldw001a", "fld3", "[I", 0, NULL}, + {"nsk/jvmti/ClearFieldAccessWatch/clrfldw001b", "fld4", "F", 0, NULL}, +}; + +void switchWatch(JNIEnv *env, jint ind, jboolean on) { + jvmtiError err; + jclass cls; + field fld = fields[ind]; + const char *msg; + + cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, fld.klass)); + if (fld.fid == NULL) { + if (fld.stat) { + fields[ind].fid = JNI_ENV_PTR(env)-> + GetStaticFieldID(JNI_ENV_ARG(env, cls), fld.name, fld.sig); + } else { + fields[ind].fid = JNI_ENV_PTR(env)-> + GetFieldID(JNI_ENV_ARG(env, cls), fld.name, fld.sig); + } + } + + if (on == JNI_TRUE) { + msg = "Set"; + err = jvmti->SetFieldAccessWatch(cls, fields[ind].fid); + } else { + msg = "Clear"; + err = jvmti->ClearFieldAccessWatch(cls, fields[ind].fid); + } + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_generate_field_access_events) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(%sFieldAccessWatch#%d) unexpected error: %s (%d)\n", + msg, ind, TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thd, jmethodID mid, jlocation loc, + jclass field_klass, jobject obj, jfieldID field) { + thrown_fid = field; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_clrfldw001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_clrfldw001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_clrfldw001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldAccess watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw001_setWatch(JNIEnv *env, + jclass cls, jint fld_ind) { + switchWatch(env, fld_ind, JNI_TRUE); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw001_clearWatch(JNIEnv *env, + jclass cls, jint fld_ind) { + switchWatch(env, fld_ind, JNI_FALSE); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw001_touchfld0(JNIEnv *env, + jobject obj) { + jint val; + + val = JNI_ENV_PTR(env)->GetIntField(JNI_ENV_ARG(env, obj), fields[0].fid); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw001_check(JNIEnv *env, + jclass cls, jint fld_ind, jboolean flag) { + if (caps.can_generate_field_access_events) { + if (flag == JNI_FALSE && thrown_fid != NULL) { + result = STATUS_FAILED; + printf("(Field %d) FIELD_ACCESS event without access watch set\n", + fld_ind); + } else if (flag == JNI_TRUE && thrown_fid != fields[fld_ind].fid) { + result = STATUS_FAILED; + printf("(Field %d) thrown field ID expected: 0x%p, got: 0x%p\n", + fld_ind, fields[fld_ind].fid, thrown_fid); + } + thrown_fid = NULL; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/libclrfldw001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/libclrfldw001.c deleted file mode 100644 index 402df85ab35..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/libclrfldw001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "clrfldw001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/libclrfldw001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/libclrfldw001.cpp new file mode 100644 index 00000000000..321dd0c67fb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001/libclrfldw001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "clrfldw001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/clrfldw002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/clrfldw002.c deleted file mode 100644 index 90ccd6eb5f9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/clrfldw002.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thd, jmethodID mid, jlocation loc, - jclass field_klass, jobject obj, jfieldID field) { -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_clrfldw002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_clrfldw002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_clrfldw002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldAccess watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jfieldID fid1, fid2; - - fid1 = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - "fld1", "I"); - fid2 = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - "fld2", "I"); - - if (!caps.can_generate_field_access_events) { - err = (*jvmti)->ClearFieldAccessWatch(jvmti, cls, fid1); - if (err != JVMTI_ERROR_MUST_POSSESS_CAPABILITY) { - result = STATUS_FAILED; - printf("Failed to return MUST_POSSESS_CAPABILITY: %s (%d)\n", - TranslateError(err), err); - } - } else { - err = (*jvmti)->ClearFieldAccessWatch(jvmti, NULL, fid2); - if (err != JVMTI_ERROR_INVALID_CLASS) { - result = STATUS_FAILED; - printf("Failed to return JVMTI_ERROR_INVALID_CLASS: %s (%d)\n", - TranslateError(err), err); - } - - err = (*jvmti)->ClearFieldAccessWatch(jvmti, cls, NULL); - if (err != JVMTI_ERROR_INVALID_FIELDID) { - result = STATUS_FAILED; - printf("Failed to return INVALID_FIELDID: %s (%d)\n", - TranslateError(err), err); - } - - err = (*jvmti)->ClearFieldAccessWatch(jvmti, cls, fid2); - if (err != JVMTI_ERROR_NOT_FOUND) { - result = STATUS_FAILED; - printf("Failed to return NOT_FOUND: %s (%d)\n", - TranslateError(err), err); - } - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw002_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/clrfldw002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/clrfldw002.cpp new file mode 100644 index 00000000000..e4687f55cd1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/clrfldw002.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thd, jmethodID mid, jlocation loc, + jclass field_klass, jobject obj, jfieldID field) { +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_clrfldw002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_clrfldw002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_clrfldw002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldAccess watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jfieldID fid1, fid2; + + fid1 = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + "fld1", "I"); + fid2 = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + "fld2", "I"); + + if (!caps.can_generate_field_access_events) { + err = jvmti->ClearFieldAccessWatch(cls, fid1); + if (err != JVMTI_ERROR_MUST_POSSESS_CAPABILITY) { + result = STATUS_FAILED; + printf("Failed to return MUST_POSSESS_CAPABILITY: %s (%d)\n", + TranslateError(err), err); + } + } else { + err = jvmti->ClearFieldAccessWatch(NULL, fid2); + if (err != JVMTI_ERROR_INVALID_CLASS) { + result = STATUS_FAILED; + printf("Failed to return JVMTI_ERROR_INVALID_CLASS: %s (%d)\n", + TranslateError(err), err); + } + + err = jvmti->ClearFieldAccessWatch(cls, NULL); + if (err != JVMTI_ERROR_INVALID_FIELDID) { + result = STATUS_FAILED; + printf("Failed to return INVALID_FIELDID: %s (%d)\n", + TranslateError(err), err); + } + + err = jvmti->ClearFieldAccessWatch(cls, fid2); + if (err != JVMTI_ERROR_NOT_FOUND) { + result = STATUS_FAILED; + printf("Failed to return NOT_FOUND: %s (%d)\n", + TranslateError(err), err); + } + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw002_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/libclrfldw002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/libclrfldw002.c deleted file mode 100644 index 49111697363..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/libclrfldw002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "clrfldw002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/libclrfldw002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/libclrfldw002.cpp new file mode 100644 index 00000000000..4e07e03ae24 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/libclrfldw002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "clrfldw002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/clrfmodw001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/clrfmodw001.c deleted file mode 100644 index 85310844178..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/clrfmodw001.c +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *class; - char *name; - char *sig; - int stat; - jfieldID fid; -} field; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jfieldID thrown_fid = NULL; -static field fields[] = { - {"nsk/jvmti/ClearFieldModificationWatch/clrfmodw001", "fld0", "I", 0, NULL}, - {"nsk/jvmti/ClearFieldModificationWatch/clrfmodw001", "fld1", "I", 1, NULL}, - {"nsk/jvmti/ClearFieldModificationWatch/clrfmodw001", "fld2", - "Lnsk/jvmti/ClearFieldModificationWatch/clrfmodw001a;", 0, NULL}, - {"nsk/jvmti/ClearFieldModificationWatch/clrfmodw001a", "fld3", "[I", 0, NULL}, - {"nsk/jvmti/ClearFieldModificationWatch/clrfmodw001b", "fld4", "F", 0, NULL}, -}; - -void switchWatch(JNIEnv *env, jint ind, jboolean on) { - jvmtiError err; - jclass cls; - field fld = fields[ind]; - char *msg; - - cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, fld.class)); - if (fld.fid == NULL) { - if (fld.stat) { - fields[ind].fid = JNI_ENV_PTR(env)-> - GetStaticFieldID(JNI_ENV_ARG(env, cls), fld.name, fld.sig); - } else { - fields[ind].fid = JNI_ENV_PTR(env)-> - GetFieldID(JNI_ENV_ARG(env, cls), fld.name, fld.sig); - } - } - - if (on == JNI_TRUE) { - msg = "Set"; - err = (*jvmti)->SetFieldModificationWatch(jvmti, cls, fields[ind].fid); - } else { - msg = "Clear"; - err = (*jvmti)->ClearFieldModificationWatch(jvmti, cls, fields[ind].fid); - } - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_generate_field_modification_events) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(%sFieldModificationWatch#%d) unexpected error: %s (%d)\n", - msg, ind, TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thd, jmethodID mid, jlocation loc, jclass field_klass, jobject obj, - jfieldID field, char sig, jvalue new_value) { - thrown_fid = field; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_clrfmodw001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_clrfmodw001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_clrfmodw001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_modification_events) { - callbacks.FieldModification = &FieldModification; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_MODIFICATION, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldModification watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw001_setWatch(JNIEnv *env, jclass cls, jint fld_ind) { - switchWatch(env, fld_ind, JNI_TRUE); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw001_clearWatch(JNIEnv *env, jclass cls, jint fld_ind) { - switchWatch(env, fld_ind, JNI_FALSE); -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw001_touchfld0(JNIEnv *env, jobject obj) { - JNI_ENV_PTR(env)->SetIntField(JNI_ENV_ARG(env, obj), fields[0].fid, 2000); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw001_check(JNIEnv *env, jclass cls, jint fld_ind, jboolean flag) { - if (caps.can_generate_field_modification_events) { - if (flag == JNI_FALSE && thrown_fid != NULL) { - result = STATUS_FAILED; - printf("(Field %d) ", fld_ind); - printf("FieldModification event without modification watch set\n"); - } else if (flag == JNI_TRUE && thrown_fid != fields[fld_ind].fid) { - result = STATUS_FAILED; - printf("(Field %d) thrown field ID expected: 0x%p, got: 0x%p\n", - fld_ind, fields[fld_ind].fid, thrown_fid); - } - thrown_fid = NULL; - } -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/clrfmodw001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/clrfmodw001.cpp new file mode 100644 index 00000000000..ad04adb9ad6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/clrfmodw001.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *klass; + const char *name; + const char *sig; + int stat; + jfieldID fid; +} field; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jfieldID thrown_fid = NULL; +static field fields[] = { + {"nsk/jvmti/ClearFieldModificationWatch/clrfmodw001", "fld0", "I", 0, NULL}, + {"nsk/jvmti/ClearFieldModificationWatch/clrfmodw001", "fld1", "I", 1, NULL}, + {"nsk/jvmti/ClearFieldModificationWatch/clrfmodw001", "fld2", + "Lnsk/jvmti/ClearFieldModificationWatch/clrfmodw001a;", 0, NULL}, + {"nsk/jvmti/ClearFieldModificationWatch/clrfmodw001a", "fld3", "[I", 0, NULL}, + {"nsk/jvmti/ClearFieldModificationWatch/clrfmodw001b", "fld4", "F", 0, NULL}, +}; + +void switchWatch(JNIEnv *env, jint ind, jboolean on) { + jvmtiError err; + jclass cls; + field fld = fields[ind]; + const char *msg; + + cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, fld.klass)); + if (fld.fid == NULL) { + if (fld.stat) { + fields[ind].fid = JNI_ENV_PTR(env)-> + GetStaticFieldID(JNI_ENV_ARG(env, cls), fld.name, fld.sig); + } else { + fields[ind].fid = JNI_ENV_PTR(env)-> + GetFieldID(JNI_ENV_ARG(env, cls), fld.name, fld.sig); + } + } + + if (on == JNI_TRUE) { + msg = "Set"; + err = jvmti->SetFieldModificationWatch(cls, fields[ind].fid); + } else { + msg = "Clear"; + err = jvmti->ClearFieldModificationWatch(cls, fields[ind].fid); + } + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_generate_field_modification_events) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(%sFieldModificationWatch#%d) unexpected error: %s (%d)\n", + msg, ind, TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thd, jmethodID mid, jlocation loc, jclass field_klass, jobject obj, + jfieldID field, char sig, jvalue new_value) { + thrown_fid = field; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_clrfmodw001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_clrfmodw001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_clrfmodw001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_modification_events) { + callbacks.FieldModification = &FieldModification; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_MODIFICATION, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldModification watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw001_setWatch(JNIEnv *env, jclass cls, jint fld_ind) { + switchWatch(env, fld_ind, JNI_TRUE); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw001_clearWatch(JNIEnv *env, jclass cls, jint fld_ind) { + switchWatch(env, fld_ind, JNI_FALSE); +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw001_touchfld0(JNIEnv *env, jobject obj) { + JNI_ENV_PTR(env)->SetIntField(JNI_ENV_ARG(env, obj), fields[0].fid, 2000); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw001_check(JNIEnv *env, jclass cls, jint fld_ind, jboolean flag) { + if (caps.can_generate_field_modification_events) { + if (flag == JNI_FALSE && thrown_fid != NULL) { + result = STATUS_FAILED; + printf("(Field %d) ", fld_ind); + printf("FieldModification event without modification watch set\n"); + } else if (flag == JNI_TRUE && thrown_fid != fields[fld_ind].fid) { + result = STATUS_FAILED; + printf("(Field %d) thrown field ID expected: 0x%p, got: 0x%p\n", + fld_ind, fields[fld_ind].fid, thrown_fid); + } + thrown_fid = NULL; + } +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/libclrfmodw001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/libclrfmodw001.c deleted file mode 100644 index 33bfe137015..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/libclrfmodw001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "clrfmodw001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/libclrfmodw001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/libclrfmodw001.cpp new file mode 100644 index 00000000000..08ad82bb484 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw001/libclrfmodw001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "clrfmodw001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/clrfmodw002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/clrfmodw002.c deleted file mode 100644 index 1868399f43a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/clrfmodw002.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; - -void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thd, jmethodID mid, jlocation loc, - jclass field_klass, jobject obj, jfieldID field, - char sig, jvalue new_value) { -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_clrfmodw002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_clrfmodw002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_clrfmodw002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_modification_events) { - callbacks.FieldModification = &FieldModification; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_MODIFICATION, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldModification watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw002_check(JNIEnv *env, - jclass cls) { - jvmtiError err; - jfieldID fid1, fid2; - - fid1 = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - "fld1", "I"); - fid2 = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - "fld2", "I"); - - if (!caps.can_generate_field_modification_events) { - printf("Warning: ClearFieldModificationWatch is not implemented\n"); - err = (*jvmti)->ClearFieldModificationWatch(jvmti, cls, fid1); - if (err != JVMTI_ERROR_MUST_POSSESS_CAPABILITY) { - result = STATUS_FAILED; - printf("Failed to return MUST_POSSESS_CAPABILITY: %s (%d)\n", - TranslateError(err), err); - } - } else { - err = (*jvmti)->ClearFieldModificationWatch(jvmti, NULL, fid2); - if (err != JVMTI_ERROR_INVALID_CLASS) { - result = STATUS_FAILED; - printf("Failed to return JVMTI_ERROR_INVALID_CLASS: %s (%d)\n", - TranslateError(err), err); - } - - err = (*jvmti)->ClearFieldModificationWatch(jvmti, cls, NULL); - if (err != JVMTI_ERROR_INVALID_FIELDID) { - result = STATUS_FAILED; - printf("Failed to return INVALID_FIELDID: %s (%d)\n", - TranslateError(err), err); - } - - err = (*jvmti)->ClearFieldModificationWatch(jvmti, cls, fid2); - if (err != JVMTI_ERROR_NOT_FOUND) { - result = STATUS_FAILED; - printf("Failed to return NOT_FOUND: %s (%d)\n", - TranslateError(err), err); - } - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw002_getRes(JNIEnv *env, - jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/clrfmodw002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/clrfmodw002.cpp new file mode 100644 index 00000000000..bf2b663654d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/clrfmodw002.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; + +void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thd, jmethodID mid, jlocation loc, + jclass field_klass, jobject obj, jfieldID field, + char sig, jvalue new_value) { +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_clrfmodw002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_clrfmodw002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_clrfmodw002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_modification_events) { + callbacks.FieldModification = &FieldModification; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_MODIFICATION, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldModification watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw002_check(JNIEnv *env, + jclass cls) { + jvmtiError err; + jfieldID fid1, fid2; + + fid1 = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + "fld1", "I"); + fid2 = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + "fld2", "I"); + + if (!caps.can_generate_field_modification_events) { + printf("Warning: ClearFieldModificationWatch is not implemented\n"); + err = jvmti->ClearFieldModificationWatch(cls, fid1); + if (err != JVMTI_ERROR_MUST_POSSESS_CAPABILITY) { + result = STATUS_FAILED; + printf("Failed to return MUST_POSSESS_CAPABILITY: %s (%d)\n", + TranslateError(err), err); + } + } else { + err = jvmti->ClearFieldModificationWatch(NULL, fid2); + if (err != JVMTI_ERROR_INVALID_CLASS) { + result = STATUS_FAILED; + printf("Failed to return JVMTI_ERROR_INVALID_CLASS: %s (%d)\n", + TranslateError(err), err); + } + + err = jvmti->ClearFieldModificationWatch(cls, NULL); + if (err != JVMTI_ERROR_INVALID_FIELDID) { + result = STATUS_FAILED; + printf("Failed to return INVALID_FIELDID: %s (%d)\n", + TranslateError(err), err); + } + + err = jvmti->ClearFieldModificationWatch(cls, fid2); + if (err != JVMTI_ERROR_NOT_FOUND) { + result = STATUS_FAILED; + printf("Failed to return NOT_FOUND: %s (%d)\n", + TranslateError(err), err); + } + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw002_getRes(JNIEnv *env, + jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/libclrfmodw002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/libclrfmodw002.c deleted file mode 100644 index 52108cb2dc9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/libclrfmodw002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "clrfmodw002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/libclrfmodw002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/libclrfmodw002.cpp new file mode 100644 index 00000000000..bb8a122ba68 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/libclrfmodw002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "clrfmodw002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/compmethload001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/compmethload001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/compmethload001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/compmethload001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/libcompmethload001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/libcompmethload001.c deleted file mode 100644 index d36e07fc104..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/libcompmethload001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "compmethload001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/libcompmethload001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/libcompmethload001.cpp new file mode 100644 index 00000000000..f4918ef24bd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/libcompmethload001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "compmethload001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/compmethunload001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/compmethunload001.c deleted file mode 100644 index 0cc77cd3cda..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/compmethunload001.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static volatile jint result = PASSED; -static volatile int compunload = 0; -static volatile int class_unloaded = 0; -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; - -/** callback functions **/ -void JNICALL -VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - NSK_DISPLAY0("VMInit event received\n\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GenerateEvents, - jvmti_env, JVMTI_EVENT_COMPILED_METHOD_LOAD))) { - NSK_COMPLAIN0("TEST FAILED: unable to generate events to represent the current state of the VM\n"); - result = STATUS_FAILED; - } -} - -void JNICALL -CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map, - const void* compile_info) { - char *name; - char *sig; - char *generic; - - NSK_DISPLAY0("CompiledMethodLoad event received for:\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &name, &sig, &generic))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILURE: unable to obtain method info\n\n"); - return; - } - NSK_DISPLAY4("\tmethod: name=\"%s\" signature=\"%s\"\n\tcompiled code size=%d\n\tnumber of address location map entries=%d\n\n", - name, sig, code_size, map_length); -} - -void JNICALL -CompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - char *name; - char *sig; - jvmtiPhase phase; - jvmtiError err; - - compunload++; - - /* jmethodID: Identifies a Java programming language method, initializer, or constructor. - * jmethodIDs returned by JVM TI functions and events may be safely stored. However, if - * the class is unloaded, they become invalid and must not be used. */ - - NSK_DISPLAY0("CompiledMethodUnload event received\n"); - // Check for the case that the class has been unloaded - err = (*jvmti_env)->GetMethodName(jvmti_env, method, &name, &sig, NULL); - if (err == JVMTI_ERROR_NONE) { - NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", - name, sig, code_addr); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); - } else { - // The class metadata has been completely unloaded so the name is not available. - NSK_DISPLAY0("for: \tmethod: name=\n"); - } - - // Count unloaded events - class_unloaded++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, - jvmti_env, &phase))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILURE: unable to obtain phase of the VM execution\n"); - return; - } - - if (phase != JVMTI_PHASE_LIVE) { - result = STATUS_FAILED; - NSK_COMPLAIN1("TEST FAILED: CompiledMethodUnload event received during non-live phase %s\n", - TranslatePhase(phase)); - } - else - NSK_DISPLAY0("CHECK PASSED: CompiledMethodUnload event received during the live phase as expected\n\n"); -} -/************************/ - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_CompiledMethodUnload_compmethunload001_check( - JNIEnv *env, jobject obj) { - if (!caps.can_generate_compiled_method_load_events) - return PASSED; - - if (compunload == 0) - NSK_DISPLAY0("Warning: no CompiledMethodUnload events\n\tthe test has no results\n"); - - return result; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_CompiledMethodUnload_compmethunload001_unloaded( - JNIEnv *env, jobject obj) { - if (!caps.can_generate_compiled_method_load_events) - return 1; - - return class_unloaded; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_compmethunload001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_compmethunload001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_compmethunload001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* add capability to generate compiled method events */ - memset(&caps, 0, sizeof(jvmtiCapabilities)); - caps.can_generate_compiled_method_load_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, - jvmti, &caps))) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, - jvmti, &caps))) - return JNI_ERR; - - if (!caps.can_generate_compiled_method_load_events) - NSK_DISPLAY0("Warning: generation of compiled method events is not implemented\n"); - - /* set event callback */ - NSK_DISPLAY0("setting event callbacks ...\n"); - (void) memset(&callbacks, 0, sizeof(callbacks)); - callbacks.VMInit = &VMInit; - callbacks.CompiledMethodLoad = &CompiledMethodLoad; - callbacks.CompiledMethodUnload = &CompiledMethodUnload; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - NSK_DISPLAY0("setting event callbacks done\nenabling JVMTI events ...\n"); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_UNLOAD, NULL))) - return JNI_ERR; - NSK_DISPLAY0("enabling the events done\n\n"); - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/compmethunload001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/compmethunload001.cpp new file mode 100644 index 00000000000..442eef8c225 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/compmethunload001.cpp @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static volatile jint result = PASSED; +static volatile int compunload = 0; +static volatile int class_unloaded = 0; +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; + +/** callback functions **/ +void JNICALL +VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + NSK_DISPLAY0("VMInit event received\n\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GenerateEvents, + jvmti_env, JVMTI_EVENT_COMPILED_METHOD_LOAD))) { + NSK_COMPLAIN0("TEST FAILED: unable to generate events to represent the current state of the VM\n"); + result = STATUS_FAILED; + } +} + +void JNICALL +CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map, + const void* compile_info) { + char *name; + char *sig; + char *generic; + + NSK_DISPLAY0("CompiledMethodLoad event received for:\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &name, &sig, &generic))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILURE: unable to obtain method info\n\n"); + return; + } + NSK_DISPLAY4("\tmethod: name=\"%s\" signature=\"%s\"\n\tcompiled code size=%d\n\tnumber of address location map entries=%d\n\n", + name, sig, code_size, map_length); +} + +void JNICALL +CompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + char *name; + char *sig; + jvmtiPhase phase; + jvmtiError err; + + compunload++; + + /* jmethodID: Identifies a Java programming language method, initializer, or constructor. + * jmethodIDs returned by JVM TI functions and events may be safely stored. However, if + * the class is unloaded, they become invalid and must not be used. */ + + NSK_DISPLAY0("CompiledMethodUnload event received\n"); + // Check for the case that the class has been unloaded + err = jvmti_env->GetMethodName(method, &name, &sig, NULL); + if (err == JVMTI_ERROR_NONE) { + NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", + name, sig, code_addr); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); + } else { + // The class metadata has been completely unloaded so the name is not available. + NSK_DISPLAY0("for: \tmethod: name=\n"); + } + + // Count unloaded events + class_unloaded++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, + jvmti_env, &phase))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILURE: unable to obtain phase of the VM execution\n"); + return; + } + + if (phase != JVMTI_PHASE_LIVE) { + result = STATUS_FAILED; + NSK_COMPLAIN1("TEST FAILED: CompiledMethodUnload event received during non-live phase %s\n", + TranslatePhase(phase)); + } + else + NSK_DISPLAY0("CHECK PASSED: CompiledMethodUnload event received during the live phase as expected\n\n"); +} +/************************/ + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_CompiledMethodUnload_compmethunload001_check( + JNIEnv *env, jobject obj) { + if (!caps.can_generate_compiled_method_load_events) + return PASSED; + + if (compunload == 0) + NSK_DISPLAY0("Warning: no CompiledMethodUnload events\n\tthe test has no results\n"); + + return result; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_CompiledMethodUnload_compmethunload001_unloaded( + JNIEnv *env, jobject obj) { + if (!caps.can_generate_compiled_method_load_events) + return 1; + + return class_unloaded; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_compmethunload001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_compmethunload001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_compmethunload001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* add capability to generate compiled method events */ + memset(&caps, 0, sizeof(jvmtiCapabilities)); + caps.can_generate_compiled_method_load_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, + jvmti, &caps))) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, + jvmti, &caps))) + return JNI_ERR; + + if (!caps.can_generate_compiled_method_load_events) + NSK_DISPLAY0("Warning: generation of compiled method events is not implemented\n"); + + /* set event callback */ + NSK_DISPLAY0("setting event callbacks ...\n"); + (void) memset(&callbacks, 0, sizeof(callbacks)); + callbacks.VMInit = &VMInit; + callbacks.CompiledMethodLoad = &CompiledMethodLoad; + callbacks.CompiledMethodUnload = &CompiledMethodUnload; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + NSK_DISPLAY0("setting event callbacks done\nenabling JVMTI events ...\n"); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_UNLOAD, NULL))) + return JNI_ERR; + NSK_DISPLAY0("enabling the events done\n\n"); + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/libcompmethunload001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/libcompmethunload001.c deleted file mode 100644 index e2a7fadaff3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/libcompmethunload001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "compmethunload001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/libcompmethunload001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/libcompmethunload001.cpp new file mode 100644 index 00000000000..47d447dacb2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/libcompmethunload001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "compmethunload001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/crrawmon001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/crrawmon001.c deleted file mode 100644 index efb7a4f73ef..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/crrawmon001.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define RAW_MONITORS_NUMBER 1024 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - jvmtiError err; - char name[32]; - int i; - - if (printdump == JNI_TRUE) { - printf(">>> VMInit event\n"); - printf(">>> trying to create %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - sprintf(name, "RawMonitor-%d", i); - err = (*jvmti)->CreateRawMonitor(jvmti, name, &monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } else if (monitors[i] == NULL) { - printf("(CreateRawMonitor#%d) jrawMonitorID is null\n", i); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_crrawmon001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_crrawmon001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_crrawmon001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_CreateRawMonitor_crrawmon001_check(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/crrawmon001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/crrawmon001.cpp new file mode 100644 index 00000000000..8cc05b811cb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/crrawmon001.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define RAW_MONITORS_NUMBER 1024 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + jvmtiError err; + char name[32]; + int i; + + if (printdump == JNI_TRUE) { + printf(">>> VMInit event\n"); + printf(">>> trying to create %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + sprintf(name, "RawMonitor-%d", i); + err = jvmti->CreateRawMonitor(name, &monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } else if (monitors[i] == NULL) { + printf("(CreateRawMonitor#%d) jrawMonitorID is null\n", i); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_crrawmon001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_crrawmon001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_crrawmon001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_CreateRawMonitor_crrawmon001_check(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/libcrrawmon001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/libcrrawmon001.c deleted file mode 100644 index 77b2ca87596..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/libcrrawmon001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "crrawmon001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/libcrrawmon001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/libcrrawmon001.cpp new file mode 100644 index 00000000000..8ce964c61c9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon001/libcrrawmon001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "crrawmon001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/crrawmon002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/crrawmon002.c deleted file mode 100644 index e1dcfa7deaf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/crrawmon002.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_crrawmon002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_crrawmon002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_crrawmon002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_CreateRawMonitor_crrawmon002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jrawMonitorID monitor; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> name null pointer check ...\n"); - } - err = (*jvmti)->CreateRawMonitor(jvmti, NULL, &monitor); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s\n", - TranslateError(err)); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> monitorPtr null pointer check ...\n"); - } - err = (*jvmti)->CreateRawMonitor(jvmti, "dummy", NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s\n", - TranslateError(err)); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/crrawmon002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/crrawmon002.cpp new file mode 100644 index 00000000000..258787a4b95 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/crrawmon002.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_crrawmon002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_crrawmon002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_crrawmon002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_CreateRawMonitor_crrawmon002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jrawMonitorID monitor; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> name null pointer check ...\n"); + } + err = jvmti->CreateRawMonitor(NULL, &monitor); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s\n", + TranslateError(err)); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> monitorPtr null pointer check ...\n"); + } + err = jvmti->CreateRawMonitor("dummy", NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s\n", + TranslateError(err)); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/libcrrawmon002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/libcrrawmon002.c deleted file mode 100644 index 9f731308e06..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/libcrrawmon002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "crrawmon002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/libcrrawmon002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/libcrrawmon002.cpp new file mode 100644 index 00000000000..b77fc2f7b16 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/libcrrawmon002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "crrawmon002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/datadumpreq001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/datadumpreq001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/datadumpreq001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/datadumpreq001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/libdatadumpreq001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/libdatadumpreq001.c deleted file mode 100644 index 4b19f5715d0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/libdatadumpreq001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "datadumpreq001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/libdatadumpreq001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/libdatadumpreq001.cpp new file mode 100644 index 00000000000..9911c705ad9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/libdatadumpreq001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "datadumpreq001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/dealloc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/dealloc001.c deleted file mode 100644 index 12c2be0536e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/dealloc001.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_dealloc001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_dealloc001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_dealloc001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_Deallocate_dealloc001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> Null pointer check ...\n"); - } - err = (*jvmti)->Deallocate(jvmti, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Error expected: JVMTI_ERROR_NONE, got: %s\n", - TranslateError(err)); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/dealloc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/dealloc001.cpp new file mode 100644 index 00000000000..bffe9c5d9e5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/dealloc001.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_dealloc001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_dealloc001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_dealloc001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_Deallocate_dealloc001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> Null pointer check ...\n"); + } + err = jvmti->Deallocate(NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Error expected: JVMTI_ERROR_NONE, got: %s\n", + TranslateError(err)); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/libdealloc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/libdealloc001.c deleted file mode 100644 index a5fbf68e3af..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/libdealloc001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "dealloc001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/libdealloc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/libdealloc001.cpp new file mode 100644 index 00000000000..730de26fa88 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Deallocate/dealloc001/libdealloc001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "dealloc001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/drrawmon001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/drrawmon001.c deleted file mode 100644 index 4ce1ed76159..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/drrawmon001.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define RAW_MONITORS_NUMBER 1024 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - jvmtiError err; - char name[32]; - int i; - - if (printdump == JNI_TRUE) { - printf(">>> VMInit event\n"); - printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - sprintf(name, "RawMonitor-%d", i); - err = (*jvmti)->CreateRawMonitor(jvmti_env, name, &monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } else if (monitors[i] == NULL) { - printf("(CreateRawMonitor#%d) jrawMonitorID is null\n", i); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->DestroyRawMonitor(jvmti_env, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_drrawmon001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_drrawmon001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_drrawmon001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_DestroyRawMonitor_drrawmon001_check(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/drrawmon001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/drrawmon001.cpp new file mode 100644 index 00000000000..a95c0a62e57 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/drrawmon001.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define RAW_MONITORS_NUMBER 1024 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + jvmtiError err; + char name[32]; + int i; + + if (printdump == JNI_TRUE) { + printf(">>> VMInit event\n"); + printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + sprintf(name, "RawMonitor-%d", i); + err = jvmti_env->CreateRawMonitor(name, &monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } else if (monitors[i] == NULL) { + printf("(CreateRawMonitor#%d) jrawMonitorID is null\n", i); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti_env->DestroyRawMonitor(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_drrawmon001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_drrawmon001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_drrawmon001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_DestroyRawMonitor_drrawmon001_check(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/libdrrawmon001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/libdrrawmon001.c deleted file mode 100644 index b437e82357a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/libdrrawmon001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "drrawmon001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/libdrrawmon001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/libdrrawmon001.cpp new file mode 100644 index 00000000000..9b2c5a7aa7a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon001/libdrrawmon001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "drrawmon001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/drrawmon003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/drrawmon003.c deleted file mode 100644 index dfcb3032231..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/drrawmon003.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_drrawmon003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_drrawmon003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_drrawmon003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_DestroyRawMonitor_drrawmon003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jrawMonitorID monitor; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "testMonitor", &monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - err = (*jvmti)->DestroyRawMonitor(jvmti, monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> already destroyed monitor check ...\n"); - } - - // Create an invalid monitor by allocating a sufficiently big zeroed memory block - // and treating the pointer to the block as a monitor id - // Expect such fake monitor to be recognized as an invalid one - monitor = (jrawMonitorID)calloc(1, 1024); - err = (*jvmti)->DestroyRawMonitor(jvmti, monitor); - if (err != JVMTI_ERROR_INVALID_MONITOR) { - printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return PASSED; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/drrawmon003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/drrawmon003.cpp new file mode 100644 index 00000000000..b0184601f82 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/drrawmon003.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_drrawmon003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_drrawmon003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_drrawmon003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_DestroyRawMonitor_drrawmon003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jrawMonitorID monitor; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->CreateRawMonitor("testMonitor", &monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + err = jvmti->DestroyRawMonitor(monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> already destroyed monitor check ...\n"); + } + + // Create an invalid monitor by allocating a sufficiently big zeroed memory block + // and treating the pointer to the block as a monitor id + // Expect such fake monitor to be recognized as an invalid one + monitor = (jrawMonitorID)calloc(1, 1024); + err = jvmti->DestroyRawMonitor(monitor); + if (err != JVMTI_ERROR_INVALID_MONITOR) { + printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return PASSED; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/libdrrawmon003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/libdrrawmon003.c deleted file mode 100644 index 743cfd2e87f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/libdrrawmon003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "drrawmon003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/libdrrawmon003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/libdrrawmon003.cpp new file mode 100644 index 00000000000..3da99a4ea43 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/libdrrawmon003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "drrawmon003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/drrawmon004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/drrawmon004.c deleted file mode 100644 index dd45a7671cb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/drrawmon004.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_drrawmon004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_drrawmon004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_drrawmon004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_DestroyRawMonitor_drrawmon004_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid monitor check ...\n"); - } - - err = (*jvmti)->DestroyRawMonitor(jvmti, NULL); - if (err != JVMTI_ERROR_INVALID_MONITOR) { - printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/drrawmon004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/drrawmon004.cpp new file mode 100644 index 00000000000..e0946eabd20 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/drrawmon004.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_drrawmon004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_drrawmon004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_drrawmon004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_DestroyRawMonitor_drrawmon004_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid monitor check ...\n"); + } + + err = jvmti->DestroyRawMonitor(NULL); + if (err != JVMTI_ERROR_INVALID_MONITOR) { + printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/libdrrawmon004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/libdrrawmon004.c deleted file mode 100644 index d7268b13b39..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/libdrrawmon004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "drrawmon004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/libdrrawmon004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/libdrrawmon004.cpp new file mode 100644 index 00000000000..7afe48a4f0a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/libdrrawmon004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "drrawmon004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/disposeenv001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/disposeenv001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/disposeenv001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/disposeenv001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/libdisposeenv001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/libdisposeenv001.c deleted file mode 100644 index 8322747c997..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/libdisposeenv001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "disposeenv001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/libdisposeenv001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/libdisposeenv001.cpp new file mode 100644 index 00000000000..d58be5cb5d2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv001/libdisposeenv001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "disposeenv001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/disposeenv002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/disposeenv002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/disposeenv002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/disposeenv002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/libdisposeenv002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/libdisposeenv002.c deleted file mode 100644 index e24cbb30af6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/libdisposeenv002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "disposeenv002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/libdisposeenv002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/libdisposeenv002.cpp new file mode 100644 index 00000000000..65aef9a397c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/libdisposeenv002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "disposeenv002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/dyncodgen001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/dyncodgen001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/dyncodgen001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/dyncodgen001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/libdyncodgen001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/libdyncodgen001.c deleted file mode 100644 index ab16c783481..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/libdyncodgen001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "dyncodgen001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/libdyncodgen001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/libdyncodgen001.cpp new file mode 100644 index 00000000000..ef3aa6e69fd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/libdyncodgen001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "dyncodgen001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/exception001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/exception001.c deleted file mode 100644 index b9bd3ed6c99..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/exception001.c +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *name; - char *t_cls; - char *t_name; - char *t_sig; - jlocation t_loc; - char *c_cls; - char *c_name; - char *c_sig; - jlocation c_loc; -} exceptionInfo; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static exceptionInfo exs[] = { - {"Lnsk/jvmti/Exception/exception001c;", - "Lnsk/jvmti/Exception/exception001b;", "meth1", "()V", 7, - "Lnsk/jvmti/Exception/exception001a;", "run", "()V", 14}, - {"Ljava/lang/ArithmeticException;", - "Lnsk/jvmti/Exception/exception001b;", "meth2", "(I)I", 3, - "Lnsk/jvmti/Exception/exception001a;", "run", "()V", 24}, - {"Ljava/lang/ArrayIndexOutOfBoundsException;", - "Lnsk/jvmti/Exception/exception001b;", "meth3", "(I)I", 10, - "Lnsk/jvmti/Exception/exception001a;", "run", "()V", 34} -}; -static int eventsCount = 0; -static int eventsExpected = 0; - -void JNICALL -Exception(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - jvmtiError err; - exceptionInfo ex; - jclass cls; - char *generic; - size_t i; - - if (printdump == JNI_TRUE) { - printf(">>> retrieving Exception info ...\n"); - } - cls = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG((JNIEnv *)env, exception)); - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &ex.name, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#t) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &ex.t_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#t) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, method, - &ex.t_name, &ex.t_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#t) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - ex.t_loc = location; - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, catch_method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#c) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &ex.c_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#c) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, catch_method, - &ex.c_name, &ex.c_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#c) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - ex.c_loc = catch_location; - if (printdump == JNI_TRUE) { - printf(">>> %s\n", ex.name); - printf(">>> thrown at %s.%s%s:0x%x%08x\n", - ex.t_cls, ex.t_name, ex.t_sig, - (jint)(ex.t_loc >> 32), (jint)ex.t_loc); - printf(">>> catch at %s.%s%s:0x%x%08x\n", - ex.c_cls, ex.c_name, ex.c_sig, - (jint)(ex.c_loc >> 32), (jint)ex.c_loc); - printf(">>> ... done\n"); - } - for (i = 0; i < sizeof(exs)/sizeof(exceptionInfo); i++) { - if (ex.name != NULL && strcmp(ex.name, exs[i].name) == 0 - && ex.t_cls != NULL && strcmp(ex.t_cls, exs[i].t_cls) == 0 - && ex.t_name != NULL && strcmp(ex.t_name, exs[i].t_name) == 0 - && ex.t_sig != NULL && strcmp(ex.t_sig, exs[i].t_sig) == 0 - && ex.c_cls != NULL && strcmp(ex.c_cls, exs[i].c_cls) == 0 - && ex.c_name != NULL && strcmp(ex.c_name, exs[i].c_name) == 0 - && ex.c_sig != NULL && strcmp(ex.c_sig, exs[i].c_sig) == 0 - && ex.t_loc == exs[i].t_loc && ex.c_loc == exs[i].c_loc) { - eventsCount++; - break; - } - } - if (i == sizeof(exs)/sizeof(exceptionInfo)) { - printf("Unexpected exception event:\n"); - printf(" %s\n", ex.name); - printf(" thrown at %s.%s%s:0x%x%08x\n", - ex.t_cls, ex.t_name, ex.t_sig, - (jint)(ex.t_loc >> 32), (jint)ex.t_loc); - printf(" catch at %s.%s%s:0x%x%08x\n", - ex.c_cls, ex.c_name, ex.c_sig, - (jint)(ex.c_loc >> 32), (jint)ex.c_loc); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_exception001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_exception001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_exception001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_exception_events) { - callbacks.Exception = &Exception; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Exception event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_Exception_exception001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jthread thread; - jclass clz; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_generate_exception_events) { - return result; - } - - clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/Exception/exception001c")); - if (clz == NULL) { - printf("Cannot find exception001c class!\n"); - return STATUS_FAILED; - } - clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/Exception/exception001b")); - if (clz == NULL) { - printf("Cannot find exception001b class!\n"); - return STATUS_FAILED; - } - clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/Exception/exception001a")); - if (clz == NULL) { - printf("Cannot find exception001a class!\n"); - return STATUS_FAILED; - } - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clz), - "run", "()V"); - if (mid == NULL) { - printf("Cannot find method run!\n"); - return STATUS_FAILED; - } - - if ((err = ((*jvmti)->GetCurrentThread(jvmti, &thread))) != JVMTI_ERROR_NONE) { - printf("Failed to get current thread: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - return STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_EXCEPTION, thread); - if (err == JVMTI_ERROR_NONE) { - eventsExpected = sizeof(exs)/sizeof(exceptionInfo); - } else { - printf("Failed to enable JVMTI_EVENT_EXCEPTION: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, clz), mid); - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_EXCEPTION, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_EXCEPTION: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (eventsCount != eventsExpected) { - printf("Wrong number of exception events: %d, expected: %d\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/exception001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/exception001.cpp new file mode 100644 index 00000000000..f792bcfe543 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/exception001.cpp @@ -0,0 +1,327 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + char *name; + char *t_cls; + char *t_name; + char *t_sig; + jlocation t_loc; + char *c_cls; + char *c_name; + char *c_sig; + jlocation c_loc; +} writable_exceptionInfo; + +typedef struct { + const char *name; + const char *t_cls; + const char *t_name; + const char *t_sig; + jlocation t_loc; + const char *c_cls; + const char *c_name; + const char *c_sig; + jlocation c_loc; +} exceptionInfo; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static exceptionInfo exs[] = { + {"Lnsk/jvmti/Exception/exception001c;", + "Lnsk/jvmti/Exception/exception001b;", "meth1", "()V", 7, + "Lnsk/jvmti/Exception/exception001a;", "run", "()V", 14}, + {"Ljava/lang/ArithmeticException;", + "Lnsk/jvmti/Exception/exception001b;", "meth2", "(I)I", 3, + "Lnsk/jvmti/Exception/exception001a;", "run", "()V", 24}, + {"Ljava/lang/ArrayIndexOutOfBoundsException;", + "Lnsk/jvmti/Exception/exception001b;", "meth3", "(I)I", 10, + "Lnsk/jvmti/Exception/exception001a;", "run", "()V", 34} +}; +static int eventsCount = 0; +static int eventsExpected = 0; + +void JNICALL +Exception(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + jvmtiError err; + writable_exceptionInfo ex; + jclass cls; + char *generic; + size_t i; + + if (printdump == JNI_TRUE) { + printf(">>> retrieving Exception info ...\n"); + } + cls = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG((JNIEnv *)env, exception)); + err = jvmti_env->GetClassSignature(cls, &ex.name, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#t) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, &ex.t_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#t) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetMethodName(method, + &ex.t_name, &ex.t_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#t) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + ex.t_loc = location; + err = jvmti_env->GetMethodDeclaringClass(catch_method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#c) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, &ex.c_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#c) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetMethodName(catch_method, + &ex.c_name, &ex.c_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#c) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + ex.c_loc = catch_location; + if (printdump == JNI_TRUE) { + printf(">>> %s\n", ex.name); + printf(">>> thrown at %s.%s%s:0x%x%08x\n", + ex.t_cls, ex.t_name, ex.t_sig, + (jint)(ex.t_loc >> 32), (jint)ex.t_loc); + printf(">>> catch at %s.%s%s:0x%x%08x\n", + ex.c_cls, ex.c_name, ex.c_sig, + (jint)(ex.c_loc >> 32), (jint)ex.c_loc); + printf(">>> ... done\n"); + } + for (i = 0; i < sizeof(exs)/sizeof(exceptionInfo); i++) { + if (ex.name != NULL && strcmp(ex.name, exs[i].name) == 0 + && ex.t_cls != NULL && strcmp(ex.t_cls, exs[i].t_cls) == 0 + && ex.t_name != NULL && strcmp(ex.t_name, exs[i].t_name) == 0 + && ex.t_sig != NULL && strcmp(ex.t_sig, exs[i].t_sig) == 0 + && ex.c_cls != NULL && strcmp(ex.c_cls, exs[i].c_cls) == 0 + && ex.c_name != NULL && strcmp(ex.c_name, exs[i].c_name) == 0 + && ex.c_sig != NULL && strcmp(ex.c_sig, exs[i].c_sig) == 0 + && ex.t_loc == exs[i].t_loc && ex.c_loc == exs[i].c_loc) { + eventsCount++; + break; + } + } + if (i == sizeof(exs)/sizeof(exceptionInfo)) { + printf("Unexpected exception event:\n"); + printf(" %s\n", ex.name); + printf(" thrown at %s.%s%s:0x%x%08x\n", + ex.t_cls, ex.t_name, ex.t_sig, + (jint)(ex.t_loc >> 32), (jint)ex.t_loc); + printf(" catch at %s.%s%s:0x%x%08x\n", + ex.c_cls, ex.c_name, ex.c_sig, + (jint)(ex.c_loc >> 32), (jint)ex.c_loc); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_exception001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_exception001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_exception001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_exception_events) { + callbacks.Exception = &Exception; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Exception event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_Exception_exception001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jthread thread; + jclass clz; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_generate_exception_events) { + return result; + } + + clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/Exception/exception001c")); + if (clz == NULL) { + printf("Cannot find exception001c class!\n"); + return STATUS_FAILED; + } + clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/Exception/exception001b")); + if (clz == NULL) { + printf("Cannot find exception001b class!\n"); + return STATUS_FAILED; + } + clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/Exception/exception001a")); + if (clz == NULL) { + printf("Cannot find exception001a class!\n"); + return STATUS_FAILED; + } + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clz), + "run", "()V"); + if (mid == NULL) { + printf("Cannot find method run!\n"); + return STATUS_FAILED; + } + + if ((err = (jvmti->GetCurrentThread(&thread))) != JVMTI_ERROR_NONE) { + printf("Failed to get current thread: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + return STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_EXCEPTION, thread); + if (err == JVMTI_ERROR_NONE) { + eventsExpected = sizeof(exs)/sizeof(exceptionInfo); + } else { + printf("Failed to enable JVMTI_EVENT_EXCEPTION: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, clz), mid); + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_EXCEPTION, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_EXCEPTION: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (eventsCount != eventsExpected) { + printf("Wrong number of exception events: %d, expected: %d\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/libexception001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/libexception001.c deleted file mode 100644 index acbeed1ad66..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/libexception001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "exception001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/libexception001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/libexception001.cpp new file mode 100644 index 00000000000..bb87b6cd3e7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Exception/exception001/libexception001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "exception001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/excatch001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/excatch001.c deleted file mode 100644 index 045194dfca8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/excatch001.c +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *name; - char *c_cls; - char *c_name; - char *c_sig; - jlocation c_loc; -} exceptionInfo; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static exceptionInfo exs[] = { - {"Lnsk/jvmti/ExceptionCatch/excatch001c;", - "Lnsk/jvmti/ExceptionCatch/excatch001a;", "run", "()V", 14}, - {"Ljava/lang/ArithmeticException;", - "Lnsk/jvmti/ExceptionCatch/excatch001a;", "run", "()V", 24}, - {"Ljava/lang/ArrayIndexOutOfBoundsException;", - "Lnsk/jvmti/ExceptionCatch/excatch001a;", "run", "()V", 34} -}; -static int eventsCount = 0; -static int eventsExpected = 0; - -void JNICALL -ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, - jmethodID method, jlocation location, jobject exception) { - jvmtiError err; - jclass cls; - exceptionInfo ex; - char *generic; - size_t i; - - if (printdump == JNI_TRUE) { - printf(">>> retrieving ExceptionCatch info ...\n"); - } - cls = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG((JNIEnv *)env, exception)); - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &ex.name, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#e) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &ex.c_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#c) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, method, - &ex.c_name, &ex.c_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - ex.c_loc = location; - if (printdump == JNI_TRUE) { - printf(">>> %s\n", ex.name); - printf(">>> catch at %s.%s%s:0x%x%08x\n", - ex.c_cls, ex.c_name, ex.c_sig, - (jint)(ex.c_loc >> 32), (jint)ex.c_loc); - printf(">>> ... done\n"); - } - for (i = 0; i < sizeof(exs)/sizeof(exceptionInfo); i++) { - if (ex.name != NULL && strcmp(ex.name, exs[i].name) == 0 - && ex.c_cls != NULL && strcmp(ex.c_cls, exs[i].c_cls) == 0 - && ex.c_name != NULL && strcmp(ex.c_name, exs[i].c_name) == 0 - && ex.c_sig != NULL && strcmp(ex.c_sig, exs[i].c_sig) == 0 - && ex.c_loc == exs[i].c_loc) { - eventsCount++; - break; - } - } - if (i == sizeof(exs)/sizeof(exceptionInfo)) { - printf("Unexpected exception catch event:\n"); - printf(" %s\n", ex.name); - printf(" catch at %s.%s%s:0x%x%08x\n", - ex.c_cls, ex.c_name, ex.c_sig, - (jint)(ex.c_loc >> 32), (jint)ex.c_loc); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_excatch001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_excatch001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_excatch001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_exception_events) { - callbacks.ExceptionCatch = &ExceptionCatch; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Exception event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_ExceptionCatch_excatch001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jclass clz; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_generate_exception_events) { - return result; - } - - clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/ExceptionCatch/excatch001c")); - if (clz == NULL) { - printf("Cannot find excatch001c class!\n"); - return STATUS_FAILED; - } - clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/ExceptionCatch/excatch001b")); - if (clz == NULL) { - printf("Cannot find excatch001b class!\n"); - return STATUS_FAILED; - } - clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/ExceptionCatch/excatch001a")); - if (clz == NULL) { - printf("Cannot find excatch001a class!\n"); - return STATUS_FAILED; - } - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clz), - "run", "()V"); - if (mid == NULL) { - printf("Cannot find method run!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_EXCEPTION_CATCH, NULL); - if (err == JVMTI_ERROR_NONE) { - eventsExpected = sizeof(exs)/sizeof(exceptionInfo); - } else { - printf("Failed to enable JVMTI_EVENT_EXCEPTION_CATCH: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, clz), mid); - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_EXCEPTION_CATCH, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_EXCEPTION_CATCH: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (eventsCount != eventsExpected) { - printf("Wrong number of exception catch events: %d, expected: %d\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/excatch001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/excatch001.cpp new file mode 100644 index 00000000000..08a770a3018 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/excatch001.cpp @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + char *name; + char *c_cls; + char *c_name; + char *c_sig; + jlocation c_loc; +} writable_exceptionInfo; + +typedef struct { + const char *name; + const char *c_cls; + const char *c_name; + const char *c_sig; + jlocation c_loc; +} exceptionInfo; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static exceptionInfo exs[] = { + {"Lnsk/jvmti/ExceptionCatch/excatch001c;", + "Lnsk/jvmti/ExceptionCatch/excatch001a;", "run", "()V", 14}, + {"Ljava/lang/ArithmeticException;", + "Lnsk/jvmti/ExceptionCatch/excatch001a;", "run", "()V", 24}, + {"Ljava/lang/ArrayIndexOutOfBoundsException;", + "Lnsk/jvmti/ExceptionCatch/excatch001a;", "run", "()V", 34} +}; +static int eventsCount = 0; +static int eventsExpected = 0; + +void JNICALL +ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, + jmethodID method, jlocation location, jobject exception) { + jvmtiError err; + jclass cls; + writable_exceptionInfo ex; + char *generic; + size_t i; + + if (printdump == JNI_TRUE) { + printf(">>> retrieving ExceptionCatch info ...\n"); + } + cls = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG((JNIEnv *)env, exception)); + err = jvmti_env->GetClassSignature(cls, &ex.name, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#e) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, &ex.c_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#c) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetMethodName(method, + &ex.c_name, &ex.c_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + ex.c_loc = location; + if (printdump == JNI_TRUE) { + printf(">>> %s\n", ex.name); + printf(">>> catch at %s.%s%s:0x%x%08x\n", + ex.c_cls, ex.c_name, ex.c_sig, + (jint)(ex.c_loc >> 32), (jint)ex.c_loc); + printf(">>> ... done\n"); + } + for (i = 0; i < sizeof(exs)/sizeof(exceptionInfo); i++) { + if (ex.name != NULL && strcmp(ex.name, exs[i].name) == 0 + && ex.c_cls != NULL && strcmp(ex.c_cls, exs[i].c_cls) == 0 + && ex.c_name != NULL && strcmp(ex.c_name, exs[i].c_name) == 0 + && ex.c_sig != NULL && strcmp(ex.c_sig, exs[i].c_sig) == 0 + && ex.c_loc == exs[i].c_loc) { + eventsCount++; + break; + } + } + if (i == sizeof(exs)/sizeof(exceptionInfo)) { + printf("Unexpected exception catch event:\n"); + printf(" %s\n", ex.name); + printf(" catch at %s.%s%s:0x%x%08x\n", + ex.c_cls, ex.c_name, ex.c_sig, + (jint)(ex.c_loc >> 32), (jint)ex.c_loc); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_excatch001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_excatch001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_excatch001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_exception_events) { + callbacks.ExceptionCatch = &ExceptionCatch; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Exception event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_ExceptionCatch_excatch001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jclass clz; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_generate_exception_events) { + return result; + } + + clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/ExceptionCatch/excatch001c")); + if (clz == NULL) { + printf("Cannot find excatch001c class!\n"); + return STATUS_FAILED; + } + clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/ExceptionCatch/excatch001b")); + if (clz == NULL) { + printf("Cannot find excatch001b class!\n"); + return STATUS_FAILED; + } + clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/ExceptionCatch/excatch001a")); + if (clz == NULL) { + printf("Cannot find excatch001a class!\n"); + return STATUS_FAILED; + } + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clz), + "run", "()V"); + if (mid == NULL) { + printf("Cannot find method run!\n"); + return STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_EXCEPTION_CATCH, NULL); + if (err == JVMTI_ERROR_NONE) { + eventsExpected = sizeof(exs)/sizeof(exceptionInfo); + } else { + printf("Failed to enable JVMTI_EVENT_EXCEPTION_CATCH: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, clz), mid); + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_EXCEPTION_CATCH, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_EXCEPTION_CATCH: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (eventsCount != eventsExpected) { + printf("Wrong number of exception catch events: %d, expected: %d\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/libexcatch001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/libexcatch001.c deleted file mode 100644 index 1fd7bc92880..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/libexcatch001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "excatch001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/libexcatch001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/libexcatch001.cpp new file mode 100644 index 00000000000..980aca7d4fb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/libexcatch001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "excatch001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/fieldacc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/fieldacc001.c deleted file mode 100644 index a4560688537..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/fieldacc001.c +++ /dev/null @@ -1,360 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - jfieldID fid; - char *m_cls; - char *m_name; - char *m_sig; - jlocation loc; - char *f_cls; - char *f_name; - char *f_sig; - jboolean is_static; -} watch_info; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int eventsExpected = 0; -static int eventsCount = 0; -static watch_info watches[] = { - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 2, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticBoolean", "Z", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 6, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceBoolean", "Z", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 15, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticByte", "B", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 19, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceByte", "B", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 28, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticShort", "S", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 32, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceShort", "S", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 41, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticInt", "I", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 45, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceInt", "I", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 54, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticLong", "J", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 58, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceLong", "J", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 68, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticFloat", "F", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 72, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceFloat", "F", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 82, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticDouble", "D", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 86, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceDouble", "D", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 96, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticChar", "C", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 100, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceChar", "C", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 109, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticObject", "Ljava/lang/Object;", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 113, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceObject", "Ljava/lang/Object;", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 122, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticArrInt", "[I", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 128, - "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceArrInt", "[I", JNI_FALSE } -}; - - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jlocation location, jclass field_klass, jobject obj, jfieldID field) { - jvmtiError err; - jclass cls; - watch_info watch; - char *generic; - size_t i; - - eventsCount++; - if (printdump == JNI_TRUE) { - printf(">>> retrieving access watch info ...\n"); - } - watch.fid = field; - watch.loc = location; - watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE; - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, - &watch.m_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, method, - &watch.m_name, &watch.m_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, field_klass, - &watch.f_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetFieldName(jvmti_env, field_klass, field, - &watch.f_name, &watch.f_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", watch.m_cls); - printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig); - printf(">>> location: 0x%x%08x\n", - (jint)(watch.loc >> 32), (jint)watch.loc); - printf(">>> field cls: \"%s\"\n", watch.f_cls); - printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig); - printf(">>> object: 0x%p\n", obj); - printf(">>> ... done\n"); - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (watch.fid == watches[i].fid) { - if (watch.m_cls == NULL || - strcmp(watch.m_cls, watches[i].m_cls) != 0) { - printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n", - i, watch.m_cls, watches[i].m_cls); - result = STATUS_FAILED; - } - if (watch.m_name == NULL || - strcmp(watch.m_name, watches[i].m_name) != 0) { - printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"", - i, watch.m_name); - printf(", expected: \"%s\"\n", watches[i].m_name); - result = STATUS_FAILED; - } - if (watch.m_sig == NULL || - strcmp(watch.m_sig, watches[i].m_sig) != 0) { - printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"", - i, watch.m_sig); - printf(", expected: \"%s\"\n", watches[i].m_sig); - result = STATUS_FAILED; - } - if (watch.loc != watches[i].loc) { - printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x", - i, (jint)(watch.loc >> 32), (jint)watch.loc); - printf(", expected: 0x%x%08x\n", - (jint)(watches[i].loc >> 32), (jint)watches[i].loc); - result = STATUS_FAILED; - } - if (watch.f_name == NULL || - strcmp(watch.f_name, watches[i].f_name) != 0) { - printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"", - i, watch.f_name); - printf(", expected: \"%s\"\n", watches[i].f_name); - result = STATUS_FAILED; - } - if (watch.f_sig == NULL || - strcmp(watch.f_sig, watches[i].f_sig) != 0) { - printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"", - i, watch.f_sig); - printf(", expected: \"%s\"\n", watches[i].f_sig); - result = STATUS_FAILED; - } - if (watch.is_static != watches[i].is_static) { - printf("(watch#%" PRIuPTR ") wrong field type: %s", i, - (watch.is_static==JNI_TRUE)?"static":"instance"); - printf(", expected: %s\n", - (watches[i].is_static==JNI_TRUE)?"static":"instance"); - result = STATUS_FAILED; - } - return; - } - } - printf("Unexpected field access catched: 0x%p\n", watch.fid); - result = STATUS_FAILED; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_fieldacc001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_fieldacc001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_fieldacc001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldAccess watch is not implemented\n"); - } - - return JNI_OK; -} - - -JNIEXPORT void JNICALL -Java_nsk_jvmti_FieldAccess_fieldacc001_getReady(JNIEnv *env, jclass klass) { - jvmtiError err; - jclass cls; - size_t i; - - if (!caps.can_generate_field_access_events) { - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> setting field access watches ...\n"); - } - cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/FieldAccess/fieldacc001a")); - if (cls == NULL) { - printf("Cannot find fieldacc001a class!\n"); - result = STATUS_FAILED; - return; - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (watches[i].is_static == JNI_TRUE) { - watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } else { - watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } - if (watches[i].fid == NULL) { - printf("Cannot find field \"%s\"!\n", watches[i].f_name); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, watches[i].fid); - if (err == JVMTI_ERROR_NONE) { - eventsExpected++; - } else { - printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_FieldAccess_fieldacc001_check(JNIEnv *env, jclass cls) { - if (eventsCount != eventsExpected) { - printf("Wrong number of field access events: %d, expected: %d\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/fieldacc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/fieldacc001.cpp new file mode 100644 index 00000000000..a934d93e588 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/fieldacc001.cpp @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + jfieldID fid; + char *m_cls; + char *m_name; + char *m_sig; + jlocation loc; + char *f_cls; + char *f_name; + char *f_sig; + jboolean is_static; +} writable_watch_info; + +typedef struct { + jfieldID fid; + const char *m_cls; + const char *m_name; + const char *m_sig; + jlocation loc; + const char *f_cls; + const char *f_name; + const char *f_sig; + jboolean is_static; +} watch_info; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int eventsExpected = 0; +static int eventsCount = 0; +static watch_info watches[] = { + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 2, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticBoolean", "Z", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 6, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceBoolean", "Z", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 15, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticByte", "B", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 19, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceByte", "B", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 28, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticShort", "S", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 32, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceShort", "S", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 41, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticInt", "I", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 45, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceInt", "I", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 54, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticLong", "J", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 58, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceLong", "J", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 68, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticFloat", "F", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 72, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceFloat", "F", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 82, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticDouble", "D", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 86, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceDouble", "D", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 96, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticChar", "C", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 100, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceChar", "C", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 109, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticObject", "Ljava/lang/Object;", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 113, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceObject", "Ljava/lang/Object;", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 122, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticArrInt", "[I", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 128, + "Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceArrInt", "[I", JNI_FALSE } +}; + + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jlocation location, jclass field_klass, jobject obj, jfieldID field) { + jvmtiError err; + jclass cls; + writable_watch_info watch; + char *generic; + size_t i; + + eventsCount++; + if (printdump == JNI_TRUE) { + printf(">>> retrieving access watch info ...\n"); + } + watch.fid = field; + watch.loc = location; + watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE; + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, + &watch.m_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetMethodName(method, + &watch.m_name, &watch.m_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(field_klass, + &watch.f_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetFieldName(field_klass, field, + &watch.f_name, &watch.f_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", watch.m_cls); + printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig); + printf(">>> location: 0x%x%08x\n", + (jint)(watch.loc >> 32), (jint)watch.loc); + printf(">>> field cls: \"%s\"\n", watch.f_cls); + printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig); + printf(">>> object: 0x%p\n", obj); + printf(">>> ... done\n"); + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (watch.fid == watches[i].fid) { + if (watch.m_cls == NULL || + strcmp(watch.m_cls, watches[i].m_cls) != 0) { + printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n", + i, watch.m_cls, watches[i].m_cls); + result = STATUS_FAILED; + } + if (watch.m_name == NULL || + strcmp(watch.m_name, watches[i].m_name) != 0) { + printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"", + i, watch.m_name); + printf(", expected: \"%s\"\n", watches[i].m_name); + result = STATUS_FAILED; + } + if (watch.m_sig == NULL || + strcmp(watch.m_sig, watches[i].m_sig) != 0) { + printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"", + i, watch.m_sig); + printf(", expected: \"%s\"\n", watches[i].m_sig); + result = STATUS_FAILED; + } + if (watch.loc != watches[i].loc) { + printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x", + i, (jint)(watch.loc >> 32), (jint)watch.loc); + printf(", expected: 0x%x%08x\n", + (jint)(watches[i].loc >> 32), (jint)watches[i].loc); + result = STATUS_FAILED; + } + if (watch.f_name == NULL || + strcmp(watch.f_name, watches[i].f_name) != 0) { + printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"", + i, watch.f_name); + printf(", expected: \"%s\"\n", watches[i].f_name); + result = STATUS_FAILED; + } + if (watch.f_sig == NULL || + strcmp(watch.f_sig, watches[i].f_sig) != 0) { + printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"", + i, watch.f_sig); + printf(", expected: \"%s\"\n", watches[i].f_sig); + result = STATUS_FAILED; + } + if (watch.is_static != watches[i].is_static) { + printf("(watch#%" PRIuPTR ") wrong field type: %s", i, + (watch.is_static==JNI_TRUE)?"static":"instance"); + printf(", expected: %s\n", + (watches[i].is_static==JNI_TRUE)?"static":"instance"); + result = STATUS_FAILED; + } + return; + } + } + printf("Unexpected field access catched: 0x%p\n", watch.fid); + result = STATUS_FAILED; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_fieldacc001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_fieldacc001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_fieldacc001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldAccess watch is not implemented\n"); + } + + return JNI_OK; +} + + +JNIEXPORT void JNICALL +Java_nsk_jvmti_FieldAccess_fieldacc001_getReady(JNIEnv *env, jclass klass) { + jvmtiError err; + jclass cls; + size_t i; + + if (!caps.can_generate_field_access_events) { + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> setting field access watches ...\n"); + } + cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/FieldAccess/fieldacc001a")); + if (cls == NULL) { + printf("Cannot find fieldacc001a class!\n"); + result = STATUS_FAILED; + return; + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (watches[i].is_static == JNI_TRUE) { + watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } else { + watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } + if (watches[i].fid == NULL) { + printf("Cannot find field \"%s\"!\n", watches[i].f_name); + result = STATUS_FAILED; + return; + } + err = jvmti->SetFieldAccessWatch(cls, watches[i].fid); + if (err == JVMTI_ERROR_NONE) { + eventsExpected++; + } else { + printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_FieldAccess_fieldacc001_check(JNIEnv *env, jclass cls) { + if (eventsCount != eventsExpected) { + printf("Wrong number of field access events: %d, expected: %d\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/libfieldacc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/libfieldacc001.c deleted file mode 100644 index 2c4877bddb2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/libfieldacc001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "fieldacc001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/libfieldacc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/libfieldacc001.cpp new file mode 100644 index 00000000000..2b0e209d416 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/libfieldacc001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "fieldacc001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/fieldacc002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/fieldacc002.c deleted file mode 100644 index f0059611985..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/fieldacc002.c +++ /dev/null @@ -1,412 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - jfieldID fid; - char *m_cls; - char *m_name; - char *m_sig; - jlocation loc; - char *f_cls; - char *f_name; - char *f_sig; - jboolean is_static; -} watch_info; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int eventsExpected = 0; -static int eventsCount = 0; -static watch_info watches[] = { - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticBoolean", "Z", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticByte", "B", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticShort", "S", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticInt", "I", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticLong", "J", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticFloat", "F", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticDouble", "D", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticChar", "C", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticObject", "Ljava/lang/Object;", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticArrInt", "[I", JNI_TRUE }, - - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceBoolean", "Z", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceByte", "B", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceShort", "S", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceInt", "I", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceLong", "J", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceFloat", "F", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceDouble", "D", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceChar", "C", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceObject", "Ljava/lang/Object;", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceArrInt", "[I", JNI_FALSE } -}; - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jlocation location, jclass field_klass, jobject obj, jfieldID field) { - jvmtiError err; - jclass cls; - watch_info watch; - char *generic; - size_t i; - - eventsCount++; - if (printdump == JNI_TRUE) { - printf(">>> retrieving access watch info ...\n"); - } - watch.fid = field; - watch.loc = location; - watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE; - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, - &watch.m_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, method, - &watch.m_name, &watch.m_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, field_klass, - &watch.f_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetFieldName(jvmti_env, field_klass, field, - &watch.f_name, &watch.f_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", watch.m_cls); - printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig); - printf(">>> location: 0x%x%08x\n", - (jint)(watch.loc >> 32), (jint)watch.loc); - printf(">>> field cls: \"%s\"\n", watch.f_cls); - printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig); - printf(">>> object: 0x%p\n", obj); - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (watch.fid == watches[i].fid) { - if (watch.m_cls == NULL || - strcmp(watch.m_cls, watches[i].m_cls) != 0) { - printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n", - i, watch.m_cls, watches[i].m_cls); - result = STATUS_FAILED; - } - if (watch.m_name == NULL || - strcmp(watch.m_name, watches[i].m_name) != 0) { - printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"", - i, watch.m_name); - printf(", expected: \"%s\"\n", watches[i].m_name); - result = STATUS_FAILED; - } - if (watch.m_sig == NULL || - strcmp(watch.m_sig, watches[i].m_sig) != 0) { - printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"", - i, watch.m_sig); - printf(", expected: \"%s\"\n", watches[i].m_sig); - result = STATUS_FAILED; - } - if (watch.loc != watches[i].loc) { - printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x", - i, (jint)(watch.loc >> 32), (jint)watch.loc); - printf(", expected: 0x%x%08x\n", - (jint)(watches[i].loc >> 32), (jint)watches[i].loc); - result = STATUS_FAILED; - } - if (watch.f_name == NULL || - strcmp(watch.f_name, watches[i].f_name) != 0) { - printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"", - i, watch.f_name); - printf(", expected: \"%s\"\n", watches[i].f_name); - result = STATUS_FAILED; - } - if (watch.f_sig == NULL || - strcmp(watch.f_sig, watches[i].f_sig) != 0) { - printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"", - i, watch.f_sig); - printf(", expected: \"%s\"\n", watches[i].f_sig); - result = STATUS_FAILED; - } - if (watch.is_static != watches[i].is_static) { - printf("(watch#%" PRIuPTR ") wrong field type: %s", i, - (watch.is_static==JNI_TRUE)?"static":"instance"); - printf(", expected: %s\n", - (watches[i].is_static==JNI_TRUE)?"static":"instance"); - result = STATUS_FAILED; - } - return; - } - } - printf("Unexpected field access catched: 0x%p\n", watch.fid); - result = STATUS_FAILED; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_fieldacc002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_fieldacc002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_fieldacc002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldAccess watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_FieldAccess_fieldacc002_getReady(JNIEnv *env, jclass clz) { - jvmtiError err; - jclass cls; - size_t i; - - if (!caps.can_generate_field_access_events) { - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> setting field access watches ...\n"); - } - - cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/FieldAccess/fieldacc002a")); - if (cls == NULL) { - printf("Cannot find fieldacc002a class!\n"); - result = STATUS_FAILED; - return; - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (watches[i].is_static == JNI_TRUE) { - watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } else { - watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } - if (watches[i].fid == NULL) { - printf("Cannot find field \"%s\"!\n", watches[i].f_name); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, watches[i].fid); - if (err == JVMTI_ERROR_NONE) { - eventsExpected++; - } else { - printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_FieldAccess_fieldacc002_check(JNIEnv *env, jclass clz, jobject obj) { - jclass cls; - - if (!caps.can_generate_field_access_events) { - return result; - } - - if (printdump == JNI_TRUE) { - printf(">>> accessing fields ...\n"); - } - - cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/FieldAccess/fieldacc002a")); - if (cls == NULL) { - printf("Cannot find fieldacc002a class!\n"); - return STATUS_FAILED; - } - - JNI_ENV_PTR(env)->GetStaticBooleanField(JNI_ENV_ARG(env, cls), - watches[0].fid); - JNI_ENV_PTR(env)->GetStaticByteField(JNI_ENV_ARG(env, cls), - watches[1].fid); - JNI_ENV_PTR(env)->GetStaticShortField(JNI_ENV_ARG(env, cls), - watches[2].fid); - JNI_ENV_PTR(env)->GetStaticIntField(JNI_ENV_ARG(env, cls), - watches[3].fid); - JNI_ENV_PTR(env)->GetStaticLongField(JNI_ENV_ARG(env, cls), - watches[4].fid); - JNI_ENV_PTR(env)->GetStaticFloatField(JNI_ENV_ARG(env, cls), - watches[5].fid); - JNI_ENV_PTR(env)->GetStaticDoubleField(JNI_ENV_ARG(env, cls), - watches[6].fid); - JNI_ENV_PTR(env)->GetStaticCharField(JNI_ENV_ARG(env, cls), - watches[7].fid); - JNI_ENV_PTR(env)->GetStaticObjectField(JNI_ENV_ARG(env, cls), - watches[8].fid); - JNI_ENV_PTR(env)->GetStaticObjectField(JNI_ENV_ARG(env, cls), - watches[9].fid); - - JNI_ENV_PTR(env)->GetBooleanField(JNI_ENV_ARG(env, obj), watches[10].fid); - JNI_ENV_PTR(env)->GetByteField(JNI_ENV_ARG(env, obj), watches[11].fid); - JNI_ENV_PTR(env)->GetShortField(JNI_ENV_ARG(env, obj), watches[12].fid); - JNI_ENV_PTR(env)->GetIntField(JNI_ENV_ARG(env, obj), watches[13].fid); - JNI_ENV_PTR(env)->GetLongField(JNI_ENV_ARG(env, obj), watches[14].fid); - JNI_ENV_PTR(env)->GetFloatField(JNI_ENV_ARG(env, obj), watches[15].fid); - JNI_ENV_PTR(env)->GetDoubleField(JNI_ENV_ARG(env, obj), watches[16].fid); - JNI_ENV_PTR(env)->GetCharField(JNI_ENV_ARG(env, obj), watches[17].fid); - JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG(env, obj), watches[18].fid); - JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG(env, obj), watches[19].fid); - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - if (eventsCount != eventsExpected) { - printf("Wrong number of field access events: %d, expected: %d\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/fieldacc002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/fieldacc002.cpp new file mode 100644 index 00000000000..722065f4c7c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/fieldacc002.cpp @@ -0,0 +1,424 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + jfieldID fid; + char *m_cls; + char *m_name; + char *m_sig; + jlocation loc; + char *f_cls; + char *f_name; + char *f_sig; + jboolean is_static; +} writable_watch_info; + +typedef struct { + jfieldID fid; + const char *m_cls; + const char *m_name; + const char *m_sig; + jlocation loc; + const char *f_cls; + const char *f_name; + const char *f_sig; + jboolean is_static; +} watch_info; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int eventsExpected = 0; +static int eventsCount = 0; +static watch_info watches[] = { + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticBoolean", "Z", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticByte", "B", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticShort", "S", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticInt", "I", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticLong", "J", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticFloat", "F", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticDouble", "D", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticChar", "C", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticObject", "Ljava/lang/Object;", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticArrInt", "[I", JNI_TRUE }, + + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceBoolean", "Z", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceByte", "B", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceShort", "S", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceInt", "I", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceLong", "J", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceFloat", "F", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceDouble", "D", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceChar", "C", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceObject", "Ljava/lang/Object;", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceArrInt", "[I", JNI_FALSE } +}; + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jlocation location, jclass field_klass, jobject obj, jfieldID field) { + jvmtiError err; + jclass cls; + writable_watch_info watch; + char *generic; + size_t i; + + eventsCount++; + if (printdump == JNI_TRUE) { + printf(">>> retrieving access watch info ...\n"); + } + watch.fid = field; + watch.loc = location; + watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE; + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, + &watch.m_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetMethodName(method, + &watch.m_name, &watch.m_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(field_klass, + &watch.f_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetFieldName(field_klass, field, + &watch.f_name, &watch.f_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", watch.m_cls); + printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig); + printf(">>> location: 0x%x%08x\n", + (jint)(watch.loc >> 32), (jint)watch.loc); + printf(">>> field cls: \"%s\"\n", watch.f_cls); + printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig); + printf(">>> object: 0x%p\n", obj); + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (watch.fid == watches[i].fid) { + if (watch.m_cls == NULL || + strcmp(watch.m_cls, watches[i].m_cls) != 0) { + printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n", + i, watch.m_cls, watches[i].m_cls); + result = STATUS_FAILED; + } + if (watch.m_name == NULL || + strcmp(watch.m_name, watches[i].m_name) != 0) { + printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"", + i, watch.m_name); + printf(", expected: \"%s\"\n", watches[i].m_name); + result = STATUS_FAILED; + } + if (watch.m_sig == NULL || + strcmp(watch.m_sig, watches[i].m_sig) != 0) { + printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"", + i, watch.m_sig); + printf(", expected: \"%s\"\n", watches[i].m_sig); + result = STATUS_FAILED; + } + if (watch.loc != watches[i].loc) { + printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x", + i, (jint)(watch.loc >> 32), (jint)watch.loc); + printf(", expected: 0x%x%08x\n", + (jint)(watches[i].loc >> 32), (jint)watches[i].loc); + result = STATUS_FAILED; + } + if (watch.f_name == NULL || + strcmp(watch.f_name, watches[i].f_name) != 0) { + printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"", + i, watch.f_name); + printf(", expected: \"%s\"\n", watches[i].f_name); + result = STATUS_FAILED; + } + if (watch.f_sig == NULL || + strcmp(watch.f_sig, watches[i].f_sig) != 0) { + printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"", + i, watch.f_sig); + printf(", expected: \"%s\"\n", watches[i].f_sig); + result = STATUS_FAILED; + } + if (watch.is_static != watches[i].is_static) { + printf("(watch#%" PRIuPTR ") wrong field type: %s", i, + (watch.is_static==JNI_TRUE)?"static":"instance"); + printf(", expected: %s\n", + (watches[i].is_static==JNI_TRUE)?"static":"instance"); + result = STATUS_FAILED; + } + return; + } + } + printf("Unexpected field access catched: 0x%p\n", watch.fid); + result = STATUS_FAILED; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_fieldacc002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_fieldacc002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_fieldacc002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldAccess watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_FieldAccess_fieldacc002_getReady(JNIEnv *env, jclass clz) { + jvmtiError err; + jclass cls; + size_t i; + + if (!caps.can_generate_field_access_events) { + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> setting field access watches ...\n"); + } + + cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/FieldAccess/fieldacc002a")); + if (cls == NULL) { + printf("Cannot find fieldacc002a class!\n"); + result = STATUS_FAILED; + return; + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (watches[i].is_static == JNI_TRUE) { + watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } else { + watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } + if (watches[i].fid == NULL) { + printf("Cannot find field \"%s\"!\n", watches[i].f_name); + result = STATUS_FAILED; + return; + } + err = jvmti->SetFieldAccessWatch(cls, watches[i].fid); + if (err == JVMTI_ERROR_NONE) { + eventsExpected++; + } else { + printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_FieldAccess_fieldacc002_check(JNIEnv *env, jclass clz, jobject obj) { + jclass cls; + + if (!caps.can_generate_field_access_events) { + return result; + } + + if (printdump == JNI_TRUE) { + printf(">>> accessing fields ...\n"); + } + + cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/FieldAccess/fieldacc002a")); + if (cls == NULL) { + printf("Cannot find fieldacc002a class!\n"); + return STATUS_FAILED; + } + + JNI_ENV_PTR(env)->GetStaticBooleanField(JNI_ENV_ARG(env, cls), + watches[0].fid); + JNI_ENV_PTR(env)->GetStaticByteField(JNI_ENV_ARG(env, cls), + watches[1].fid); + JNI_ENV_PTR(env)->GetStaticShortField(JNI_ENV_ARG(env, cls), + watches[2].fid); + JNI_ENV_PTR(env)->GetStaticIntField(JNI_ENV_ARG(env, cls), + watches[3].fid); + JNI_ENV_PTR(env)->GetStaticLongField(JNI_ENV_ARG(env, cls), + watches[4].fid); + JNI_ENV_PTR(env)->GetStaticFloatField(JNI_ENV_ARG(env, cls), + watches[5].fid); + JNI_ENV_PTR(env)->GetStaticDoubleField(JNI_ENV_ARG(env, cls), + watches[6].fid); + JNI_ENV_PTR(env)->GetStaticCharField(JNI_ENV_ARG(env, cls), + watches[7].fid); + JNI_ENV_PTR(env)->GetStaticObjectField(JNI_ENV_ARG(env, cls), + watches[8].fid); + JNI_ENV_PTR(env)->GetStaticObjectField(JNI_ENV_ARG(env, cls), + watches[9].fid); + + JNI_ENV_PTR(env)->GetBooleanField(JNI_ENV_ARG(env, obj), watches[10].fid); + JNI_ENV_PTR(env)->GetByteField(JNI_ENV_ARG(env, obj), watches[11].fid); + JNI_ENV_PTR(env)->GetShortField(JNI_ENV_ARG(env, obj), watches[12].fid); + JNI_ENV_PTR(env)->GetIntField(JNI_ENV_ARG(env, obj), watches[13].fid); + JNI_ENV_PTR(env)->GetLongField(JNI_ENV_ARG(env, obj), watches[14].fid); + JNI_ENV_PTR(env)->GetFloatField(JNI_ENV_ARG(env, obj), watches[15].fid); + JNI_ENV_PTR(env)->GetDoubleField(JNI_ENV_ARG(env, obj), watches[16].fid); + JNI_ENV_PTR(env)->GetCharField(JNI_ENV_ARG(env, obj), watches[17].fid); + JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG(env, obj), watches[18].fid); + JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG(env, obj), watches[19].fid); + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + if (eventsCount != eventsExpected) { + printf("Wrong number of field access events: %d, expected: %d\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/libfieldacc002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/libfieldacc002.c deleted file mode 100644 index 6c607dd20c8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/libfieldacc002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "fieldacc002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/libfieldacc002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/libfieldacc002.cpp new file mode 100644 index 00000000000..709b522a39f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/libfieldacc002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "fieldacc002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/fieldacc003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/fieldacc003.c deleted file mode 100644 index 4839773bbea..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/fieldacc003.c +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - jfieldID fid; - char *m_cls; - char *m_name; - char *m_sig; - jlocation loc; - char *f_cls; - char *f_name; - char *f_sig; - jboolean is_static; -} watch_info; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int eventsExpected = 0; -static int eventsCount = 0; -static watch_info watches[] = { - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 3, - "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsBoolean", "Z", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 14, - "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsByte", "B", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 25, - "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsShort", "S", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 36, - "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsInt", "I", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 47, - "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsLong", "J", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 61, - "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsFloat", "F", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 74, - "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsDouble", "D", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 88, - "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsChar", "C", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 100, - "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsObject", "Ljava/lang/Object;", JNI_FALSE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 111, - "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsArrInt", "[I", JNI_FALSE } -}; - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jlocation location, jclass field_klass, jobject obj, jfieldID field) { - jvmtiError err; - jclass cls; - watch_info watch; - char *generic; - size_t i; - - eventsCount++; - if (printdump == JNI_TRUE) { - printf(">>> retrieving access watch info ...\n"); - } - watch.fid = field; - watch.loc = location; - watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE; - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, - &watch.m_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, method, - &watch.m_name, &watch.m_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, field_klass, - &watch.f_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetFieldName(jvmti_env, field_klass, field, - &watch.f_name, &watch.f_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", watch.m_cls); - printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig); - printf(">>> location: 0x%x%08x\n", - (jint)(watch.loc >> 32), (jint)watch.loc); - printf(">>> field cls: \"%s\"\n", watch.f_cls); - printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig); - printf(">>> object: 0x%p\n", obj); - printf(">>> ... done\n"); - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (watch.fid == watches[i].fid) { - if (watch.m_cls == NULL || - strcmp(watch.m_cls, watches[i].m_cls) != 0) { - printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n", - i, watch.m_cls, watches[i].m_cls); - result = STATUS_FAILED; - } - if (watch.m_name == NULL || - strcmp(watch.m_name, watches[i].m_name) != 0) { - printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"", - i, watch.m_name); - printf(", expected: \"%s\"\n", watches[i].m_name); - result = STATUS_FAILED; - } - if (watch.m_sig == NULL || - strcmp(watch.m_sig, watches[i].m_sig) != 0) { - printf("(watch#%" PRIuPTR " ) wrong method sig: \"%s\"", - i, watch.m_sig); - printf(", expected: \"%s\"\n", watches[i].m_sig); - result = STATUS_FAILED; - } - if (watch.loc != watches[i].loc) { - printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x", - i, (jint)(watch.loc >> 32), (jint)watch.loc); - printf(", expected: 0x%x%08x\n", - (jint)(watches[i].loc >> 32), (jint)watches[i].loc); - result = STATUS_FAILED; - } - if (watch.f_name == NULL || - strcmp(watch.f_name, watches[i].f_name) != 0) { - printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"", - i, watch.f_name); - printf(", expected: \"%s\"\n", watches[i].f_name); - result = STATUS_FAILED; - } - if (watch.f_sig == NULL || - strcmp(watch.f_sig, watches[i].f_sig) != 0) { - printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"", - i, watch.f_sig); - printf(", expected: \"%s\"\n", watches[i].f_sig); - result = STATUS_FAILED; - } - if (watch.is_static != watches[i].is_static) { - printf("(watch#%" PRIuPTR ") wrong field type: %s", i, - (watch.is_static==JNI_TRUE)?"static":"instance"); - printf(", expected: %s\n", - (watches[i].is_static==JNI_TRUE)?"static":"instance"); - result = STATUS_FAILED; - } - return; - } - } - printf("Unexpected field access catched: 0x%p\n", watch.fid); - result = STATUS_FAILED; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_fieldacc003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_fieldacc003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_fieldacc003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldAccess watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_FieldAccess_fieldacc003_getReady(JNIEnv *env, jclass klass) { - jvmtiError err; - jclass cls; - size_t i; - - if (!caps.can_generate_field_access_events) { - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> setting field access watches ...\n"); - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, watches[i].f_cls)); - if (cls == NULL) { - printf("Cannot find %s class!\n", watches[i].f_cls); - result = STATUS_FAILED; - return; - } - if (watches[i].is_static == JNI_TRUE) { - watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } else { - watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } - if (watches[i].fid == NULL) { - printf("Cannot get field ID for \"%s:%s\"\n", - watches[i].f_name, watches[i].f_sig); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, watches[i].fid); - if (err == JVMTI_ERROR_NONE) { - eventsExpected++; - } else { - printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_FieldAccess_fieldacc003_check(JNIEnv *env, jclass cls) { - if (eventsCount != eventsExpected) { - printf("Wrong number of field access events: %d, expected: %d\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/fieldacc003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/fieldacc003.cpp new file mode 100644 index 00000000000..eee67696172 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/fieldacc003.cpp @@ -0,0 +1,350 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + jfieldID fid; + char *m_cls; + char *m_name; + char *m_sig; + jlocation loc; + char *f_cls; + char *f_name; + char *f_sig; + jboolean is_static; +} writable_watch_info; + +typedef struct { + jfieldID fid; + const char *m_cls; + const char *m_name; + const char *m_sig; + jlocation loc; + const char *f_cls; + const char *f_name; + const char *f_sig; + jboolean is_static; +} watch_info; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int eventsExpected = 0; +static int eventsCount = 0; +static watch_info watches[] = { + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 3, + "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsBoolean", "Z", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 14, + "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsByte", "B", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 25, + "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsShort", "S", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 36, + "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsInt", "I", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 47, + "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsLong", "J", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 61, + "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsFloat", "F", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 74, + "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsDouble", "D", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 88, + "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsChar", "C", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 100, + "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsObject", "Ljava/lang/Object;", JNI_FALSE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 111, + "Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsArrInt", "[I", JNI_FALSE } +}; + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jlocation location, jclass field_klass, jobject obj, jfieldID field) { + jvmtiError err; + jclass cls; + writable_watch_info watch; + char *generic; + size_t i; + + eventsCount++; + if (printdump == JNI_TRUE) { + printf(">>> retrieving access watch info ...\n"); + } + watch.fid = field; + watch.loc = location; + watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE; + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, + &watch.m_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetMethodName(method, + &watch.m_name, &watch.m_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(field_klass, + &watch.f_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetFieldName(field_klass, field, + &watch.f_name, &watch.f_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", watch.m_cls); + printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig); + printf(">>> location: 0x%x%08x\n", + (jint)(watch.loc >> 32), (jint)watch.loc); + printf(">>> field cls: \"%s\"\n", watch.f_cls); + printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig); + printf(">>> object: 0x%p\n", obj); + printf(">>> ... done\n"); + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (watch.fid == watches[i].fid) { + if (watch.m_cls == NULL || + strcmp(watch.m_cls, watches[i].m_cls) != 0) { + printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n", + i, watch.m_cls, watches[i].m_cls); + result = STATUS_FAILED; + } + if (watch.m_name == NULL || + strcmp(watch.m_name, watches[i].m_name) != 0) { + printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"", + i, watch.m_name); + printf(", expected: \"%s\"\n", watches[i].m_name); + result = STATUS_FAILED; + } + if (watch.m_sig == NULL || + strcmp(watch.m_sig, watches[i].m_sig) != 0) { + printf("(watch#%" PRIuPTR " ) wrong method sig: \"%s\"", + i, watch.m_sig); + printf(", expected: \"%s\"\n", watches[i].m_sig); + result = STATUS_FAILED; + } + if (watch.loc != watches[i].loc) { + printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x", + i, (jint)(watch.loc >> 32), (jint)watch.loc); + printf(", expected: 0x%x%08x\n", + (jint)(watches[i].loc >> 32), (jint)watches[i].loc); + result = STATUS_FAILED; + } + if (watch.f_name == NULL || + strcmp(watch.f_name, watches[i].f_name) != 0) { + printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"", + i, watch.f_name); + printf(", expected: \"%s\"\n", watches[i].f_name); + result = STATUS_FAILED; + } + if (watch.f_sig == NULL || + strcmp(watch.f_sig, watches[i].f_sig) != 0) { + printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"", + i, watch.f_sig); + printf(", expected: \"%s\"\n", watches[i].f_sig); + result = STATUS_FAILED; + } + if (watch.is_static != watches[i].is_static) { + printf("(watch#%" PRIuPTR ") wrong field type: %s", i, + (watch.is_static==JNI_TRUE)?"static":"instance"); + printf(", expected: %s\n", + (watches[i].is_static==JNI_TRUE)?"static":"instance"); + result = STATUS_FAILED; + } + return; + } + } + printf("Unexpected field access catched: 0x%p\n", watch.fid); + result = STATUS_FAILED; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_fieldacc003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_fieldacc003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_fieldacc003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldAccess watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_FieldAccess_fieldacc003_getReady(JNIEnv *env, jclass klass) { + jvmtiError err; + jclass cls; + size_t i; + + if (!caps.can_generate_field_access_events) { + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> setting field access watches ...\n"); + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, watches[i].f_cls)); + if (cls == NULL) { + printf("Cannot find %s class!\n", watches[i].f_cls); + result = STATUS_FAILED; + return; + } + if (watches[i].is_static == JNI_TRUE) { + watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } else { + watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } + if (watches[i].fid == NULL) { + printf("Cannot get field ID for \"%s:%s\"\n", + watches[i].f_name, watches[i].f_sig); + result = STATUS_FAILED; + return; + } + err = jvmti->SetFieldAccessWatch(cls, watches[i].fid); + if (err == JVMTI_ERROR_NONE) { + eventsExpected++; + } else { + printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_FieldAccess_fieldacc003_check(JNIEnv *env, jclass cls) { + if (eventsCount != eventsExpected) { + printf("Wrong number of field access events: %d, expected: %d\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/libfieldacc003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/libfieldacc003.c deleted file mode 100644 index 554ecd9a841..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/libfieldacc003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "fieldacc003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/libfieldacc003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/libfieldacc003.cpp new file mode 100644 index 00000000000..8685d8aac74 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/libfieldacc003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "fieldacc003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/fieldacc004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/fieldacc004.c deleted file mode 100644 index efac675e2d3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/fieldacc004.c +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - jfieldID fid; - char *m_cls; - char *m_name; - char *m_sig; - jlocation loc; - char *f_cls; - char *f_name; - char *f_sig; - jboolean is_static; -} watch_info; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int eventsExpected = 0; -static int eventsCount = 0; -static watch_info watches[] = { - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc004a;", "run", "()I", 2, - "Lnsk/jvmti/FieldAccess/fieldacc004a;", "interfaceObject", - "Ljava/lang/Object;", JNI_TRUE }, - { NULL, "Lnsk/jvmti/FieldAccess/fieldacc004a;", "run", "()I", 12, - "Lnsk/jvmti/FieldAccess/fieldacc004a;", "interfaceArrInt", - "[I", JNI_TRUE } -}; - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jlocation location, jclass field_klass, jobject obj, jfieldID field) { - jvmtiError err; - jclass cls; - watch_info watch; - char *generic; - size_t i; - - eventsCount++; - if (printdump == JNI_TRUE) { - printf(">>> retrieving access watch info ...\n"); - } - watch.fid = field; - watch.loc = location; - watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE; - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, - &watch.m_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, method, - &watch.m_name, &watch.m_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, field_klass, - &watch.f_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetFieldName(jvmti_env, field_klass, field, - &watch.f_name, &watch.f_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", watch.m_cls); - printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig); - printf(">>> location: 0x%x%08x\n", - (jint)(watch.loc >> 32), (jint)watch.loc); - printf(">>> field cls: \"%s\"\n", watch.f_cls); - printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig); - printf(">>> object: 0x%p\n", obj); - printf(">>> ... done\n"); - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (watch.fid == watches[i].fid) { - if (watch.m_cls == NULL || - strcmp(watch.m_cls, watches[i].m_cls) != 0) { - printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n", - i, watch.m_cls, watches[i].m_cls); - result = STATUS_FAILED; - } - if (watch.m_name == NULL || - strcmp(watch.m_name, watches[i].m_name) != 0) { - printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"", - i, watch.m_name); - printf(", expected: \"%s\"\n", watches[i].m_name); - result = STATUS_FAILED; - } - if (watch.m_sig == NULL || - strcmp(watch.m_sig, watches[i].m_sig) != 0) { - printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"", - i, watch.m_sig); - printf(", expected: \"%s\"\n", watches[i].m_sig); - result = STATUS_FAILED; - } - if (watch.loc != watches[i].loc) { - printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x", - i, (jint)(watch.loc >> 32), (jint)watch.loc); - printf(", expected: 0x%x%08x\n", - (jint)(watches[i].loc >> 32), (jint)watches[i].loc); - result = STATUS_FAILED; - } - if (watch.f_name == NULL || - strcmp(watch.f_name, watches[i].f_name) != 0) { - printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"", - i, watch.f_name); - printf(", expected: \"%s\"\n", watches[i].f_name); - result = STATUS_FAILED; - } - if (watch.f_sig == NULL || - strcmp(watch.f_sig, watches[i].f_sig) != 0) { - printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"", - i, watch.f_sig); - printf(", expected: \"%s\"\n", watches[i].f_sig); - result = STATUS_FAILED; - } - if (watch.is_static != watches[i].is_static) { - printf("(watch#%" PRIuPTR ") wrong field type: %s", i, - (watch.is_static==JNI_TRUE)?"static":"instance"); - printf(", expected: %s\n", - (watches[i].is_static==JNI_TRUE)?"static":"instance"); - result = STATUS_FAILED; - } - return; - } - } - printf("Unexpected field access catched: 0x%p\n", watch.fid); - result = STATUS_FAILED; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_fieldacc004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_fieldacc004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_fieldacc004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldAccess watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_FieldAccess_fieldacc004_getReady(JNIEnv *env, jclass klass) { - jvmtiError err; - jclass cls; - size_t i; - - if (!caps.can_generate_field_access_events) { - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> setting field access watches ...\n"); - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, watches[i].f_cls)); - if (cls == NULL) { - printf("Cannot find %s class!\n", watches[i].f_cls); - result = STATUS_FAILED; - return; - } - if (watches[i].is_static == JNI_TRUE) { - watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } else { - watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } - if (watches[i].fid == NULL) { - printf("Cannot get field ID for \"%s:%s\"\n", - watches[i].f_name, watches[i].f_sig); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, watches[i].fid); - if (err == JVMTI_ERROR_NONE) { - eventsExpected++; - } else { - printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_FieldAccess_fieldacc004_check(JNIEnv *env, jclass cls) { - if (eventsCount != eventsExpected) { - printf("Wrong number of field access events: %d, expected: %d\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/fieldacc004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/fieldacc004.cpp new file mode 100644 index 00000000000..4e4e64c35f6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/fieldacc004.cpp @@ -0,0 +1,336 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + jfieldID fid; + char *m_cls; + char *m_name; + char *m_sig; + jlocation loc; + char *f_cls; + char *f_name; + char *f_sig; + jboolean is_static; +} writable_watch_info; + +typedef struct { + jfieldID fid; + const char *m_cls; + const char *m_name; + const char *m_sig; + jlocation loc; + const char *f_cls; + const char *f_name; + const char *f_sig; + jboolean is_static; +} watch_info; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int eventsExpected = 0; +static int eventsCount = 0; +static watch_info watches[] = { + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc004a;", "run", "()I", 2, + "Lnsk/jvmti/FieldAccess/fieldacc004a;", "interfaceObject", + "Ljava/lang/Object;", JNI_TRUE }, + { NULL, "Lnsk/jvmti/FieldAccess/fieldacc004a;", "run", "()I", 12, + "Lnsk/jvmti/FieldAccess/fieldacc004a;", "interfaceArrInt", + "[I", JNI_TRUE } +}; + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jlocation location, jclass field_klass, jobject obj, jfieldID field) { + jvmtiError err; + jclass cls; + writable_watch_info watch; + char *generic; + size_t i; + + eventsCount++; + if (printdump == JNI_TRUE) { + printf(">>> retrieving access watch info ...\n"); + } + watch.fid = field; + watch.loc = location; + watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE; + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, + &watch.m_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetMethodName(method, + &watch.m_name, &watch.m_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(field_klass, + &watch.f_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetFieldName(field_klass, field, + &watch.f_name, &watch.f_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", watch.m_cls); + printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig); + printf(">>> location: 0x%x%08x\n", + (jint)(watch.loc >> 32), (jint)watch.loc); + printf(">>> field cls: \"%s\"\n", watch.f_cls); + printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig); + printf(">>> object: 0x%p\n", obj); + printf(">>> ... done\n"); + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (watch.fid == watches[i].fid) { + if (watch.m_cls == NULL || + strcmp(watch.m_cls, watches[i].m_cls) != 0) { + printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n", + i, watch.m_cls, watches[i].m_cls); + result = STATUS_FAILED; + } + if (watch.m_name == NULL || + strcmp(watch.m_name, watches[i].m_name) != 0) { + printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"", + i, watch.m_name); + printf(", expected: \"%s\"\n", watches[i].m_name); + result = STATUS_FAILED; + } + if (watch.m_sig == NULL || + strcmp(watch.m_sig, watches[i].m_sig) != 0) { + printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"", + i, watch.m_sig); + printf(", expected: \"%s\"\n", watches[i].m_sig); + result = STATUS_FAILED; + } + if (watch.loc != watches[i].loc) { + printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x", + i, (jint)(watch.loc >> 32), (jint)watch.loc); + printf(", expected: 0x%x%08x\n", + (jint)(watches[i].loc >> 32), (jint)watches[i].loc); + result = STATUS_FAILED; + } + if (watch.f_name == NULL || + strcmp(watch.f_name, watches[i].f_name) != 0) { + printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"", + i, watch.f_name); + printf(", expected: \"%s\"\n", watches[i].f_name); + result = STATUS_FAILED; + } + if (watch.f_sig == NULL || + strcmp(watch.f_sig, watches[i].f_sig) != 0) { + printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"", + i, watch.f_sig); + printf(", expected: \"%s\"\n", watches[i].f_sig); + result = STATUS_FAILED; + } + if (watch.is_static != watches[i].is_static) { + printf("(watch#%" PRIuPTR ") wrong field type: %s", i, + (watch.is_static==JNI_TRUE)?"static":"instance"); + printf(", expected: %s\n", + (watches[i].is_static==JNI_TRUE)?"static":"instance"); + result = STATUS_FAILED; + } + return; + } + } + printf("Unexpected field access catched: 0x%p\n", watch.fid); + result = STATUS_FAILED; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_fieldacc004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_fieldacc004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_fieldacc004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldAccess watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_FieldAccess_fieldacc004_getReady(JNIEnv *env, jclass klass) { + jvmtiError err; + jclass cls; + size_t i; + + if (!caps.can_generate_field_access_events) { + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> setting field access watches ...\n"); + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, watches[i].f_cls)); + if (cls == NULL) { + printf("Cannot find %s class!\n", watches[i].f_cls); + result = STATUS_FAILED; + return; + } + if (watches[i].is_static == JNI_TRUE) { + watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } else { + watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } + if (watches[i].fid == NULL) { + printf("Cannot get field ID for \"%s:%s\"\n", + watches[i].f_name, watches[i].f_sig); + result = STATUS_FAILED; + return; + } + err = jvmti->SetFieldAccessWatch(cls, watches[i].fid); + if (err == JVMTI_ERROR_NONE) { + eventsExpected++; + } else { + printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_FieldAccess_fieldacc004_check(JNIEnv *env, jclass cls) { + if (eventsCount != eventsExpected) { + printf("Wrong number of field access events: %d, expected: %d\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/libfieldacc004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/libfieldacc004.c deleted file mode 100644 index e1aac1047c3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/libfieldacc004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "fieldacc004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/libfieldacc004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/libfieldacc004.cpp new file mode 100644 index 00000000000..c4fb9d9c556 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/libfieldacc004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "fieldacc004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/fieldmod001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/fieldmod001.c deleted file mode 100644 index 274a3a217eb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/fieldmod001.c +++ /dev/null @@ -1,460 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - jfieldID fid; - char *m_cls; - char *m_name; - char *m_sig; - jlocation loc; - char *f_cls; - char *f_name; - char *f_sig; - jboolean is_static; - jvalue val; -} watch_info; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int eventsExpected = 0; -static int eventsCount = 0; -static watch_info watches[] = { - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 1, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticBoolean", "Z", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 5, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticByte", "B", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 9, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticShort", "S", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 13, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticInt", "I", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 19, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticLong", "J", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 24, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticFloat", "F", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 30, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticDouble", "D", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 35, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticChar", "C", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 41, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticObject", "Ljava/lang/Object;", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 47, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticArrInt", "[I", JNI_TRUE, {0} }, - - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 52, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceBoolean", "Z", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 58, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceByte", "B", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 64, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceShort", "S", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 70, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceInt", "I", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 77, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceLong", "J", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 83, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceFloat", "F", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 90, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceDouble", "D", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 96, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceChar", "C", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 103, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceObject", "Ljava/lang/Object;", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 110, - "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceArrInt", "[I", JNI_FALSE, {0} } -}; - -void printValue(jvalue val, char *sig) { - switch (*sig) { - case 'J': - printf("0x%x%08x", (jint)(val.j >> 32), (jint)val.j); - break; - case 'F': - printf("%.3f", (double)val.f); - break; - case 'D': - printf("%f", (double)val.d); - break; - case 'L': - case '[': - printf("0x%p", val.l); - break; - case 'Z': - printf("0x%x", val.z); - break; - case 'B': - printf("%d", val.b); - break; - case 'S': - printf("%d", val.s); - break; - case 'C': - printf("0x%x", val.c); - break; - case 'I': - printf("%d", val.i); - break; - default: - printf("0x%x%08x", (jint)(val.j >> 32), (jint)val.j); - break; - } -} - -int isEqual(JNIEnv *env, char *sig, jvalue v1, jvalue v2) { - switch (*sig) { - case 'J': - return (v1.j == v2.j); - case 'F': - return (v1.f == v2.f); - case 'D': - return (v1.d == v2.d); - case 'L': - case '[': - return (JNI_TRUE == - JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, v1.l), v2.l)); - case 'Z': - return (v1.z == v2.z); - case 'B': - return (v1.b == v2.b); - case 'S': - return (v1.s == v2.s); - case 'C': - return (v1.c == v2.c); - case 'I': - return (v1.i == v2.i); - default: - return (1); - } -} - -void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location, - jclass field_klass, jobject obj, - jfieldID field, char sig, jvalue new_value) { - jvmtiError err; - jclass cls; - watch_info watch; - char *generic; - size_t i; - - eventsCount++; - if (printdump == JNI_TRUE) { - printf(">>> retrieving modification watch info ...\n"); - } - watch.fid = field; - watch.loc = location; - watch.val = new_value; - watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE; - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, - &watch.m_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, method, - &watch.m_name, &watch.m_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, field_klass, - &watch.f_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetFieldName(jvmti_env, field_klass, field, - &watch.f_name, &watch.f_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", watch.m_cls); - printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig); - printf(">>> location: 0x%x%08x\n", - (jint)(watch.loc >> 32), (jint)watch.loc); - printf(">>> field cls: \"%s\"\n", watch.f_cls); - printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig); - printf(">>> object: 0x%p\n", obj); - printf(">>> new value: "); - printValue(watch.val, watch.f_sig); - printf("\n"); - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (watch.fid == watches[i].fid) { - if (watch.m_cls == NULL || - strcmp(watch.m_cls, watches[i].m_cls) != 0) { - printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n", - i, watch.m_cls, watches[i].m_cls); - result = STATUS_FAILED; - } - if (watch.m_name == NULL || - strcmp(watch.m_name, watches[i].m_name) != 0) { - printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"", - i, watch.m_name); - printf(", expected: \"%s\"\n", watches[i].m_name); - result = STATUS_FAILED; - } - if (watch.m_sig == NULL || - strcmp(watch.m_sig, watches[i].m_sig) != 0) { - printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"", - i, watch.m_sig); - printf(", expected: \"%s\"\n", watches[i].m_sig); - result = STATUS_FAILED; - } - if (watch.loc != watches[i].loc) { - printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x", - i, (jint)(watch.loc >> 32), (jint)watch.loc); - printf(", expected: 0x%x%08x\n", - (jint)(watches[i].loc >> 32), (jint)watches[i].loc); - result = STATUS_FAILED; - } - if (watch.f_name == NULL || - strcmp(watch.f_name, watches[i].f_name) != 0) { - printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"", - i, watch.f_name); - printf(", expected: \"%s\"\n", watches[i].f_name); - result = STATUS_FAILED; - } - if (watch.f_sig == NULL || - strcmp(watch.f_sig, watches[i].f_sig) != 0) { - printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"", - i, watch.f_sig); - printf(", expected: \"%s\"\n", watches[i].f_sig); - result = STATUS_FAILED; - } - if (watch.is_static != watches[i].is_static) { - printf("(watch#%" PRIuPTR ") wrong field type: %s", i, - (watch.is_static==JNI_TRUE)?"static":"instance"); - printf(", expected: %s\n", - (watches[i].is_static==JNI_TRUE)?"static":"instance"); - result = STATUS_FAILED; - } - if (!isEqual((JNIEnv *)env, watch.f_sig, watch.val, watches[i].val)) { - printf("(watch#%" PRIuPTR ") wrong new value: ", i); - printValue(watch.val, watch.f_sig); - printf(", expected: "); - printValue(watches[i].val, watch.f_sig); - printf("\n"); - result = STATUS_FAILED; - } - return; - } - } - printf("Unexpected field modification catched: 0x%p\n", watch.fid); - result = STATUS_FAILED; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_fieldmod001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_fieldmod001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_fieldmod001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_modification_events) { - callbacks.FieldModification = &FieldModification; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_MODIFICATION, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldModification watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_FieldModification_fieldmod001_getReady(JNIEnv *env, jclass klass, - jobject obj1, jobject obj2, jobject arr1, jobject arr2) { - jvmtiError err; - jclass cls; - size_t i; - - if (!caps.can_generate_field_modification_events) { - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> setting field modification watches ...\n"); - } - cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/FieldModification/fieldmod001a")); - if (cls == NULL) { - printf("Cannot find fieldmod001a class!\n"); - result = STATUS_FAILED; - return; - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (watches[i].is_static == JNI_TRUE) { - watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } else { - watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } - if (watches[i].fid == NULL) { - printf("Cannot get field ID for \"%s:%s\"\n", - watches[i].f_name, watches[i].f_sig); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->SetFieldModificationWatch(jvmti, cls, watches[i].fid); - if (err == JVMTI_ERROR_NONE) { - eventsExpected++; - } else { - printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - watches[0].val.z = JNI_TRUE; - watches[1].val.b = 1; - watches[2].val.s = 2; - watches[3].val.i = 3; - watches[4].val.j = 4; - watches[5].val.f = 0.5F; - watches[6].val.d = 0.6; - watches[7].val.c = 0x61; - watches[8].val.l = (*env)->NewGlobalRef(env, obj1); - watches[9].val.l = (*env)->NewGlobalRef(env, arr1); - - watches[10].val.z = JNI_FALSE; - watches[11].val.b = 10; - watches[12].val.s = 20; - watches[13].val.i = 30; - watches[14].val.j = 40; - watches[15].val.f = 0.05F; - watches[16].val.d = 0.06; - watches[17].val.c = 0x7a; - watches[18].val.l = (*env)->NewGlobalRef(env, obj2); - watches[19].val.l = (*env)->NewGlobalRef(env, arr2); - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_FieldModification_fieldmod001_check(JNIEnv *env, jclass cls) { - if (eventsCount != eventsExpected) { - printf("Wrong number of field modification events: %d, expected: %d\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/fieldmod001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/fieldmod001.cpp new file mode 100644 index 00000000000..da5e10a7762 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/fieldmod001.cpp @@ -0,0 +1,473 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + jfieldID fid; + char *m_cls; + char *m_name; + char *m_sig; + jlocation loc; + char *f_cls; + char *f_name; + char *f_sig; + jboolean is_static; + jvalue val; +} writable_watch_info; + +typedef struct { + jfieldID fid; + const char *m_cls; + const char *m_name; + const char *m_sig; + jlocation loc; + const char *f_cls; + const char *f_name; + const char *f_sig; + const jboolean is_static; + jvalue val; +} watch_info; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int eventsExpected = 0; +static int eventsCount = 0; +static watch_info watches[] = { + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 1, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticBoolean", "Z", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 5, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticByte", "B", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 9, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticShort", "S", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 13, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticInt", "I", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 19, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticLong", "J", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 24, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticFloat", "F", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 30, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticDouble", "D", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 35, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticChar", "C", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 41, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticObject", "Ljava/lang/Object;", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 47, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "staticArrInt", "[I", JNI_TRUE, {} }, + + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 52, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceBoolean", "Z", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 58, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceByte", "B", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 64, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceShort", "S", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 70, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceInt", "I", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 77, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceLong", "J", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 83, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceFloat", "F", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 90, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceDouble", "D", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 96, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceChar", "C", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 103, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceObject", "Ljava/lang/Object;", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 110, + "Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceArrInt", "[I", JNI_FALSE, {} } +}; + +void printValue(jvalue val, char *sig) { + switch (*sig) { + case 'J': + printf("0x%x%08x", (jint)(val.j >> 32), (jint)val.j); + break; + case 'F': + printf("%.3f", (double)val.f); + break; + case 'D': + printf("%f", (double)val.d); + break; + case 'L': + case '[': + printf("0x%p", val.l); + break; + case 'Z': + printf("0x%x", val.z); + break; + case 'B': + printf("%d", val.b); + break; + case 'S': + printf("%d", val.s); + break; + case 'C': + printf("0x%x", val.c); + break; + case 'I': + printf("%d", val.i); + break; + default: + printf("0x%x%08x", (jint)(val.j >> 32), (jint)val.j); + break; + } +} + +int isEqual(JNIEnv *env, char *sig, jvalue v1, jvalue v2) { + switch (*sig) { + case 'J': + return (v1.j == v2.j); + case 'F': + return (v1.f == v2.f); + case 'D': + return (v1.d == v2.d); + case 'L': + case '[': + return (JNI_TRUE == + JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, v1.l), v2.l)); + case 'Z': + return (v1.z == v2.z); + case 'B': + return (v1.b == v2.b); + case 'S': + return (v1.s == v2.s); + case 'C': + return (v1.c == v2.c); + case 'I': + return (v1.i == v2.i); + default: + return (1); + } +} + +void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location, + jclass field_klass, jobject obj, + jfieldID field, char sig, jvalue new_value) { + jvmtiError err; + jclass cls; + writable_watch_info watch; + char *generic; + size_t i; + + eventsCount++; + if (printdump == JNI_TRUE) { + printf(">>> retrieving modification watch info ...\n"); + } + watch.fid = field; + watch.loc = location; + watch.val = new_value; + watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE; + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, + &watch.m_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetMethodName(method, + &watch.m_name, &watch.m_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(field_klass, + &watch.f_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetFieldName(field_klass, field, + &watch.f_name, &watch.f_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", watch.m_cls); + printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig); + printf(">>> location: 0x%x%08x\n", + (jint)(watch.loc >> 32), (jint)watch.loc); + printf(">>> field cls: \"%s\"\n", watch.f_cls); + printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig); + printf(">>> object: 0x%p\n", obj); + printf(">>> new value: "); + printValue(watch.val, watch.f_sig); + printf("\n"); + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (watch.fid == watches[i].fid) { + if (watch.m_cls == NULL || + strcmp(watch.m_cls, watches[i].m_cls) != 0) { + printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n", + i, watch.m_cls, watches[i].m_cls); + result = STATUS_FAILED; + } + if (watch.m_name == NULL || + strcmp(watch.m_name, watches[i].m_name) != 0) { + printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"", + i, watch.m_name); + printf(", expected: \"%s\"\n", watches[i].m_name); + result = STATUS_FAILED; + } + if (watch.m_sig == NULL || + strcmp(watch.m_sig, watches[i].m_sig) != 0) { + printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"", + i, watch.m_sig); + printf(", expected: \"%s\"\n", watches[i].m_sig); + result = STATUS_FAILED; + } + if (watch.loc != watches[i].loc) { + printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x", + i, (jint)(watch.loc >> 32), (jint)watch.loc); + printf(", expected: 0x%x%08x\n", + (jint)(watches[i].loc >> 32), (jint)watches[i].loc); + result = STATUS_FAILED; + } + if (watch.f_name == NULL || + strcmp(watch.f_name, watches[i].f_name) != 0) { + printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"", + i, watch.f_name); + printf(", expected: \"%s\"\n", watches[i].f_name); + result = STATUS_FAILED; + } + if (watch.f_sig == NULL || + strcmp(watch.f_sig, watches[i].f_sig) != 0) { + printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"", + i, watch.f_sig); + printf(", expected: \"%s\"\n", watches[i].f_sig); + result = STATUS_FAILED; + } + if (watch.is_static != watches[i].is_static) { + printf("(watch#%" PRIuPTR ") wrong field type: %s", i, + (watch.is_static==JNI_TRUE)?"static":"instance"); + printf(", expected: %s\n", + (watches[i].is_static==JNI_TRUE)?"static":"instance"); + result = STATUS_FAILED; + } + if (!isEqual((JNIEnv *)env, watch.f_sig, watch.val, watches[i].val)) { + printf("(watch#%" PRIuPTR ") wrong new value: ", i); + printValue(watch.val, watch.f_sig); + printf(", expected: "); + printValue(watches[i].val, watch.f_sig); + printf("\n"); + result = STATUS_FAILED; + } + return; + } + } + printf("Unexpected field modification catched: 0x%p\n", watch.fid); + result = STATUS_FAILED; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_fieldmod001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_fieldmod001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_fieldmod001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_modification_events) { + callbacks.FieldModification = &FieldModification; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_MODIFICATION, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldModification watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_FieldModification_fieldmod001_getReady(JNIEnv *env, jclass klass, + jobject obj1, jobject obj2, jobject arr1, jobject arr2) { + jvmtiError err; + jclass cls; + size_t i; + + if (!caps.can_generate_field_modification_events) { + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> setting field modification watches ...\n"); + } + cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/FieldModification/fieldmod001a")); + if (cls == NULL) { + printf("Cannot find fieldmod001a class!\n"); + result = STATUS_FAILED; + return; + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (watches[i].is_static == JNI_TRUE) { + watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } else { + watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } + if (watches[i].fid == NULL) { + printf("Cannot get field ID for \"%s:%s\"\n", + watches[i].f_name, watches[i].f_sig); + result = STATUS_FAILED; + return; + } + err = jvmti->SetFieldModificationWatch(cls, watches[i].fid); + if (err == JVMTI_ERROR_NONE) { + eventsExpected++; + } else { + printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + watches[0].val.z = JNI_TRUE; + watches[1].val.b = 1; + watches[2].val.s = 2; + watches[3].val.i = 3; + watches[4].val.j = 4; + watches[5].val.f = 0.5F; + watches[6].val.d = 0.6; + watches[7].val.c = 0x61; + watches[8].val.l = env->NewGlobalRef(obj1); + watches[9].val.l = env->NewGlobalRef(arr1); + + watches[10].val.z = JNI_FALSE; + watches[11].val.b = 10; + watches[12].val.s = 20; + watches[13].val.i = 30; + watches[14].val.j = 40; + watches[15].val.f = 0.05F; + watches[16].val.d = 0.06; + watches[17].val.c = 0x7a; + watches[18].val.l = env->NewGlobalRef(obj2); + watches[19].val.l = env->NewGlobalRef(arr2); + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_FieldModification_fieldmod001_check(JNIEnv *env, jclass cls) { + if (eventsCount != eventsExpected) { + printf("Wrong number of field modification events: %d, expected: %d\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/libfieldmod001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/libfieldmod001.c deleted file mode 100644 index 39ede348cea..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/libfieldmod001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "fieldmod001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/libfieldmod001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/libfieldmod001.cpp new file mode 100644 index 00000000000..ec3681bacae --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod001/libfieldmod001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "fieldmod001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/fieldmod002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/fieldmod002.c deleted file mode 100644 index e96cccc70a9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/fieldmod002.c +++ /dev/null @@ -1,539 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - jfieldID fid; - char *m_cls; - char *m_name; - char *m_sig; - jlocation loc; - char *f_cls; - char *f_name; - char *f_sig; - jboolean is_static; - jvalue val; -} watch_info; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int eventsExpected = 0; -static int eventsCount = 0; -static watch_info watches[] = { - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticBoolean", "Z", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticByte", "B", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticShort", "S", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticInt", "I", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticLong", "J", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticFloat", "F", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticDouble", "D", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticChar", "C", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticObject", "Ljava/lang/Object;", JNI_TRUE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticArrInt", "[I", JNI_TRUE, {0} }, - - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceBoolean", "Z", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceByte", "B", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceShort", "S", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceInt", "I", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceLong", "J", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceFloat", "F", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceDouble", "D", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceChar", "C", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceObject", "Ljava/lang/Object;", JNI_FALSE, {0} }, - { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, - "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceArrInt", "[I", JNI_FALSE, {0} } -}; - -void printValue(jvalue val, char *sig) { - switch (*sig) { - case 'J': - printf("0x%x%08x", (jint)(val.j >> 32), (jint)val.j); - break; - case 'F': - printf("%.3f", (double)val.f); - break; - case 'D': - printf("%f", (double)val.d); - break; - case 'L': - case '[': - printf("0x%p", val.l); - break; - case 'Z': - printf("0x%x", val.z); - break; - case 'B': - printf("%d", val.b); - break; - case 'S': - printf("%d", val.s); - break; - case 'C': - printf("0x%x", val.c); - break; - case 'I': - printf("%d", val.i); - break; - default: - printf("0x%x%08x", (jint)(val.j >> 32), (jint)val.j); - break; - } -} - -int isEqual(JNIEnv *env, char *sig, jvalue v1, jvalue v2) { - switch (*sig) { - case 'J': - return (v1.j == v2.j); - case 'F': - return (v1.f == v2.f); - case 'D': - return (v1.d == v2.d); - case 'L': - case '[': - return (JNI_TRUE == - JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, v1.l), v2.l)); - case 'Z': - return (v1.z == v2.z); - case 'B': - return (v1.b == v2.b); - case 'S': - return (v1.s == v2.s); - case 'C': - return (v1.c == v2.c); - case 'I': - return (v1.i == v2.i); - default: - return (1); - } -} - -void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location, - jclass field_klass, jobject obj, - jfieldID field, char sig, jvalue new_value) { - jvmtiError err; - jclass cls; - watch_info watch; - char *generic; - size_t i; - - eventsCount++; - if (printdump == JNI_TRUE) { - printf(">>> retrieving modification watch info ...\n"); - } - watch.fid = field; - watch.loc = location; - watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE; - watch.val = new_value; - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, - &watch.m_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, method, - &watch.m_name, &watch.m_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, field_klass, - &watch.f_cls, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetFieldName(jvmti_env, field_klass, field, - &watch.f_name, &watch.f_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", watch.m_cls); - printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig); - printf(">>> location: 0x%x%08x\n", - (jint)(watch.loc >> 32), (jint)watch.loc); - printf(">>> field cls: \"%s\"\n", watch.f_cls); - printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig); - printf(">>> object: 0x%p\n", obj); - printf(">>> new value: "); - printValue(watch.val, watch.f_sig); - printf("\n"); - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (watch.fid == watches[i].fid) { - if (watch.m_cls == NULL || - strcmp(watch.m_cls, watches[i].m_cls) != 0) { - printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n", - i, watch.m_cls, watches[i].m_cls); - result = STATUS_FAILED; - } - if (watch.m_name == NULL || - strcmp(watch.m_name, watches[i].m_name) != 0) { - printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"", - i, watch.m_name); - printf(", expected: \"%s\"\n", watches[i].m_name); - result = STATUS_FAILED; - } - if (watch.m_sig == NULL || - strcmp(watch.m_sig, watches[i].m_sig) != 0) { - printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"", - i, watch.m_sig); - printf(", expected: \"%s\"\n", watches[i].m_sig); - result = STATUS_FAILED; - } - if (watch.loc != watches[i].loc) { - printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x", - i, (jint)(watch.loc >> 32), (jint)watch.loc); - printf(", expected: 0x%x%08x\n", - (jint)(watches[i].loc >> 32), (jint)watches[i].loc); - result = STATUS_FAILED; - } - if (watch.f_name == NULL || - strcmp(watch.f_name, watches[i].f_name) != 0) { - printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"", - i, watch.f_name); - printf(", expected: \"%s\"\n", watches[i].f_name); - result = STATUS_FAILED; - } - if (watch.f_sig == NULL || - strcmp(watch.f_sig, watches[i].f_sig) != 0) { - printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"", - i, watch.f_sig); - printf(", expected: \"%s\"\n", watches[i].f_sig); - result = STATUS_FAILED; - } - if (watch.is_static != watches[i].is_static) { - printf("(watch#%" PRIuPTR ") wrong field type: %s", i, - (watch.is_static==JNI_TRUE)?"static":"instance"); - printf(", expected: %s\n", - (watches[i].is_static==JNI_TRUE)?"static":"instance"); - result = STATUS_FAILED; - } - if (!isEqual((JNIEnv *)env, watch.f_sig, watch.val, watches[i].val)) { - printf("(watch#%" PRIuPTR ") wrong new value: ", i); - printValue(watch.val, watch.f_sig); - printf(", expected: "); - printValue(watches[i].val, watch.f_sig); - printf("\n"); - result = STATUS_FAILED; - } - return; - } - } - printf("Unexpected field modification catched: 0x%p\n", watch.fid); - result = STATUS_FAILED; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_fieldmod002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_fieldmod002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_fieldmod002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_modification_events) { - callbacks.FieldModification = &FieldModification; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_MODIFICATION, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldModification watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_FieldModification_fieldmod002_getReady(JNIEnv *env, jclass clz) { - jvmtiError err; - jclass cls; - jmethodID ctor; - jintArray arr1, arr2; - jobject obj1, obj2; - size_t i; - - if (!caps.can_generate_field_modification_events) { - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> setting field modification watches ...\n"); - } - cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/FieldModification/fieldmod002a")); - if (cls == NULL) { - printf("Cannot find fieldmod001a class!\n"); - result = STATUS_FAILED; - return; - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (watches[i].is_static == JNI_TRUE) { - watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } else { - watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } - if (watches[i].fid == NULL) { - printf("Cannot get field ID for \"%s:%s\"\n", - watches[i].f_name, watches[i].f_sig); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->SetFieldModificationWatch(jvmti, cls, watches[i].fid); - if (err == JVMTI_ERROR_NONE) { - eventsExpected++; - } else { - printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - ctor = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "", "()V"); - obj1 = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, - JNI_ENV_PTR(env)->NewObject(JNI_ENV_ARG(env, cls), ctor))); - obj2 = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, - JNI_ENV_PTR(env)->NewObject(JNI_ENV_ARG(env, cls), ctor))); - arr1 = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, - JNI_ENV_PTR(env)->NewIntArray(JNI_ENV_ARG(env, (jsize)1)))); - arr2 = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, - JNI_ENV_PTR(env)->NewIntArray(JNI_ENV_ARG(env, (jsize)1)))); - - watches[0].val.z = JNI_TRUE; - watches[1].val.b = 1; - watches[2].val.s = 2; - watches[3].val.i = 3; - watches[4].val.j = 4; - watches[5].val.f = 0.5F; - watches[6].val.d = 0.6; - watches[7].val.c = 0x7; - watches[8].val.l = obj1; - watches[9].val.l = arr1; - - watches[10].val.z = JNI_FALSE; - watches[11].val.b = 10; - watches[12].val.s = 20; - watches[13].val.i = 30; - watches[14].val.j = 40; - watches[15].val.f = 0.05F; - watches[16].val.d = 0.06; - watches[17].val.c = 0x70; - watches[18].val.l = obj2; - watches[19].val.l = arr2; - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_FieldModification_fieldmod002_check(JNIEnv *env, - jclass clz, jobject obj) { - jclass cls; - - if (!caps.can_generate_field_modification_events) { - return PASSED; - } - - - - if (printdump == JNI_TRUE) { - printf(">>> modifying fields ...\n"); - } - - cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/FieldModification/fieldmod002a")); - if (cls == NULL) { - printf("Cannot find fieldmod001a class!\n"); - return STATUS_FAILED; - } - - JNI_ENV_PTR(env)->SetStaticBooleanField(JNI_ENV_ARG(env, cls), - watches[0].fid, watches[0].val.z); - JNI_ENV_PTR(env)->SetStaticByteField(JNI_ENV_ARG(env, cls), - watches[1].fid, watches[1].val.b); - JNI_ENV_PTR(env)->SetStaticShortField(JNI_ENV_ARG(env, cls), - watches[2].fid, watches[2].val.s); - JNI_ENV_PTR(env)->SetStaticIntField(JNI_ENV_ARG(env, cls), - watches[3].fid, watches[3].val.i); - JNI_ENV_PTR(env)->SetStaticLongField(JNI_ENV_ARG(env, cls), - watches[4].fid, watches[4].val.j); - JNI_ENV_PTR(env)->SetStaticFloatField(JNI_ENV_ARG(env, cls), - watches[5].fid, watches[5].val.f); - JNI_ENV_PTR(env)->SetStaticDoubleField(JNI_ENV_ARG(env, cls), - watches[6].fid, watches[6].val.d); - JNI_ENV_PTR(env)->SetStaticCharField(JNI_ENV_ARG(env, cls), - watches[7].fid, watches[7].val.c); - JNI_ENV_PTR(env)->SetStaticObjectField(JNI_ENV_ARG(env, cls), - watches[8].fid, watches[8].val.l); - JNI_ENV_PTR(env)->SetStaticObjectField(JNI_ENV_ARG(env, cls), - watches[9].fid, watches[9].val.l); - - JNI_ENV_PTR(env)->SetBooleanField(JNI_ENV_ARG(env, obj), - watches[10].fid, watches[10].val.z); - JNI_ENV_PTR(env)->SetByteField(JNI_ENV_ARG(env, obj), - watches[11].fid, watches[11].val.b); - JNI_ENV_PTR(env)->SetShortField(JNI_ENV_ARG(env, obj), - watches[12].fid, watches[12].val.s); - JNI_ENV_PTR(env)->SetIntField(JNI_ENV_ARG(env, obj), - watches[13].fid, watches[13].val.i); - JNI_ENV_PTR(env)->SetLongField(JNI_ENV_ARG(env, obj), - watches[14].fid, watches[14].val.j); - JNI_ENV_PTR(env)->SetFloatField(JNI_ENV_ARG(env, obj), - watches[15].fid, watches[15].val.f); - JNI_ENV_PTR(env)->SetDoubleField(JNI_ENV_ARG(env, obj), - watches[16].fid, watches[16].val.d); - JNI_ENV_PTR(env)->SetCharField(JNI_ENV_ARG(env, obj), - watches[17].fid, watches[17].val.c); - JNI_ENV_PTR(env)->SetObjectField(JNI_ENV_ARG(env, obj), - watches[18].fid, watches[18].val.l); - JNI_ENV_PTR(env)->SetObjectField(JNI_ENV_ARG(env, obj), - watches[19].fid, watches[19].val.l); - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - if (eventsCount != eventsExpected) { - printf("Wrong number of field modification events: %d, expected: %d\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/fieldmod002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/fieldmod002.cpp new file mode 100644 index 00000000000..6ce5b6e8913 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/fieldmod002.cpp @@ -0,0 +1,552 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + jfieldID fid; + char *m_cls; + char *m_name; + char *m_sig; + jlocation loc; + char *f_cls; + char *f_name; + char *f_sig; + jboolean is_static; + jvalue val; +} writable_watch_info; + +typedef struct { + jfieldID fid; + const char *m_cls; + const char *m_name; + const char *m_sig; + jlocation loc; + const char *f_cls; + const char *f_name; + const char *f_sig; + jboolean is_static; + jvalue val; +} watch_info; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int eventsExpected = 0; +static int eventsCount = 0; +static watch_info watches[] = { + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticBoolean", "Z", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticByte", "B", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticShort", "S", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticInt", "I", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticLong", "J", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticFloat", "F", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticDouble", "D", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticChar", "C", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticObject", "Ljava/lang/Object;", JNI_TRUE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "staticArrInt", "[I", JNI_TRUE, {} }, + + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceBoolean", "Z", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceByte", "B", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceShort", "S", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceInt", "I", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceLong", "J", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceFloat", "F", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceDouble", "D", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceChar", "C", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceObject", "Ljava/lang/Object;", JNI_FALSE, {} }, + { NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0, + "Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceArrInt", "[I", JNI_FALSE, {} } +}; + +void printValue(jvalue val, char *sig) { + switch (*sig) { + case 'J': + printf("0x%x%08x", (jint)(val.j >> 32), (jint)val.j); + break; + case 'F': + printf("%.3f", (double)val.f); + break; + case 'D': + printf("%f", (double)val.d); + break; + case 'L': + case '[': + printf("0x%p", val.l); + break; + case 'Z': + printf("0x%x", val.z); + break; + case 'B': + printf("%d", val.b); + break; + case 'S': + printf("%d", val.s); + break; + case 'C': + printf("0x%x", val.c); + break; + case 'I': + printf("%d", val.i); + break; + default: + printf("0x%x%08x", (jint)(val.j >> 32), (jint)val.j); + break; + } +} + +int isEqual(JNIEnv *env, char *sig, jvalue v1, jvalue v2) { + switch (*sig) { + case 'J': + return (v1.j == v2.j); + case 'F': + return (v1.f == v2.f); + case 'D': + return (v1.d == v2.d); + case 'L': + case '[': + return (JNI_TRUE == + JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, v1.l), v2.l)); + case 'Z': + return (v1.z == v2.z); + case 'B': + return (v1.b == v2.b); + case 'S': + return (v1.s == v2.s); + case 'C': + return (v1.c == v2.c); + case 'I': + return (v1.i == v2.i); + default: + return (1); + } +} + +void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location, + jclass field_klass, jobject obj, + jfieldID field, char sig, jvalue new_value) { + jvmtiError err; + jclass cls; + writable_watch_info watch; + char *generic; + size_t i; + + eventsCount++; + if (printdump == JNI_TRUE) { + printf(">>> retrieving modification watch info ...\n"); + } + watch.fid = field; + watch.loc = location; + watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE; + watch.val = new_value; + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, + &watch.m_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetMethodName(method, + &watch.m_name, &watch.m_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(field_klass, + &watch.f_cls, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetFieldName(field_klass, field, + &watch.f_name, &watch.f_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", watch.m_cls); + printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig); + printf(">>> location: 0x%x%08x\n", + (jint)(watch.loc >> 32), (jint)watch.loc); + printf(">>> field cls: \"%s\"\n", watch.f_cls); + printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig); + printf(">>> object: 0x%p\n", obj); + printf(">>> new value: "); + printValue(watch.val, watch.f_sig); + printf("\n"); + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (watch.fid == watches[i].fid) { + if (watch.m_cls == NULL || + strcmp(watch.m_cls, watches[i].m_cls) != 0) { + printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n", + i, watch.m_cls, watches[i].m_cls); + result = STATUS_FAILED; + } + if (watch.m_name == NULL || + strcmp(watch.m_name, watches[i].m_name) != 0) { + printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"", + i, watch.m_name); + printf(", expected: \"%s\"\n", watches[i].m_name); + result = STATUS_FAILED; + } + if (watch.m_sig == NULL || + strcmp(watch.m_sig, watches[i].m_sig) != 0) { + printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"", + i, watch.m_sig); + printf(", expected: \"%s\"\n", watches[i].m_sig); + result = STATUS_FAILED; + } + if (watch.loc != watches[i].loc) { + printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x", + i, (jint)(watch.loc >> 32), (jint)watch.loc); + printf(", expected: 0x%x%08x\n", + (jint)(watches[i].loc >> 32), (jint)watches[i].loc); + result = STATUS_FAILED; + } + if (watch.f_name == NULL || + strcmp(watch.f_name, watches[i].f_name) != 0) { + printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"", + i, watch.f_name); + printf(", expected: \"%s\"\n", watches[i].f_name); + result = STATUS_FAILED; + } + if (watch.f_sig == NULL || + strcmp(watch.f_sig, watches[i].f_sig) != 0) { + printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"", + i, watch.f_sig); + printf(", expected: \"%s\"\n", watches[i].f_sig); + result = STATUS_FAILED; + } + if (watch.is_static != watches[i].is_static) { + printf("(watch#%" PRIuPTR ") wrong field type: %s", i, + (watch.is_static==JNI_TRUE)?"static":"instance"); + printf(", expected: %s\n", + (watches[i].is_static==JNI_TRUE)?"static":"instance"); + result = STATUS_FAILED; + } + if (!isEqual((JNIEnv *)env, watch.f_sig, watch.val, watches[i].val)) { + printf("(watch#%" PRIuPTR ") wrong new value: ", i); + printValue(watch.val, watch.f_sig); + printf(", expected: "); + printValue(watches[i].val, watch.f_sig); + printf("\n"); + result = STATUS_FAILED; + } + return; + } + } + printf("Unexpected field modification catched: 0x%p\n", watch.fid); + result = STATUS_FAILED; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_fieldmod002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_fieldmod002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_fieldmod002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_modification_events) { + callbacks.FieldModification = &FieldModification; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_MODIFICATION, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldModification watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_FieldModification_fieldmod002_getReady(JNIEnv *env, jclass clz) { + jvmtiError err; + jclass cls; + jmethodID ctor; + jintArray arr1, arr2; + jobject obj1, obj2; + size_t i; + + if (!caps.can_generate_field_modification_events) { + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> setting field modification watches ...\n"); + } + cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/FieldModification/fieldmod002a")); + if (cls == NULL) { + printf("Cannot find fieldmod001a class!\n"); + result = STATUS_FAILED; + return; + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (watches[i].is_static == JNI_TRUE) { + watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } else { + watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } + if (watches[i].fid == NULL) { + printf("Cannot get field ID for \"%s:%s\"\n", + watches[i].f_name, watches[i].f_sig); + result = STATUS_FAILED; + return; + } + err = jvmti->SetFieldModificationWatch(cls, watches[i].fid); + if (err == JVMTI_ERROR_NONE) { + eventsExpected++; + } else { + printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + ctor = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "", "()V"); + obj1 = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, + JNI_ENV_PTR(env)->NewObject(JNI_ENV_ARG(env, cls), ctor))); + obj2 = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, + JNI_ENV_PTR(env)->NewObject(JNI_ENV_ARG(env, cls), ctor))); + arr1 = (jintArray) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, + JNI_ENV_PTR(env)->NewIntArray(JNI_ENV_ARG(env, (jsize)1)))); + arr2 = (jintArray) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, + JNI_ENV_PTR(env)->NewIntArray(JNI_ENV_ARG(env, (jsize)1)))); + + watches[0].val.z = JNI_TRUE; + watches[1].val.b = 1; + watches[2].val.s = 2; + watches[3].val.i = 3; + watches[4].val.j = 4; + watches[5].val.f = 0.5F; + watches[6].val.d = 0.6; + watches[7].val.c = 0x7; + watches[8].val.l = obj1; + watches[9].val.l = arr1; + + watches[10].val.z = JNI_FALSE; + watches[11].val.b = 10; + watches[12].val.s = 20; + watches[13].val.i = 30; + watches[14].val.j = 40; + watches[15].val.f = 0.05F; + watches[16].val.d = 0.06; + watches[17].val.c = 0x70; + watches[18].val.l = obj2; + watches[19].val.l = arr2; + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_FieldModification_fieldmod002_check(JNIEnv *env, + jclass clz, jobject obj) { + jclass cls; + + if (!caps.can_generate_field_modification_events) { + return PASSED; + } + + + + if (printdump == JNI_TRUE) { + printf(">>> modifying fields ...\n"); + } + + cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/FieldModification/fieldmod002a")); + if (cls == NULL) { + printf("Cannot find fieldmod001a class!\n"); + return STATUS_FAILED; + } + + JNI_ENV_PTR(env)->SetStaticBooleanField(JNI_ENV_ARG(env, cls), + watches[0].fid, watches[0].val.z); + JNI_ENV_PTR(env)->SetStaticByteField(JNI_ENV_ARG(env, cls), + watches[1].fid, watches[1].val.b); + JNI_ENV_PTR(env)->SetStaticShortField(JNI_ENV_ARG(env, cls), + watches[2].fid, watches[2].val.s); + JNI_ENV_PTR(env)->SetStaticIntField(JNI_ENV_ARG(env, cls), + watches[3].fid, watches[3].val.i); + JNI_ENV_PTR(env)->SetStaticLongField(JNI_ENV_ARG(env, cls), + watches[4].fid, watches[4].val.j); + JNI_ENV_PTR(env)->SetStaticFloatField(JNI_ENV_ARG(env, cls), + watches[5].fid, watches[5].val.f); + JNI_ENV_PTR(env)->SetStaticDoubleField(JNI_ENV_ARG(env, cls), + watches[6].fid, watches[6].val.d); + JNI_ENV_PTR(env)->SetStaticCharField(JNI_ENV_ARG(env, cls), + watches[7].fid, watches[7].val.c); + JNI_ENV_PTR(env)->SetStaticObjectField(JNI_ENV_ARG(env, cls), + watches[8].fid, watches[8].val.l); + JNI_ENV_PTR(env)->SetStaticObjectField(JNI_ENV_ARG(env, cls), + watches[9].fid, watches[9].val.l); + + JNI_ENV_PTR(env)->SetBooleanField(JNI_ENV_ARG(env, obj), + watches[10].fid, watches[10].val.z); + JNI_ENV_PTR(env)->SetByteField(JNI_ENV_ARG(env, obj), + watches[11].fid, watches[11].val.b); + JNI_ENV_PTR(env)->SetShortField(JNI_ENV_ARG(env, obj), + watches[12].fid, watches[12].val.s); + JNI_ENV_PTR(env)->SetIntField(JNI_ENV_ARG(env, obj), + watches[13].fid, watches[13].val.i); + JNI_ENV_PTR(env)->SetLongField(JNI_ENV_ARG(env, obj), + watches[14].fid, watches[14].val.j); + JNI_ENV_PTR(env)->SetFloatField(JNI_ENV_ARG(env, obj), + watches[15].fid, watches[15].val.f); + JNI_ENV_PTR(env)->SetDoubleField(JNI_ENV_ARG(env, obj), + watches[16].fid, watches[16].val.d); + JNI_ENV_PTR(env)->SetCharField(JNI_ENV_ARG(env, obj), + watches[17].fid, watches[17].val.c); + JNI_ENV_PTR(env)->SetObjectField(JNI_ENV_ARG(env, obj), + watches[18].fid, watches[18].val.l); + JNI_ENV_PTR(env)->SetObjectField(JNI_ENV_ARG(env, obj), + watches[19].fid, watches[19].val.l); + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + if (eventsCount != eventsExpected) { + printf("Wrong number of field modification events: %d, expected: %d\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/libfieldmod002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/libfieldmod002.c deleted file mode 100644 index ee99546bccd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/libfieldmod002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "fieldmod002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/libfieldmod002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/libfieldmod002.cpp new file mode 100644 index 00000000000..4c500c25a73 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FieldModification/fieldmod002/libfieldmod002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "fieldmod002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/ForceEarlyReturn001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/ForceEarlyReturn001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/ForceEarlyReturn001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/ForceEarlyReturn001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/libForceEarlyReturn001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/libForceEarlyReturn001.c deleted file mode 100644 index a9144ca2186..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/libForceEarlyReturn001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ForceEarlyReturn001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/libForceEarlyReturn001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/libForceEarlyReturn001.cpp new file mode 100644 index 00000000000..a9290006fc6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/libForceEarlyReturn001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ForceEarlyReturn001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/forcegc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/forcegc001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/forcegc001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/forcegc001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/libforcegc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/libforcegc001.c deleted file mode 100644 index 5cb40a56991..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/libforcegc001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "forcegc001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/libforcegc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/libforcegc001.cpp new file mode 100644 index 00000000000..a57c9dff952 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/libforcegc001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "forcegc001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/forcegc002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/forcegc002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/forcegc002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/forcegc002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/libforcegc002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/libforcegc002.c deleted file mode 100644 index 16101e912f3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/libforcegc002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "forcegc002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/libforcegc002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/libforcegc002.cpp new file mode 100644 index 00000000000..946eae3f250 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/libforcegc002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "forcegc002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/framepop001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/framepop001.c deleted file mode 100644 index 635a12b7555..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/framepop001.c +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls_sig; - char *name; - char *sig; - jlocation loc; -} pop_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static size_t eventsExpected = 0; -static size_t eventsCount = 0; -static pop_info pops[] = { - {"Lnsk/jvmti/FramePop/framepop001;", "chain", "()V", 0}, - {"Lnsk/jvmti/FramePop/framepop001a;", "dummy", "()V", 3}, -}; - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - jvmtiError err; - - err = (*jvmti_env)->NotifyFramePop(jvmti_env, thr, 0); - if (err == JVMTI_ERROR_NONE) { - eventsExpected++; - } else { - printf("(NotifyFramePop#0) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->NotifyFramePop(jvmti_env, thr, 1); - if (err == JVMTI_ERROR_NONE) { - eventsExpected++; - } else { - printf("(NotifyFramePop#1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jboolean wasPopedByException) { - jvmtiError err; - char *cls_sig, *name, *sig, *generic; - jclass cls; - jmethodID mid; - jlocation loc; - - if (printdump == JNI_TRUE) { - printf(">>> retrieving frame pop info ...\n"); - } - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &cls_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, method, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thr, 0, &mid, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", cls_sig); - printf(">>> method: \"%s%s\"\n", name, sig); - printf(">>> location: 0x%x%08x\n", - (jint)(loc >> 32), (jint)loc); - printf(">>> ... done\n"); - } - if (eventsCount < sizeof(pops)/sizeof(pop_info)) { - if (cls_sig == NULL || - strcmp(cls_sig, pops[eventsCount].cls_sig) != 0) { - printf("(pop#%" PRIuPTR ") wrong class: \"%s\"", - eventsCount, cls_sig); - printf(", expected: \"%s\"\n", pops[eventsCount].cls_sig); - result = STATUS_FAILED; - } - if (name == NULL || - strcmp(name, pops[eventsCount].name) != 0) { - printf("(pop#%" PRIuPTR ") wrong method name: \"%s\"", - eventsCount, name); - printf(", expected: \"%s\"\n", pops[eventsCount].name); - result = STATUS_FAILED; - } - if (sig == NULL || - strcmp(sig, pops[eventsCount].sig) != 0) { - printf("(pop#%" PRIuPTR ") wrong method sig: \"%s\"", - eventsCount, sig); - printf(", expected: \"%s\"\n", pops[eventsCount].sig); - result = STATUS_FAILED; - } - if (loc != pops[eventsCount].loc) { - printf("(pop#%" PRIuPTR ") wrong location: 0x%x%08x", - eventsCount, (jint)(loc >> 32), (jint)loc); - printf(", expected: 0x%x\n", (jint)pops[eventsCount].loc); - result = STATUS_FAILED; - } - } else { - printf("Unexpected frame pop catched:"); - printf(" class: \"%s\"\n", cls_sig); - printf(" method: \"%s%s\"\n", name, sig); - printf(" location: 0x%x%08x\n", (jint)(loc >> 32), (jint)loc); - result = STATUS_FAILED; - } - eventsCount++; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_framepop001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_framepop001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_framepop001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_frame_pop_events && - caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - callbacks.FramePop = &FramePop; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FramePop or Breakpoint event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_FramePop_framepop001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jclass clz; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_generate_frame_pop_events || - !caps.can_generate_breakpoint_events) { - return result; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "chain", "()V"); - if (mid == 0) { - printf("Cannot find Method ID for method chain\n"); - return STATUS_FAILED; - } - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to SetBreakpoint: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FRAME_POP, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/FramePop/framepop001a")); - if (clz == NULL) { - printf("Cannot find framepop001a class!\n"); - result = STATUS_FAILED; - return STATUS_FAILED; - } - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clz), - "dummy", "()V"); - if (mid == 0) { - printf("Cannot find Method ID for method dummy\n"); - return STATUS_FAILED; - } - JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, clz), mid); - - if (eventsCount != eventsExpected) { - printf("Wrong number of frame pop events: %" PRIuPTR ", expected: %" PRIuPTR "\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/framepop001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/framepop001.cpp new file mode 100644 index 00000000000..7cdcd237deb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/framepop001.cpp @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls_sig; + const char *name; + const char *sig; + jlocation loc; +} pop_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static size_t eventsExpected = 0; +static size_t eventsCount = 0; +static pop_info pops[] = { + {"Lnsk/jvmti/FramePop/framepop001;", "chain", "()V", 0}, + {"Lnsk/jvmti/FramePop/framepop001a;", "dummy", "()V", 3}, +}; + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + jvmtiError err; + + err = jvmti_env->NotifyFramePop(thr, 0); + if (err == JVMTI_ERROR_NONE) { + eventsExpected++; + } else { + printf("(NotifyFramePop#0) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->NotifyFramePop(thr, 1); + if (err == JVMTI_ERROR_NONE) { + eventsExpected++; + } else { + printf("(NotifyFramePop#1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jboolean wasPopedByException) { + jvmtiError err; + char *cls_sig, *name, *sig, *generic; + jclass cls; + jmethodID mid; + jlocation loc; + + if (printdump == JNI_TRUE) { + printf(">>> retrieving frame pop info ...\n"); + } + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, &cls_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetMethodName(method, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetFrameLocation(thr, 0, &mid, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", cls_sig); + printf(">>> method: \"%s%s\"\n", name, sig); + printf(">>> location: 0x%x%08x\n", + (jint)(loc >> 32), (jint)loc); + printf(">>> ... done\n"); + } + if (eventsCount < sizeof(pops)/sizeof(pop_info)) { + if (cls_sig == NULL || + strcmp(cls_sig, pops[eventsCount].cls_sig) != 0) { + printf("(pop#%" PRIuPTR ") wrong class: \"%s\"", + eventsCount, cls_sig); + printf(", expected: \"%s\"\n", pops[eventsCount].cls_sig); + result = STATUS_FAILED; + } + if (name == NULL || + strcmp(name, pops[eventsCount].name) != 0) { + printf("(pop#%" PRIuPTR ") wrong method name: \"%s\"", + eventsCount, name); + printf(", expected: \"%s\"\n", pops[eventsCount].name); + result = STATUS_FAILED; + } + if (sig == NULL || + strcmp(sig, pops[eventsCount].sig) != 0) { + printf("(pop#%" PRIuPTR ") wrong method sig: \"%s\"", + eventsCount, sig); + printf(", expected: \"%s\"\n", pops[eventsCount].sig); + result = STATUS_FAILED; + } + if (loc != pops[eventsCount].loc) { + printf("(pop#%" PRIuPTR ") wrong location: 0x%x%08x", + eventsCount, (jint)(loc >> 32), (jint)loc); + printf(", expected: 0x%x\n", (jint)pops[eventsCount].loc); + result = STATUS_FAILED; + } + } else { + printf("Unexpected frame pop catched:"); + printf(" class: \"%s\"\n", cls_sig); + printf(" method: \"%s%s\"\n", name, sig); + printf(" location: 0x%x%08x\n", (jint)(loc >> 32), (jint)loc); + result = STATUS_FAILED; + } + eventsCount++; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_framepop001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_framepop001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_framepop001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_frame_pop_events && + caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + callbacks.FramePop = &FramePop; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FramePop or Breakpoint event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_FramePop_framepop001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jclass clz; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_generate_frame_pop_events || + !caps.can_generate_breakpoint_events) { + return result; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "chain", "()V"); + if (mid == 0) { + printf("Cannot find Method ID for method chain\n"); + return STATUS_FAILED; + } + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to SetBreakpoint: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FRAME_POP, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/FramePop/framepop001a")); + if (clz == NULL) { + printf("Cannot find framepop001a class!\n"); + result = STATUS_FAILED; + return STATUS_FAILED; + } + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clz), + "dummy", "()V"); + if (mid == 0) { + printf("Cannot find Method ID for method dummy\n"); + return STATUS_FAILED; + } + JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, clz), mid); + + if (eventsCount != eventsExpected) { + printf("Wrong number of frame pop events: %" PRIuPTR ", expected: %" PRIuPTR "\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/libframepop001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/libframepop001.c deleted file mode 100644 index 79b0ce7d280..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/libframepop001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "framepop001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/libframepop001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/libframepop001.cpp new file mode 100644 index 00000000000..fd538ae0aa0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/libframepop001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "framepop001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/framepop002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/framepop002.c deleted file mode 100644 index bc89e9cd417..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/framepop002.c +++ /dev/null @@ -1,441 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define MAX_THREADS 32 - -typedef struct item *item_t; -struct item { - item_t next; - jmethodID method; - int depth; -} item; - -typedef struct thr { - jthread thread; - item_t tos; -} thr; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jrawMonitorID event_lock; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jboolean watch_events = JNI_FALSE; - -static int pop_count = 0; -static int push_count = 0; -static int thr_count = 0; -static int max_depth = 0; -static thr threads[MAX_THREADS]; - -static -int isTestThread(jvmtiEnv *jvmti_env, jthread thr) { - jvmtiError err; - jvmtiThreadInfo inf; - const char* TEST_THREAD_NAME_BASE = "Test Thread"; - - err = (*jvmti_env)->GetThreadInfo(jvmti_env, thr, &inf); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo) unexpected error: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - return 0; - } - return strncmp(inf.name, TEST_THREAD_NAME_BASE, strlen(TEST_THREAD_NAME_BASE)) == 0; -} - -static -void printInfo(jvmtiEnv *jvmti_env, jthread thr, jmethodID method, int depth) { - jvmtiError err; - jvmtiThreadInfo inf; - char *clsig, *name, *sig, *generic; - jclass cls; - - err = (*jvmti_env)->GetThreadInfo(jvmti_env, thr, &inf); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &clsig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetMethodName(jvmti_env, method, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - printf(" %s: %s.%s%s, depth = %d\n", inf.name, clsig, name, sig, depth); - - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)sig); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)name); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)clsig); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)inf.name); -} - -static -void pop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jmethodID method, int depth) { - item_t old; - int i, count = 0; - - for (i = 0; i < thr_count; i++) { - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, threads[i].thread), - thr) == JNI_TRUE) { - break; - } - } - - if (i == thr_count) { - watch_events = JNI_FALSE; - printf("Unknown thread:\n"); - printInfo(jvmti_env, thr, method, depth); - result = STATUS_FAILED; - return; - } - - if (threads[i].tos == NULL) { - watch_events = JNI_FALSE; - printf("Stack underflow:\n"); - printInfo(jvmti_env, thr, method, depth); - result = STATUS_FAILED; - return; - } - - do { - pop_count++; - old = threads[i].tos; - threads[i].tos = threads[i].tos->next; - if (old->method == method && old->depth == depth) { - free(old); - return; - } - free(old); - } while (threads[i].tos != NULL); - - watch_events = JNI_FALSE; - printf("Frame pop does not match any entry:\n"); - printInfo(jvmti_env, thr, method, depth); - result = STATUS_FAILED; -} - -static -void push(JNIEnv *env, jthread thr, jmethodID method, int depth) { - item_t new; - int i; - - for (i = 0; i < thr_count; i++) { - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, threads[i].thread), - thr) == JNI_TRUE) { - break; - } - } - - if (i == thr_count) { - thr_count++; - if (thr_count == MAX_THREADS) { - watch_events = JNI_FALSE; - printf("Out of threads\n"); - result = STATUS_FAILED; - return; - } - threads[i].thread = (*env)->NewGlobalRef(env, thr); - threads[i].tos = NULL; - } - - new = (item_t)malloc(sizeof(item)); - if (new == NULL) { - watch_events = JNI_FALSE; - printf("Out of memory\n"); - result = STATUS_FAILED; - return; - } - - new->next = threads[i].tos; - new->method = method; - new->depth = depth; - threads[i].tos = new; - push_count++; - max_depth = (max_depth < depth) ? depth: max_depth; -} - -void JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method) { - jvmtiError err; - jboolean isNative; - jint frameCount; - - if (watch_events == JNI_FALSE) return; - - err = (*jvmti_env)->GetFrameCount(jvmti_env, thr, &frameCount); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameCount#entry) unexpected error: %s (%d)\n", - TranslateError(err), err); - printInfo(jvmti_env, thr, method, frameCount); - result = STATUS_FAILED; - return; - } - - err = (*jvmti_env)->IsMethodNative(jvmti_env, method, &isNative); - if (err != JVMTI_ERROR_NONE) { - printf("(IsMethodNative) unexpected error: %s (%d)\n", - TranslateError(err), err); - printInfo(jvmti_env, thr, method, frameCount); - result = STATUS_FAILED; - } - - if (isTestThread(jvmti_env, thr)) { - if (printdump == JNI_TRUE) { - printf(">>> %sMethod entry\n>>>", - (isNative == JNI_TRUE) ? "Native " : ""); - printInfo(jvmti_env, thr, method, frameCount); - } - if (isNative == JNI_FALSE) { - err = (*jvmti_env)->RawMonitorEnter(jvmti_env, event_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - printInfo(jvmti_env, thr, method, frameCount); - result = STATUS_FAILED; - } - push((JNIEnv *)env, thr, method, frameCount); - err = (*jvmti_env)->RawMonitorExit(jvmti_env, event_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - printInfo(jvmti_env, thr, method, frameCount); - result = STATUS_FAILED; - } - err = (*jvmti_env)->NotifyFramePop(jvmti_env, thr, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(NotifyFramePop) unexpected error: %s (%d)\n", - TranslateError(err), err); - printInfo(jvmti_env, thr, method, frameCount); - result = STATUS_FAILED; - } - } - } -} - -void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jboolean wasPopedByException) { - jvmtiError err; - int frameCount; - - err = (*jvmti_env)->GetFrameCount(jvmti_env, thr, &frameCount); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameCount#entry) unexpected error: %s (%d)\n", - TranslateError(err), err); - printInfo(jvmti_env, thr, method, frameCount); - result = STATUS_FAILED; - return; - } - - if (isTestThread(jvmti_env, thr)) { - if (printdump == JNI_TRUE) { - printf(">>> Frame Pop\n>>>"); - printInfo(jvmti_env, thr, method, frameCount); - } - err = (*jvmti_env)->RawMonitorEnter(jvmti_env, event_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - printInfo(jvmti_env, thr, method, frameCount); - result = STATUS_FAILED; - } - pop(jvmti_env, (JNIEnv *)env, thr, method, frameCount); - err = (*jvmti_env)->RawMonitorExit(jvmti_env, event_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - printInfo(jvmti_env, thr, method, frameCount); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_framepop002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_framepop002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_framepop002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "_event_lock", &event_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_frame_pop_events && - caps.can_generate_method_entry_events) { - callbacks.MethodEntry = &MethodEntry; - callbacks.FramePop = &FramePop; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FramePop or MethodEntry event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_FramePop_framepop002_getReady(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (!caps.can_generate_frame_pop_events || - !caps.can_generate_method_entry_events) { - return ; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_ENTRY, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FRAME_POP, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - watch_events = JNI_TRUE; -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_FramePop_framepop002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - watch_events = JNI_FALSE; - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_FRAME_POP, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_ENTRY, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf("%d threads, %d method entrys, %d frame pops, max depth = %d\n", - thr_count, push_count, pop_count, max_depth); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/framepop002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/framepop002.cpp new file mode 100644 index 00000000000..a4f74e64a59 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/framepop002.cpp @@ -0,0 +1,441 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define MAX_THREADS 32 + +typedef struct item *item_t; +struct item { + item_t next; + jmethodID method; + int depth; +} item; + +typedef struct thr { + jthread thread; + item_t tos; +} thr; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jrawMonitorID event_lock; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jboolean watch_events = JNI_FALSE; + +static int pop_count = 0; +static int push_count = 0; +static int thr_count = 0; +static int max_depth = 0; +static thr threads[MAX_THREADS]; + +static +int isTestThread(jvmtiEnv *jvmti_env, jthread thr) { + jvmtiError err; + jvmtiThreadInfo inf; + const char* TEST_THREAD_NAME_BASE = "Test Thread"; + + err = jvmti_env->GetThreadInfo(thr, &inf); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo) unexpected error: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + return 0; + } + return strncmp(inf.name, TEST_THREAD_NAME_BASE, strlen(TEST_THREAD_NAME_BASE)) == 0; +} + +static +void printInfo(jvmtiEnv *jvmti_env, jthread thr, jmethodID method, int depth) { + jvmtiError err; + jvmtiThreadInfo inf; + char *clsig, *name, *sig, *generic; + jclass cls; + + err = jvmti_env->GetThreadInfo(thr, &inf); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetClassSignature(cls, &clsig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetMethodName(method, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + printf(" %s: %s.%s%s, depth = %d\n", inf.name, clsig, name, sig, depth); + + jvmti_env->Deallocate((unsigned char *)sig); + jvmti_env->Deallocate((unsigned char *)name); + jvmti_env->Deallocate((unsigned char *)clsig); + jvmti_env->Deallocate((unsigned char *)inf.name); +} + +static +void pop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jmethodID method, int depth) { + item_t old; + int i, count = 0; + + for (i = 0; i < thr_count; i++) { + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, threads[i].thread), + thr) == JNI_TRUE) { + break; + } + } + + if (i == thr_count) { + watch_events = JNI_FALSE; + printf("Unknown thread:\n"); + printInfo(jvmti_env, thr, method, depth); + result = STATUS_FAILED; + return; + } + + if (threads[i].tos == NULL) { + watch_events = JNI_FALSE; + printf("Stack underflow:\n"); + printInfo(jvmti_env, thr, method, depth); + result = STATUS_FAILED; + return; + } + + do { + pop_count++; + old = threads[i].tos; + threads[i].tos = threads[i].tos->next; + if (old->method == method && old->depth == depth) { + free(old); + return; + } + free(old); + } while (threads[i].tos != NULL); + + watch_events = JNI_FALSE; + printf("Frame pop does not match any entry:\n"); + printInfo(jvmti_env, thr, method, depth); + result = STATUS_FAILED; +} + +static +void push(JNIEnv *env, jthread thr, jmethodID method, int depth) { + item_t new_item; + int i; + + for (i = 0; i < thr_count; i++) { + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, threads[i].thread), + thr) == JNI_TRUE) { + break; + } + } + + if (i == thr_count) { + thr_count++; + if (thr_count == MAX_THREADS) { + watch_events = JNI_FALSE; + printf("Out of threads\n"); + result = STATUS_FAILED; + return; + } + threads[i].thread = env->NewGlobalRef(thr); + threads[i].tos = NULL; + } + + new_item = (item_t)malloc(sizeof(item)); + if (new_item == NULL) { + watch_events = JNI_FALSE; + printf("Out of memory\n"); + result = STATUS_FAILED; + return; + } + + new_item->next = threads[i].tos; + new_item->method = method; + new_item->depth = depth; + threads[i].tos = new_item; + push_count++; + max_depth = (max_depth < depth) ? depth: max_depth; +} + +void JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method) { + jvmtiError err; + jboolean isNative; + jint frameCount; + + if (watch_events == JNI_FALSE) return; + + err = jvmti_env->GetFrameCount(thr, &frameCount); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameCount#entry) unexpected error: %s (%d)\n", + TranslateError(err), err); + printInfo(jvmti_env, thr, method, frameCount); + result = STATUS_FAILED; + return; + } + + err = jvmti_env->IsMethodNative(method, &isNative); + if (err != JVMTI_ERROR_NONE) { + printf("(IsMethodNative) unexpected error: %s (%d)\n", + TranslateError(err), err); + printInfo(jvmti_env, thr, method, frameCount); + result = STATUS_FAILED; + } + + if (isTestThread(jvmti_env, thr)) { + if (printdump == JNI_TRUE) { + printf(">>> %sMethod entry\n>>>", + (isNative == JNI_TRUE) ? "Native " : ""); + printInfo(jvmti_env, thr, method, frameCount); + } + if (isNative == JNI_FALSE) { + err = jvmti_env->RawMonitorEnter(event_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + printInfo(jvmti_env, thr, method, frameCount); + result = STATUS_FAILED; + } + push((JNIEnv *)env, thr, method, frameCount); + err = jvmti_env->RawMonitorExit(event_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + printInfo(jvmti_env, thr, method, frameCount); + result = STATUS_FAILED; + } + err = jvmti_env->NotifyFramePop(thr, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(NotifyFramePop) unexpected error: %s (%d)\n", + TranslateError(err), err); + printInfo(jvmti_env, thr, method, frameCount); + result = STATUS_FAILED; + } + } + } +} + +void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jboolean wasPopedByException) { + jvmtiError err; + jint frameCount; + + err = jvmti_env->GetFrameCount(thr, &frameCount); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameCount#entry) unexpected error: %s (%d)\n", + TranslateError(err), err); + printInfo(jvmti_env, thr, method, frameCount); + result = STATUS_FAILED; + return; + } + + if (isTestThread(jvmti_env, thr)) { + if (printdump == JNI_TRUE) { + printf(">>> Frame Pop\n>>>"); + printInfo(jvmti_env, thr, method, frameCount); + } + err = jvmti_env->RawMonitorEnter(event_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + printInfo(jvmti_env, thr, method, frameCount); + result = STATUS_FAILED; + } + pop(jvmti_env, (JNIEnv *)env, thr, method, frameCount); + err = jvmti_env->RawMonitorExit(event_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + printInfo(jvmti_env, thr, method, frameCount); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_framepop002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_framepop002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_framepop002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->CreateRawMonitor("_event_lock", &event_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_frame_pop_events && + caps.can_generate_method_entry_events) { + callbacks.MethodEntry = &MethodEntry; + callbacks.FramePop = &FramePop; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FramePop or MethodEntry event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_FramePop_framepop002_getReady(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (!caps.can_generate_frame_pop_events || + !caps.can_generate_method_entry_events) { + return ; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_ENTRY, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FRAME_POP, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + watch_events = JNI_TRUE; +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_FramePop_framepop002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + watch_events = JNI_FALSE; + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_FRAME_POP, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_ENTRY, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf("%d threads, %d method entrys, %d frame pops, max depth = %d\n", + thr_count, push_count, pop_count, max_depth); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/libframepop002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/libframepop002.c deleted file mode 100644 index 32a66371345..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/libframepop002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "framepop002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/libframepop002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/libframepop002.cpp new file mode 100644 index 00000000000..16e157267f5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop002/libframepop002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "framepop002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/gcfinish001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/gcfinish001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/gcfinish001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/gcfinish001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/libgcfinish001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/libgcfinish001.c deleted file mode 100644 index 229cf00cfaa..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/libgcfinish001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "gcfinish001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/libgcfinish001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/libgcfinish001.cpp new file mode 100644 index 00000000000..3f869e3568f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionFinish/gcfinish001/libgcfinish001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "gcfinish001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/gcstart001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/gcstart001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/gcstart001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/gcstart001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/libgcstart001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/libgcstart001.c deleted file mode 100644 index 6fc096ceaed..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/libgcstart001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "gcstart001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/libgcstart001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/libgcstart001.cpp new file mode 100644 index 00000000000..486691c9278 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/libgcstart001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "gcstart001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/gcstart002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/gcstart002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/gcstart002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/gcstart002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/libgcstart002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/libgcstart002.c deleted file mode 100644 index c4ac5d7e4db..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/libgcstart002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "gcstart002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/libgcstart002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/libgcstart002.cpp new file mode 100644 index 00000000000..7e0243ee523 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart002/libgcstart002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "gcstart002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/genevents001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/genevents001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/genevents001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/genevents001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/libgenevents001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/libgenevents001.c deleted file mode 100644 index 2e00e7ee5c7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/libgenevents001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "genevents001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/libgenevents001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/libgenevents001.cpp new file mode 100644 index 00000000000..e81e5392be8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GenerateEvents/genevents001/libgenevents001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "genevents001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/allthr001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/allthr001.c deleted file mode 100644 index 5081d5aaca1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/allthr001.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - int cnt; - char **thrNames; -} info; - -static jvmtiEnv *jvmti; -static jrawMonitorID lock1; -static jrawMonitorID lock2; -static jboolean printdump = JNI_FALSE; -static jint result = PASSED; -static jvmtiThreadInfo inf; -static int sys_cnt; -static char *names0[] = {"main"}; -static char *names1[] = {"main", "thread1"}; -static char *names2[] = {"main", "Thread-"}; -static info thrInfo[] = { - {1, names0}, {1, names0}, {2, names1}, {1, names0}, {2, names2} -}; - -jthread jthr(JNIEnv *env) { - jclass thrClass; - jmethodID cid; - jthread res; - thrClass = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "java/lang/Thread")); - cid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, thrClass), - "", "()V"); - res = JNI_ENV_PTR(env)->NewObject(JNI_ENV_ARG(env, thrClass), cid); - return res; -} - -static void JNICALL -sys_thread(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { - jvmtiError err; - - err = (*jvmti)->RawMonitorEnter(jvmti, lock2); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enter raw monitor 2 (thread): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - /* allows the main thread to wait until the child thread is running */ - err = (*jvmti)->RawMonitorEnter(jvmti, lock1); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enter raw monitor 1 (thread): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorNotify(jvmti, lock1); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to notify raw monitor (thread): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorExit(jvmti, lock1); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to exit raw monitor 1 (thread): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - /* keeps the child thread from exiting */ - err = (*jvmti)->RawMonitorWait(jvmti, lock2, (jlong)0); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to wait raw monitor (thread): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorExit(jvmti, lock2); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to exit raw monitor 2 (thread): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_allthr001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_allthr001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_allthr001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "_lock1", &lock1); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to create raw monitor 1, err = %d\n", err); - return JNI_ERR; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "_lock2", &lock2); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to create raw monitor 2, err = %d\n", err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void checkInfo(JNIEnv *env, int ind) { - jint threadsCount = -1; - jthread *threads; - int i, j, found; - jvmtiError err; - int num_unexpected = 0; - - if (printdump == JNI_TRUE) { - printf(" >>> Check: %d\n", ind); - } - - if (ind == 4) { - err = (*jvmti)->RawMonitorEnter(jvmti, lock1); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enter raw monitor (check): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RunAgentThread(jvmti, jthr(env), sys_thread, NULL, - JVMTI_THREAD_NORM_PRIORITY); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to start agent thread: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorWait(jvmti, lock1, (jlong)0); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to wait raw monitor (check): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorExit(jvmti, lock1); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to exit raw monitor (check): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - - err = (*jvmti)->GetAllThreads(jvmti, &threadsCount, &threads); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to get all threads (check): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - for (i = 0; i < threadsCount; i++) { - if (!isThreadExpected(jvmti, threads[i])) { - num_unexpected++; - } - } - - if (threadsCount - num_unexpected != thrInfo[ind].cnt + sys_cnt) { - printf("Point %d: number of threads expected: %d, got: %d\n", - ind, thrInfo[ind].cnt + sys_cnt, threadsCount - num_unexpected); - result = STATUS_FAILED; - } - - for (i = 0; i < thrInfo[ind].cnt; i++) { - for (j = 0, found = 0; j < threadsCount && !found; j++) { - err = (*jvmti)->GetThreadInfo(jvmti, threads[j], &inf); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to get thread info: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(" >>> %s", inf.name); - } - found = (inf.name != NULL && - strstr(inf.name, thrInfo[ind].thrNames[i]) == inf.name && - (ind == 4 || strlen(inf.name) == - strlen(thrInfo[ind].thrNames[i]))); - } - if (printdump == JNI_TRUE) { - printf("\n"); - } - if (!found) { - printf("Point %d: thread %s not detected\n", - ind, thrInfo[ind].thrNames[i]); - result = STATUS_FAILED; - } - } - - err = (*jvmti)->Deallocate(jvmti, (unsigned char *)threads); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to deallocate array: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (ind == 4) { - err = (*jvmti)->RawMonitorEnter(jvmti, lock2); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enter raw monitor (check): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorNotify(jvmti, lock2); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to notify raw monitor (check): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorExit(jvmti, lock2); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to exit raw monitor (check): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_GetAllThreads_allthr001_setSysCnt(JNIEnv *env, jclass cls) { - jint threadsCount = -1; - jthread *threads; - jvmtiError err; - int i; - - err = (*jvmti)->GetAllThreads(jvmti, &threadsCount, &threads); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to get all threads (count): %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - sys_cnt = threadsCount - 1; - - for (i = 0; i < threadsCount; i++) { - if (!isThreadExpected(jvmti, threads[i])) { - sys_cnt--; - } - } - - if (printdump == JNI_TRUE) { - printf(" >>> number of system threads: %d\n", sys_cnt); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetAllThreads_allthr001_checkInfo(JNIEnv *env, jclass cls, jint ind) { - checkInfo(env, ind); -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_GetAllThreads_allthr001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/allthr001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/allthr001.cpp new file mode 100644 index 00000000000..e27d4b1e5f2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/allthr001.cpp @@ -0,0 +1,318 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + int cnt; + const char **thrNames; +} info; + +static jvmtiEnv *jvmti; +static jrawMonitorID lock1; +static jrawMonitorID lock2; +static jboolean printdump = JNI_FALSE; +static jint result = PASSED; +static jvmtiThreadInfo inf; +static int sys_cnt; +static const char *names0[] = {"main"}; +static const char *names1[] = {"main", "thread1"}; +static const char *names2[] = {"main", "Thread-"}; +static info thrInfo[] = { + {1, names0}, {1, names0}, {2, names1}, {1, names0}, {2, names2} +}; + +jthread jthr(JNIEnv *env) { + jclass thrClass; + jmethodID cid; + jthread res; + thrClass = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "java/lang/Thread")); + cid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, thrClass), + "", "()V"); + res = JNI_ENV_PTR(env)->NewObject(JNI_ENV_ARG(env, thrClass), cid); + return res; +} + +static void JNICALL +sys_thread(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { + jvmtiError err; + + err = jvmti->RawMonitorEnter(lock2); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enter raw monitor 2 (thread): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + /* allows the main thread to wait until the child thread is running */ + err = jvmti->RawMonitorEnter(lock1); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enter raw monitor 1 (thread): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorNotify(lock1); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to notify raw monitor (thread): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorExit(lock1); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to exit raw monitor 1 (thread): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + /* keeps the child thread from exiting */ + err = jvmti->RawMonitorWait(lock2, (jlong)0); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to wait raw monitor (thread): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorExit(lock2); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to exit raw monitor 2 (thread): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_allthr001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_allthr001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_allthr001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->CreateRawMonitor("_lock1", &lock1); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to create raw monitor 1, err = %d\n", err); + return JNI_ERR; + } + + err = jvmti->CreateRawMonitor("_lock2", &lock2); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to create raw monitor 2, err = %d\n", err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void checkInfo(JNIEnv *env, int ind) { + jint threadsCount = -1; + jthread *threads; + int i, j, found; + jvmtiError err; + int num_unexpected = 0; + + if (printdump == JNI_TRUE) { + printf(" >>> Check: %d\n", ind); + } + + if (ind == 4) { + err = jvmti->RawMonitorEnter(lock1); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enter raw monitor (check): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RunAgentThread(jthr(env), sys_thread, NULL, + JVMTI_THREAD_NORM_PRIORITY); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to start agent thread: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorWait(lock1, (jlong)0); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to wait raw monitor (check): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorExit(lock1); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to exit raw monitor (check): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + + err = jvmti->GetAllThreads(&threadsCount, &threads); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to get all threads (check): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + for (i = 0; i < threadsCount; i++) { + if (!isThreadExpected(jvmti, threads[i])) { + num_unexpected++; + } + } + + if (threadsCount - num_unexpected != thrInfo[ind].cnt + sys_cnt) { + printf("Point %d: number of threads expected: %d, got: %d\n", + ind, thrInfo[ind].cnt + sys_cnt, threadsCount - num_unexpected); + result = STATUS_FAILED; + } + + for (i = 0; i < thrInfo[ind].cnt; i++) { + for (j = 0, found = 0; j < threadsCount && !found; j++) { + err = jvmti->GetThreadInfo(threads[j], &inf); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to get thread info: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(" >>> %s", inf.name); + } + found = (inf.name != NULL && + strstr(inf.name, thrInfo[ind].thrNames[i]) == inf.name && + (ind == 4 || strlen(inf.name) == + strlen(thrInfo[ind].thrNames[i]))); + } + if (printdump == JNI_TRUE) { + printf("\n"); + } + if (!found) { + printf("Point %d: thread %s not detected\n", + ind, thrInfo[ind].thrNames[i]); + result = STATUS_FAILED; + } + } + + err = jvmti->Deallocate((unsigned char *)threads); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to deallocate array: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (ind == 4) { + err = jvmti->RawMonitorEnter(lock2); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enter raw monitor (check): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorNotify(lock2); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to notify raw monitor (check): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorExit(lock2); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to exit raw monitor (check): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_GetAllThreads_allthr001_setSysCnt(JNIEnv *env, jclass cls) { + jint threadsCount = -1; + jthread *threads; + jvmtiError err; + int i; + + err = jvmti->GetAllThreads(&threadsCount, &threads); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to get all threads (count): %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + sys_cnt = threadsCount - 1; + + for (i = 0; i < threadsCount; i++) { + if (!isThreadExpected(jvmti, threads[i])) { + sys_cnt--; + } + } + + if (printdump == JNI_TRUE) { + printf(" >>> number of system threads: %d\n", sys_cnt); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetAllThreads_allthr001_checkInfo(JNIEnv *env, jclass cls, jint ind) { + checkInfo(env, ind); +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_GetAllThreads_allthr001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/liballthr001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/liballthr001.c deleted file mode 100644 index 9e5abcd7804..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/liballthr001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "allthr001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/liballthr001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/liballthr001.cpp new file mode 100644 index 00000000000..7b521d9e3ed --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001/liballthr001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "allthr001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/allthr002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/allthr002.c deleted file mode 100644 index daae918d35d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/allthr002.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_allthr002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_allthr002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_allthr002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetAllThreads_allthr002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jint threadsCountPtr; - jthread *threadsPtr; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (threadsCountPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetAllThreads(jvmti, NULL, &threadsPtr); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(threadsCountPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (threadsPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetAllThreads(jvmti, &threadsCountPtr, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(threadsPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/allthr002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/allthr002.cpp new file mode 100644 index 00000000000..c40bd811e97 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/allthr002.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_allthr002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_allthr002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_allthr002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetAllThreads_allthr002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jint threadsCountPtr; + jthread *threadsPtr; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (threadsCountPtr) null pointer check ...\n"); + } + err = jvmti->GetAllThreads(NULL, &threadsPtr); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(threadsCountPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (threadsPtr) null pointer check ...\n"); + } + err = jvmti->GetAllThreads(&threadsCountPtr, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(threadsPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/liballthr002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/liballthr002.c deleted file mode 100644 index f96743f05d5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/liballthr002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "allthr002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/liballthr002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/liballthr002.cpp new file mode 100644 index 00000000000..5992cf36781 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr002/liballthr002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "allthr002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/argsize001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/argsize001.c deleted file mode 100644 index 0b2cf2e96ae..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/argsize001.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; - -void chk(JNIEnv *env, jclass cl, char *name, char *sig, int stat, int size) { - jvmtiError err; - jmethodID mid = NULL; - jint ret_size; - - if (stat) { - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), - name, sig); - } else { - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); - } - if (mid == NULL) { - printf("Name = %s, sig = %s: mid = 0\n", name, sig); - } - err = (*jvmti)->GetArgumentsSize(jvmti, mid, &ret_size); - if (err != JVMTI_ERROR_NONE) { - printf("(GetArgumentsSize) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (ret_size != size) { - result = STATUS_FAILED; - printf("Name = %s, sig = %s: arg size expected: %d, got: %d\n", - name, sig, size, ret_size); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_argsize001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_argsize001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_argsize001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetArgumentsSize_argsize001_check(JNIEnv *env, jclass cls, - jclass klass1, jclass klass2) { - chk(env, cls, "", "()V", 0, 1); - chk(env, cls, "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I", 1, 2); - chk(env, cls, "meth_stat", "(ILjava/lang/String;)[F", 1, 2); - chk(env, cls, "meth_1", "(CCC)C", 0, 4); - chk(env, cls, "meth_2", "(FDJ)F", 0, 6); - chk(env, klass1, "meth_new", - "(Lnsk/jvmti/GetArgumentsSize/argsize001;Lnsk/jvmti/GetArgumentsSize/argsize001;)Lnsk/jvmti/GetArgumentsSize/argsize001;", 0, 3); - chk(env, klass1, "meth_abs", "()V", 0, 1); - chk(env, klass2, "meth_inn", "(Ljava/lang/String;J)V", 0, 4); - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/argsize001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/argsize001.cpp new file mode 100644 index 00000000000..a653dc98cc4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/argsize001.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; + +void chk(JNIEnv *env, jclass cl, const char *name, const char *sig, int stat, int size) { + jvmtiError err; + jmethodID mid = NULL; + jint ret_size; + + if (stat) { + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), + name, sig); + } else { + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); + } + if (mid == NULL) { + printf("Name = %s, sig = %s: mid = 0\n", name, sig); + } + err = jvmti->GetArgumentsSize(mid, &ret_size); + if (err != JVMTI_ERROR_NONE) { + printf("(GetArgumentsSize) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (ret_size != size) { + result = STATUS_FAILED; + printf("Name = %s, sig = %s: arg size expected: %d, got: %d\n", + name, sig, size, ret_size); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_argsize001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_argsize001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_argsize001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetArgumentsSize_argsize001_check(JNIEnv *env, jclass cls, + jclass klass1, jclass klass2) { + chk(env, cls, "", "()V", 0, 1); + chk(env, cls, "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I", 1, 2); + chk(env, cls, "meth_stat", "(ILjava/lang/String;)[F", 1, 2); + chk(env, cls, "meth_1", "(CCC)C", 0, 4); + chk(env, cls, "meth_2", "(FDJ)F", 0, 6); + chk(env, klass1, "meth_new", + "(Lnsk/jvmti/GetArgumentsSize/argsize001;Lnsk/jvmti/GetArgumentsSize/argsize001;)Lnsk/jvmti/GetArgumentsSize/argsize001;", 0, 3); + chk(env, klass1, "meth_abs", "()V", 0, 1); + chk(env, klass2, "meth_inn", "(Ljava/lang/String;J)V", 0, 4); + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/libargsize001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/libargsize001.c deleted file mode 100644 index aa1fc00adb0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/libargsize001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "argsize001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/libargsize001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/libargsize001.cpp new file mode 100644 index 00000000000..41ec249dfcc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize001/libargsize001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "argsize001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/argsize002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/argsize002.c deleted file mode 100644 index 2767746c107..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/argsize002.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_argsize002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_argsize002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_argsize002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetArgumentsSize_argsize002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jint size; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "", "()V"); - if (mid == NULL) { - printf("Cannot get method ID for \"\"!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->GetArgumentsSize(jvmti, NULL, &size); - if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetArgumentsSize(jvmti, mid, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "check", "()I"); - if (mid == NULL) { - printf("Cannot get method ID for \"check\"!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> native method check ...\n"); - } - err = (*jvmti)->GetArgumentsSize(jvmti, mid, &size); - if (err != JVMTI_ERROR_NATIVE_METHOD) { - printf("Error expected: JVMTI_ERROR_NATIVE_METHOD,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/argsize002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/argsize002.cpp new file mode 100644 index 00000000000..c3bc1a3047f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/argsize002.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_argsize002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_argsize002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_argsize002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetArgumentsSize_argsize002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jint size; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "", "()V"); + if (mid == NULL) { + printf("Cannot get method ID for \"\"!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->GetArgumentsSize(NULL, &size); + if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetArgumentsSize(mid, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "check", "()I"); + if (mid == NULL) { + printf("Cannot get method ID for \"check\"!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> native method check ...\n"); + } + err = jvmti->GetArgumentsSize(mid, &size); + if (err != JVMTI_ERROR_NATIVE_METHOD) { + printf("Error expected: JVMTI_ERROR_NATIVE_METHOD,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/libargsize002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/libargsize002.c deleted file mode 100644 index 8471c50331b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/libargsize002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "argsize002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/libargsize002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/libargsize002.cpp new file mode 100644 index 00000000000..bc7f6bccd16 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetArgumentsSize/argsize002/libargsize002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "argsize002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/getavailproc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/getavailproc001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/getavailproc001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/getavailproc001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/libgetavailproc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/libgetavailproc001.c deleted file mode 100644 index 6ad02e2edf4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/libgetavailproc001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getavailproc001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/libgetavailproc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/libgetavailproc001.cpp new file mode 100644 index 00000000000..479c68a5038 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAvailableProcessors/getavailproc001/libgetavailproc001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getavailproc001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/bytecodes001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/bytecodes001.c deleted file mode 100644 index 6cb9d8db9b8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/bytecodes001.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - const char *name; - const char *sig; - jboolean stat; - jint count; - unsigned char *codes; -} info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -static unsigned char m0[] = {0x2A, 0xB7, 0x00, 0x01, 0xB1}; -static unsigned char m1[] = {0xB1}; -static unsigned char m2[] = {0x1A, 0xBC, 0x06, 0x4C, 0x2B, 0xB0}; -static info meth_tab[3] = { - {"", "()V", JNI_FALSE, 5, m0}, - {"meth1", "()V", JNI_FALSE, 1, m1}, - {"meth2", "(I)[F", JNI_TRUE, 6, m2} -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_bytecodes001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_bytecodes001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_bytecodes001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - if ((err = ((*jvmti)->GetCapabilities(jvmti, &caps))) != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_bytecodes) { - printf("Warning: GetBytecodes is not implemented\n"); - } - - return JNI_OK; -} - -void checkMeth(JNIEnv *env, jclass cl, int meth_ind) { - jvmtiError err; - jmethodID mid = NULL; - jint count = -1; - unsigned char *codes = NULL; - int i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (meth_tab[meth_ind].stat == JNI_TRUE) { - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), - meth_tab[meth_ind].name, meth_tab[meth_ind].sig); - } else { - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), - meth_tab[meth_ind].name, meth_tab[meth_ind].sig); - } - if (mid == NULL) { - printf("\"%s%s\": cannot get method ID!\n", - meth_tab[meth_ind].name, meth_tab[meth_ind].sig); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> \"%s%s\" check ...\n", - meth_tab[meth_ind].name, meth_tab[meth_ind].sig); - } - - err = (*jvmti)->GetBytecodes(jvmti, mid, &count, &codes); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && !caps.can_get_bytecodes) { - /* It is OK */ - return; - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetBytecodes#%s) unexpected error: %s (%d)\n", - meth_tab[meth_ind].name, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (count != meth_tab[meth_ind].count) { - printf("\"%s%s\": byte codes count expected: %d, actual: %d\n", - meth_tab[meth_ind].name, meth_tab[meth_ind].sig, - meth_tab[meth_ind].count, count); - result = STATUS_FAILED; - return; - } - for (i = 0; i < count; i++) { - if (codes[i] != meth_tab[meth_ind].codes[i]) { - printf("\"%s%s\": [%d] byte expected: 0x%x, actual: 0x%x\n", - meth_tab[meth_ind].name, meth_tab[meth_ind].sig, i, - meth_tab[meth_ind].codes[i], codes[i]); - result = STATUS_FAILED; - } - } -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_GetBytecodes_bytecodes001_check(JNIEnv *env, jclass cls) { - checkMeth(env, cls, 0); - checkMeth(env, cls, 1); - checkMeth(env, cls, 2); - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/bytecodes001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/bytecodes001.cpp new file mode 100644 index 00000000000..412bc0f3d96 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/bytecodes001.cpp @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + const char *sig; + jboolean stat; + jint count; + unsigned char *codes; +} info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +static unsigned char m0[] = {0x2A, 0xB7, 0x00, 0x01, 0xB1}; +static unsigned char m1[] = {0xB1}; +static unsigned char m2[] = {0x1A, 0xBC, 0x06, 0x4C, 0x2B, 0xB0}; +static info meth_tab[3] = { + {"", "()V", JNI_FALSE, 5, m0}, + {"meth1", "()V", JNI_FALSE, 1, m1}, + {"meth2", "(I)[F", JNI_TRUE, 6, m2} +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_bytecodes001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_bytecodes001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_bytecodes001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + if ((err = (jvmti->GetCapabilities(&caps))) != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_bytecodes) { + printf("Warning: GetBytecodes is not implemented\n"); + } + + return JNI_OK; +} + +void checkMeth(JNIEnv *env, jclass cl, int meth_ind) { + jvmtiError err; + jmethodID mid = NULL; + jint count = -1; + unsigned char *codes = NULL; + int i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (meth_tab[meth_ind].stat == JNI_TRUE) { + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), + meth_tab[meth_ind].name, meth_tab[meth_ind].sig); + } else { + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), + meth_tab[meth_ind].name, meth_tab[meth_ind].sig); + } + if (mid == NULL) { + printf("\"%s%s\": cannot get method ID!\n", + meth_tab[meth_ind].name, meth_tab[meth_ind].sig); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> \"%s%s\" check ...\n", + meth_tab[meth_ind].name, meth_tab[meth_ind].sig); + } + + err = jvmti->GetBytecodes(mid, &count, &codes); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && !caps.can_get_bytecodes) { + /* It is OK */ + return; + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetBytecodes#%s) unexpected error: %s (%d)\n", + meth_tab[meth_ind].name, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (count != meth_tab[meth_ind].count) { + printf("\"%s%s\": byte codes count expected: %d, actual: %d\n", + meth_tab[meth_ind].name, meth_tab[meth_ind].sig, + meth_tab[meth_ind].count, count); + result = STATUS_FAILED; + return; + } + for (i = 0; i < count; i++) { + if (codes[i] != meth_tab[meth_ind].codes[i]) { + printf("\"%s%s\": [%d] byte expected: 0x%x, actual: 0x%x\n", + meth_tab[meth_ind].name, meth_tab[meth_ind].sig, i, + meth_tab[meth_ind].codes[i], codes[i]); + result = STATUS_FAILED; + } + } +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_GetBytecodes_bytecodes001_check(JNIEnv *env, jclass cls) { + checkMeth(env, cls, 0); + checkMeth(env, cls, 1); + checkMeth(env, cls, 2); + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/libbytecodes001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/libbytecodes001.c deleted file mode 100644 index 29116a7a1d4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/libbytecodes001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "bytecodes001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/libbytecodes001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/libbytecodes001.cpp new file mode 100644 index 00000000000..e1c42b05939 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/libbytecodes001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "bytecodes001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/bytecodes002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/bytecodes002.c deleted file mode 100644 index 8ae0aa10d62..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/bytecodes002.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_bytecodes002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_bytecodes002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_bytecodes002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - if ((err = ((*jvmti)->GetCapabilities(jvmti, &caps))) != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_bytecodes) { - printf("Warning: GetBytecodes is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetBytecodes_bytecodes002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jint bytecodeCount; - unsigned char *bytecodes; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "", "()V"); - if (mid == NULL) { - printf("Cannot get method ID for \"\"!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->GetBytecodes(jvmti, NULL, &bytecodeCount, &bytecodes); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && !caps.can_get_bytecodes) { - /* It is OK */ - } else if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (bytecodeCountPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetBytecodes(jvmti, mid, NULL, &bytecodes); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && !caps.can_get_bytecodes) { - /* It is OK */ - } else if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (bytecodesPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetBytecodes(jvmti, mid, &bytecodeCount, NULL); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && !caps.can_get_bytecodes) { - /* It is OK */ - } else if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "check", "()I"); - if (mid == NULL) { - printf("Cannot get method ID for \"check\"!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> native method check ...\n"); - } - err = (*jvmti)->GetBytecodes(jvmti, mid, &bytecodeCount, &bytecodes); - if (err != JVMTI_ERROR_NATIVE_METHOD) { - printf("Error expected: JVMTI_ERROR_NATIVE_METHOD,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/bytecodes002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/bytecodes002.cpp new file mode 100644 index 00000000000..e36fc4744c4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/bytecodes002.cpp @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_bytecodes002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_bytecodes002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_bytecodes002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + if ((err = (jvmti->GetCapabilities(&caps))) != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_bytecodes) { + printf("Warning: GetBytecodes is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetBytecodes_bytecodes002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jint bytecodeCount; + unsigned char *bytecodes; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "", "()V"); + if (mid == NULL) { + printf("Cannot get method ID for \"\"!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->GetBytecodes(NULL, &bytecodeCount, &bytecodes); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && !caps.can_get_bytecodes) { + /* It is OK */ + } else if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (bytecodeCountPtr) null pointer check ...\n"); + } + err = jvmti->GetBytecodes(mid, NULL, &bytecodes); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && !caps.can_get_bytecodes) { + /* It is OK */ + } else if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (bytecodesPtr) null pointer check ...\n"); + } + err = jvmti->GetBytecodes(mid, &bytecodeCount, NULL); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && !caps.can_get_bytecodes) { + /* It is OK */ + } else if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "check", "()I"); + if (mid == NULL) { + printf("Cannot get method ID for \"check\"!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> native method check ...\n"); + } + err = jvmti->GetBytecodes(mid, &bytecodeCount, &bytecodes); + if (err != JVMTI_ERROR_NATIVE_METHOD) { + printf("Error expected: JVMTI_ERROR_NATIVE_METHOD,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/libbytecodes002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/libbytecodes002.c deleted file mode 100644 index b26b33de72d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/libbytecodes002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "bytecodes002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/libbytecodes002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/libbytecodes002.cpp new file mode 100644 index 00000000000..57971324341 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/libbytecodes002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "bytecodes002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/bytecodes003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/bytecodes003.c deleted file mode 100644 index 6ba78447e47..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/bytecodes003.c +++ /dev/null @@ -1,540 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef enum { - opc_iinc = 132, - opc_tableswitch = 170, - opc_lookupswitch = 171, - opc_wide = 196 -} opcode_type; - -typedef struct { - char *name; - unsigned char code; - int length; -} opcode_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int eventsCount = 0; -static opcode_info opcodes[] = { - {"nop", 0, 1}, - {"aconst_null", 1, 1}, - {"iconst_m1", 2, 1}, - {"iconst_0", 3, 1}, - {"iconst_1", 4, 1}, - {"iconst_2", 5, 1}, - {"iconst_3", 6, 1}, - {"iconst_4", 7, 1}, - {"iconst_5", 8, 1}, - {"lconst_0", 9, 1}, - {"lconst_1", 10, 1}, - {"fconst_0", 11, 1}, - {"fconst_1", 12, 1}, - {"fconst_2", 13, 1}, - {"dconst_0", 14, 1}, - {"dconst_1", 15, 1}, - {"bipush", 16, 2}, - {"sipush", 17, 3}, - {"ldc", 18, 2}, - {"ldc_w", 19, 3}, - {"ldc2_w", 20, 3}, - {"iload", 21, 2}, - {"lload", 22, 2}, - {"fload", 23, 2}, - {"dload", 24, 2}, - {"aload", 25, 2}, - {"iload_0", 26, 1}, - {"iload_1", 27, 1}, - {"iload_2", 28, 1}, - {"iload_3", 29, 1}, - {"lload_0", 30, 1}, - {"lload_1", 31, 1}, - {"lload_2", 32, 1}, - {"lload_3", 33, 1}, - {"fload_0", 34, 1}, - {"fload_1", 35, 1}, - {"fload_2", 36, 1}, - {"fload_3", 37, 1}, - {"dload_0", 38, 1}, - {"dload_1", 39, 1}, - {"dload_2", 40, 1}, - {"dload_3", 41, 1}, - {"aload_0", 42, 1}, - {"aload_1", 43, 1}, - {"aload_2", 44, 1}, - {"aload_3", 45, 1}, - {"iaload", 46, 1}, - {"laload", 47, 1}, - {"faload", 48, 1}, - {"daload", 49, 1}, - {"aaload", 50, 1}, - {"baload", 51, 1}, - {"caload", 52, 1}, - {"saload", 53, 1}, - {"istore", 54, 2}, - {"lstore", 55, 2}, - {"fstore", 56, 2}, - {"dstore", 57, 2}, - {"astore", 58, 2}, - {"istore_0", 59, 1}, - {"istore_1", 60, 1}, - {"istore_2", 61, 1}, - {"istore_3", 62, 1}, - {"lstore_0", 63, 1}, - {"lstore_1", 64, 1}, - {"lstore_2", 65, 1}, - {"lstore_3", 66, 1}, - {"fstore_0", 67, 1}, - {"fstore_1", 68, 1}, - {"fstore_2", 69, 1}, - {"fstore_3", 70, 1}, - {"dstore_0", 71, 1}, - {"dstore_1", 72, 1}, - {"dstore_2", 73, 1}, - {"dstore_3", 74, 1}, - {"astore_0", 75, 1}, - {"astore_1", 76, 1}, - {"astore_2", 77, 1}, - {"astore_3", 78, 1}, - {"iastore", 79, 1}, - {"lastore", 80, 1}, - {"fastore", 81, 1}, - {"dastore", 82, 1}, - {"aastore", 83, 1}, - {"bastore", 84, 1}, - {"castore", 85, 1}, - {"sastore", 86, 1}, - {"pop", 87, 1}, - {"pop2", 88, 1}, - {"dup", 89, 1}, - {"dup_x1", 90, 1}, - {"dup_x2", 91, 1}, - {"dup2", 92, 1}, - {"dup2_x1", 93, 1}, - {"dup2_x2", 94, 1}, - {"swap", 95, 1}, - {"iadd", 96, 1}, - {"ladd", 97, 1}, - {"fadd", 98, 1}, - {"dadd", 99, 1}, - {"isub", 100, 1}, - {"lsub", 101, 1}, - {"fsub", 102, 1}, - {"dsub", 103, 1}, - {"imul", 104, 1}, - {"lmul", 105, 1}, - {"fmul", 106, 1}, - {"dmul", 107, 1}, - {"idiv", 108, 1}, - {"ldiv", 109, 1}, - {"fdiv", 110, 1}, - {"ddiv", 111, 1}, - {"irem", 112, 1}, - {"lrem", 113, 1}, - {"frem", 114, 1}, - {"drem", 115, 1}, - {"ineg", 116, 1}, - {"lneg", 117, 1}, - {"fneg", 118, 1}, - {"dneg", 119, 1}, - {"ishl", 120, 1}, - {"lshl", 121, 1}, - {"ishr", 122, 1}, - {"lshr", 123, 1}, - {"iushr", 124, 1}, - {"lushr", 125, 1}, - {"iand", 126, 1}, - {"land", 127, 1}, - {"ior", 128, 1}, - {"lor", 129, 1}, - {"ixor", 130, 1}, - {"lxor", 131, 1}, - {"iinc", 132, 3}, - {"i2l", 133, 1}, - {"i2f", 134, 1}, - {"i2d", 135, 1}, - {"l2i", 136, 1}, - {"l2f", 137, 1}, - {"l2d", 138, 1}, - {"f2i", 139, 1}, - {"f2l", 140, 1}, - {"f2d", 141, 1}, - {"d2i", 142, 1}, - {"d2l", 143, 1}, - {"d2f", 144, 1}, - {"i2b", 145, 1}, - {"i2c", 146, 1}, - {"i2s", 147, 1}, - {"lcmp", 148, 1}, - {"fcmpl", 149, 1}, - {"fcmpg", 150, 1}, - {"dcmpl", 151, 1}, - {"dcmpg", 152, 1}, - {"ifeq", 153, 3}, - {"ifne", 154, 3}, - {"iflt", 155, 3}, - {"ifge", 156, 3}, - {"ifgt", 157, 3}, - {"ifle", 158, 3}, - {"if_icmpeq", 159, 3}, - {"if_icmpne", 160, 3}, - {"if_icmplt", 161, 3}, - {"if_icmpge", 162, 3}, - {"if_icmpgt", 163, 3}, - {"if_icmple", 164, 3}, - {"if_acmpeq", 165, 3}, - {"if_acmpne", 166, 3}, - {"goto", 167, 3}, - {"jsr", 168, 3}, - {"ret", 169, 2}, - {"tableswitch", 170, 0}, - {"lookupswitch", 171, 0}, - {"ireturn", 172, 1}, - {"lreturn", 173, 1}, - {"freturn", 174, 1}, - {"dreturn", 175, 1}, - {"areturn", 176, 1}, - {"return", 177, 1}, - {"getstatic", 178, 3}, - {"putstatic", 179, 3}, - {"getfield", 180, 3}, - {"putfield", 181, 3}, - {"invokevirtual", 182, 3}, - {"invokespecial", 183, 3}, - {"invokestatic", 184, 3}, - {"invokeinterface", 185, 5}, - {"invokedynamic", 186, 5}, - {"new", 187, 3}, - {"newarray", 188, 2}, - {"anewarray", 189, 3}, - {"arraylength", 190, 1}, - {"athrow", 191, 1}, - {"checkcast", 192, 3}, - {"instanceof", 193, 3}, - {"monitorenter", 194, 1}, - {"monitorexit", 195, 1}, - {"wide", 196, 0}, - {"multianewarray", 197, 4}, - {"ifnull", 198, 3}, - {"ifnonnull", 199, 3}, - {"goto_w", 200, 5}, - {"jsr_w", 201, 5}, - {"breakpoint", 202, 1}, - {"impdep1", 254, 1}, - {"impdep2", 255, 1} -}; - -jint get_u4(unsigned char *p) { - return (jint)p[3] | ((jint)p[2]<<8) | ((jint)p[1]<<16) | ((jint)p[0]<<24); -} - -jboolean checkCode(jint bytecodeCount, unsigned char *buf) { - unsigned char code; - jint pc, cur_pc, length; - size_t i; - - for (pc = 0; pc >= 0 && pc < bytecodeCount; pc += length) { - code = buf[pc]; - for (i = 0; i < sizeof(opcodes)/sizeof(opcode_info); i++) { - if (code == opcodes[i].code) { - switch (code) { - case opc_wide: - length = (buf[pc + 1] == opc_iinc ? 6 : 4); - break; - case opc_lookupswitch: - cur_pc = (pc + 4) & (~3); - length = cur_pc - pc + 8; - length += get_u4(buf + cur_pc + 4) * 8; - break; - case opc_tableswitch: - cur_pc = (pc + 4) & (~3); - length = cur_pc - pc + 12; - length += (get_u4(buf + cur_pc + 8) - - get_u4(buf + cur_pc + 4) + 1) * 4; - break; - default: - length = opcodes[i].length; - break; - } - if (printdump == JNI_TRUE) { - printf(">>> %4d: %s (%d)\n", - pc, opcodes[i].name, length); - } - if (length <= 0) { - printf("Invalid length: %d for opcode \"%s\" (%d)\n", - length, opcodes[i].name, code); - return JNI_FALSE; - } - break; - } - } - if (i >= sizeof(opcodes)/sizeof(opcode_info)) { - /* opcode not found */ - printf("Non-standard opcode: %d (0x%x)\n", code, code); - return JNI_FALSE; - } - } - return JNI_TRUE; -} - -void JNICALL ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jclass cls) { - jvmtiError err; - char *sig, *name, *msig; - jint mcount; - jmethodID *methods; - jboolean isNative; - jint bytecodeCount; - unsigned char *bytecodes; - jint i; - - sig = NULL; - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sig, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassMethods(jvmti_env, cls, &mcount, &methods); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassMethods#%d) unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> [class prepare event #%d]", eventsCount); - printf(" \"%s\"\n", sig); - printf(">>> %d methods:\n", mcount); - } - - for (i = 0; i < mcount; i++) { - if (methods[i] == NULL) { - if (printdump == JNI_TRUE) { - printf(" null"); - } - } else { - name = NULL; - msig = NULL; - bytecodes = NULL; - err = (*jvmti_env)->GetMethodName(jvmti_env, methods[i], - &name, &msig, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - printf(" class: \"%s\"\n", sig); - result = STATUS_FAILED; - } - isNative = JNI_TRUE; - err = (*jvmti_env)->IsMethodNative(jvmti_env, methods[i], &isNative); - if (err != JVMTI_ERROR_NONE) { - printf("(IsMethodNative) unexpected error: %s (%d)\n", - TranslateError(err), err); - printf(" class: \"%s\"\n", sig); - printf(" method = \"%s%s\"\n", name, msig); - result = STATUS_FAILED; - } - if (isNative == JNI_TRUE) { - if (printdump == JNI_TRUE) { - printf(">>> \"%s%s\", native\n", name, msig); - } - } else { - err = (*jvmti_env)->GetBytecodes(jvmti_env, methods[i], - &bytecodeCount, &bytecodes); - if (err != JVMTI_ERROR_NONE) { - printf("(GetBytecodes#%d:%d) unexpected error: %s (%d)\n", - eventsCount, i, TranslateError(err), err); - result = STATUS_FAILED; - } else { - if (printdump == JNI_TRUE) { - printf(">>> \"%s%s\", %d bytes\n", - name, msig, bytecodeCount); - } - if (checkCode(bytecodeCount, bytecodes) == JNI_FALSE) { - printf(" class: \"%s\"\n", sig); - printf(" method = \"%s%s\"\n", name, msig); - result = STATUS_FAILED; - } - } - } - if (name != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)name); - } - if (msig != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)msig); - } - if (bytecodes != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, bytecodes); - } - } - } - - if (methods != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)methods); - } - if (sig != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)sig); - } - eventsCount++; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_bytecodes003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_bytecodes003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_bytecodes003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - if ((err = ((*jvmti)->GetCapabilities(jvmti, &caps))) != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if ((err = ((*jvmti)->GetCapabilities(jvmti, &caps))) != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_get_bytecodes) { - callbacks.ClassPrepare = &ClassPrepare; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_CLASS_PREPARE, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable ClassPrepare: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else { - printf("Warning: GetBytecodes is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetBytecodes_bytecodes003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (caps.can_get_bytecodes) { - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_CLASS_PREPARE, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf("Total number of class prepare events: %d\n", eventsCount); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/bytecodes003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/bytecodes003.cpp new file mode 100644 index 00000000000..1c946703498 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/bytecodes003.cpp @@ -0,0 +1,540 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef enum { + opc_iinc = 132, + opc_tableswitch = 170, + opc_lookupswitch = 171, + opc_wide = 196 +} opcode_type; + +typedef struct { + const char *name; + unsigned char code; + int length; +} opcode_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int eventsCount = 0; +static opcode_info opcodes[] = { + {"nop", 0, 1}, + {"aconst_null", 1, 1}, + {"iconst_m1", 2, 1}, + {"iconst_0", 3, 1}, + {"iconst_1", 4, 1}, + {"iconst_2", 5, 1}, + {"iconst_3", 6, 1}, + {"iconst_4", 7, 1}, + {"iconst_5", 8, 1}, + {"lconst_0", 9, 1}, + {"lconst_1", 10, 1}, + {"fconst_0", 11, 1}, + {"fconst_1", 12, 1}, + {"fconst_2", 13, 1}, + {"dconst_0", 14, 1}, + {"dconst_1", 15, 1}, + {"bipush", 16, 2}, + {"sipush", 17, 3}, + {"ldc", 18, 2}, + {"ldc_w", 19, 3}, + {"ldc2_w", 20, 3}, + {"iload", 21, 2}, + {"lload", 22, 2}, + {"fload", 23, 2}, + {"dload", 24, 2}, + {"aload", 25, 2}, + {"iload_0", 26, 1}, + {"iload_1", 27, 1}, + {"iload_2", 28, 1}, + {"iload_3", 29, 1}, + {"lload_0", 30, 1}, + {"lload_1", 31, 1}, + {"lload_2", 32, 1}, + {"lload_3", 33, 1}, + {"fload_0", 34, 1}, + {"fload_1", 35, 1}, + {"fload_2", 36, 1}, + {"fload_3", 37, 1}, + {"dload_0", 38, 1}, + {"dload_1", 39, 1}, + {"dload_2", 40, 1}, + {"dload_3", 41, 1}, + {"aload_0", 42, 1}, + {"aload_1", 43, 1}, + {"aload_2", 44, 1}, + {"aload_3", 45, 1}, + {"iaload", 46, 1}, + {"laload", 47, 1}, + {"faload", 48, 1}, + {"daload", 49, 1}, + {"aaload", 50, 1}, + {"baload", 51, 1}, + {"caload", 52, 1}, + {"saload", 53, 1}, + {"istore", 54, 2}, + {"lstore", 55, 2}, + {"fstore", 56, 2}, + {"dstore", 57, 2}, + {"astore", 58, 2}, + {"istore_0", 59, 1}, + {"istore_1", 60, 1}, + {"istore_2", 61, 1}, + {"istore_3", 62, 1}, + {"lstore_0", 63, 1}, + {"lstore_1", 64, 1}, + {"lstore_2", 65, 1}, + {"lstore_3", 66, 1}, + {"fstore_0", 67, 1}, + {"fstore_1", 68, 1}, + {"fstore_2", 69, 1}, + {"fstore_3", 70, 1}, + {"dstore_0", 71, 1}, + {"dstore_1", 72, 1}, + {"dstore_2", 73, 1}, + {"dstore_3", 74, 1}, + {"astore_0", 75, 1}, + {"astore_1", 76, 1}, + {"astore_2", 77, 1}, + {"astore_3", 78, 1}, + {"iastore", 79, 1}, + {"lastore", 80, 1}, + {"fastore", 81, 1}, + {"dastore", 82, 1}, + {"aastore", 83, 1}, + {"bastore", 84, 1}, + {"castore", 85, 1}, + {"sastore", 86, 1}, + {"pop", 87, 1}, + {"pop2", 88, 1}, + {"dup", 89, 1}, + {"dup_x1", 90, 1}, + {"dup_x2", 91, 1}, + {"dup2", 92, 1}, + {"dup2_x1", 93, 1}, + {"dup2_x2", 94, 1}, + {"swap", 95, 1}, + {"iadd", 96, 1}, + {"ladd", 97, 1}, + {"fadd", 98, 1}, + {"dadd", 99, 1}, + {"isub", 100, 1}, + {"lsub", 101, 1}, + {"fsub", 102, 1}, + {"dsub", 103, 1}, + {"imul", 104, 1}, + {"lmul", 105, 1}, + {"fmul", 106, 1}, + {"dmul", 107, 1}, + {"idiv", 108, 1}, + {"ldiv", 109, 1}, + {"fdiv", 110, 1}, + {"ddiv", 111, 1}, + {"irem", 112, 1}, + {"lrem", 113, 1}, + {"frem", 114, 1}, + {"drem", 115, 1}, + {"ineg", 116, 1}, + {"lneg", 117, 1}, + {"fneg", 118, 1}, + {"dneg", 119, 1}, + {"ishl", 120, 1}, + {"lshl", 121, 1}, + {"ishr", 122, 1}, + {"lshr", 123, 1}, + {"iushr", 124, 1}, + {"lushr", 125, 1}, + {"iand", 126, 1}, + {"land", 127, 1}, + {"ior", 128, 1}, + {"lor", 129, 1}, + {"ixor", 130, 1}, + {"lxor", 131, 1}, + {"iinc", 132, 3}, + {"i2l", 133, 1}, + {"i2f", 134, 1}, + {"i2d", 135, 1}, + {"l2i", 136, 1}, + {"l2f", 137, 1}, + {"l2d", 138, 1}, + {"f2i", 139, 1}, + {"f2l", 140, 1}, + {"f2d", 141, 1}, + {"d2i", 142, 1}, + {"d2l", 143, 1}, + {"d2f", 144, 1}, + {"i2b", 145, 1}, + {"i2c", 146, 1}, + {"i2s", 147, 1}, + {"lcmp", 148, 1}, + {"fcmpl", 149, 1}, + {"fcmpg", 150, 1}, + {"dcmpl", 151, 1}, + {"dcmpg", 152, 1}, + {"ifeq", 153, 3}, + {"ifne", 154, 3}, + {"iflt", 155, 3}, + {"ifge", 156, 3}, + {"ifgt", 157, 3}, + {"ifle", 158, 3}, + {"if_icmpeq", 159, 3}, + {"if_icmpne", 160, 3}, + {"if_icmplt", 161, 3}, + {"if_icmpge", 162, 3}, + {"if_icmpgt", 163, 3}, + {"if_icmple", 164, 3}, + {"if_acmpeq", 165, 3}, + {"if_acmpne", 166, 3}, + {"goto", 167, 3}, + {"jsr", 168, 3}, + {"ret", 169, 2}, + {"tableswitch", 170, 0}, + {"lookupswitch", 171, 0}, + {"ireturn", 172, 1}, + {"lreturn", 173, 1}, + {"freturn", 174, 1}, + {"dreturn", 175, 1}, + {"areturn", 176, 1}, + {"return", 177, 1}, + {"getstatic", 178, 3}, + {"putstatic", 179, 3}, + {"getfield", 180, 3}, + {"putfield", 181, 3}, + {"invokevirtual", 182, 3}, + {"invokespecial", 183, 3}, + {"invokestatic", 184, 3}, + {"invokeinterface", 185, 5}, + {"invokedynamic", 186, 5}, + {"new", 187, 3}, + {"newarray", 188, 2}, + {"anewarray", 189, 3}, + {"arraylength", 190, 1}, + {"athrow", 191, 1}, + {"checkcast", 192, 3}, + {"instanceof", 193, 3}, + {"monitorenter", 194, 1}, + {"monitorexit", 195, 1}, + {"wide", 196, 0}, + {"multianewarray", 197, 4}, + {"ifnull", 198, 3}, + {"ifnonnull", 199, 3}, + {"goto_w", 200, 5}, + {"jsr_w", 201, 5}, + {"breakpoint", 202, 1}, + {"impdep1", 254, 1}, + {"impdep2", 255, 1} +}; + +jint get_u4(unsigned char *p) { + return (jint)p[3] | ((jint)p[2]<<8) | ((jint)p[1]<<16) | ((jint)p[0]<<24); +} + +jboolean checkCode(jint bytecodeCount, unsigned char *buf) { + unsigned char code; + jint pc, cur_pc, length; + size_t i; + + for (pc = 0; pc >= 0 && pc < bytecodeCount; pc += length) { + code = buf[pc]; + for (i = 0; i < sizeof(opcodes)/sizeof(opcode_info); i++) { + if (code == opcodes[i].code) { + switch (code) { + case opc_wide: + length = (buf[pc + 1] == opc_iinc ? 6 : 4); + break; + case opc_lookupswitch: + cur_pc = (pc + 4) & (~3); + length = cur_pc - pc + 8; + length += get_u4(buf + cur_pc + 4) * 8; + break; + case opc_tableswitch: + cur_pc = (pc + 4) & (~3); + length = cur_pc - pc + 12; + length += (get_u4(buf + cur_pc + 8) - + get_u4(buf + cur_pc + 4) + 1) * 4; + break; + default: + length = opcodes[i].length; + break; + } + if (printdump == JNI_TRUE) { + printf(">>> %4d: %s (%d)\n", + pc, opcodes[i].name, length); + } + if (length <= 0) { + printf("Invalid length: %d for opcode \"%s\" (%d)\n", + length, opcodes[i].name, code); + return JNI_FALSE; + } + break; + } + } + if (i >= sizeof(opcodes)/sizeof(opcode_info)) { + /* opcode not found */ + printf("Non-standard opcode: %d (0x%x)\n", code, code); + return JNI_FALSE; + } + } + return JNI_TRUE; +} + +void JNICALL ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jclass cls) { + jvmtiError err; + char *sig, *name, *msig; + jint mcount; + jmethodID *methods; + jboolean isNative; + jint bytecodeCount; + unsigned char *bytecodes; + jint i; + + sig = NULL; + err = jvmti_env->GetClassSignature(cls, &sig, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassMethods(cls, &mcount, &methods); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassMethods#%d) unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> [class prepare event #%d]", eventsCount); + printf(" \"%s\"\n", sig); + printf(">>> %d methods:\n", mcount); + } + + for (i = 0; i < mcount; i++) { + if (methods[i] == NULL) { + if (printdump == JNI_TRUE) { + printf(" null"); + } + } else { + name = NULL; + msig = NULL; + bytecodes = NULL; + err = jvmti_env->GetMethodName(methods[i], + &name, &msig, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + printf(" class: \"%s\"\n", sig); + result = STATUS_FAILED; + } + isNative = JNI_TRUE; + err = jvmti_env->IsMethodNative(methods[i], &isNative); + if (err != JVMTI_ERROR_NONE) { + printf("(IsMethodNative) unexpected error: %s (%d)\n", + TranslateError(err), err); + printf(" class: \"%s\"\n", sig); + printf(" method = \"%s%s\"\n", name, msig); + result = STATUS_FAILED; + } + if (isNative == JNI_TRUE) { + if (printdump == JNI_TRUE) { + printf(">>> \"%s%s\", native\n", name, msig); + } + } else { + err = jvmti_env->GetBytecodes(methods[i], + &bytecodeCount, &bytecodes); + if (err != JVMTI_ERROR_NONE) { + printf("(GetBytecodes#%d:%d) unexpected error: %s (%d)\n", + eventsCount, i, TranslateError(err), err); + result = STATUS_FAILED; + } else { + if (printdump == JNI_TRUE) { + printf(">>> \"%s%s\", %d bytes\n", + name, msig, bytecodeCount); + } + if (checkCode(bytecodeCount, bytecodes) == JNI_FALSE) { + printf(" class: \"%s\"\n", sig); + printf(" method = \"%s%s\"\n", name, msig); + result = STATUS_FAILED; + } + } + } + if (name != NULL) { + jvmti_env->Deallocate((unsigned char *)name); + } + if (msig != NULL) { + jvmti_env->Deallocate((unsigned char *)msig); + } + if (bytecodes != NULL) { + jvmti_env->Deallocate(bytecodes); + } + } + } + + if (methods != NULL) { + jvmti_env->Deallocate((unsigned char *)methods); + } + if (sig != NULL) { + jvmti_env->Deallocate((unsigned char *)sig); + } + eventsCount++; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_bytecodes003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_bytecodes003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_bytecodes003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + if ((err = (jvmti->GetCapabilities(&caps))) != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if ((err = (jvmti->GetCapabilities(&caps))) != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_get_bytecodes) { + callbacks.ClassPrepare = &ClassPrepare; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_CLASS_PREPARE, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable ClassPrepare: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else { + printf("Warning: GetBytecodes is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetBytecodes_bytecodes003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (caps.can_get_bytecodes) { + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_CLASS_PREPARE, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf("Total number of class prepare events: %d\n", eventsCount); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/libbytecodes003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/libbytecodes003.c deleted file mode 100644 index 85fffc66643..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/libbytecodes003.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "bytecodes003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/libbytecodes003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/libbytecodes003.cpp new file mode 100644 index 00000000000..e25e248adc6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes003/libbytecodes003.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "bytecodes003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/getcaps001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/getcaps001.c deleted file mode 100644 index 105386a4734..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/getcaps001.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getcaps001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getcaps001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getcaps001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetCapabilities_getcaps001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetCapabilities(jvmti, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/getcaps001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/getcaps001.cpp new file mode 100644 index 00000000000..7e07aa8428c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/getcaps001.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getcaps001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getcaps001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getcaps001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetCapabilities_getcaps001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetCapabilities(NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/libgetcaps001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/libgetcaps001.c deleted file mode 100644 index f6eff690d00..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/libgetcaps001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getcaps001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/libgetcaps001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/libgetcaps001.cpp new file mode 100644 index 00000000000..ce1307d3cfc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps001/libgetcaps001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getcaps001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/getcaps002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/getcaps002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/getcaps002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/getcaps002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/libgetcaps002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/libgetcaps002.c deleted file mode 100644 index 103a369c9b8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/libgetcaps002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getcaps002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/libgetcaps002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/libgetcaps002.cpp new file mode 100644 index 00000000000..32e22283f3e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCapabilities/getcaps002/libgetcaps002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getcaps002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/getclfld005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/getclfld005.c deleted file mode 100644 index c4b727c6f18..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/getclfld005.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclfld005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclfld005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclfld005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetClassFields_getclfld005_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jint fcount; - jfieldID *fields; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->GetClassFields(jvmti, NULL, &fcount, &fields); - if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (fieldCountPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetClassFields(jvmti, cls, NULL, &fields); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(fieldCountPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (fieldsPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetClassFields(jvmti, cls, &fcount, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(fieldsPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/getclfld005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/getclfld005.cpp new file mode 100644 index 00000000000..67595926296 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/getclfld005.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclfld005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclfld005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclfld005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetClassFields_getclfld005_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jint fcount; + jfieldID *fields; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->GetClassFields(NULL, &fcount, &fields); + if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (fieldCountPtr) null pointer check ...\n"); + } + err = jvmti->GetClassFields(cls, NULL, &fields); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(fieldCountPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (fieldsPtr) null pointer check ...\n"); + } + err = jvmti->GetClassFields(cls, &fcount, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(fieldsPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/libgetclfld005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/libgetclfld005.c deleted file mode 100644 index 59f80fcca35..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/libgetclfld005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclfld005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/libgetclfld005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/libgetclfld005.cpp new file mode 100644 index 00000000000..55c935fc7d2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld005/libgetclfld005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclfld005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/getclfld006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/getclfld006.c deleted file mode 100644 index a5ef9b1994b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/getclfld006.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclfld006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclfld006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclfld006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetClassFields_getclfld006_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { - jvmtiError err; - jint fcount; - jfieldID *fields; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> trying #%d\n", i); - } - - err = (*jvmti)->GetClassFields(jvmti, clazz, &fcount, &fields); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassFields#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (fcount != 0) { - printf("(%d) field list is not empty, fcount=%d\n", i, fcount); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassFields_getclfld006_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/getclfld006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/getclfld006.cpp new file mode 100644 index 00000000000..ea0eaafae53 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/getclfld006.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclfld006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclfld006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclfld006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetClassFields_getclfld006_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { + jvmtiError err; + jint fcount; + jfieldID *fields; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> trying #%d\n", i); + } + + err = jvmti->GetClassFields(clazz, &fcount, &fields); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassFields#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (fcount != 0) { + printf("(%d) field list is not empty, fcount=%d\n", i, fcount); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassFields_getclfld006_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/libgetclfld006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/libgetclfld006.c deleted file mode 100644 index 016bd30e63b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/libgetclfld006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclfld006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/libgetclfld006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/libgetclfld006.cpp new file mode 100644 index 00000000000..f1b692ec004 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld006/libgetclfld006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclfld006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/getclfld007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/getclfld007.c deleted file mode 100644 index ed17507e590..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/getclfld007.c +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *name; - char *sig; -} fld_info; - -typedef struct { - char *name; - jint fcount; - fld_info *flds; -} class_info; - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -static fld_info f0[] = { - {"fld_1", "Ljava/lang/String;"} -}; - -static fld_info f1[] = { - {"fld_n1", "I"} -}; - -static fld_info f2[] = { - {"fld_n2", "I"} -}; - -static fld_info f4[] = { - {"fld_o2", "I"} -}; - -static fld_info f5[] = { - {"fld_o3", "I"} -}; - -static fld_info f6[] = { - {"fld_i1", "I"} -}; - -static fld_info f7[] = { - {"fld_i2", "I"} -}; - -static fld_info f8[] = { - {"fld_i2", "I"} -}; - -static fld_info f9[] = { - {"fld_i1", "I"} -}; - -static class_info classes[] = { - {"InnerClass1", 1, f0}, - {"InnerInterface", 1, f1}, - {"InnerClass2", 1, f2}, - {"OuterClass1", 0, NULL}, - {"OuterClass2", 1, f4}, - {"OuterClass3", 1, f5}, - {"OuterInterface1", 1, f6}, - {"OuterInterface2", 1, f7}, - {"OuterClass4", 1, f8}, - {"OuterClass5", 1, f9} -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclfld007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclfld007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclfld007(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetClassFields_getclfld007_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { - jvmtiError err; - jint fcount; - jfieldID *fields; - char *name, *sig, *generic; - int j; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %s:\n", classes[i].name); - } - - err = (*jvmti)->GetClassFields(jvmti, clazz, &fcount, &fields); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassFields#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (fcount != classes[i].fcount) { - printf("(%d) wrong number of fields: %d, expected: %d\n", - i, fcount, classes[i].fcount); - result = STATUS_FAILED; - } - for (j = 0; j < fcount; j++) { - if (fields[j] == NULL) { - printf("(%d:%d) fieldID = null\n", i, j); - } else { - err = (*jvmti)->GetFieldName(jvmti, clazz, fields[j], - &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldName#%d:%d) unexpected error: %s (%d)\n", - i, j, TranslateError(err), err); - } else { - if (printdump == JNI_TRUE) { - printf(">>> [%d]: %s, sig = \"%s\"\n", j, name, sig); - } - if ((j < classes[i].fcount) && - (name == NULL || sig == NULL || - strcmp(name, classes[i].flds[j].name) != 0 || - strcmp(sig, classes[i].flds[j].sig) != 0)) { - printf("(%d:%d) wrong field: \"%s%s\"", i, j, name, sig); - printf(", expected: \"%s%s\"\n", - classes[i].flds[j].name, classes[i].flds[j].sig); - result = STATUS_FAILED; - } - } - } - } -} - -JNIEXPORT int JNICALL -Java_nsk_jvmti_GetClassFields_getclfld007_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/getclfld007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/getclfld007.cpp new file mode 100644 index 00000000000..7c5aa2b4b23 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/getclfld007.cpp @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + const char *sig; +} fld_info; + +typedef struct { + const char *name; + jint fcount; + fld_info *flds; +} class_info; + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +static fld_info f0[] = { + {"fld_1", "Ljava/lang/String;"} +}; + +static fld_info f1[] = { + {"fld_n1", "I"} +}; + +static fld_info f2[] = { + {"fld_n2", "I"} +}; + +static fld_info f4[] = { + {"fld_o2", "I"} +}; + +static fld_info f5[] = { + {"fld_o3", "I"} +}; + +static fld_info f6[] = { + {"fld_i1", "I"} +}; + +static fld_info f7[] = { + {"fld_i2", "I"} +}; + +static fld_info f8[] = { + {"fld_i2", "I"} +}; + +static fld_info f9[] = { + {"fld_i1", "I"} +}; + +static class_info classes[] = { + {"InnerClass1", 1, f0}, + {"InnerInterface", 1, f1}, + {"InnerClass2", 1, f2}, + {"OuterClass1", 0, NULL}, + {"OuterClass2", 1, f4}, + {"OuterClass3", 1, f5}, + {"OuterInterface1", 1, f6}, + {"OuterInterface2", 1, f7}, + {"OuterClass4", 1, f8}, + {"OuterClass5", 1, f9} +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclfld007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclfld007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclfld007(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetClassFields_getclfld007_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { + jvmtiError err; + jint fcount; + jfieldID *fields; + char *name, *sig, *generic; + int j; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %s:\n", classes[i].name); + } + + err = jvmti->GetClassFields(clazz, &fcount, &fields); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassFields#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (fcount != classes[i].fcount) { + printf("(%d) wrong number of fields: %d, expected: %d\n", + i, fcount, classes[i].fcount); + result = STATUS_FAILED; + } + for (j = 0; j < fcount; j++) { + if (fields[j] == NULL) { + printf("(%d:%d) fieldID = null\n", i, j); + } else { + err = jvmti->GetFieldName(clazz, fields[j], + &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldName#%d:%d) unexpected error: %s (%d)\n", + i, j, TranslateError(err), err); + } else { + if (printdump == JNI_TRUE) { + printf(">>> [%d]: %s, sig = \"%s\"\n", j, name, sig); + } + if ((j < classes[i].fcount) && + (name == NULL || sig == NULL || + strcmp(name, classes[i].flds[j].name) != 0 || + strcmp(sig, classes[i].flds[j].sig) != 0)) { + printf("(%d:%d) wrong field: \"%s%s\"", i, j, name, sig); + printf(", expected: \"%s%s\"\n", + classes[i].flds[j].name, classes[i].flds[j].sig); + result = STATUS_FAILED; + } + } + } + } +} + +JNIEXPORT int JNICALL +Java_nsk_jvmti_GetClassFields_getclfld007_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/libgetclfld007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/libgetclfld007.c deleted file mode 100644 index 8be1cf7d1ee..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/libgetclfld007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclfld007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/libgetclfld007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/libgetclfld007.cpp new file mode 100644 index 00000000000..b81919f9946 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/libgetclfld007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclfld007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/getclsldr001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/getclsldr001.c deleted file mode 100644 index 7153d694877..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/getclsldr001.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclsldr001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclsldr001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclsldr001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetClassLoader_getclsldr001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jobject classloader; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->GetClassLoader(jvmti, NULL, &classloader); - if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetClassLoader(jvmti, cls, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/getclsldr001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/getclsldr001.cpp new file mode 100644 index 00000000000..bf54f693caf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/getclsldr001.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclsldr001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclsldr001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclsldr001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetClassLoader_getclsldr001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jobject classloader; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->GetClassLoader(NULL, &classloader); + if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetClassLoader(cls, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/libgetclsldr001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/libgetclsldr001.c deleted file mode 100644 index 151b597b445..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/libgetclsldr001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclsldr001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/libgetclsldr001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/libgetclsldr001.cpp new file mode 100644 index 00000000000..d1ab687a24f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr001/libgetclsldr001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclsldr001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/getclsldr002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/getclsldr002.c deleted file mode 100644 index c2b94eca474..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/getclsldr002.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclsldr002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclsldr002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclsldr002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetClassLoader_getclsldr002_check(JNIEnv *env, - jclass cls, jint i, jclass clazz) { - jvmtiError err; - jobject classloader; - char *sig, *generic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassSignature(jvmti, clazz, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->GetClassLoader(jvmti, clazz, &classloader); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassLoader#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> %d: %s\n", i, sig); - } - - if (classloader != NULL) { - printf("(%d:%s) class loader is not NULL: 0x%p\n", - i, sig, classloader); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL -Java_nsk_jvmti_GetClassLoader_getclsldr002_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/getclsldr002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/getclsldr002.cpp new file mode 100644 index 00000000000..1ffa12d0816 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/getclsldr002.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclsldr002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclsldr002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclsldr002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetClassLoader_getclsldr002_check(JNIEnv *env, + jclass cls, jint i, jclass clazz) { + jvmtiError err; + jobject classloader; + char *sig, *generic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassSignature(clazz, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->GetClassLoader(clazz, &classloader); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassLoader#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> %d: %s\n", i, sig); + } + + if (classloader != NULL) { + printf("(%d:%s) class loader is not NULL: 0x%p\n", + i, sig, classloader); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL +Java_nsk_jvmti_GetClassLoader_getclsldr002_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/libgetclsldr002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/libgetclsldr002.c deleted file mode 100644 index 0183e86764c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/libgetclsldr002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclsldr002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/libgetclsldr002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/libgetclsldr002.cpp new file mode 100644 index 00000000000..2d5b53a25dd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr002/libgetclsldr002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclsldr002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/getclsldr003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/getclsldr003.c deleted file mode 100644 index a34fdb7f9d1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/getclsldr003.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclsldr003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclsldr003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclsldr003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetClassLoader_getclsldr003_check(JNIEnv *env, - jclass cls, jclass clazz, jobject cl) { - jvmtiError err; - jobject classloader; - char *sig, *generic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassSignature(jvmti, clazz, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->GetClassLoader(jvmti, clazz, &classloader); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassLoader) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> %s - 0x%p\n", sig, classloader); - } - - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, classloader), - cl) != JNI_TRUE) { - printf("(%s) unexpected class loader\n", sig); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL -Java_nsk_jvmti_GetClassLoader_getclsldr003_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/getclsldr003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/getclsldr003.cpp new file mode 100644 index 00000000000..9f7bb781db7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/getclsldr003.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclsldr003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclsldr003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclsldr003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetClassLoader_getclsldr003_check(JNIEnv *env, + jclass cls, jclass clazz, jobject cl) { + jvmtiError err; + jobject classloader; + char *sig, *generic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassSignature(clazz, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->GetClassLoader(clazz, &classloader); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassLoader) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> %s - 0x%p\n", sig, classloader); + } + + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, classloader), + cl) != JNI_TRUE) { + printf("(%s) unexpected class loader\n", sig); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL +Java_nsk_jvmti_GetClassLoader_getclsldr003_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/libgetclsldr003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/libgetclsldr003.c deleted file mode 100644 index 7fbfe82a091..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/libgetclsldr003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclsldr003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/libgetclsldr003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/libgetclsldr003.cpp new file mode 100644 index 00000000000..97c6d0f98ed --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoader/getclsldr003/libgetclsldr003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclsldr003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/clsldrclss001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/clsldrclss001.c deleted file mode 100644 index 04bab974a8b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/clsldrclss001.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_clsldrclss001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_clsldrclss001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_clsldrclss001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetClassLoaderClasses_clsldrclss001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jobject classloader; - jclass *classes; - jint classCount; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->GetClassLoader(jvmti, cls, &classloader); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassLoader) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (initiatingLoader) null pointer check ...\n"); - } - err = (*jvmti)->GetClassLoaderClasses(jvmti, NULL, &classCount, &classes); - if (err == JVMTI_ERROR_NULL_POINTER) { - printf("Expected: the classes initiated by the bootstrap loader,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (classCountPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetClassLoaderClasses(jvmti, classloader, NULL, &classes); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (classesPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetClassLoaderClasses(jvmti, classloader, &classCount, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/clsldrclss001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/clsldrclss001.cpp new file mode 100644 index 00000000000..2160b464d34 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/clsldrclss001.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_clsldrclss001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_clsldrclss001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_clsldrclss001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetClassLoaderClasses_clsldrclss001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jobject classloader; + jclass *classes; + jint classCount; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->GetClassLoader(cls, &classloader); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassLoader) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (initiatingLoader) null pointer check ...\n"); + } + err = jvmti->GetClassLoaderClasses(NULL, &classCount, &classes); + if (err == JVMTI_ERROR_NULL_POINTER) { + printf("Expected: the classes initiated by the bootstrap loader,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (classCountPtr) null pointer check ...\n"); + } + err = jvmti->GetClassLoaderClasses(classloader, NULL, &classes); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (classesPtr) null pointer check ...\n"); + } + err = jvmti->GetClassLoaderClasses(classloader, &classCount, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/libclsldrclss001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/libclsldrclss001.c deleted file mode 100644 index 74f37a3af06..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/libclsldrclss001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "clsldrclss001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/libclsldrclss001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/libclsldrclss001.cpp new file mode 100644 index 00000000000..363b075f7e6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/libclsldrclss001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "clsldrclss001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/clsldrclss002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/clsldrclss002.c deleted file mode 100644 index 117ec346565..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/clsldrclss002.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* test objects */ -static jobject testedClassLoader = NULL; -static jclass testedClass = NULL; -static jfieldID testedFieldID = NULL; - -static const char* CLASS_SIG = - "Lnsk/jvmti/GetClassLoaderClasses/clsldrclss002;"; -static const char* CLASS_SIG_A = - "Lnsk/jvmti/GetClassLoaderClasses/clsldrclss002a;"; -static const char* CLASS_SIG_E = - "Lnsk/jvmti/GetClassLoaderClasses/clsldrclss002e;"; -static const char* CLASS_SIG_I = - "Lnsk/jvmti/GetClassLoaderClasses/clsldrclss002i;"; - -/* ========================================================================== */ - -static int prepare(JNIEnv* jni) { - const char* CLASS_NAME = "nsk/jvmti/GetClassLoaderClasses/clsldrclss002"; - const char* FIELD_NAME = "testedClassLoader"; - const char* FIELD_SIGNATURE = "Ljava/lang/ClassLoader;"; - - NSK_DISPLAY0("Obtain tested object from a static field of debugee class\n"); - - NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) - return NSK_FALSE; - - NSK_DISPLAY2("Find field: %s:%s\n", FIELD_NAME, FIELD_SIGNATURE); - if (!NSK_JNI_VERIFY(jni, (testedFieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, testedClass, - FIELD_NAME, FIELD_SIGNATURE)) != NULL)) - return NSK_FALSE; - - return NSK_TRUE; -} - -static int lookup(jvmtiEnv* jvmti, - jint classCount, jclass *classes, const char *exp_sig) { - char *signature, *generic; - int found = NSK_FALSE; - jint i; - - for (i = 0; i < classCount && !found; i++) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti, - classes[i], &signature, &generic))) - break; - - if (signature != NULL && strcmp(signature, exp_sig) == 0) { - NSK_DISPLAY1("Expected class found: %s\n", exp_sig); - found = NSK_TRUE; - } - - if (signature != NULL) - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)signature); - - if (generic != NULL) - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)generic); - } - - return found; -} - -/* ========================================================================== */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - jclass *classes; - jint classCount; - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!prepare(jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Testcase #1: check on default classloader\n"); - if (!NSK_JNI_VERIFY(jni, (testedClassLoader = - NSK_CPP_STUB3(GetStaticObjectField, jni, - testedClass, testedFieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassLoaderClasses, jvmti, - testedClassLoader, &classCount, &classes))) { - nsk_jvmti_setFailStatus(); - return; - } - if (!NSK_VERIFY(classCount != 0)) { - nsk_jvmti_setFailStatus(); - return; - } - if (!NSK_VERIFY(classes != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - if (!lookup(jvmti, classCount, classes, CLASS_SIG)) { - NSK_COMPLAIN1("Cannot find class in the list: %s\n", CLASS_SIG); - nsk_jvmti_setFailStatus(); - return; - } - if (classes != NULL) - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)classes); - - if (!nsk_jvmti_resumeSync()) - return; - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("Testcase #2: check on custom classloader\n"); - if (!NSK_JNI_VERIFY(jni, (testedClassLoader = - NSK_CPP_STUB3(GetStaticObjectField, jni, - testedClass, testedFieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassLoaderClasses, jvmti, - testedClassLoader, &classCount, &classes))) { - nsk_jvmti_setFailStatus(); - return; - } - if (!NSK_VERIFY(classCount != 0)) { - nsk_jvmti_setFailStatus(); - return; - } - if (!NSK_VERIFY(classes != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - if (!lookup(jvmti, classCount, classes, CLASS_SIG_A)) { - NSK_COMPLAIN1("Cannot find class in the list: %s\n", CLASS_SIG_A); - nsk_jvmti_setFailStatus(); - } - if (!lookup(jvmti, classCount, classes, CLASS_SIG_I)) { - NSK_COMPLAIN1("Cannot find class in the list: %s\n", CLASS_SIG_I); - nsk_jvmti_setFailStatus(); - } - if (!lookup(jvmti, classCount, classes, CLASS_SIG_E)) { - NSK_COMPLAIN1("Cannot find class in the list: %s\n", CLASS_SIG_E); - nsk_jvmti_setFailStatus(); - } - if (classes != NULL) - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)classes); - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_clsldrclss002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_clsldrclss002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_clsldrclss002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - NSK_DISPLAY0("Agent_OnLoad\n"); - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/clsldrclss002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/clsldrclss002.cpp new file mode 100644 index 00000000000..a3c785cd0c8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/clsldrclss002.cpp @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* test objects */ +static jobject testedClassLoader = NULL; +static jclass testedClass = NULL; +static jfieldID testedFieldID = NULL; + +static const char* CLASS_SIG = + "Lnsk/jvmti/GetClassLoaderClasses/clsldrclss002;"; +static const char* CLASS_SIG_A = + "Lnsk/jvmti/GetClassLoaderClasses/clsldrclss002a;"; +static const char* CLASS_SIG_E = + "Lnsk/jvmti/GetClassLoaderClasses/clsldrclss002e;"; +static const char* CLASS_SIG_I = + "Lnsk/jvmti/GetClassLoaderClasses/clsldrclss002i;"; + +/* ========================================================================== */ + +static int prepare(JNIEnv* jni) { + const char* CLASS_NAME = "nsk/jvmti/GetClassLoaderClasses/clsldrclss002"; + const char* FIELD_NAME = "testedClassLoader"; + const char* FIELD_SIGNATURE = "Ljava/lang/ClassLoader;"; + + NSK_DISPLAY0("Obtain tested object from a static field of debugee class\n"); + + NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (testedClass = + NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) + return NSK_FALSE; + + NSK_DISPLAY2("Find field: %s:%s\n", FIELD_NAME, FIELD_SIGNATURE); + if (!NSK_JNI_VERIFY(jni, (testedFieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, testedClass, + FIELD_NAME, FIELD_SIGNATURE)) != NULL)) + return NSK_FALSE; + + return NSK_TRUE; +} + +static int lookup(jvmtiEnv* jvmti, + jint classCount, jclass *classes, const char *exp_sig) { + char *signature, *generic; + int found = NSK_FALSE; + jint i; + + for (i = 0; i < classCount && !found; i++) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti, + classes[i], &signature, &generic))) + break; + + if (signature != NULL && strcmp(signature, exp_sig) == 0) { + NSK_DISPLAY1("Expected class found: %s\n", exp_sig); + found = NSK_TRUE; + } + + if (signature != NULL) + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)signature); + + if (generic != NULL) + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)generic); + } + + return found; +} + +/* ========================================================================== */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + jclass *classes; + jint classCount; + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!prepare(jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Testcase #1: check on default classloader\n"); + if (!NSK_JNI_VERIFY(jni, (testedClassLoader = + NSK_CPP_STUB3(GetStaticObjectField, jni, + testedClass, testedFieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassLoaderClasses, jvmti, + testedClassLoader, &classCount, &classes))) { + nsk_jvmti_setFailStatus(); + return; + } + if (!NSK_VERIFY(classCount != 0)) { + nsk_jvmti_setFailStatus(); + return; + } + if (!NSK_VERIFY(classes != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + if (!lookup(jvmti, classCount, classes, CLASS_SIG)) { + NSK_COMPLAIN1("Cannot find class in the list: %s\n", CLASS_SIG); + nsk_jvmti_setFailStatus(); + return; + } + if (classes != NULL) + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)classes); + + if (!nsk_jvmti_resumeSync()) + return; + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("Testcase #2: check on custom classloader\n"); + if (!NSK_JNI_VERIFY(jni, (testedClassLoader = + NSK_CPP_STUB3(GetStaticObjectField, jni, + testedClass, testedFieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassLoaderClasses, jvmti, + testedClassLoader, &classCount, &classes))) { + nsk_jvmti_setFailStatus(); + return; + } + if (!NSK_VERIFY(classCount != 0)) { + nsk_jvmti_setFailStatus(); + return; + } + if (!NSK_VERIFY(classes != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + if (!lookup(jvmti, classCount, classes, CLASS_SIG_A)) { + NSK_COMPLAIN1("Cannot find class in the list: %s\n", CLASS_SIG_A); + nsk_jvmti_setFailStatus(); + } + if (!lookup(jvmti, classCount, classes, CLASS_SIG_I)) { + NSK_COMPLAIN1("Cannot find class in the list: %s\n", CLASS_SIG_I); + nsk_jvmti_setFailStatus(); + } + if (!lookup(jvmti, classCount, classes, CLASS_SIG_E)) { + NSK_COMPLAIN1("Cannot find class in the list: %s\n", CLASS_SIG_E); + nsk_jvmti_setFailStatus(); + } + if (classes != NULL) + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)classes); + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_clsldrclss002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_clsldrclss002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_clsldrclss002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + NSK_DISPLAY0("Agent_OnLoad\n"); + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/libclsldrclss002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/libclsldrclss002.c deleted file mode 100644 index 13d410a78f6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/libclsldrclss002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "clsldrclss002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/libclsldrclss002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/libclsldrclss002.cpp new file mode 100644 index 00000000000..504438e30c0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/libclsldrclss002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "clsldrclss002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/getclmthd005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/getclmthd005.c deleted file mode 100644 index dd146f9eeae..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/getclmthd005.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclmthd005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclmthd005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclmthd005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetClassMethods_getclmthd005_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jint mcount; - jmethodID *methods; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->GetClassMethods(jvmti, NULL, &mcount, &methods); - if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (methodCountPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetClassMethods(jvmti, cls, NULL, &methods); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(methodCountPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (methodsPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetClassMethods(jvmti, cls, &mcount, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(methodsPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/getclmthd005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/getclmthd005.cpp new file mode 100644 index 00000000000..01ebb9f0cba --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/getclmthd005.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclmthd005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclmthd005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclmthd005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetClassMethods_getclmthd005_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jint mcount; + jmethodID *methods; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->GetClassMethods(NULL, &mcount, &methods); + if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (methodCountPtr) null pointer check ...\n"); + } + err = jvmti->GetClassMethods(cls, NULL, &methods); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(methodCountPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (methodsPtr) null pointer check ...\n"); + } + err = jvmti->GetClassMethods(cls, &mcount, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(methodsPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/libgetclmthd005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/libgetclmthd005.c deleted file mode 100644 index 4882c28ae24..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/libgetclmthd005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclmthd005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/libgetclmthd005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/libgetclmthd005.cpp new file mode 100644 index 00000000000..5742998fc58 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd005/libgetclmthd005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclmthd005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/getclmthd006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/getclmthd006.c deleted file mode 100644 index a82b8319690..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/getclmthd006.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclmthd006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclmthd006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclmthd006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetClassMethods_getclmthd006_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { - jvmtiError err; - jint mcount; - jmethodID *methods; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> trying #%d\n", i); - } - - err = (*jvmti)->GetClassMethods(jvmti, clazz, &mcount, &methods); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassMethods#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (mcount != 0) { - printf("(%d) method list is not empty, mcount=%d\n", i, mcount); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassMethods_getclmthd006_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/getclmthd006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/getclmthd006.cpp new file mode 100644 index 00000000000..28c58312515 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/getclmthd006.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclmthd006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclmthd006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclmthd006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetClassMethods_getclmthd006_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { + jvmtiError err; + jint mcount; + jmethodID *methods; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> trying #%d\n", i); + } + + err = jvmti->GetClassMethods(clazz, &mcount, &methods); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassMethods#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (mcount != 0) { + printf("(%d) method list is not empty, mcount=%d\n", i, mcount); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassMethods_getclmthd006_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/libgetclmthd006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/libgetclmthd006.c deleted file mode 100644 index c26b998ef46..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/libgetclmthd006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclmthd006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/libgetclmthd006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/libgetclmthd006.cpp new file mode 100644 index 00000000000..b70b64c04d5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd006/libgetclmthd006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclmthd006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/getclmthd007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/getclmthd007.c deleted file mode 100644 index 9755805b30b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/getclmthd007.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *name; - char *sig; -} meth_info; - -typedef struct { - char *name; - jint mcount; - meth_info *meths; -} class_info; - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -static meth_info m0[] = { - {"", "(Lnsk/jvmti/GetClassMethods/getclmthd007;)V"}, - {"meth_1", "(Ljava/lang/String;)V"} -}; - -static meth_info m1[] = { - {"meth_n1", "()V"}, - {"meth_def1", "()V"} -}; - -static meth_info m2[] = { - {"", "()V"}, - {"meth_n1", "()V"}, - {"meth_n2", "()I"}, - {"", "()V"} -}; - -static meth_info m3[] = { - {"", "()V"} -}; - -static meth_info m4[] = { - {"", "()V"}, - {"meth_o2", "()V"} -}; - -static meth_info m5[] = { - {"", "()V"}, - {"meth_o3", "()I"} -}; - -static meth_info m6[] = { - {"meth_i1", "()I"} -}; - -static meth_info m7[] = { - {"meth_i2", "()I"} -}; - -static meth_info m8[] = { - {"", "()V"}, - {"meth_i2", "()I"} -}; - -static meth_info m9[] = { - {"", "()V"}, - {"meth_i1", "()I"} -}; - -static class_info classes[] = { - {"InnerClass1", 2, m0}, - {"InnerInterface", 2, m1}, - {"InnerClass2", 4, m2}, - {"OuterClass1", 1, m3}, - {"OuterClass2", 2, m4}, - {"OuterClass3", 2, m5}, - {"OuterInterface1", 1, m6}, - {"OuterInterface2", 1, m7}, - {"OuterClass4", 2, m8}, - {"OuterClass5", 2, m9} -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclmthd007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclmthd007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclmthd007(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetClassMethods_getclmthd007_check(JNIEnv *env, - jclass cls, jint i, jclass clazz) { - jvmtiError err; - jint mcount; - jmethodID *methods; - char *name, *sig, *generic; - int j, k; - - int failed = JNI_FALSE; // enable debugging on failure - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %s:\n", classes[i].name); - } - - err = (*jvmti)->GetClassMethods(jvmti, clazz, &mcount, &methods); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassMethods#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (mcount != classes[i].mcount) { - printf("(%d) wrong number of methods: %d, expected: %d\n", - i, mcount, classes[i].mcount); - result = STATUS_FAILED; - failed = JNI_TRUE; // show the methods found - printf(">>> %s:\n", classes[i].name); - } - for (k = 0; k < mcount; k++) { - if (methods[k] == NULL) { - printf("(%d:%d) methodID = null\n", i, k); - result = STATUS_FAILED; - } else if (printdump == JNI_TRUE || failed == JNI_TRUE) { - err = (*jvmti)->GetMethodName(jvmti, methods[k], - &name, &sig, &generic); - if (err == JVMTI_ERROR_NONE) { - printf(">>> [%d]: %s%s\n", k, name, sig); - } - } - } - for (j = 0; j < classes[i].mcount; j++) { - /* search the returned table for each expected entry */ - for (k = 0; k < mcount; k++) { - if (methods[k] != NULL) { - err = (*jvmti)->GetMethodName(jvmti, methods[k], - &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d:%d) unexpected error: %s (%d)\n", - i, k, TranslateError(err), err); - result = STATUS_FAILED; - } else { - if (name != NULL && sig != NULL && - strcmp(name, classes[i].meths[j].name) == 0 && - strcmp(sig, classes[i].meths[j].sig) == 0) break; - } - } - } - if (k == mcount) { - printf("(%d:%d) method not found: \"%s%s\"", i, j, - classes[i].meths[j].name, classes[i].meths[j].sig); - result = STATUS_FAILED; - } - } -} - -JNIEXPORT int JNICALL -Java_nsk_jvmti_GetClassMethods_getclmthd007_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/getclmthd007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/getclmthd007.cpp new file mode 100644 index 00000000000..d3ed8d1f769 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/getclmthd007.cpp @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + const char *sig; +} meth_info; + +typedef struct { + const char *name; + jint mcount; + meth_info *meths; +} class_info; + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +static meth_info m0[] = { + {"", "(Lnsk/jvmti/GetClassMethods/getclmthd007;)V"}, + {"meth_1", "(Ljava/lang/String;)V"} +}; + +static meth_info m1[] = { + {"meth_n1", "()V"}, + {"meth_def1", "()V"} +}; + +static meth_info m2[] = { + {"", "()V"}, + {"meth_n1", "()V"}, + {"meth_n2", "()I"}, + {"", "()V"} +}; + +static meth_info m3[] = { + {"", "()V"} +}; + +static meth_info m4[] = { + {"", "()V"}, + {"meth_o2", "()V"} +}; + +static meth_info m5[] = { + {"", "()V"}, + {"meth_o3", "()I"} +}; + +static meth_info m6[] = { + {"meth_i1", "()I"} +}; + +static meth_info m7[] = { + {"meth_i2", "()I"} +}; + +static meth_info m8[] = { + {"", "()V"}, + {"meth_i2", "()I"} +}; + +static meth_info m9[] = { + {"", "()V"}, + {"meth_i1", "()I"} +}; + +static class_info classes[] = { + {"InnerClass1", 2, m0}, + {"InnerInterface", 2, m1}, + {"InnerClass2", 4, m2}, + {"OuterClass1", 1, m3}, + {"OuterClass2", 2, m4}, + {"OuterClass3", 2, m5}, + {"OuterInterface1", 1, m6}, + {"OuterInterface2", 1, m7}, + {"OuterClass4", 2, m8}, + {"OuterClass5", 2, m9} +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclmthd007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclmthd007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclmthd007(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetClassMethods_getclmthd007_check(JNIEnv *env, + jclass cls, jint i, jclass clazz) { + jvmtiError err; + jint mcount; + jmethodID *methods; + char *name, *sig, *generic; + int j, k; + + int failed = JNI_FALSE; // enable debugging on failure + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %s:\n", classes[i].name); + } + + err = jvmti->GetClassMethods(clazz, &mcount, &methods); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassMethods#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (mcount != classes[i].mcount) { + printf("(%d) wrong number of methods: %d, expected: %d\n", + i, mcount, classes[i].mcount); + result = STATUS_FAILED; + failed = JNI_TRUE; // show the methods found + printf(">>> %s:\n", classes[i].name); + } + for (k = 0; k < mcount; k++) { + if (methods[k] == NULL) { + printf("(%d:%d) methodID = null\n", i, k); + result = STATUS_FAILED; + } else if (printdump == JNI_TRUE || failed == JNI_TRUE) { + err = jvmti->GetMethodName(methods[k], + &name, &sig, &generic); + if (err == JVMTI_ERROR_NONE) { + printf(">>> [%d]: %s%s\n", k, name, sig); + } + } + } + for (j = 0; j < classes[i].mcount; j++) { + /* search the returned table for each expected entry */ + for (k = 0; k < mcount; k++) { + if (methods[k] != NULL) { + err = jvmti->GetMethodName(methods[k], + &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d:%d) unexpected error: %s (%d)\n", + i, k, TranslateError(err), err); + result = STATUS_FAILED; + } else { + if (name != NULL && sig != NULL && + strcmp(name, classes[i].meths[j].name) == 0 && + strcmp(sig, classes[i].meths[j].sig) == 0) break; + } + } + } + if (k == mcount) { + printf("(%d:%d) method not found: \"%s%s\"", i, j, + classes[i].meths[j].name, classes[i].meths[j].sig); + result = STATUS_FAILED; + } + } +} + +JNIEXPORT int JNICALL +Java_nsk_jvmti_GetClassMethods_getclmthd007_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/libgetclmthd007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/libgetclmthd007.c deleted file mode 100644 index 68fc64a8ee2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/libgetclmthd007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclmthd007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/libgetclmthd007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/libgetclmthd007.cpp new file mode 100644 index 00000000000..9a0317afeef --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/libgetclmthd007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclmthd007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/getclmdf004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/getclmdf004.c deleted file mode 100644 index 7b6eda368db..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/getclmdf004.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclmdf004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclmdf004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclmdf004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetClassModifiers_getclmdf004_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jint modifiers; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->GetClassModifiers(jvmti, NULL, &modifiers); - if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetClassModifiers(jvmti, cls, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/getclmdf004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/getclmdf004.cpp new file mode 100644 index 00000000000..c204c7960e5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/getclmdf004.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclmdf004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclmdf004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclmdf004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetClassModifiers_getclmdf004_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jint modifiers; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->GetClassModifiers(NULL, &modifiers); + if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetClassModifiers(cls, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/libgetclmdf004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/libgetclmdf004.c deleted file mode 100644 index 8dcb531696c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/libgetclmdf004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclmdf004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/libgetclmdf004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/libgetclmdf004.cpp new file mode 100644 index 00000000000..84af2739e19 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf004/libgetclmdf004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclmdf004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/getclmdf005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/getclmdf005.c deleted file mode 100644 index 64e2bed74d6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/getclmdf005.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define ACC_PUBLIC 0x0001 -#define ACC_PRIVATE 0x0002 -#define ACC_PROTECTED 0x0004 -#define ACC_FINAL 0x0010 -#define ACC_INTERFACE 0x0200 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclmdf005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclmdf005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclmdf005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetClassModifiers_getclmdf005_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { - jvmtiError err; - jint modifiers; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassModifiers(jvmti, clazz, &modifiers); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassModifiers#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %d: 0x%0x\n", i, modifiers); - } - - if ((modifiers & ACC_PUBLIC) == 0) { - printf("(%d) ACC_PUBLIC bit should be set\n", i); - result = STATUS_FAILED; - } - - if ((modifiers & ACC_FINAL) == 0) { - printf("(%d) ACC_FINAL bit should be set\n", i); - result = STATUS_FAILED; - } - - if ((modifiers & ACC_INTERFACE) != 0) { - printf("(%d) ACC_INTERFACE bit should be clear\n", i); - result = STATUS_FAILED; - } - - if ((modifiers & ACC_PROTECTED) != 0) { - printf("(%d) ACC_PROTECTED bit should be clear\n", i); - result = STATUS_FAILED; - } - - if ((modifiers & ACC_PRIVATE) != 0) { - printf("(%d) ACC_PRIVATE bit should be clear\n", i); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassModifiers_getclmdf005_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/getclmdf005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/getclmdf005.cpp new file mode 100644 index 00000000000..5de9b483dc8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/getclmdf005.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define ACC_PUBLIC 0x0001 +#define ACC_PRIVATE 0x0002 +#define ACC_PROTECTED 0x0004 +#define ACC_FINAL 0x0010 +#define ACC_INTERFACE 0x0200 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclmdf005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclmdf005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclmdf005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetClassModifiers_getclmdf005_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { + jvmtiError err; + jint modifiers; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassModifiers(clazz, &modifiers); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassModifiers#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %d: 0x%0x\n", i, modifiers); + } + + if ((modifiers & ACC_PUBLIC) == 0) { + printf("(%d) ACC_PUBLIC bit should be set\n", i); + result = STATUS_FAILED; + } + + if ((modifiers & ACC_FINAL) == 0) { + printf("(%d) ACC_FINAL bit should be set\n", i); + result = STATUS_FAILED; + } + + if ((modifiers & ACC_INTERFACE) != 0) { + printf("(%d) ACC_INTERFACE bit should be clear\n", i); + result = STATUS_FAILED; + } + + if ((modifiers & ACC_PROTECTED) != 0) { + printf("(%d) ACC_PROTECTED bit should be clear\n", i); + result = STATUS_FAILED; + } + + if ((modifiers & ACC_PRIVATE) != 0) { + printf("(%d) ACC_PRIVATE bit should be clear\n", i); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassModifiers_getclmdf005_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/libgetclmdf005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/libgetclmdf005.c deleted file mode 100644 index 449030b2e3d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/libgetclmdf005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclmdf005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/libgetclmdf005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/libgetclmdf005.cpp new file mode 100644 index 00000000000..00510cf6254 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/libgetclmdf005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclmdf005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/getclmdf006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/getclmdf006.c deleted file mode 100644 index f8c8b0010b9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/getclmdf006.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define ACC_PUBLIC 0x0001 -#define ACC_PRIVATE 0x0002 -#define ACC_PROTECTED 0x0004 -#define ACC_STATIC 0x0008 -#define ACC_FINAL 0x0010 -#define ACC_SUPER 0x0020 -#define ACC_INTERFACE 0x0200 -#define ACC_ABSTRACT 0x0400 -#define ACC_STRICT 0x0800 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclmdf006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclmdf006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclmdf006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -void printModifiers(jint mod) { - if (mod & ACC_PUBLIC) printf(" PUBLIC"); - if (mod & ACC_PRIVATE) printf(" PRIVATE"); - if (mod & ACC_PROTECTED) printf(" PROTECTED"); - if (mod & ACC_STATIC) printf(" STATIC"); - if (mod & ACC_FINAL) printf(" FINAL"); - if (mod & ACC_SUPER) printf(" SUPER"); - if (mod & ACC_INTERFACE) printf(" INTERFACE"); - if (mod & ACC_ABSTRACT) printf(" ABSTRACT"); - if (mod & ACC_STRICT) printf(" STRICT"); - printf(" (0x%0x)\n", mod); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetClassModifiers_getclmdf006_check(JNIEnv *env, jclass cls, jclass clazz, jint mod) { - jvmtiError err; - jint modifiers; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassModifiers(jvmti, clazz, &modifiers); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassModifiers:0x%x) unexpected error: %s (%d)\n", - mod, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>>"); - printModifiers(modifiers); - } - - if ((modifiers & (~ACC_SUPER)) != mod) { - printf("Access flags expected:"); - printModifiers(mod); - printf("\t actual:"); - printModifiers(modifiers); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassModifiers_getclmdf006_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/getclmdf006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/getclmdf006.cpp new file mode 100644 index 00000000000..d236f9cab11 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/getclmdf006.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define ACC_PUBLIC 0x0001 +#define ACC_PRIVATE 0x0002 +#define ACC_PROTECTED 0x0004 +#define ACC_STATIC 0x0008 +#define ACC_FINAL 0x0010 +#define ACC_SUPER 0x0020 +#define ACC_INTERFACE 0x0200 +#define ACC_ABSTRACT 0x0400 +#define ACC_STRICT 0x0800 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclmdf006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclmdf006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclmdf006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +void printModifiers(jint mod) { + if (mod & ACC_PUBLIC) printf(" PUBLIC"); + if (mod & ACC_PRIVATE) printf(" PRIVATE"); + if (mod & ACC_PROTECTED) printf(" PROTECTED"); + if (mod & ACC_STATIC) printf(" STATIC"); + if (mod & ACC_FINAL) printf(" FINAL"); + if (mod & ACC_SUPER) printf(" SUPER"); + if (mod & ACC_INTERFACE) printf(" INTERFACE"); + if (mod & ACC_ABSTRACT) printf(" ABSTRACT"); + if (mod & ACC_STRICT) printf(" STRICT"); + printf(" (0x%0x)\n", mod); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetClassModifiers_getclmdf006_check(JNIEnv *env, jclass cls, jclass clazz, jint mod) { + jvmtiError err; + jint modifiers; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassModifiers(clazz, &modifiers); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassModifiers:0x%x) unexpected error: %s (%d)\n", + mod, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>>"); + printModifiers(modifiers); + } + + if ((modifiers & (~ACC_SUPER)) != mod) { + printf("Access flags expected:"); + printModifiers(mod); + printf("\t actual:"); + printModifiers(modifiers); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassModifiers_getclmdf006_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/libgetclmdf006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/libgetclmdf006.c deleted file mode 100644 index 21c238cbbad..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/libgetclmdf006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclmdf006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/libgetclmdf006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/libgetclmdf006.cpp new file mode 100644 index 00000000000..f9841d891d1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/libgetclmdf006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclmdf006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/getclmdf007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/getclmdf007.c deleted file mode 100644 index e462e279bc3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/getclmdf007.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define ACC_PUBLIC 0x0001 -#define ACC_PRIVATE 0x0002 -#define ACC_PROTECTED 0x0004 -#define ACC_STATIC 0x0008 -#define ACC_FINAL 0x0010 -#define ACC_SUPER 0x0020 -#define ACC_INTERFACE 0x0200 -#define ACC_ABSTRACT 0x0400 -#define ACC_STRICT 0x0800 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclmdf007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclmdf007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclmdf007(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -void printModifiers(jint mod) { - if (mod & ACC_PUBLIC) printf(" PUBLIC"); - if (mod & ACC_PRIVATE) printf(" PRIVATE"); - if (mod & ACC_PROTECTED) printf(" PROTECTED"); - if (mod & ACC_STATIC) printf(" STATIC"); - if (mod & ACC_FINAL) printf(" FINAL"); - if (mod & ACC_SUPER) printf(" SUPER"); - if (mod & ACC_INTERFACE) printf(" INTERFACE"); - if (mod & ACC_ABSTRACT) printf(" ABSTRACT"); - if (mod & ACC_STRICT) printf(" STRICT"); - printf(" (0x%0x)\n", mod); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetClassModifiers_getclmdf007_check(JNIEnv *env, jclass cls, jint i, jclass arr, jclass comp) { - jvmtiError err; - jint ArrayModifiers; - jint ComponentModifiers; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassModifiers(jvmti, arr, &ArrayModifiers); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassModifiers#%d, arr) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %d:", i); - printModifiers(ArrayModifiers); - } - - if ((ArrayModifiers & ACC_FINAL) == 0) { - printf("(%d) ACC_FINAL bit should be set\n", i); - result = STATUS_FAILED; - } - - if ((ArrayModifiers & ACC_INTERFACE) != 0) { - printf("(%d) ACC_INTERFACE bit should be clear\n", i); - result = STATUS_FAILED; - } - - err = (*jvmti)->GetClassModifiers(jvmti, comp, &ComponentModifiers); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassModifiers#%d, comp) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - ArrayModifiers &= (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED); - ComponentModifiers &= (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED); - if (ArrayModifiers != ComponentModifiers) { - printf("(%d) access bits of array do not match component ones\n", i); - printf(" array:"); - printModifiers(ArrayModifiers); - printf(" component:"); - printModifiers(ComponentModifiers); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassModifiers_getclmdf007_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/getclmdf007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/getclmdf007.cpp new file mode 100644 index 00000000000..be6dcd7a279 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/getclmdf007.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define ACC_PUBLIC 0x0001 +#define ACC_PRIVATE 0x0002 +#define ACC_PROTECTED 0x0004 +#define ACC_STATIC 0x0008 +#define ACC_FINAL 0x0010 +#define ACC_SUPER 0x0020 +#define ACC_INTERFACE 0x0200 +#define ACC_ABSTRACT 0x0400 +#define ACC_STRICT 0x0800 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclmdf007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclmdf007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclmdf007(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +void printModifiers(jint mod) { + if (mod & ACC_PUBLIC) printf(" PUBLIC"); + if (mod & ACC_PRIVATE) printf(" PRIVATE"); + if (mod & ACC_PROTECTED) printf(" PROTECTED"); + if (mod & ACC_STATIC) printf(" STATIC"); + if (mod & ACC_FINAL) printf(" FINAL"); + if (mod & ACC_SUPER) printf(" SUPER"); + if (mod & ACC_INTERFACE) printf(" INTERFACE"); + if (mod & ACC_ABSTRACT) printf(" ABSTRACT"); + if (mod & ACC_STRICT) printf(" STRICT"); + printf(" (0x%0x)\n", mod); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetClassModifiers_getclmdf007_check(JNIEnv *env, jclass cls, jint i, jclass arr, jclass comp) { + jvmtiError err; + jint ArrayModifiers; + jint ComponentModifiers; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassModifiers(arr, &ArrayModifiers); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassModifiers#%d, arr) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %d:", i); + printModifiers(ArrayModifiers); + } + + if ((ArrayModifiers & ACC_FINAL) == 0) { + printf("(%d) ACC_FINAL bit should be set\n", i); + result = STATUS_FAILED; + } + + if ((ArrayModifiers & ACC_INTERFACE) != 0) { + printf("(%d) ACC_INTERFACE bit should be clear\n", i); + result = STATUS_FAILED; + } + + err = jvmti->GetClassModifiers(comp, &ComponentModifiers); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassModifiers#%d, comp) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + ArrayModifiers &= (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED); + ComponentModifiers &= (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED); + if (ArrayModifiers != ComponentModifiers) { + printf("(%d) access bits of array do not match component ones\n", i); + printf(" array:"); + printModifiers(ArrayModifiers); + printf(" component:"); + printModifiers(ComponentModifiers); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassModifiers_getclmdf007_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/libgetclmdf007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/libgetclmdf007.c deleted file mode 100644 index 144975966be..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/libgetclmdf007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclmdf007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/libgetclmdf007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/libgetclmdf007.cpp new file mode 100644 index 00000000000..3baa213ddc1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/libgetclmdf007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclmdf007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/getclsig004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/getclsig004.c deleted file mode 100644 index d59a747b2eb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/getclsig004.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static const char *sigs[] = { - "B", - "C", - "D", - "F", - "I", - "J", - "Ljava/lang/Object;", - "S", - "V", - "Z" -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclsig004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclsig004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclsig004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetClassSignature_getclsig004_check(JNIEnv *env, - jclass cls, jint i, jclass clazz) { - jvmtiError err; - char *sig, *generic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassSignature(jvmti, clazz, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %d: %s\n", i, sig); - } - - if (strcmp(sig, sigs[i]) != 0) { - printf("(%d) wrong sig: \"%s\", expected: \"%s\"\n", i, sig, sigs[i]); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL -Java_nsk_jvmti_GetClassSignature_getclsig004_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/getclsig004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/getclsig004.cpp new file mode 100644 index 00000000000..32aefa4d0c3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/getclsig004.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static const char *sigs[] = { + "B", + "C", + "D", + "F", + "I", + "J", + "Ljava/lang/Object;", + "S", + "V", + "Z" +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclsig004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclsig004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclsig004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetClassSignature_getclsig004_check(JNIEnv *env, + jclass cls, jint i, jclass clazz) { + jvmtiError err; + char *sig, *generic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassSignature(clazz, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %d: %s\n", i, sig); + } + + if (strcmp(sig, sigs[i]) != 0) { + printf("(%d) wrong sig: \"%s\", expected: \"%s\"\n", i, sig, sigs[i]); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL +Java_nsk_jvmti_GetClassSignature_getclsig004_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/libgetclsig004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/libgetclsig004.c deleted file mode 100644 index ab3b560c4e4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/libgetclsig004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclsig004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/libgetclsig004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/libgetclsig004.cpp new file mode 100644 index 00000000000..efd7bd0625b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/libgetclsig004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclsig004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/getclsig005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/getclsig005.c deleted file mode 100644 index 914b78ad780..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/getclsig005.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define CLASS_SIGNATURE "Lnsk/jvmti/GetClassSignature/getclsig005;" - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclsig005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclsig005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclsig005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetClassSignature_getclsig005_check(JNIEnv *env, jclass cls) { - jvmtiError err; - char *sig, *generic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->GetClassSignature(jvmti, NULL, &sig, &generic); - if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (signature_ptr) null pointer check ...\n"); - } - err = (*jvmti)->GetClassSignature(jvmti, cls, NULL, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(signature_ptr) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - if (printdump == JNI_TRUE) { - printf(">>> generic = \"%s\"\n", generic); - } - } - - if (printdump == JNI_TRUE) { - printf(">>> (generic_ptr) null pointer check ...\n"); - } - err = (*jvmti)->GetClassSignature(jvmti, cls, &sig, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(generic_ptr) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - if (printdump == JNI_TRUE) { - printf(">>> sig = \"%s\"\n", sig); - } - if (sig == NULL || strcmp(sig, CLASS_SIGNATURE) != 0) { - printf("Wrong class sig: \"%s\", expected: \"%s\"\n", - CLASS_SIGNATURE, sig); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/getclsig005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/getclsig005.cpp new file mode 100644 index 00000000000..1cd4a527be0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/getclsig005.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define CLASS_SIGNATURE "Lnsk/jvmti/GetClassSignature/getclsig005;" + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclsig005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclsig005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclsig005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetClassSignature_getclsig005_check(JNIEnv *env, jclass cls) { + jvmtiError err; + char *sig, *generic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->GetClassSignature(NULL, &sig, &generic); + if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (signature_ptr) null pointer check ...\n"); + } + err = jvmti->GetClassSignature(cls, NULL, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(signature_ptr) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + if (printdump == JNI_TRUE) { + printf(">>> generic = \"%s\"\n", generic); + } + } + + if (printdump == JNI_TRUE) { + printf(">>> (generic_ptr) null pointer check ...\n"); + } + err = jvmti->GetClassSignature(cls, &sig, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(generic_ptr) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + if (printdump == JNI_TRUE) { + printf(">>> sig = \"%s\"\n", sig); + } + if (sig == NULL || strcmp(sig, CLASS_SIGNATURE) != 0) { + printf("Wrong class sig: \"%s\", expected: \"%s\"\n", + CLASS_SIGNATURE, sig); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/libgetclsig005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/libgetclsig005.c deleted file mode 100644 index d10f78686ad..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/libgetclsig005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclsig005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/libgetclsig005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/libgetclsig005.cpp new file mode 100644 index 00000000000..bc09693aa88 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/libgetclsig005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclsig005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/getclsig006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/getclsig006.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/getclsig006.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/getclsig006.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/libgetclsig006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/libgetclsig006.c deleted file mode 100644 index dfc6e007cc9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/libgetclsig006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclsig006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/libgetclsig006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/libgetclsig006.cpp new file mode 100644 index 00000000000..6ecafc120d7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig006/libgetclsig006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclsig006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/getclstat005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/getclstat005.c deleted file mode 100644 index 08b458c9225..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/getclstat005.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclstat005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclstat005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclstat005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetClassStatus_getclstat005_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jint status; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->GetClassStatus(jvmti, NULL, &status); - if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetClassStatus(jvmti, cls, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/getclstat005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/getclstat005.cpp new file mode 100644 index 00000000000..6f15efa513b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/getclstat005.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclstat005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclstat005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclstat005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetClassStatus_getclstat005_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jint status; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->GetClassStatus(NULL, &status); + if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetClassStatus(cls, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/libgetclstat005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/libgetclstat005.c deleted file mode 100644 index 43b4f95af4f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/libgetclstat005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclstat005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/libgetclstat005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/libgetclstat005.cpp new file mode 100644 index 00000000000..543b70d6551 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/libgetclstat005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclstat005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/getclstat006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/getclstat006.c deleted file mode 100644 index 15fa9867f3f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/getclstat006.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - jint value; - char *name; -} bit_info; - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static bit_info bits[] = { - { JVMTI_CLASS_STATUS_INITIALIZED, "JVMTI_CLASS_STATUS_INITIALIZED" }, - { JVMTI_CLASS_STATUS_ERROR, "JVMTI_CLASS_STATUS_ERROR" } -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclstat006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclstat006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclstat006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetClassStatus_getclstat006_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { - jvmtiError err; - jint status; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassStatus(jvmti, clazz, &status); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassStatus#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %d: status = 0x%0x\n", i, status); - } - - if ((status & bits[i].value) == 0) { - printf("(%d) %s bit not set\n", i, bits[i].name); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassStatus_getclstat006_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/getclstat006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/getclstat006.cpp new file mode 100644 index 00000000000..28202ac41cc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/getclstat006.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + jint value; + const char *name; +} bit_info; + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static bit_info bits[] = { + { JVMTI_CLASS_STATUS_INITIALIZED, "JVMTI_CLASS_STATUS_INITIALIZED" }, + { JVMTI_CLASS_STATUS_ERROR, "JVMTI_CLASS_STATUS_ERROR" } +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclstat006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclstat006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclstat006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetClassStatus_getclstat006_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { + jvmtiError err; + jint status; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassStatus(clazz, &status); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassStatus#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %d: status = 0x%0x\n", i, status); + } + + if ((status & bits[i].value) == 0) { + printf("(%d) %s bit not set\n", i, bits[i].name); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassStatus_getclstat006_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/libgetclstat006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/libgetclstat006.c deleted file mode 100644 index 35ad11878c1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/libgetclstat006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclstat006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/libgetclstat006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/libgetclstat006.cpp new file mode 100644 index 00000000000..ce23248f3a7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/libgetclstat006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclstat006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/getclstat007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/getclstat007.c deleted file mode 100644 index 7ac3003654a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/getclstat007.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getclstat007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getclstat007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getclstat007(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetClassStatus_getclstat007_check(JNIEnv *env, jclass cls, - jint i, jclass klass, jboolean is_array) { - jvmtiError err; - jint status; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassStatus(jvmti, klass, &status); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassStatus#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %d: 0x%0x\n", i, status); - } - - if (i == 0) { - if ((status & JVMTI_CLASS_STATUS_VERIFIED) == 0) { - printf("(%d) JVMTI_CLASS_STATUS_VERIFIED bit should be set\n", i); - result = STATUS_FAILED; - } - if ((status & JVMTI_CLASS_STATUS_PREPARED) == 0) { - printf("(%d) JVMTI_CLASS_STATUS_PREPARED bit should be set\n", i); - result = STATUS_FAILED; - } - if ((status & JVMTI_CLASS_STATUS_INITIALIZED) == 0) { - printf("(%d) JVMTI_CLASS_STATUS_INITIALIZED bit should be set\n", i); - result = STATUS_FAILED; - } - if ((status & JVMTI_CLASS_STATUS_ERROR) != 0) { - printf("(%d) JVMTI_CLASS_STATUS_ERROR bit should be clear\n", i); - result = STATUS_FAILED; - } - if ((status & JVMTI_CLASS_STATUS_ARRAY) != 0) { - printf("(%d) JVMTI_CLASS_STATUS_ARRAY bit should be clear\n", i); - result = STATUS_FAILED; - } - if ((status & JVMTI_CLASS_STATUS_PRIMITIVE) != 0) { - printf("(%d) JVMTI_CLASS_STATUS_PRIMITIVEbit should be clear\n", i); - result = STATUS_FAILED; - } - } else if (is_array == JNI_TRUE) { - if ((status & JVMTI_CLASS_STATUS_ARRAY) == 0) { - printf("(%d) JVMTI_CLASS_STATUS_ARRAY bit should be set\n", i); - result = STATUS_FAILED; - } - if ((status & (~JVMTI_CLASS_STATUS_ARRAY)) != 0) { - printf("(%d) not JVMTI_CLASS_STATUS_ARRAY bits should be clear: 0x%0x\n", - i, status); - result = STATUS_FAILED; - } - } else { - if ((status & JVMTI_CLASS_STATUS_PRIMITIVE) == 0) { - printf("(%d) JVMTI_CLASS_STATUS_PRIMITIVE bit should be set\n", i); - result = STATUS_FAILED; - } - if ((status & (~JVMTI_CLASS_STATUS_PRIMITIVE)) != 0) { - printf("(%d) not JVMTI_CLASS_STATUS_PRIMITIVE bits should be clear: 0x%0x\n", - i, status); - result = STATUS_FAILED; - } - } -} - -JNIEXPORT int JNICALL -Java_nsk_jvmti_GetClassStatus_getclstat007_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/getclstat007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/getclstat007.cpp new file mode 100644 index 00000000000..cfeb3a5fda2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/getclstat007.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getclstat007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getclstat007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getclstat007(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetClassStatus_getclstat007_check(JNIEnv *env, jclass cls, + jint i, jclass klass, jboolean is_array) { + jvmtiError err; + jint status; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassStatus(klass, &status); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassStatus#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %d: 0x%0x\n", i, status); + } + + if (i == 0) { + if ((status & JVMTI_CLASS_STATUS_VERIFIED) == 0) { + printf("(%d) JVMTI_CLASS_STATUS_VERIFIED bit should be set\n", i); + result = STATUS_FAILED; + } + if ((status & JVMTI_CLASS_STATUS_PREPARED) == 0) { + printf("(%d) JVMTI_CLASS_STATUS_PREPARED bit should be set\n", i); + result = STATUS_FAILED; + } + if ((status & JVMTI_CLASS_STATUS_INITIALIZED) == 0) { + printf("(%d) JVMTI_CLASS_STATUS_INITIALIZED bit should be set\n", i); + result = STATUS_FAILED; + } + if ((status & JVMTI_CLASS_STATUS_ERROR) != 0) { + printf("(%d) JVMTI_CLASS_STATUS_ERROR bit should be clear\n", i); + result = STATUS_FAILED; + } + if ((status & JVMTI_CLASS_STATUS_ARRAY) != 0) { + printf("(%d) JVMTI_CLASS_STATUS_ARRAY bit should be clear\n", i); + result = STATUS_FAILED; + } + if ((status & JVMTI_CLASS_STATUS_PRIMITIVE) != 0) { + printf("(%d) JVMTI_CLASS_STATUS_PRIMITIVEbit should be clear\n", i); + result = STATUS_FAILED; + } + } else if (is_array == JNI_TRUE) { + if ((status & JVMTI_CLASS_STATUS_ARRAY) == 0) { + printf("(%d) JVMTI_CLASS_STATUS_ARRAY bit should be set\n", i); + result = STATUS_FAILED; + } + if ((status & (~JVMTI_CLASS_STATUS_ARRAY)) != 0) { + printf("(%d) not JVMTI_CLASS_STATUS_ARRAY bits should be clear: 0x%0x\n", + i, status); + result = STATUS_FAILED; + } + } else { + if ((status & JVMTI_CLASS_STATUS_PRIMITIVE) == 0) { + printf("(%d) JVMTI_CLASS_STATUS_PRIMITIVE bit should be set\n", i); + result = STATUS_FAILED; + } + if ((status & (~JVMTI_CLASS_STATUS_PRIMITIVE)) != 0) { + printf("(%d) not JVMTI_CLASS_STATUS_PRIMITIVE bits should be clear: 0x%0x\n", + i, status); + result = STATUS_FAILED; + } + } +} + +JNIEXPORT int JNICALL +Java_nsk_jvmti_GetClassStatus_getclstat007_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/libgetclstat007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/libgetclstat007.c deleted file mode 100644 index 5fef33afb72..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/libgetclstat007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getclstat007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/libgetclstat007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/libgetclstat007.cpp new file mode 100644 index 00000000000..375ca5def93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/libgetclstat007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getclstat007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/contmon001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/contmon001.c deleted file mode 100644 index a8e86a13e39..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/contmon001.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_contmon001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_contmon001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_contmon001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - if ((err = ((*jvmti)->GetCapabilities(jvmti, &caps))) != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_current_contended_monitor) { - /* GetCurrentContendedMonitor is not currently available, but - * is it potentially available? - */ - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - if (caps.can_get_current_contended_monitor) { - /* Yes, GetCurrentContendedMonitor is potentially available. - * Let's turn it on! - */ - memset(&caps, 0, sizeof(jvmtiCapabilities)); - caps.can_get_current_contended_monitor = 1; - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: GetCurrentContendedMonitor is not implemented\n"); - } - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_GetCurrentContendedMonitor_contmon001_checkMon(JNIEnv *env, jclass cls, - jint point, jthread thr, jobject lock) { - jvmtiError err; - jobject mon = NULL; - - err = (*jvmti)->GetCurrentContendedMonitor(jvmti, thr, &mon); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_current_contended_monitor) { - /* It's OK */ - } else if (err == JVMTI_ERROR_THREAD_NOT_ALIVE && point == 5) { - return; /* Ok, it must be a dead thread */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetCurrentContendedMonitor#%d) unexpected error: %s (%d)\n", - point, TranslateError(err), err); - result = STATUS_FAILED; - } else if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, lock), mon) - == JNI_FALSE) { - printf("(IsSameObject#%d) unexpected monitor object: 0x%p\n", - point, mon); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_GetCurrentContendedMonitor_contmon001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/contmon001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/contmon001.cpp new file mode 100644 index 00000000000..55dadc13a78 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/contmon001.cpp @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_contmon001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_contmon001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_contmon001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + if ((err = (jvmti->GetCapabilities(&caps))) != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_current_contended_monitor) { + /* GetCurrentContendedMonitor is not currently available, but + * is it potentially available? + */ + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + if (caps.can_get_current_contended_monitor) { + /* Yes, GetCurrentContendedMonitor is potentially available. + * Let's turn it on! + */ + memset(&caps, 0, sizeof(jvmtiCapabilities)); + caps.can_get_current_contended_monitor = 1; + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: GetCurrentContendedMonitor is not implemented\n"); + } + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_GetCurrentContendedMonitor_contmon001_checkMon(JNIEnv *env, jclass cls, + jint point, jthread thr, jobject lock) { + jvmtiError err; + jobject mon = NULL; + + err = jvmti->GetCurrentContendedMonitor(thr, &mon); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_current_contended_monitor) { + /* It's OK */ + } else if (err == JVMTI_ERROR_THREAD_NOT_ALIVE && point == 5) { + return; /* Ok, it must be a dead thread */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetCurrentContendedMonitor#%d) unexpected error: %s (%d)\n", + point, TranslateError(err), err); + result = STATUS_FAILED; + } else if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, lock), mon) + == JNI_FALSE) { + printf("(IsSameObject#%d) unexpected monitor object: 0x%p\n", + point, mon); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_GetCurrentContendedMonitor_contmon001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/libcontmon001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/libcontmon001.c deleted file mode 100644 index db97710ec35..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/libcontmon001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "contmon001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/libcontmon001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/libcontmon001.cpp new file mode 100644 index 00000000000..ddea0c6bc8f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/libcontmon001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "contmon001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/contmon002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/contmon002.c deleted file mode 100644 index d1ac6809906..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/contmon002.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static jint result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_contmon002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_contmon002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_contmon002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - if ((err = ((*jvmti)->GetCapabilities(jvmti, &caps))) != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_current_contended_monitor) { - /* - * GetCurrentContendedMonitor is not currently available, but - * is it potentially available? - */ - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - if (caps.can_get_current_contended_monitor) { - /* - * Yes, GetCurrentContendedMonitor is potentially available. - * Let's turn it on! - */ - memset(&caps, 0, sizeof(jvmtiCapabilities)); - caps.can_get_current_contended_monitor = 1; - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: GetCurrentContendedMonitor is not implemented\n"); - } - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetCurrentContendedMonitor_contmon002_checkMon(JNIEnv *env, jclass cls, jint point, jthread thr) { - jvmtiError err; - jobject mon = NULL; - - err = (*jvmti)->GetCurrentContendedMonitor(jvmti, thr, &mon); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_current_contended_monitor) { - /* It is OK */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetCurrentContendedMonitor#%d) unexpected error: %s (%d)\n", - point, TranslateError(err), err); - result = STATUS_FAILED; - } else if (mon != NULL) { - printf("(#%d) unexpected monitor object: 0x%p\n", point, mon); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_GetCurrentContendedMonitor_contmon002_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/contmon002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/contmon002.cpp new file mode 100644 index 00000000000..018aaad3330 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/contmon002.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static jint result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_contmon002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_contmon002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_contmon002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + if ((err = (jvmti->GetCapabilities(&caps))) != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_current_contended_monitor) { + /* + * GetCurrentContendedMonitor is not currently available, but + * is it potentially available? + */ + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + if (caps.can_get_current_contended_monitor) { + /* + * Yes, GetCurrentContendedMonitor is potentially available. + * Let's turn it on! + */ + memset(&caps, 0, sizeof(jvmtiCapabilities)); + caps.can_get_current_contended_monitor = 1; + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: GetCurrentContendedMonitor is not implemented\n"); + } + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetCurrentContendedMonitor_contmon002_checkMon(JNIEnv *env, jclass cls, jint point, jthread thr) { + jvmtiError err; + jobject mon = NULL; + + err = jvmti->GetCurrentContendedMonitor(thr, &mon); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_current_contended_monitor) { + /* It is OK */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetCurrentContendedMonitor#%d) unexpected error: %s (%d)\n", + point, TranslateError(err), err); + result = STATUS_FAILED; + } else if (mon != NULL) { + printf("(#%d) unexpected monitor object: 0x%p\n", point, mon); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_GetCurrentContendedMonitor_contmon002_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/libcontmon002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/libcontmon002.c deleted file mode 100644 index 38dc0a1ba4b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/libcontmon002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "contmon002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/libcontmon002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/libcontmon002.cpp new file mode 100644 index 00000000000..2dfb30b25ac --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/libcontmon002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "contmon002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/contmon003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/contmon003.c deleted file mode 100644 index 2bbbfb825cc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/contmon003.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_contmon003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_contmon003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_contmon003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - if ((err = ((*jvmti)->GetCapabilities(jvmti, &caps))) != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_current_contended_monitor) { - /* - * GetCurrentContendedMonitor is not currently available, but - * is it potentially available? - */ - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - if (caps.can_get_current_contended_monitor) { - /* - * Yes, GetCurrentContendedMonitor is potentially available. - * Let's turn it on! - */ - memset(&caps, 0, sizeof(jvmtiCapabilities)); - caps.can_get_current_contended_monitor = 1; - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: GetCurrentContendedMonitor is not implemented\n"); - } - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetCurrentContendedMonitor_contmon003_check(JNIEnv *env, - jclass cls, jthread thr) { - jvmtiError err; - jobject monitor; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid thread check ...\n"); - } - err = (*jvmti)->GetCurrentContendedMonitor(jvmti, cls, &monitor); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_current_contended_monitor) { - /* It is OK */ - } else if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetCurrentContendedMonitor(jvmti, thr, NULL); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_current_contended_monitor) { - /* It is OK */ - } else if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/contmon003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/contmon003.cpp new file mode 100644 index 00000000000..4d94ae81a58 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/contmon003.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_contmon003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_contmon003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_contmon003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + if ((err = (jvmti->GetCapabilities(&caps))) != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_current_contended_monitor) { + /* + * GetCurrentContendedMonitor is not currently available, but + * is it potentially available? + */ + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + if (caps.can_get_current_contended_monitor) { + /* + * Yes, GetCurrentContendedMonitor is potentially available. + * Let's turn it on! + */ + memset(&caps, 0, sizeof(jvmtiCapabilities)); + caps.can_get_current_contended_monitor = 1; + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: GetCurrentContendedMonitor is not implemented\n"); + } + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetCurrentContendedMonitor_contmon003_check(JNIEnv *env, + jclass cls, jthread thr) { + jvmtiError err; + jobject monitor; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid thread check ...\n"); + } + err = jvmti->GetCurrentContendedMonitor(cls, &monitor); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_current_contended_monitor) { + /* It is OK */ + } else if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetCurrentContendedMonitor(thr, NULL); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_current_contended_monitor) { + /* It is OK */ + } else if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/libcontmon003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/libcontmon003.c deleted file mode 100644 index 8f98e75f22e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/libcontmon003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "contmon003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/libcontmon003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/libcontmon003.cpp new file mode 100644 index 00000000000..26194420029 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/libcontmon003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "contmon003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/curthrcputime001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/curthrcputime001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/curthrcputime001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/curthrcputime001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/libcurthrcputime001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/libcurthrcputime001.c deleted file mode 100644 index 88cd051647b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/libcurthrcputime001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "curthrcputime001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/libcurthrcputime001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/libcurthrcputime001.cpp new file mode 100644 index 00000000000..d094a23f94a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/libcurthrcputime001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "curthrcputime001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/curthrtimerinfo001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/curthrtimerinfo001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/curthrtimerinfo001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/curthrtimerinfo001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/libcurthrtimerinfo001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/libcurthrtimerinfo001.c deleted file mode 100644 index 15822c690f6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/libcurthrtimerinfo001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "curthrtimerinfo001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/libcurthrtimerinfo001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/libcurthrtimerinfo001.cpp new file mode 100644 index 00000000000..5e0fb6c2b2d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/libcurthrtimerinfo001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "curthrtimerinfo001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/GetEnv001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/GetEnv001.c deleted file mode 100644 index dce2e64e41b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/GetEnv001.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include -#include "agent_common.h" -#include -#include "JVMTITools.h" - -/* ============================================================================= */ - -static int loaded_classes_num = 0; - -/* ============================================================================= */ -static void JNICALL -ClassFileLoadHook ( - jvmtiEnv *jvmti - , JNIEnv *jni - , jclass class_being_redefined - , jobject loader - , const char* name - , jobject protection_domain - , jint class_data_len - , const unsigned char* class_data - , jint *new_class_data_len - , unsigned char** new_class_data - ) -{ - loaded_classes_num++; - - NSK_DISPLAY2("ClassFileLoadHook: class \"%s\", loader %X\n" - , name - , loader - ); -} - -/* ============================================================================= */ -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetEnv_GetEnv001_GetEnv001_getLoadedClassesCount(JNIEnv *env, jobject owner) { - return loaded_classes_num; -} - -/* ============================================================================= */ -/* Agent initialization procedure */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_GetEnv001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_GetEnv001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_GetEnv001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) -{ - jvmtiEventCallbacks callbacks; - jvmtiCapabilities caps; - jvmtiEnv* jvmti; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) { - return JNI_ERR; - } - - if (NSK_CPP_STUB3( - GetEnv - , vm - , (void **) &jvmti - , JVMTI_VERSION_1_1 - ) != JNI_OK || jvmti == NULL) - { - NSK_COMPLAIN0("JVMTI_VERSION_1_1 isn't supported."); - return JNI_OK; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - GetCapabilities - , jvmti - , &caps) - ) - ) - return JNI_ERR; - - caps.can_retransform_classes = 1; - - // Register all necessary JVM capabilities - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - AddCapabilities - , jvmti - , &caps) - ) - ) - return JNI_ERR; - - // Register all necessary event callbacks - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - SetEventCallbacks - , jvmti - , &callbacks - , sizeof(callbacks) - ) - ) - ) - return JNI_ERR; - - // Enable class retransformation - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4( - SetEventNotificationMode - , jvmti - , JVMTI_ENABLE - , JVMTI_EVENT_CLASS_FILE_LOAD_HOOK - , NULL - ) - ) - ) - return JNI_ERR; - - return JNI_OK; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/GetEnv001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/GetEnv001.cpp new file mode 100644 index 00000000000..988595b0ada --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/GetEnv001.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include +#include "agent_common.h" +#include +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static int loaded_classes_num = 0; + +/* ============================================================================= */ +static void JNICALL +ClassFileLoadHook ( + jvmtiEnv *jvmti + , JNIEnv *jni + , jclass class_being_redefined + , jobject loader + , const char* name + , jobject protection_domain + , jint class_data_len + , const unsigned char* class_data + , jint *new_class_data_len + , unsigned char** new_class_data + ) +{ + loaded_classes_num++; + + NSK_DISPLAY2("ClassFileLoadHook: class \"%s\", loader %X\n" + , name + , loader + ); +} + +/* ============================================================================= */ +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetEnv_GetEnv001_GetEnv001_getLoadedClassesCount(JNIEnv *env, jobject owner) { + return loaded_classes_num; +} + +/* ============================================================================= */ +/* Agent initialization procedure */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_GetEnv001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_GetEnv001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_GetEnv001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) +{ + jvmtiEventCallbacks callbacks; + jvmtiCapabilities caps; + jvmtiEnv* jvmti; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) { + return JNI_ERR; + } + + if (NSK_CPP_STUB3( + GetEnv + , vm + , (void **) &jvmti + , JVMTI_VERSION_1_1 + ) != JNI_OK || jvmti == NULL) + { + NSK_COMPLAIN0("JVMTI_VERSION_1_1 isn't supported."); + return JNI_OK; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + GetCapabilities + , jvmti + , &caps) + ) + ) + return JNI_ERR; + + caps.can_retransform_classes = 1; + + // Register all necessary JVM capabilities + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + AddCapabilities + , jvmti + , &caps) + ) + ) + return JNI_ERR; + + // Register all necessary event callbacks + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + SetEventCallbacks + , jvmti + , &callbacks + , sizeof(callbacks) + ) + ) + ) + return JNI_ERR; + + // Enable class retransformation + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4( + SetEventNotificationMode + , jvmti + , JVMTI_ENABLE + , JVMTI_EVENT_CLASS_FILE_LOAD_HOOK + , NULL + ) + ) + ) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/libGetEnv001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/libGetEnv001.c deleted file mode 100644 index 549699e1504..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/libGetEnv001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "GetEnv001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/libGetEnv001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/libGetEnv001.cpp new file mode 100644 index 00000000000..ca94ca2793a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnv/GetEnv001/libGetEnv001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "GetEnv001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/getenvstor001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/getenvstor001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/getenvstor001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/getenvstor001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/libgetenvstor001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/libgetenvstor001.c deleted file mode 100644 index 78783a26631..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/libgetenvstor001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getenvstor001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/libgetenvstor001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/libgetenvstor001.cpp new file mode 100644 index 00000000000..f91400249b1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/libgetenvstor001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getenvstor001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/geterrname001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/geterrname001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/geterrname001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/geterrname001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/libgeterrname001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/libgeterrname001.c deleted file mode 100644 index 7c3415e1db9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/libgeterrname001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "geterrname001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/libgeterrname001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/libgeterrname001.cpp new file mode 100644 index 00000000000..fa7ec18d207 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname001/libgeterrname001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "geterrname001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/geterrname002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/geterrname002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/geterrname002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/geterrname002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/libgeterrname002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/libgeterrname002.c deleted file mode 100644 index bf6a46b1632..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/libgeterrname002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "geterrname002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/libgeterrname002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/libgeterrname002.cpp new file mode 100644 index 00000000000..e763291ac74 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetErrorName/geterrname002/libgeterrname002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "geterrname002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/extevents001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/extevents001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/extevents001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/extevents001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/libextevents001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/libextevents001.c deleted file mode 100644 index 5d18782cff9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/libextevents001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "extevents001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/libextevents001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/libextevents001.cpp new file mode 100644 index 00000000000..ffeff754674 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionEvents/extevents001/libextevents001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "extevents001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/extfuncs001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/extfuncs001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/extfuncs001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/extfuncs001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/libextfuncs001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/libextfuncs001.c deleted file mode 100644 index c564a7b6715..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/libextfuncs001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "extfuncs001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/libextfuncs001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/libextfuncs001.cpp new file mode 100644 index 00000000000..ca0f1bcc6d3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetExtensionFunctions/extfuncs001/libextfuncs001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "extfuncs001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/getfldecl001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/getfldecl001.c deleted file mode 100644 index 9b6cd916715..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/getfldecl001.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x,y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x,y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static char* fields[] = { "x", "y", "z" }; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getfldecl001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getfldecl001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getfldecl001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetFieldDeclaringClass_getfldecl001_check(JNIEnv *env, - jclass cls, jint i, jclass cls1, jclass cls2) { - jvmtiError err; - jfieldID fid; - jclass declaringClass; - char *sig, *generic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (i == 0) { - fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls1), - fields[i], "I"); - } else { - fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls1), - fields[i], "I"); - } - if (fid == NULL) { - printf("(%d) cannot get field ID for %s:\"I\"\n", i, fields[i]); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetFieldDeclaringClass(jvmti, cls1, fid, &declaringClass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassSignature(jvmti, declaringClass, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %d -- %s: \"%s\"\n", i, fields[i], sig); - } - - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, cls2), - declaringClass) != JNI_TRUE) { - printf("(%d) unexpected declaringClass: %s\n", i, sig); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetFieldDeclaringClass_getfldecl001_getResult(JNIEnv *env, - jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/getfldecl001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/getfldecl001.cpp new file mode 100644 index 00000000000..ce5fc83143a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/getfldecl001.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x,y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x,y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static const char* fields[] = { "x", "y", "z" }; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getfldecl001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getfldecl001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getfldecl001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetFieldDeclaringClass_getfldecl001_check(JNIEnv *env, + jclass cls, jint i, jclass cls1, jclass cls2) { + jvmtiError err; + jfieldID fid; + jclass declaringClass; + char *sig, *generic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (i == 0) { + fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls1), + fields[i], "I"); + } else { + fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls1), + fields[i], "I"); + } + if (fid == NULL) { + printf("(%d) cannot get field ID for %s:\"I\"\n", i, fields[i]); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetFieldDeclaringClass(cls1, fid, &declaringClass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassSignature(declaringClass, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %d -- %s: \"%s\"\n", i, fields[i], sig); + } + + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, cls2), + declaringClass) != JNI_TRUE) { + printf("(%d) unexpected declaringClass: %s\n", i, sig); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetFieldDeclaringClass_getfldecl001_getResult(JNIEnv *env, + jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/libgetfldecl001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/libgetfldecl001.c deleted file mode 100644 index a83c4b587f5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/libgetfldecl001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getfldecl001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/libgetfldecl001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/libgetfldecl001.cpp new file mode 100644 index 00000000000..f7f6cd10f02 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl001/libgetfldecl001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getfldecl001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/getfldecl002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/getfldecl002.c deleted file mode 100644 index bedbcfce427..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/getfldecl002.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x,y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x,y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static char* fields[] = { "const1", "fld", "xx" }; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getfldecl002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getfldecl002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getfldecl002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetFieldDeclaringClass_getfldecl002_check(JNIEnv *env, - jclass cls, jint i, jclass cls1, jclass cls2) { - jvmtiError err; - jfieldID fid; - jclass declaringClass; - char *sig, *generic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (i == 0) { - fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls1), - fields[i], "I"); - } else { - fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls1), - fields[i], "I"); - } - if (fid == NULL) { - printf("(%d) cannot get field ID for %s:\"I\"\n", i, fields[i]); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetFieldDeclaringClass(jvmti, cls1, fid, &declaringClass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassSignature(jvmti, declaringClass, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %d -- %s: \"%s\"\n", i, fields[i], sig); - } - - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, cls2), - declaringClass) != JNI_TRUE) { - printf("(%d) unexpected declaringClass: %s\n", i, sig); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_GetFieldDeclaringClass_getfldecl002_getResult(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/getfldecl002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/getfldecl002.cpp new file mode 100644 index 00000000000..f80b6fbe158 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/getfldecl002.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x,y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x,y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static const char* fields[] = { "const1", "fld", "xx" }; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getfldecl002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getfldecl002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getfldecl002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetFieldDeclaringClass_getfldecl002_check(JNIEnv *env, + jclass cls, jint i, jclass cls1, jclass cls2) { + jvmtiError err; + jfieldID fid; + jclass declaringClass; + char *sig, *generic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (i == 0) { + fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls1), + fields[i], "I"); + } else { + fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls1), + fields[i], "I"); + } + if (fid == NULL) { + printf("(%d) cannot get field ID for %s:\"I\"\n", i, fields[i]); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetFieldDeclaringClass(cls1, fid, &declaringClass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassSignature(declaringClass, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %d -- %s: \"%s\"\n", i, fields[i], sig); + } + + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, cls2), + declaringClass) != JNI_TRUE) { + printf("(%d) unexpected declaringClass: %s\n", i, sig); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_GetFieldDeclaringClass_getfldecl002_getResult(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/libgetfldecl002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/libgetfldecl002.c deleted file mode 100644 index 095f2ebb9a9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/libgetfldecl002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getfldecl002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/libgetfldecl002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/libgetfldecl002.cpp new file mode 100644 index 00000000000..7c21fce37cf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl002/libgetfldecl002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getfldecl002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/getfldecl004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/getfldecl004.c deleted file mode 100644 index 286fcf97da9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/getfldecl004.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *name; - char *sig; - jboolean is_static; -} field_info; - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static field_info fields[] = { - { "staticField_ii1", "I", JNI_TRUE }, - { "staticField_ii2", "I", JNI_TRUE }, - { "staticField_ic1", "I", JNI_TRUE }, - { "instanceField_ic1", "I", JNI_FALSE }, - { "staticField_ic2", "I", JNI_TRUE }, - { "instanceField_ic2", "I", JNI_FALSE }, - { "staticField_oi1", "I", JNI_TRUE }, - { "staticField_oi2", "I", JNI_TRUE }, - { "staticField_oc1", "I", JNI_TRUE }, - { "instanceField_oc1", "I", JNI_FALSE }, - { "staticField_oc2", "I", JNI_TRUE }, - { "instanceField_oc2", "I", JNI_FALSE } -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getfldecl004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getfldecl004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getfldecl004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetFieldDeclaringClass_getfldecl004_check(JNIEnv *env, - jclass cls, jint i, jclass cls1, jclass cls2) { - jvmtiError err; - jfieldID fid; - jclass declaringClass; - char *sig, *generic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (fields[i].is_static == JNI_TRUE) { - fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls1), - fields[i].name, fields[i].sig); - } else { - fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls1), - fields[i].name, fields[i].sig); - } - if (fid == NULL) { - printf("(%d) cannot get field ID for %s:\"%s\"\n", - i, fields[i].name, fields[i].sig); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetFieldDeclaringClass(jvmti, cls1, fid, &declaringClass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassSignature(jvmti, declaringClass, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %d -- %s: \"%s\"\n", i, fields[i].name, sig); - } - - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, cls2), - declaringClass) != JNI_TRUE) { - printf("(%d) unexpected declaringClass: %s\n", i, sig); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL Java_nsk_jvmti_GetFieldDeclaringClass_getfldecl004_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/getfldecl004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/getfldecl004.cpp new file mode 100644 index 00000000000..84fcb41f226 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/getfldecl004.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + const char *sig; + jboolean is_static; +} field_info; + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static field_info fields[] = { + { "staticField_ii1", "I", JNI_TRUE }, + { "staticField_ii2", "I", JNI_TRUE }, + { "staticField_ic1", "I", JNI_TRUE }, + { "instanceField_ic1", "I", JNI_FALSE }, + { "staticField_ic2", "I", JNI_TRUE }, + { "instanceField_ic2", "I", JNI_FALSE }, + { "staticField_oi1", "I", JNI_TRUE }, + { "staticField_oi2", "I", JNI_TRUE }, + { "staticField_oc1", "I", JNI_TRUE }, + { "instanceField_oc1", "I", JNI_FALSE }, + { "staticField_oc2", "I", JNI_TRUE }, + { "instanceField_oc2", "I", JNI_FALSE } +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getfldecl004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getfldecl004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getfldecl004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetFieldDeclaringClass_getfldecl004_check(JNIEnv *env, + jclass cls, jint i, jclass cls1, jclass cls2) { + jvmtiError err; + jfieldID fid; + jclass declaringClass; + char *sig, *generic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (fields[i].is_static == JNI_TRUE) { + fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls1), + fields[i].name, fields[i].sig); + } else { + fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls1), + fields[i].name, fields[i].sig); + } + if (fid == NULL) { + printf("(%d) cannot get field ID for %s:\"%s\"\n", + i, fields[i].name, fields[i].sig); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetFieldDeclaringClass(cls1, fid, &declaringClass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassSignature(declaringClass, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %d -- %s: \"%s\"\n", i, fields[i].name, sig); + } + + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, cls2), + declaringClass) != JNI_TRUE) { + printf("(%d) unexpected declaringClass: %s\n", i, sig); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL Java_nsk_jvmti_GetFieldDeclaringClass_getfldecl004_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/libgetfldecl004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/libgetfldecl004.c deleted file mode 100644 index d77f3d6a7b8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/libgetfldecl004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getfldecl004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/libgetfldecl004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/libgetfldecl004.cpp new file mode 100644 index 00000000000..4fb4376ce1c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldDeclaringClass/getfldecl004/libgetfldecl004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getfldecl004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/getfldmdf003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/getfldmdf003.c deleted file mode 100644 index 6a677debe3e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/getfldmdf003.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getfldmdf003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getfldmdf003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getfldmdf003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetFieldModifiers_getfldmdf003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jfieldID fid; - jint modifiers; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld", "I"); - if (fid == NULL) { - printf("Cannot get field ID!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->GetFieldModifiers(jvmti, NULL, fid, &modifiers); - if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid field check ...\n"); - } - err = (*jvmti)->GetFieldModifiers(jvmti, cls, NULL, &modifiers); - if (err != JVMTI_ERROR_INVALID_FIELDID) { - printf("Error expected: JVMTI_ERROR_INVALID_FIELDID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetFieldModifiers(jvmti, cls, fid, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(namePtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/getfldmdf003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/getfldmdf003.cpp new file mode 100644 index 00000000000..850321fa4e6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/getfldmdf003.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getfldmdf003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getfldmdf003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getfldmdf003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetFieldModifiers_getfldmdf003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jfieldID fid; + jint modifiers; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld", "I"); + if (fid == NULL) { + printf("Cannot get field ID!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->GetFieldModifiers(NULL, fid, &modifiers); + if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid field check ...\n"); + } + err = jvmti->GetFieldModifiers(cls, NULL, &modifiers); + if (err != JVMTI_ERROR_INVALID_FIELDID) { + printf("Error expected: JVMTI_ERROR_INVALID_FIELDID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetFieldModifiers(cls, fid, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(namePtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/libgetfldmdf003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/libgetfldmdf003.c deleted file mode 100644 index 50f0ec900c7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/libgetfldmdf003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getfldmdf003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/libgetfldmdf003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/libgetfldmdf003.cpp new file mode 100644 index 00000000000..7f62cc75280 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf003/libgetfldmdf003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getfldmdf003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/getfldmdf004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/getfldmdf004.c deleted file mode 100644 index 8ab591e0eb8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/getfldmdf004.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define ACC_PUBLIC 0x0001 -#define ACC_PRIVATE 0x0002 -#define ACC_PROTECTED 0x0004 -#define ACC_STATIC 0x0008 -#define ACC_FINAL 0x0010 -#define ACC_SUPER 0x0020 -#define ACC_VOLATILE 0x0040 -#define ACC_TRANSIENT 0x0080 -#define ACC_NATIVE 0x0100 -#define ACC_INTERFACE 0x0200 -#define ACC_ABSTRACT 0x0400 -#define ACC_STRICT 0x0800 - -typedef struct { - char *name; - char *sig; - jboolean is_static; -} field_info; - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static field_info fields[] = { - { "field0", "I", JNI_FALSE }, - { "field1", "I", JNI_FALSE }, - { "field2", "I", JNI_FALSE }, - { "field3", "I", JNI_FALSE }, - { "field4", "I", JNI_FALSE }, - { "field5", "I", JNI_FALSE }, - { "field6", "I", JNI_FALSE }, - { "field7", "I", JNI_FALSE }, - { "field8", "I", JNI_FALSE }, - { "field9", "I", JNI_FALSE }, - { "field10", "I", JNI_FALSE }, - { "field11", "I", JNI_FALSE }, - { "field12", "I", JNI_FALSE }, - { "field13", "I", JNI_FALSE }, - { "field14", "I", JNI_FALSE }, - { "field15", "I", JNI_FALSE }, - { "field16", "I", JNI_FALSE }, - { "field17", "I", JNI_FALSE }, - { "field18", "I", JNI_FALSE }, - { "field19", "I", JNI_FALSE }, - { "field20", "I", JNI_FALSE }, - { "field21", "I", JNI_FALSE }, - { "field22", "I", JNI_FALSE }, - { "field23", "I", JNI_FALSE }, - - { "field24", "I", JNI_TRUE }, - { "field25", "I", JNI_TRUE }, - { "field26", "I", JNI_TRUE }, - { "field27", "I", JNI_TRUE }, - { "field28", "I", JNI_TRUE }, - { "field29", "I", JNI_TRUE }, - { "field30", "I", JNI_TRUE }, - { "field31", "I", JNI_TRUE }, - { "field32", "I", JNI_TRUE }, - { "field33", "I", JNI_TRUE }, - { "field34", "I", JNI_TRUE }, - { "field35", "I", JNI_TRUE }, - { "field36", "I", JNI_TRUE }, - { "field37", "I", JNI_TRUE }, - { "field38", "I", JNI_TRUE }, - { "field39", "I", JNI_TRUE }, - { "field40", "I", JNI_TRUE }, - { "field41", "I", JNI_TRUE }, - { "field42", "I", JNI_TRUE }, - { "field43", "I", JNI_TRUE }, - { "field44", "I", JNI_TRUE }, - { "field45", "I", JNI_TRUE }, - { "field46", "I", JNI_TRUE }, - { "field47", "I", JNI_TRUE } -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getfldmdf004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getfldmdf004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getfldmdf004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -void printModifiers(jint mod) { - if (mod & ACC_PUBLIC) printf(" PUBLIC"); - if (mod & ACC_PRIVATE) printf(" PRIVATE"); - if (mod & ACC_PROTECTED) printf(" PROTECTED"); - if (mod & ACC_STATIC) printf(" STATIC"); - if (mod & ACC_FINAL) printf(" FINAL"); - if (mod & ACC_SUPER) printf(" SUPER"); - if (mod & ACC_VOLATILE) printf(" VOLATILE"); - if (mod & ACC_TRANSIENT) printf(" TRANSIENT"); - if (mod & ACC_NATIVE) printf(" NATIVE"); - if (mod & ACC_INTERFACE) printf(" INTERFACE"); - if (mod & ACC_ABSTRACT) printf(" ABSTRACT"); - if (mod & ACC_STRICT) printf(" STRICT"); - printf(" (0x%0x)\n", mod); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetFieldModifiers_getfldmdf004_check(JNIEnv *env, - jclass cls, jint i, jint mod) { - jvmtiError err; - jfieldID fid; - jint modifiers; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (fields[i].is_static == JNI_TRUE) { - fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - fields[i].name, fields[i].sig); - } else { - fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), - fields[i].name, fields[i].sig); - } - if (fid == NULL) { - printf("(%d) cannot get field ID for %s:\"%s\"\n", - i, fields[i].name, fields[i].sig); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetFieldModifiers(jvmti, cls, fid, &modifiers); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldModifiers#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %2d:", i); - printModifiers(modifiers); - } - - if (modifiers != mod) { - printf("(%2d) access flags expected:", i); - printModifiers(mod); - printf("\t\t actual:"); - printModifiers(modifiers); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL -Java_nsk_jvmti_GetFieldModifiers_getfldmdf004_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/getfldmdf004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/getfldmdf004.cpp new file mode 100644 index 00000000000..d21c08da1a7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/getfldmdf004.cpp @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define ACC_PUBLIC 0x0001 +#define ACC_PRIVATE 0x0002 +#define ACC_PROTECTED 0x0004 +#define ACC_STATIC 0x0008 +#define ACC_FINAL 0x0010 +#define ACC_SUPER 0x0020 +#define ACC_VOLATILE 0x0040 +#define ACC_TRANSIENT 0x0080 +#define ACC_NATIVE 0x0100 +#define ACC_INTERFACE 0x0200 +#define ACC_ABSTRACT 0x0400 +#define ACC_STRICT 0x0800 + +typedef struct { + const char *name; + const char *sig; + jboolean is_static; +} field_info; + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static field_info fields[] = { + { "field0", "I", JNI_FALSE }, + { "field1", "I", JNI_FALSE }, + { "field2", "I", JNI_FALSE }, + { "field3", "I", JNI_FALSE }, + { "field4", "I", JNI_FALSE }, + { "field5", "I", JNI_FALSE }, + { "field6", "I", JNI_FALSE }, + { "field7", "I", JNI_FALSE }, + { "field8", "I", JNI_FALSE }, + { "field9", "I", JNI_FALSE }, + { "field10", "I", JNI_FALSE }, + { "field11", "I", JNI_FALSE }, + { "field12", "I", JNI_FALSE }, + { "field13", "I", JNI_FALSE }, + { "field14", "I", JNI_FALSE }, + { "field15", "I", JNI_FALSE }, + { "field16", "I", JNI_FALSE }, + { "field17", "I", JNI_FALSE }, + { "field18", "I", JNI_FALSE }, + { "field19", "I", JNI_FALSE }, + { "field20", "I", JNI_FALSE }, + { "field21", "I", JNI_FALSE }, + { "field22", "I", JNI_FALSE }, + { "field23", "I", JNI_FALSE }, + + { "field24", "I", JNI_TRUE }, + { "field25", "I", JNI_TRUE }, + { "field26", "I", JNI_TRUE }, + { "field27", "I", JNI_TRUE }, + { "field28", "I", JNI_TRUE }, + { "field29", "I", JNI_TRUE }, + { "field30", "I", JNI_TRUE }, + { "field31", "I", JNI_TRUE }, + { "field32", "I", JNI_TRUE }, + { "field33", "I", JNI_TRUE }, + { "field34", "I", JNI_TRUE }, + { "field35", "I", JNI_TRUE }, + { "field36", "I", JNI_TRUE }, + { "field37", "I", JNI_TRUE }, + { "field38", "I", JNI_TRUE }, + { "field39", "I", JNI_TRUE }, + { "field40", "I", JNI_TRUE }, + { "field41", "I", JNI_TRUE }, + { "field42", "I", JNI_TRUE }, + { "field43", "I", JNI_TRUE }, + { "field44", "I", JNI_TRUE }, + { "field45", "I", JNI_TRUE }, + { "field46", "I", JNI_TRUE }, + { "field47", "I", JNI_TRUE } +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getfldmdf004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getfldmdf004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getfldmdf004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +void printModifiers(jint mod) { + if (mod & ACC_PUBLIC) printf(" PUBLIC"); + if (mod & ACC_PRIVATE) printf(" PRIVATE"); + if (mod & ACC_PROTECTED) printf(" PROTECTED"); + if (mod & ACC_STATIC) printf(" STATIC"); + if (mod & ACC_FINAL) printf(" FINAL"); + if (mod & ACC_SUPER) printf(" SUPER"); + if (mod & ACC_VOLATILE) printf(" VOLATILE"); + if (mod & ACC_TRANSIENT) printf(" TRANSIENT"); + if (mod & ACC_NATIVE) printf(" NATIVE"); + if (mod & ACC_INTERFACE) printf(" INTERFACE"); + if (mod & ACC_ABSTRACT) printf(" ABSTRACT"); + if (mod & ACC_STRICT) printf(" STRICT"); + printf(" (0x%0x)\n", mod); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetFieldModifiers_getfldmdf004_check(JNIEnv *env, + jclass cls, jint i, jint mod) { + jvmtiError err; + jfieldID fid; + jint modifiers; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (fields[i].is_static == JNI_TRUE) { + fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + fields[i].name, fields[i].sig); + } else { + fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), + fields[i].name, fields[i].sig); + } + if (fid == NULL) { + printf("(%d) cannot get field ID for %s:\"%s\"\n", + i, fields[i].name, fields[i].sig); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetFieldModifiers(cls, fid, &modifiers); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldModifiers#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %2d:", i); + printModifiers(modifiers); + } + + if (modifiers != mod) { + printf("(%2d) access flags expected:", i); + printModifiers(mod); + printf("\t\t actual:"); + printModifiers(modifiers); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL +Java_nsk_jvmti_GetFieldModifiers_getfldmdf004_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/libgetfldmdf004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/libgetfldmdf004.c deleted file mode 100644 index 365841f1c02..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/libgetfldmdf004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getfldmdf004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/libgetfldmdf004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/libgetfldmdf004.cpp new file mode 100644 index 00000000000..f0e5886f6c0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldModifiers/getfldmdf004/libgetfldmdf004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getfldmdf004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/getfldnm003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/getfldnm003.c deleted file mode 100644 index 314f01fe1d9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/getfldnm003.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getfldnm003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getfldnm003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getfldnm003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetFieldName_getfldnm003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jfieldID field; - char *name, *sig, *generic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld", "I"); - if (field == NULL) { - printf("Cannot get field ID!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->GetFieldName(jvmti, NULL, field, &name, &sig, &generic); - if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid field check ...\n"); - } - err = (*jvmti)->GetFieldName(jvmti, cls, NULL, &name, &sig, &generic); - if (err != JVMTI_ERROR_INVALID_FIELDID) { - printf("Error expected: JVMTI_ERROR_INVALID_FIELDID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (namePtr) null pointer check ...\n"); - } - err = (*jvmti)->GetFieldName(jvmti, cls, field, NULL, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(name_ptr) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - if (printdump == JNI_TRUE) { - printf(">>> sig = \"%s\", generic = \"%s\"\n", sig, generic); - } - if (sig == NULL || strcmp(sig, "I") != 0) { - printf("Wrong field sig: \"%s\", expected: \"I\"\n", sig); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> (signature_ptr) null pointer check ...\n"); - } - err = (*jvmti)->GetFieldName(jvmti, cls, field, &name, NULL, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(signaturePtr) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - if (printdump == JNI_TRUE) { - printf(">>> name = \"%s\", generic = \"%s\"\n", name, generic); - } - if (name == NULL || strcmp(name, "fld") != 0) { - printf("Wrong field name: \"%s\", expected: \"fld\"\n", name); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> (generic_ptr) null pointer check ...\n"); - } - err = (*jvmti)->GetFieldName(jvmti, cls, field, &name, &sig, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(signaturePtr) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - if (printdump == JNI_TRUE) { - printf(">>> name = \"%s\", sig = \"%s\"\n", name, sig); - } - if (name == NULL || strcmp(name, "fld") != 0) { - printf("Wrong field name: \"%s\", expected: \"fld\"\n", name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, "I") != 0) { - printf("Wrong field sig: \"%s\", expected: \"I\"\n", sig); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/getfldnm003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/getfldnm003.cpp new file mode 100644 index 00000000000..5c2ce75d62a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/getfldnm003.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getfldnm003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getfldnm003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getfldnm003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetFieldName_getfldnm003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jfieldID field; + char *name, *sig, *generic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld", "I"); + if (field == NULL) { + printf("Cannot get field ID!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->GetFieldName(NULL, field, &name, &sig, &generic); + if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid field check ...\n"); + } + err = jvmti->GetFieldName(cls, NULL, &name, &sig, &generic); + if (err != JVMTI_ERROR_INVALID_FIELDID) { + printf("Error expected: JVMTI_ERROR_INVALID_FIELDID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (namePtr) null pointer check ...\n"); + } + err = jvmti->GetFieldName(cls, field, NULL, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(name_ptr) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + if (printdump == JNI_TRUE) { + printf(">>> sig = \"%s\", generic = \"%s\"\n", sig, generic); + } + if (sig == NULL || strcmp(sig, "I") != 0) { + printf("Wrong field sig: \"%s\", expected: \"I\"\n", sig); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> (signature_ptr) null pointer check ...\n"); + } + err = jvmti->GetFieldName(cls, field, &name, NULL, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(signaturePtr) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + if (printdump == JNI_TRUE) { + printf(">>> name = \"%s\", generic = \"%s\"\n", name, generic); + } + if (name == NULL || strcmp(name, "fld") != 0) { + printf("Wrong field name: \"%s\", expected: \"fld\"\n", name); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> (generic_ptr) null pointer check ...\n"); + } + err = jvmti->GetFieldName(cls, field, &name, &sig, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(signaturePtr) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + if (printdump == JNI_TRUE) { + printf(">>> name = \"%s\", sig = \"%s\"\n", name, sig); + } + if (name == NULL || strcmp(name, "fld") != 0) { + printf("Wrong field name: \"%s\", expected: \"fld\"\n", name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, "I") != 0) { + printf("Wrong field sig: \"%s\", expected: \"I\"\n", sig); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/libgetfldnm003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/libgetfldnm003.c deleted file mode 100644 index 3d7e66b1a92..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/libgetfldnm003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getfldnm003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/libgetfldnm003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/libgetfldnm003.cpp new file mode 100644 index 00000000000..43a2bf6455e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/libgetfldnm003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getfldnm003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/getfldnm004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/getfldnm004.c deleted file mode 100644 index 1adb681255c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/getfldnm004.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *name; - char *sig; - jboolean is_static; -} field_info; - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static field_info fields[] = { - { "staticBoolean", "Z", JNI_TRUE }, - { "staticByte", "B", JNI_TRUE }, - { "staticShort", "S", JNI_TRUE }, - { "staticInt", "I", JNI_TRUE }, - { "staticLong", "J", JNI_TRUE }, - { "staticFloat", "F", JNI_TRUE }, - { "staticDouble", "D", JNI_TRUE }, - { "staticChar", "C", JNI_TRUE }, - { "staticObject", "Ljava/lang/Object;", JNI_TRUE }, - { "staticArrInt", "[I", JNI_TRUE }, - - { "instanceBoolean", "Z", JNI_FALSE }, - { "instanceByte", "B", JNI_FALSE }, - { "instanceShort", "S", JNI_FALSE }, - { "instanceInt", "I", JNI_FALSE }, - { "instanceLong", "J", JNI_FALSE }, - { "instanceFloat", "F", JNI_FALSE }, - { "instanceDouble", "D", JNI_FALSE }, - { "instanceChar", "C", JNI_FALSE }, - { "instanceObject", "Ljava/lang/Object;", JNI_FALSE }, - { "instanceArrInt", "[I", JNI_FALSE } -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getfldnm004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getfldnm004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getfldnm004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetFieldName_getfldnm004_check(JNIEnv *env, - jclass cls, jclass clazz) { - jvmtiError err; - jfieldID fid; - char *name, *sig, *generic; - size_t i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - for (i = 0; i < sizeof(fields)/sizeof(field_info); i++) { - if (fields[i].is_static == JNI_TRUE) { - fid = JNI_ENV_PTR(env)->GetStaticFieldID( - JNI_ENV_ARG(env, clazz), fields[i].name, fields[i].sig); - } else { - fid = JNI_ENV_PTR(env)->GetFieldID( - JNI_ENV_ARG(env, clazz), fields[i].name, fields[i].sig); - } - if (fid == NULL) { - printf("(%" PRIuPTR ") cannot get field ID for %s:\"%s\"\n", - i, fields[i].name, fields[i].sig); - result = STATUS_FAILED; - continue; - } - err = (*jvmti)->GetFieldName(jvmti, clazz, fid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldName#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - if (printdump == JNI_TRUE) { - printf(">>> %" PRIuPTR " -- %s:\"%s\"\n", i, name, sig); - } - if (name == NULL || strcmp(name, fields[i].name) != 0) { - printf("(%" PRIuPTR ") wrong field name: \"%s\"", i, name); - printf(", expected: \"%s\"\n", fields[i].name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, fields[i].sig) != 0) { - printf("(%" PRIuPTR ") wrong field sig: \"%s\"", i, sig); - printf(", expected: \"%s\"\n", fields[i].sig); - result = STATUS_FAILED; - } - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/getfldnm004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/getfldnm004.cpp new file mode 100644 index 00000000000..a0fa0befc4a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/getfldnm004.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + const char *sig; + jboolean is_static; +} field_info; + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static field_info fields[] = { + { "staticBoolean", "Z", JNI_TRUE }, + { "staticByte", "B", JNI_TRUE }, + { "staticShort", "S", JNI_TRUE }, + { "staticInt", "I", JNI_TRUE }, + { "staticLong", "J", JNI_TRUE }, + { "staticFloat", "F", JNI_TRUE }, + { "staticDouble", "D", JNI_TRUE }, + { "staticChar", "C", JNI_TRUE }, + { "staticObject", "Ljava/lang/Object;", JNI_TRUE }, + { "staticArrInt", "[I", JNI_TRUE }, + + { "instanceBoolean", "Z", JNI_FALSE }, + { "instanceByte", "B", JNI_FALSE }, + { "instanceShort", "S", JNI_FALSE }, + { "instanceInt", "I", JNI_FALSE }, + { "instanceLong", "J", JNI_FALSE }, + { "instanceFloat", "F", JNI_FALSE }, + { "instanceDouble", "D", JNI_FALSE }, + { "instanceChar", "C", JNI_FALSE }, + { "instanceObject", "Ljava/lang/Object;", JNI_FALSE }, + { "instanceArrInt", "[I", JNI_FALSE } +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getfldnm004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getfldnm004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getfldnm004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetFieldName_getfldnm004_check(JNIEnv *env, + jclass cls, jclass clazz) { + jvmtiError err; + jfieldID fid; + char *name, *sig, *generic; + size_t i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + for (i = 0; i < sizeof(fields)/sizeof(field_info); i++) { + if (fields[i].is_static == JNI_TRUE) { + fid = JNI_ENV_PTR(env)->GetStaticFieldID( + JNI_ENV_ARG(env, clazz), fields[i].name, fields[i].sig); + } else { + fid = JNI_ENV_PTR(env)->GetFieldID( + JNI_ENV_ARG(env, clazz), fields[i].name, fields[i].sig); + } + if (fid == NULL) { + printf("(%" PRIuPTR ") cannot get field ID for %s:\"%s\"\n", + i, fields[i].name, fields[i].sig); + result = STATUS_FAILED; + continue; + } + err = jvmti->GetFieldName(clazz, fid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldName#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + if (printdump == JNI_TRUE) { + printf(">>> %" PRIuPTR " -- %s:\"%s\"\n", i, name, sig); + } + if (name == NULL || strcmp(name, fields[i].name) != 0) { + printf("(%" PRIuPTR ") wrong field name: \"%s\"", i, name); + printf(", expected: \"%s\"\n", fields[i].name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, fields[i].sig) != 0) { + printf("(%" PRIuPTR ") wrong field sig: \"%s\"", i, sig); + printf(", expected: \"%s\"\n", fields[i].sig); + result = STATUS_FAILED; + } + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/libgetfldnm004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/libgetfldnm004.c deleted file mode 100644 index 45449621d0c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/libgetfldnm004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getfldnm004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/libgetfldnm004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/libgetfldnm004.cpp new file mode 100644 index 00000000000..e08ee99f37e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/libgetfldnm004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getfldnm004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/getfldnm005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/getfldnm005.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/getfldnm005.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/getfldnm005.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/libgetfldnm005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/libgetfldnm005.c deleted file mode 100644 index 7ba844c8940..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/libgetfldnm005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getfldnm005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/libgetfldnm005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/libgetfldnm005.cpp new file mode 100644 index 00000000000..b0947adde6c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/libgetfldnm005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getfldnm005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/framecnt001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/framecnt001.c deleted file mode 100644 index 09f2c0536ab..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/framecnt001.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_framecnt001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_framecnt001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_framecnt001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_suspend) { - printf("Warning: suspend/resume is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_GetFrameCount_framecnt001_checkFrames(JNIEnv *env, jclass cls, - jthread thr, jint thr_num, jint fnum) { - jvmtiError err; - jint frameCount; - - if (!caps.can_suspend) { - return; - } - - if (thr_num != 0) { - err = (*jvmti)->SuspendThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(SuspendThread#%d) unexpected error: %s (%d)\n", - thr_num, TranslateError(err), err); - result = STATUS_FAILED; - } - } - err = (*jvmti)->GetFrameCount(jvmti, thr, &frameCount); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameCount#%d) unexpected error: %s (%d)\n", - thr_num, TranslateError(err), err); - result = STATUS_FAILED; - } else if (frameCount != fnum) { - printf("Thread #%d: number of frames expected: %d, got: %d\n", - thr_num, fnum, frameCount); - result = STATUS_FAILED; - } - if (thr_num != 0) { - err = (*jvmti)->ResumeThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(ResumeThread#%d) unexpected error: %s (%d)\n", - thr_num, TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_GetFrameCount_framecnt001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/framecnt001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/framecnt001.cpp new file mode 100644 index 00000000000..cca4c81a054 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/framecnt001.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_framecnt001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_framecnt001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_framecnt001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_suspend) { + printf("Warning: suspend/resume is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_GetFrameCount_framecnt001_checkFrames(JNIEnv *env, jclass cls, + jthread thr, jint thr_num, jint fnum) { + jvmtiError err; + jint frameCount; + + if (!caps.can_suspend) { + return; + } + + if (thr_num != 0) { + err = jvmti->SuspendThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(SuspendThread#%d) unexpected error: %s (%d)\n", + thr_num, TranslateError(err), err); + result = STATUS_FAILED; + } + } + err = jvmti->GetFrameCount(thr, &frameCount); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameCount#%d) unexpected error: %s (%d)\n", + thr_num, TranslateError(err), err); + result = STATUS_FAILED; + } else if (frameCount != fnum) { + printf("Thread #%d: number of frames expected: %d, got: %d\n", + thr_num, fnum, frameCount); + result = STATUS_FAILED; + } + if (thr_num != 0) { + err = jvmti->ResumeThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(ResumeThread#%d) unexpected error: %s (%d)\n", + thr_num, TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_GetFrameCount_framecnt001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/libframecnt001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/libframecnt001.c deleted file mode 100644 index 5d77bb13bdb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/libframecnt001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "framecnt001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/libframecnt001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/libframecnt001.cpp new file mode 100644 index 00000000000..aa1053c67fc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/libframecnt001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "framecnt001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/framecnt002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/framecnt002.c deleted file mode 100644 index 7b4ecef6490..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/framecnt002.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_framecnt002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_framecnt002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_framecnt002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_GetFrameCount_framecnt002_checkFrames(JNIEnv *env, jclass cls, - jthread thr, jint thr_num) { - jvmtiError err; - jint frameCount; - - if (thr_num == 0) { - err = (*jvmti)->GetFrameCount(jvmti, thr, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else { - err = (*jvmti)->GetFrameCount(jvmti, thr, &frameCount); - if (err != JVMTI_ERROR_THREAD_NOT_ALIVE) { - printf("Error expected: JVMTI_ERROR_THREAD_NOT_ALIVE, got: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_GetFrameCount_framecnt002_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/framecnt002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/framecnt002.cpp new file mode 100644 index 00000000000..3a5dd72fcd6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/framecnt002.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_framecnt002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_framecnt002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_framecnt002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_GetFrameCount_framecnt002_checkFrames(JNIEnv *env, jclass cls, + jthread thr, jint thr_num) { + jvmtiError err; + jint frameCount; + + if (thr_num == 0) { + err = jvmti->GetFrameCount(thr, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else { + err = jvmti->GetFrameCount(thr, &frameCount); + if (err != JVMTI_ERROR_THREAD_NOT_ALIVE) { + printf("Error expected: JVMTI_ERROR_THREAD_NOT_ALIVE, got: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_GetFrameCount_framecnt002_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/libframecnt002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/libframecnt002.c deleted file mode 100644 index a52ceb3b5e3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/libframecnt002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "framecnt002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/libframecnt002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/libframecnt002.cpp new file mode 100644 index 00000000000..0e950af0e6e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/libframecnt002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "framecnt002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/framecnt003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/framecnt003.c deleted file mode 100644 index 76a97b60b59..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/framecnt003.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_framecnt003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_framecnt003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_framecnt003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetFrameCount_framecnt003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jint countPtr; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->GetFrameCount(jvmti, cls, &countPtr); - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/framecnt003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/framecnt003.cpp new file mode 100644 index 00000000000..b60f7d5d07c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/framecnt003.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_framecnt003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_framecnt003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_framecnt003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetFrameCount_framecnt003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jint countPtr; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->GetFrameCount(cls, &countPtr); + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/libframecnt003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/libframecnt003.c deleted file mode 100644 index da2819676d8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/libframecnt003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "framecnt003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/libframecnt003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/libframecnt003.cpp new file mode 100644 index 00000000000..abaa142588d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/libframecnt003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "framecnt003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/frameloc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/frameloc001.c deleted file mode 100644 index 186358cba86..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/frameloc001.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jmethodID mid1; - -// If mustPass is false we just check if we have reached the correct instruction location. -// This is used to wait for the child thread to reach the expected position. -jboolean checkFrame(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID exp_mid, jlocation exp_loc, jlocation exp_loc_alternative, jboolean mustPass) { - jvmtiError err; - jmethodID mid = NULL; - jlocation loc = -1; - char *meth, *sig, *generic; - jboolean isOk = JNI_FALSE; - - err = (*jvmti_env)->GetMethodName(jvmti_env, exp_mid, - &meth, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thr, 0, &mid, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation#%s) unexpected error: %s (%d)\n", - meth, TranslateError(err), err); - result = STATUS_FAILED; - } else { - if (exp_mid != mid) { - printf("Method \"%s\" current frame's method ID", meth); - printf(" expected: 0x%p, got: 0x%p\n", exp_mid, mid); - result = STATUS_FAILED; - } - isOk = exp_loc == loc || exp_loc_alternative == loc; - if (!isOk && mustPass) { - printf("Method \"%s\" current frame's location", meth); - printf(" expected: 0x%x or 0x%x, got: 0x%x%08x\n", - (jint)exp_loc, (jint)exp_loc_alternative, (jint)(loc >> 32), (jint)loc); - result = STATUS_FAILED; - } - } - return isOk && result == PASSED; -} - -void JNICALL -ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, - jmethodID method, jlocation location, jobject exception) { - if (method == mid1) { - checkFrame(jvmti_env, (JNIEnv *)env, thr, method, location, location, JNI_TRUE); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_frameloc001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_frameloc001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_frameloc001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_suspend) { - printf("Warning: suspend/resume is not implemented\n"); - } - - if (caps.can_generate_exception_events) { - callbacks.ExceptionCatch = &ExceptionCatch; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: ExceptionCatch event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetFrameLocation_frameloc001_getReady(JNIEnv *env, jclass cls, - jclass klass) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_generate_exception_events) { - return; - } - - mid1 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, klass), - "meth01", "(I)V"); - if (mid1 == NULL) { - printf("Cannot get jmethodID for method \"meth01\"\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_EXCEPTION_CATCH, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_GetFrameLocation_frameloc001_checkFrame01(JNIEnv *env, - jclass cls, jthread thr, jclass klass, jboolean mustPass) { - jvmtiError err; - jmethodID mid; - jboolean isOk = JNI_FALSE; - - if (jvmti == NULL || !caps.can_suspend) { - return JNI_TRUE; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, klass), "run", "()V"); - if (mid == NULL) { - printf("Cannot get jmethodID for method \"run\"\n"); - result = STATUS_FAILED; - return JNI_TRUE; - } - - err = (*jvmti)->SuspendThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(SuspendThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - // This tests the location of a throw/catch statement. - // The returned location may be either the throw or the catch statement. - // It seems like the throw statement is returned in compiled code (-Xcomp), - // but the catch statement is returned in interpreted code. - // Both locations are valid. - // See bug JDK-4527281. - isOk = checkFrame(jvmti, env, thr, mid, 31, 32, mustPass); - - err = (*jvmti)->ResumeThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(ResumeThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - return isOk && result == PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetFrameLocation_frameloc001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/frameloc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/frameloc001.cpp new file mode 100644 index 00000000000..279389a9958 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/frameloc001.cpp @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jmethodID mid1; + +// If mustPass is false we just check if we have reached the correct instruction location. +// This is used to wait for the child thread to reach the expected position. +jboolean checkFrame(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID exp_mid, jlocation exp_loc, jlocation exp_loc_alternative, jboolean mustPass) { + jvmtiError err; + jmethodID mid = NULL; + jlocation loc = -1; + char *meth, *sig, *generic; + jboolean isOk = JNI_FALSE; + + err = jvmti_env->GetMethodName(exp_mid, + &meth, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetFrameLocation(thr, 0, &mid, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation#%s) unexpected error: %s (%d)\n", + meth, TranslateError(err), err); + result = STATUS_FAILED; + } else { + if (exp_mid != mid) { + printf("Method \"%s\" current frame's method ID", meth); + printf(" expected: 0x%p, got: 0x%p\n", exp_mid, mid); + result = STATUS_FAILED; + } + isOk = exp_loc == loc || exp_loc_alternative == loc; + if (!isOk && mustPass) { + printf("Method \"%s\" current frame's location", meth); + printf(" expected: 0x%x or 0x%x, got: 0x%x%08x\n", + (jint)exp_loc, (jint)exp_loc_alternative, (jint)(loc >> 32), (jint)loc); + result = STATUS_FAILED; + } + } + return isOk && result == PASSED; +} + +void JNICALL +ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, + jmethodID method, jlocation location, jobject exception) { + if (method == mid1) { + checkFrame(jvmti_env, (JNIEnv *)env, thr, method, location, location, JNI_TRUE); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_frameloc001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_frameloc001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_frameloc001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_suspend) { + printf("Warning: suspend/resume is not implemented\n"); + } + + if (caps.can_generate_exception_events) { + callbacks.ExceptionCatch = &ExceptionCatch; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: ExceptionCatch event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetFrameLocation_frameloc001_getReady(JNIEnv *env, jclass cls, + jclass klass) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_generate_exception_events) { + return; + } + + mid1 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, klass), + "meth01", "(I)V"); + if (mid1 == NULL) { + printf("Cannot get jmethodID for method \"meth01\"\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_EXCEPTION_CATCH, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_GetFrameLocation_frameloc001_checkFrame01(JNIEnv *env, + jclass cls, jthread thr, jclass klass, jboolean mustPass) { + jvmtiError err; + jmethodID mid; + jboolean isOk = JNI_FALSE; + + if (jvmti == NULL || !caps.can_suspend) { + return JNI_TRUE; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, klass), "run", "()V"); + if (mid == NULL) { + printf("Cannot get jmethodID for method \"run\"\n"); + result = STATUS_FAILED; + return JNI_TRUE; + } + + err = jvmti->SuspendThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(SuspendThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + // This tests the location of a throw/catch statement. + // The returned location may be either the throw or the catch statement. + // It seems like the throw statement is returned in compiled code (-Xcomp), + // but the catch statement is returned in interpreted code. + // Both locations are valid. + // See bug JDK-4527281. + isOk = checkFrame(jvmti, env, thr, mid, 31, 32, mustPass); + + err = jvmti->ResumeThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(ResumeThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + return isOk && result == PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetFrameLocation_frameloc001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/libframeloc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/libframeloc001.c deleted file mode 100644 index 516ca1c90c2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/libframeloc001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "frameloc001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/libframeloc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/libframeloc001.cpp new file mode 100644 index 00000000000..2f61904689b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc001/libframeloc001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "frameloc001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/frameloc002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/frameloc002.c deleted file mode 100644 index 66f78d78eee..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/frameloc002.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls_sig; - char *name; - char *sig; - jlocation loc; -} frame_info; - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static frame_info fi = - {"Lnsk/jvmti/GetFrameLocation/frameloc002;", "check", - "(Ljava/lang/Thread;)I", -1}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_frameloc002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_frameloc002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_frameloc002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetFrameLocation_frameloc002_check(JNIEnv *env, jclass cls, jthread thr) { - jvmtiError err; - jclass class; - jmethodID mid; - jlocation loc; - char *cls_sig, *name, *sig, *generic; - char buffer[32]; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> acquiring frame location ...\n"); - } - err = (*jvmti)->GetFrameLocation(jvmti, thr, 0, &mid, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> retrieving class/method info ...\n"); - } - err = (*jvmti)->GetMethodDeclaringClass(jvmti, mid, &class); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->GetClassSignature(jvmti, class, &cls_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->GetMethodName(jvmti, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", cls_sig); - printf(">>> method: \"%s%s\"\n", name, sig); - printf(">>> location: %s\n", - jlong_to_string(loc, buffer)); - } - - if (cls_sig == NULL || - strcmp(cls_sig, fi.cls_sig) != 0) { - printf("(GetFrameLocation) wrong class: \"%s\"", cls_sig); - printf(", expected: \"%s\"\n", fi.cls_sig); - result = STATUS_FAILED; - } - if (name == NULL || - strcmp(name, fi.name) != 0) { - printf("(GetFrameLocation) wrong method name: \"%s\"", name); - printf(", expected: \"%s\"\n", fi.name); - result = STATUS_FAILED; - } - if (sig == NULL || - strcmp(sig, fi.sig) != 0) { - printf("(GetFrameLocation) wrong method signature: \"%s\"", sig); - printf(", expected: \"%s\"\n", fi.sig); - result = STATUS_FAILED; - } - if (loc != fi.loc) { - printf("(GetFrameLocation) wrong location: %s", - jlong_to_string(loc, buffer)); - printf(", expected: %s\n", - jlong_to_string(fi.loc, buffer)); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/frameloc002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/frameloc002.cpp new file mode 100644 index 00000000000..a48bec7b70f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/frameloc002.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls_sig; + const char *name; + const char *sig; + jlocation loc; +} frame_info; + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static frame_info fi = + {"Lnsk/jvmti/GetFrameLocation/frameloc002;", "check", + "(Ljava/lang/Thread;)I", -1}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_frameloc002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_frameloc002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_frameloc002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetFrameLocation_frameloc002_check(JNIEnv *env, jclass cls, jthread thr) { + jvmtiError err; + jclass klass; + jmethodID mid; + jlocation loc; + char *cls_sig, *name, *sig, *generic; + char buffer[32]; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> acquiring frame location ...\n"); + } + err = jvmti->GetFrameLocation(thr, 0, &mid, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> retrieving class/method info ...\n"); + } + err = jvmti->GetMethodDeclaringClass(mid, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->GetClassSignature(klass, &cls_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", cls_sig); + printf(">>> method: \"%s%s\"\n", name, sig); + printf(">>> location: %s\n", + jlong_to_string(loc, buffer)); + } + + if (cls_sig == NULL || + strcmp(cls_sig, fi.cls_sig) != 0) { + printf("(GetFrameLocation) wrong class: \"%s\"", cls_sig); + printf(", expected: \"%s\"\n", fi.cls_sig); + result = STATUS_FAILED; + } + if (name == NULL || + strcmp(name, fi.name) != 0) { + printf("(GetFrameLocation) wrong method name: \"%s\"", name); + printf(", expected: \"%s\"\n", fi.name); + result = STATUS_FAILED; + } + if (sig == NULL || + strcmp(sig, fi.sig) != 0) { + printf("(GetFrameLocation) wrong method signature: \"%s\"", sig); + printf(", expected: \"%s\"\n", fi.sig); + result = STATUS_FAILED; + } + if (loc != fi.loc) { + printf("(GetFrameLocation) wrong location: %s", + jlong_to_string(loc, buffer)); + printf(", expected: %s\n", + jlong_to_string(fi.loc, buffer)); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/libframeloc002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/libframeloc002.c deleted file mode 100644 index 82023a63981..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/libframeloc002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "frameloc002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/libframeloc002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/libframeloc002.cpp new file mode 100644 index 00000000000..5619dfd53a2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/libframeloc002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "frameloc002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/frameloc003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/frameloc003.c deleted file mode 100644 index 387192a9374..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/frameloc003.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_frameloc003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_frameloc003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_frameloc003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_suspend) { - printf("Warning: suspend/resume is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetFrameLocation_frameloc003_check(JNIEnv *env, jclass cls, jthread thr) { - jvmtiError err; - jmethodID mid; - jlocation loc; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid thread check ...\n"); - } - err = (*jvmti)->GetFrameLocation(jvmti, cls, 0, &mid, &loc); - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (!caps.can_suspend) { - return result; - } - - err = (*jvmti)->SuspendThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(SuspendThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid depth check ...\n"); - } - err = (*jvmti)->GetFrameLocation(jvmti, thr, -1, &mid, &loc); - if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { - printf("Error expected: JVMTI_ERROR_ILLEGAL_ARGUMENT,\n"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (methodPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetFrameLocation(jvmti, thr, 0, NULL, &loc); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (locationPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetFrameLocation(jvmti, thr, 0, &mid, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->ResumeThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(ResumeThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/frameloc003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/frameloc003.cpp new file mode 100644 index 00000000000..a4050dd7d5b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/frameloc003.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_frameloc003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_frameloc003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_frameloc003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_suspend) { + printf("Warning: suspend/resume is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetFrameLocation_frameloc003_check(JNIEnv *env, jclass cls, jthread thr) { + jvmtiError err; + jmethodID mid; + jlocation loc; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid thread check ...\n"); + } + err = jvmti->GetFrameLocation(cls, 0, &mid, &loc); + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (!caps.can_suspend) { + return result; + } + + err = jvmti->SuspendThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(SuspendThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid depth check ...\n"); + } + err = jvmti->GetFrameLocation(thr, -1, &mid, &loc); + if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { + printf("Error expected: JVMTI_ERROR_ILLEGAL_ARGUMENT,\n"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (methodPtr) null pointer check ...\n"); + } + err = jvmti->GetFrameLocation(thr, 0, NULL, &loc); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (locationPtr) null pointer check ...\n"); + } + err = jvmti->GetFrameLocation(thr, 0, &mid, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->ResumeThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(ResumeThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/libframeloc003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/libframeloc003.c deleted file mode 100644 index 5c6f28d67c0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/libframeloc003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "frameloc003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/libframeloc003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/libframeloc003.cpp new file mode 100644 index 00000000000..0bb586790a4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/libframeloc003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "frameloc003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/getintrf005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/getintrf005.c deleted file mode 100644 index 863ceb79624..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/getintrf005.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getintrf005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getintrf005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getintrf005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetImplementedInterfaces_getintrf005_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jint icount; - jclass *interfaces; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->GetImplementedInterfaces(jvmti, NULL, &icount, &interfaces); - if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (interfaceCountPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetImplementedInterfaces(jvmti, cls, NULL, &interfaces); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(interfaceCountPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (interfacesPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetImplementedInterfaces(jvmti, cls, &icount, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(interfacesPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/getintrf005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/getintrf005.cpp new file mode 100644 index 00000000000..08fba7be87b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/getintrf005.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getintrf005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getintrf005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getintrf005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetImplementedInterfaces_getintrf005_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jint icount; + jclass *interfaces; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->GetImplementedInterfaces(NULL, &icount, &interfaces); + if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (interfaceCountPtr) null pointer check ...\n"); + } + err = jvmti->GetImplementedInterfaces(cls, NULL, &interfaces); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(interfaceCountPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (interfacesPtr) null pointer check ...\n"); + } + err = jvmti->GetImplementedInterfaces(cls, &icount, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(interfacesPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/libgetintrf005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/libgetintrf005.c deleted file mode 100644 index 680fbdc3be0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/libgetintrf005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getintrf005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/libgetintrf005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/libgetintrf005.cpp new file mode 100644 index 00000000000..c828710cfd3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/libgetintrf005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getintrf005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/getintrf006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/getintrf006.c deleted file mode 100644 index ae5b2546d05..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/getintrf006.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getintrf006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getintrf006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getintrf006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetImplementedInterfaces_getintrf006_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { - jvmtiError err; - jint icount; - jclass *interfaces; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> trying #%d\n", i); - } - - err = (*jvmti)->GetImplementedInterfaces(jvmti, clazz, &icount, &interfaces); - if (err != JVMTI_ERROR_NONE) { - printf("(GetImplementedInterfaces#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (icount != 0) { - printf("(%d) interface list is not empty, icount=%d\n", i, icount); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL Java_nsk_jvmti_GetImplementedInterfaces_getintrf006_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/getintrf006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/getintrf006.cpp new file mode 100644 index 00000000000..9de8917b2f4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/getintrf006.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getintrf006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getintrf006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getintrf006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetImplementedInterfaces_getintrf006_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { + jvmtiError err; + jint icount; + jclass *interfaces; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> trying #%d\n", i); + } + + err = jvmti->GetImplementedInterfaces(clazz, &icount, &interfaces); + if (err != JVMTI_ERROR_NONE) { + printf("(GetImplementedInterfaces#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (icount != 0) { + printf("(%d) interface list is not empty, icount=%d\n", i, icount); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL Java_nsk_jvmti_GetImplementedInterfaces_getintrf006_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/libgetintrf006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/libgetintrf006.c deleted file mode 100644 index 5b40e051865..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/libgetintrf006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getintrf006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/libgetintrf006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/libgetintrf006.cpp new file mode 100644 index 00000000000..6873529702e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/libgetintrf006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getintrf006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/getintrf007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/getintrf007.c deleted file mode 100644 index 25adab15110..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/getintrf007.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *sig; -} iface_info; - -typedef struct { - char *name; - jint icount; - iface_info *ifaces; -} class_info; - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -static iface_info i2[] = { - {"Lnsk/jvmti/GetImplementedInterfaces/getintrf007$InnerInterface1;"} -}; - -static iface_info i3[] = { - {"Lnsk/jvmti/GetImplementedInterfaces/getintrf007$InnerInterface2;"} -}; - -static iface_info i7[] = { - {"Lnsk/jvmti/GetImplementedInterfaces/OuterInterface1;"} -}; - -static iface_info i8[] = { - {"Lnsk/jvmti/GetImplementedInterfaces/OuterInterface1;"} -}; - -static iface_info i9[] = { - {"Lnsk/jvmti/GetImplementedInterfaces/OuterInterface2;"} -}; - -static class_info classes[] = { - {"InnerClass1", 0, NULL}, - {"InnerInterface1", 0, NULL}, - {"InnerInterface2", 1, i2}, - {"InnerClass2", 1, i3}, - {"OuterClass1", 0, NULL}, - {"OuterClass2", 0, NULL}, - {"OuterInterface1", 0, NULL}, - {"OuterClass3", 1, i7}, - {"OuterInterface2", 1, i8}, - {"OuterClass4", 1, i9}, - {"OuterClass5", 0, NULL} -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getintrf007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getintrf007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getintrf007(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetImplementedInterfaces_getintrf007_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { - jvmtiError err; - jint icount; - jclass *interfaces; - char *sig, *generic; - int j; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %s:\n", classes[i].name); - } - - err = (*jvmti)->GetImplementedInterfaces(jvmti, clazz, &icount, &interfaces); - if (err != JVMTI_ERROR_NONE) { - printf("(GetImplementedInterfaces#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (icount != classes[i].icount) { - printf("(%d) wrong number of interfaces: %d, expected: %d\n", - i, icount, classes[i].icount); - result = STATUS_FAILED; - } - - for (j = 0; j < icount; j++) { - if (interfaces[j] == NULL) { - printf("(%d:%d) null reference\n", i, j); - } else { - err = (*jvmti)->GetClassSignature(jvmti, interfaces[j], - &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d:%d) unexpected error: %s (%d)\n", - i, j, TranslateError(err), err); - } else { - if (printdump == JNI_TRUE) { - printf(">>> [%d]: %s\n", j, sig); - } - if ((j < classes[i].icount) && (sig == NULL || - strcmp(sig, classes[i].ifaces[j].sig) != 0)) { - printf("(%d:%d) wrong interface: \"%s\"", i, j, sig); - printf(", expected: \"%s\"\n", classes[i].ifaces[j].sig); - result = STATUS_FAILED; - } - } - } - } -} - -JNIEXPORT int JNICALL Java_nsk_jvmti_GetImplementedInterfaces_getintrf007_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/getintrf007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/getintrf007.cpp new file mode 100644 index 00000000000..69624a32ee0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/getintrf007.cpp @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *sig; +} iface_info; + +typedef struct { + const char *name; + jint icount; + iface_info *ifaces; +} class_info; + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +static iface_info i2[] = { + {"Lnsk/jvmti/GetImplementedInterfaces/getintrf007$InnerInterface1;"} +}; + +static iface_info i3[] = { + {"Lnsk/jvmti/GetImplementedInterfaces/getintrf007$InnerInterface2;"} +}; + +static iface_info i7[] = { + {"Lnsk/jvmti/GetImplementedInterfaces/OuterInterface1;"} +}; + +static iface_info i8[] = { + {"Lnsk/jvmti/GetImplementedInterfaces/OuterInterface1;"} +}; + +static iface_info i9[] = { + {"Lnsk/jvmti/GetImplementedInterfaces/OuterInterface2;"} +}; + +static class_info classes[] = { + {"InnerClass1", 0, NULL}, + {"InnerInterface1", 0, NULL}, + {"InnerInterface2", 1, i2}, + {"InnerClass2", 1, i3}, + {"OuterClass1", 0, NULL}, + {"OuterClass2", 0, NULL}, + {"OuterInterface1", 0, NULL}, + {"OuterClass3", 1, i7}, + {"OuterInterface2", 1, i8}, + {"OuterClass4", 1, i9}, + {"OuterClass5", 0, NULL} +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getintrf007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getintrf007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getintrf007(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetImplementedInterfaces_getintrf007_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { + jvmtiError err; + jint icount; + jclass *interfaces; + char *sig, *generic; + int j; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %s:\n", classes[i].name); + } + + err = jvmti->GetImplementedInterfaces(clazz, &icount, &interfaces); + if (err != JVMTI_ERROR_NONE) { + printf("(GetImplementedInterfaces#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (icount != classes[i].icount) { + printf("(%d) wrong number of interfaces: %d, expected: %d\n", + i, icount, classes[i].icount); + result = STATUS_FAILED; + } + + for (j = 0; j < icount; j++) { + if (interfaces[j] == NULL) { + printf("(%d:%d) null reference\n", i, j); + } else { + err = jvmti->GetClassSignature(interfaces[j], + &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d:%d) unexpected error: %s (%d)\n", + i, j, TranslateError(err), err); + } else { + if (printdump == JNI_TRUE) { + printf(">>> [%d]: %s\n", j, sig); + } + if ((j < classes[i].icount) && (sig == NULL || + strcmp(sig, classes[i].ifaces[j].sig) != 0)) { + printf("(%d:%d) wrong interface: \"%s\"", i, j, sig); + printf(", expected: \"%s\"\n", classes[i].ifaces[j].sig); + result = STATUS_FAILED; + } + } + } + } +} + +JNIEXPORT int JNICALL Java_nsk_jvmti_GetImplementedInterfaces_getintrf007_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/libgetintrf007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/libgetintrf007.c deleted file mode 100644 index d8a36bd7f27..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/libgetintrf007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getintrf007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/libgetintrf007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/libgetintrf007.cpp new file mode 100644 index 00000000000..53974504f2f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/libgetintrf007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getintrf007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/getjlocfmt001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/getjlocfmt001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/getjlocfmt001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/getjlocfmt001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/libgetjlocfmt001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/libgetjlocfmt001.c deleted file mode 100644 index b4c4ec81711..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/libgetjlocfmt001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getjlocfmt001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/libgetjlocfmt001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/libgetjlocfmt001.cpp new file mode 100644 index 00000000000..7f6ab7648f9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt001/libgetjlocfmt001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getjlocfmt001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/getjlocfmt002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/getjlocfmt002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/getjlocfmt002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/getjlocfmt002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/libgetjlocfmt002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/libgetjlocfmt002.c deleted file mode 100644 index d9f5429b2ae..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/libgetjlocfmt002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getjlocfmt002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/libgetjlocfmt002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/libgetjlocfmt002.cpp new file mode 100644 index 00000000000..7b27f49ac80 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJLocationFormat/getjlocfmt002/libgetjlocfmt002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getjlocfmt002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/getjniftab001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/getjniftab001.c deleted file mode 100644 index 3b3242593f3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/getjniftab001.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include - -#include -#include "agent_common.h" - -#include "JVMTITools.h" -#include "native_thread.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - #ifdef __cplusplus - #define JNI_ENV_ARG(x, y) y - #define JNI_ENV_PTR(x) x - #else - #define JNI_ENV_ARG(x, y) x, y - #define JNI_ENV_PTR(x) (*x) - #endif -#endif - -#ifndef JNI_ENV_ARG1 - #ifdef __cplusplus - #define JNI_ENV_ARG1(x) - #else - #define JNI_ENV_ARG1(x) x - #endif -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static JavaVM *vm; -static jvmtiEnv *jvmti = NULL; - -static int verbose = 0; - -static jint result = PASSED; - -/* the original JNI function table */ -static jniNativeInterface *orig_jni_functions = NULL; - -/* the redirected JNI function table */ -static jniNativeInterface *redir_jni_functions = NULL; - -/* number of the redirected JNI function calls */ -static volatile int redir_calls = 0; - -/** redirected JNI functions **/ -jint JNICALL MyGetVersion(JNIEnv *env) { - redir_calls++; - - if (verbose) - printf("\nMyGetVersion: the function called successfully: number of calls=%d\n", - redir_calls); - - return orig_jni_functions->GetVersion( - JNI_ENV_ARG1(env)); -} -/*****************************/ - -static void doRedirect(JNIEnv *env) { - jvmtiError err; - - if (verbose) - printf("\ndoRedirect: obtaining the JNI function table ...\n"); - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &orig_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get original JNI function table")); - } - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &redir_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get redirected JNI function table")); - } - if (verbose) - printf("doRedirect: the JNI function table obtained successfully\n"); - - if (verbose) - printf("\ndoRedirect: overwriting the function GetVersion() ...\n"); - redir_jni_functions->GetVersion = MyGetVersion; - - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, redir_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get new JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get new JNI function table")); - } - - if (verbose) - printf("\ndoRedirect: the function is overwritten successfully\n"); -} - -static void doRestore(JNIEnv *env) { - jvmtiError err; - - if (verbose) - printf("\ndoRestore: restoring the original JNI function table ...\n"); - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, orig_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to restore original JNI function table")); - } - if (verbose) - printf("doRestore: the original JNI function table is restored successfully\n"); -} - -static void checkRedir(JNIEnv *env, int exCalls) { - jniNativeInterface *tested_jni_functions = NULL; - jvmtiError err; - jint res; - - redir_calls = 0; - - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &tested_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get modified JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get modified JNI function table")); - } - if (verbose) - printf("checkRedir: the JNI function table obtained successfully\n\tcalling GetVersion() ...\n"); - res = tested_jni_functions->GetVersion(JNI_ENV_ARG1(env)); - - if (redir_calls == exCalls) { - if (verbose) - printf("\nCHECK PASSED: the %s JNI function table is returned by GetJNIFunctionTable():\n\t%d interception of GetVersion() calls as expected\n", - (exCalls==0)?"original":"modified", - redir_calls); - } - else { - result = STATUS_FAILED; - printf("\nTEST FAILED: the %s JNI function table is returned by GetJNIFunctionTable() instead of the %s one:\n\t%d interception of GetVersion() calls instead of %d as expected\n", - (exCalls==0)?"modified":"original", - (exCalls==0)?"original":"modified", - redir_calls, exCalls); - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetJNIFunctionTable_getjniftab001_check(JNIEnv *env, jobject obj) { - int exitCode = PASSED; - - if (jvmti == NULL) { - printf("(%s,%d): TEST FAILURE: JVMTI client was not properly loaded\n", - __FILE__, __LINE__); - return STATUS_FAILED; - } - - /* 1: check the assertion with the modified function table */ - doRedirect(env); - if (verbose) - printf("\na) Checking the assertion with the modified function table ...\n"); - checkRedir(env, 1); - - /* 2: check the assertion with the original function table */ - doRestore(env); - if (verbose) - printf("\nb) Checking the assertion with the original function table ...\n"); - checkRedir(env, 0); - - return result; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getjniftab001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getjniftab001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getjniftab001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "-verbose") == 0) - verbose = 1; - - if (verbose) - printf("verbose mode on\n"); - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); - return JNI_ERR; - } - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/getjniftab001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/getjniftab001.cpp new file mode 100644 index 00000000000..aa182417a87 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/getjniftab001.cpp @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include + +#include +#include "agent_common.h" + +#include "JVMTITools.h" +#include "native_thread.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + #ifdef __cplusplus + #define JNI_ENV_ARG(x, y) y + #define JNI_ENV_PTR(x) x + #else + #define JNI_ENV_ARG(x, y) x, y + #define JNI_ENV_PTR(x) (*x) + #endif +#endif + +#ifndef JNI_ENV_ARG1 + #ifdef __cplusplus + #define JNI_ENV_ARG1(x) + #else + #define JNI_ENV_ARG1(x) x + #endif +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static JavaVM *vm; +static jvmtiEnv *jvmti = NULL; + +static int verbose = 0; + +static jint result = PASSED; + +/* the original JNI function table */ +static jniNativeInterface *orig_jni_functions = NULL; + +/* the redirected JNI function table */ +static jniNativeInterface *redir_jni_functions = NULL; + +/* number of the redirected JNI function calls */ +static volatile int redir_calls = 0; + +/** redirected JNI functions **/ +jint JNICALL MyGetVersion(JNIEnv *env) { + redir_calls++; + + if (verbose) + printf("\nMyGetVersion: the function called successfully: number of calls=%d\n", + redir_calls); + + return orig_jni_functions->GetVersion(env); +} +/*****************************/ + +static void doRedirect(JNIEnv *env) { + jvmtiError err; + + if (verbose) + printf("\ndoRedirect: obtaining the JNI function table ...\n"); + if ((err = jvmti->GetJNIFunctionTable(&orig_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get original JNI function table")); + } + if ((err = jvmti->GetJNIFunctionTable(&redir_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get redirected JNI function table")); + } + if (verbose) + printf("doRedirect: the JNI function table obtained successfully\n"); + + if (verbose) + printf("\ndoRedirect: overwriting the function GetVersion() ...\n"); + redir_jni_functions->GetVersion = MyGetVersion; + + if ((err = jvmti->SetJNIFunctionTable(redir_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get new JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get new JNI function table")); + } + + if (verbose) + printf("\ndoRedirect: the function is overwritten successfully\n"); +} + +static void doRestore(JNIEnv *env) { + jvmtiError err; + + if (verbose) + printf("\ndoRestore: restoring the original JNI function table ...\n"); + if ((err = jvmti->SetJNIFunctionTable(orig_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to restore original JNI function table")); + } + if (verbose) + printf("doRestore: the original JNI function table is restored successfully\n"); +} + +static void checkRedir(JNIEnv *env, int exCalls) { + jniNativeInterface *tested_jni_functions = NULL; + jvmtiError err; + jint res; + + redir_calls = 0; + + if ((err = jvmti->GetJNIFunctionTable(&tested_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get modified JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get modified JNI function table")); + } + if (verbose) + printf("checkRedir: the JNI function table obtained successfully\n\tcalling GetVersion() ...\n"); + res = tested_jni_functions->GetVersion(env); + + if (redir_calls == exCalls) { + if (verbose) + printf("\nCHECK PASSED: the %s JNI function table is returned by GetJNIFunctionTable():\n\t%d interception of GetVersion() calls as expected\n", + (exCalls==0)?"original":"modified", + redir_calls); + } + else { + result = STATUS_FAILED; + printf("\nTEST FAILED: the %s JNI function table is returned by GetJNIFunctionTable() instead of the %s one:\n\t%d interception of GetVersion() calls instead of %d as expected\n", + (exCalls==0)?"modified":"original", + (exCalls==0)?"original":"modified", + redir_calls, exCalls); + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetJNIFunctionTable_getjniftab001_check(JNIEnv *env, jobject obj) { + int exitCode = PASSED; + + if (jvmti == NULL) { + printf("(%s,%d): TEST FAILURE: JVMTI client was not properly loaded\n", + __FILE__, __LINE__); + return STATUS_FAILED; + } + + /* 1: check the assertion with the modified function table */ + doRedirect(env); + if (verbose) + printf("\na) Checking the assertion with the modified function table ...\n"); + checkRedir(env, 1); + + /* 2: check the assertion with the original function table */ + doRestore(env); + if (verbose) + printf("\nb) Checking the assertion with the original function table ...\n"); + checkRedir(env, 0); + + return result; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getjniftab001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getjniftab001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getjniftab001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "-verbose") == 0) + verbose = 1; + + if (verbose) + printf("verbose mode on\n"); + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/libgetjniftab001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/libgetjniftab001.c deleted file mode 100644 index 0dea4d7cc6d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/libgetjniftab001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getjniftab001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/libgetjniftab001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/libgetjniftab001.cpp new file mode 100644 index 00000000000..93e94ee9089 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab001/libgetjniftab001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getjniftab001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/getjniftab002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/getjniftab002.c deleted file mode 100644 index 36b8d91ba16..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/getjniftab002.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - #ifdef __cplusplus - #define JNI_ENV_ARG(x, y) y - #define JNI_ENV_PTR(x) x - #else - #define JNI_ENV_ARG(x, y) x, y - #define JNI_ENV_PTR(x) (*x) - #endif -#endif - -#ifndef JNI_ENV_ARG1 - #ifdef __cplusplus - #define JNI_ENV_ARG1(x) - #else - #define JNI_ENV_ARG1(x) x - #endif -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static JavaVM *vm; -static jvmtiEnv *jvmti = NULL; -static jniNativeInterface *orig_jni_functions = NULL; - -static int verbose = 0; -static jint result = PASSED; - -void redirect(JNIEnv *env, jvmtiError exError) { - jvmtiError err; - - if (verbose) - printf("\ntrying to get the JNI function table expecting the error %s to be returned ...\n", - TranslateError(exError)); - - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, - (exError==JVMTI_ERROR_NULL_POINTER)?NULL:&orig_jni_functions)) != - exError) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: GetJNIFunctionTable() returns %s instead of %s as expected\n", - __FILE__, __LINE__, TranslateError(err), TranslateError(exError)); - return; - } - else if (verbose) - printf("CHECK PASSED: GetJNIFunctionTable() returns %s as expected\n", - TranslateError(err)); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetJNIFunctionTable_getjniftab002_check(JNIEnv *env, jobject obj) { - jvmtiError err; - JNIEnv *nextEnv = NULL; - - if (jvmti == NULL) { - printf("(%s,%d): TEST FAILURE: JVMTI client was not properly loaded\n", - __FILE__, __LINE__); - return STATUS_FAILED; - } - - /* a) Verifying the error JVMTI_ERROR_NULL_POINTER */ - if (verbose) - printf("\na) Checking the function with the parameter JVMTI_ERROR_NULL_POINTER ...\n"); - redirect(env, JVMTI_ERROR_NULL_POINTER); - - /* b) Verifying the error JVMTI_ERROR_UNATTACHED_THREAD - Note: the JNI spec says that the main thread can be detached from the VM - only since JDK 1.2 */ - if (verbose) - printf("\nb) Checking the function with the detached thread ...\n\ndetaching the main thread ...\n"); - if ((err = - JNI_ENV_PTR(vm)->DetachCurrentThread( - JNI_ENV_ARG1(vm))) != 0) - printf("(%s,%d): Warning: DetachCurrentThread() returns: %d\n\ -\tcheck with the detached main thread skipped\n", - __FILE__, __LINE__, err); - else { - redirect(env, JVMTI_ERROR_UNATTACHED_THREAD); - - if (verbose) - printf("\nattaching the main thread back ...\n"); - if ((err = - JNI_ENV_PTR(vm)->AttachCurrentThread( - JNI_ENV_ARG(vm, (void **) &nextEnv), (void *) 0)) != 0) { - printf("(%s,%d): TEST FAILURE: waitingThread: AttachCurrentThread() returns: %d\n", - __FILE__, __LINE__, err); - return STATUS_FAILED; - } - } - - return result; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getjniftab002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getjniftab002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getjniftab002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "-verbose") == 0) - verbose = 1; - - if (verbose) - printf("verbose mode on\n"); - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); - return JNI_ERR; - } - - vm = jvm; - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/getjniftab002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/getjniftab002.cpp new file mode 100644 index 00000000000..5cececcfd50 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/getjniftab002.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + #ifdef __cplusplus + #define JNI_ENV_ARG(x, y) y + #define JNI_ENV_PTR(x) x + #else + #define JNI_ENV_ARG(x, y) x, y + #define JNI_ENV_PTR(x) (*x) + #endif +#endif + +#ifndef JNI_ENV_ARG1 + #ifdef __cplusplus + #define JNI_ENV_ARG1(x) + #else + #define JNI_ENV_ARG1(x) x + #endif +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static JavaVM *vm; +static jvmtiEnv *jvmti = NULL; +static jniNativeInterface *orig_jni_functions = NULL; + +static int verbose = 0; +static jint result = PASSED; + +void redirect(JNIEnv *env, jvmtiError exError) { + jvmtiError err; + + if (verbose) + printf("\ntrying to get the JNI function table expecting the error %s to be returned ...\n", + TranslateError(exError)); + + if ((err = jvmti->GetJNIFunctionTable( + (exError==JVMTI_ERROR_NULL_POINTER)?NULL:&orig_jni_functions)) != + exError) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: GetJNIFunctionTable() returns %s instead of %s as expected\n", + __FILE__, __LINE__, TranslateError(err), TranslateError(exError)); + return; + } + else if (verbose) + printf("CHECK PASSED: GetJNIFunctionTable() returns %s as expected\n", + TranslateError(err)); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetJNIFunctionTable_getjniftab002_check(JNIEnv *env, jobject obj) { + jint err; + JNIEnv *nextEnv = NULL; + + if (jvmti == NULL) { + printf("(%s,%d): TEST FAILURE: JVMTI client was not properly loaded\n", + __FILE__, __LINE__); + return STATUS_FAILED; + } + + /* a) Verifying the error JVMTI_ERROR_NULL_POINTER */ + if (verbose) + printf("\na) Checking the function with the parameter JVMTI_ERROR_NULL_POINTER ...\n"); + redirect(env, JVMTI_ERROR_NULL_POINTER); + + /* b) Verifying the error JVMTI_ERROR_UNATTACHED_THREAD + Note: the JNI spec says that the main thread can be detached from the VM + only since JDK 1.2 */ + if (verbose) + printf("\nb) Checking the function with the detached thread ...\n\ndetaching the main thread ...\n"); + if ((err = + JNI_ENV_PTR(vm)->DetachCurrentThread( + JNI_ENV_ARG1(vm))) != 0) + printf("(%s,%d): Warning: DetachCurrentThread() returns: %d\n\ +\tcheck with the detached main thread skipped\n", + __FILE__, __LINE__, err); + else { + redirect(env, JVMTI_ERROR_UNATTACHED_THREAD); + + if (verbose) + printf("\nattaching the main thread back ...\n"); + if ((err = + JNI_ENV_PTR(vm)->AttachCurrentThread( + JNI_ENV_ARG(vm, (void **) &nextEnv), (void *) 0)) != 0) { + printf("(%s,%d): TEST FAILURE: waitingThread: AttachCurrentThread() returns: %d\n", + __FILE__, __LINE__, err); + return STATUS_FAILED; + } + } + + return result; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getjniftab002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getjniftab002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getjniftab002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "-verbose") == 0) + verbose = 1; + + if (verbose) + printf("verbose mode on\n"); + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); + return JNI_ERR; + } + + vm = jvm; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/libgetjniftab002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/libgetjniftab002.c deleted file mode 100644 index c77978872d8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/libgetjniftab002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getjniftab002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/libgetjniftab002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/libgetjniftab002.cpp new file mode 100644 index 00000000000..af70978df48 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetJNIFunctionTable/getjniftab002/libgetjniftab002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getjniftab002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/liblinetab001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/liblinetab001.c deleted file mode 100644 index e774d5d9bc2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/liblinetab001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "linetab001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/liblinetab001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/liblinetab001.cpp new file mode 100644 index 00000000000..1d58b676667 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/liblinetab001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "linetab001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/linetab001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/linetab001.c deleted file mode 100644 index 4fb923d0acc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/linetab001.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - int count; - jvmtiLineNumberEntry *table; -} info; - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jvmtiLineNumberEntry m0[] = { - {0, 64} -}; -static jvmtiLineNumberEntry m1[] = { - {0, 67}, - {4, 68}, - {7, 69}, - {12,70} -}; -static info meth_tab[] = {{1, m0}, {4, m1}}; - -void checkMeth(JNIEnv *env, jclass cl, char *name, char *sig, - int stat, int meth_ind) { - jvmtiError err; - int i, j, flag; - jmethodID mid; - jint count = -1; - jvmtiLineNumberEntry *table; - int exp_count = meth_tab[meth_ind].count; - jvmtiLineNumberEntry *exp_table = meth_tab[meth_ind].table; - - if (stat) { - mid = JNI_ENV_PTR(env)-> - GetStaticMethodID(JNI_ENV_ARG(env, cl), name, sig); - } else { - mid = JNI_ENV_PTR(env)-> - GetMethodID(JNI_ENV_ARG(env, cl), name, sig); - } - if (mid == NULL) { - printf("Name = %s, sig = %s: mid = NULL\n", name, sig); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->GetLineNumberTable(jvmti, mid, &count, &table); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_line_numbers) { - /* It is OK */ - return; - } else if (err != JVMTI_ERROR_NONE) { - printf("Name = %s, sig = %s:\n", name, sig); - printf(" Failed get line number table: (%s) %d\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - if (count != exp_count) { - result = STATUS_FAILED; - printf("Name = %s, sig = %s: number of entries expected: %d, got: %d\n", - name, sig, exp_count, count); - return; - } - - for (i = 0; i < count; i++) { /* for each expected entry */ - flag = 0; - for (j = 0; j < count; j++) { /* search returned table for the entry */ - if (table[j].line_number == exp_table[i].line_number) { - flag = 1; - if (table[j].start_location != exp_table[i].start_location) { - result = STATUS_FAILED; - printf("Name = %s, sig = %s, line %d:\n", - name, sig, table[j].line_number); - printf(" start_location expected: 0x%x, got: 0x%08x%08x\n", - (jint)exp_table[i].start_location, - (jint)(table[j].start_location >> 32), - (jint)table[j].start_location); - } - break; - } - } - if (!flag) { - result = STATUS_FAILED; - printf("Name = %s, sig = %s, no line: %d\n", - name, sig, exp_table[i].line_number); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_linetab001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_linetab001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_linetab001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_line_numbers) { - printf("Warning: GetLineNumberTable is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetLineNumberTable_linetab001_check(JNIEnv *env, jclass cls) { - checkMeth(env, cls, "meth00", "()V", 1, 0); - checkMeth(env, cls, "meth01", "()D", 0, 1); - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/linetab001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/linetab001.cpp new file mode 100644 index 00000000000..f5e14c8fe13 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab001/linetab001.cpp @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + int count; + jvmtiLineNumberEntry *table; +} info; + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jvmtiLineNumberEntry m0[] = { + {0, 64} +}; +static jvmtiLineNumberEntry m1[] = { + {0, 67}, + {4, 68}, + {7, 69}, + {12,70} +}; +static info meth_tab[] = {{1, m0}, {4, m1}}; + +void checkMeth(JNIEnv *env, jclass cl, const char *name, const char *sig, + int stat, int meth_ind) { + jvmtiError err; + int i, j, flag; + jmethodID mid; + jint count = -1; + jvmtiLineNumberEntry *table; + int exp_count = meth_tab[meth_ind].count; + jvmtiLineNumberEntry *exp_table = meth_tab[meth_ind].table; + + if (stat) { + mid = JNI_ENV_PTR(env)-> + GetStaticMethodID(JNI_ENV_ARG(env, cl), name, sig); + } else { + mid = JNI_ENV_PTR(env)-> + GetMethodID(JNI_ENV_ARG(env, cl), name, sig); + } + if (mid == NULL) { + printf("Name = %s, sig = %s: mid = NULL\n", name, sig); + result = STATUS_FAILED; + return; + } + err = jvmti->GetLineNumberTable(mid, &count, &table); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_line_numbers) { + /* It is OK */ + return; + } else if (err != JVMTI_ERROR_NONE) { + printf("Name = %s, sig = %s:\n", name, sig); + printf(" Failed get line number table: (%s) %d\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + if (count != exp_count) { + result = STATUS_FAILED; + printf("Name = %s, sig = %s: number of entries expected: %d, got: %d\n", + name, sig, exp_count, count); + return; + } + + for (i = 0; i < count; i++) { /* for each expected entry */ + flag = 0; + for (j = 0; j < count; j++) { /* search returned table for the entry */ + if (table[j].line_number == exp_table[i].line_number) { + flag = 1; + if (table[j].start_location != exp_table[i].start_location) { + result = STATUS_FAILED; + printf("Name = %s, sig = %s, line %d:\n", + name, sig, table[j].line_number); + printf(" start_location expected: 0x%x, got: 0x%08x%08x\n", + (jint)exp_table[i].start_location, + (jint)(table[j].start_location >> 32), + (jint)table[j].start_location); + } + break; + } + } + if (!flag) { + result = STATUS_FAILED; + printf("Name = %s, sig = %s, no line: %d\n", + name, sig, exp_table[i].line_number); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_linetab001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_linetab001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_linetab001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_line_numbers) { + printf("Warning: GetLineNumberTable is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetLineNumberTable_linetab001_check(JNIEnv *env, jclass cls) { + checkMeth(env, cls, "meth00", "()V", 1, 0); + checkMeth(env, cls, "meth01", "()D", 0, 1); + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/liblinetab002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/liblinetab002.c deleted file mode 100644 index bb590abe22c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/liblinetab002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "linetab002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/liblinetab002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/liblinetab002.cpp new file mode 100644 index 00000000000..96537b218e0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/liblinetab002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "linetab002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/linetab002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/linetab002.c deleted file mode 100644 index e14f0edc926..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/linetab002.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_linetab002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_linetab002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_linetab002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_line_numbers) { - printf("Warning: GetLineNumberTable is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetLineNumberTable_linetab002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jint entryCount; - jvmtiLineNumberEntry *table; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_get_line_numbers) { - return result; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "", "()V"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->GetLineNumberTable(jvmti, NULL, &entryCount, &table); - if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (entryCountPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetLineNumberTable(jvmti, mid, NULL, &table); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(entryCountPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (tablePtr) null pointer check ...\n"); - } - err = (*jvmti)->GetLineNumberTable(jvmti, mid, &entryCount, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(tablePtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/linetab002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/linetab002.cpp new file mode 100644 index 00000000000..c4da71acf90 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab002/linetab002.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_linetab002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_linetab002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_linetab002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_line_numbers) { + printf("Warning: GetLineNumberTable is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetLineNumberTable_linetab002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jint entryCount; + jvmtiLineNumberEntry *table; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_get_line_numbers) { + return result; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "", "()V"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->GetLineNumberTable(NULL, &entryCount, &table); + if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (entryCountPtr) null pointer check ...\n"); + } + err = jvmti->GetLineNumberTable(mid, NULL, &table); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(entryCountPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (tablePtr) null pointer check ...\n"); + } + err = jvmti->GetLineNumberTable(mid, &entryCount, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(tablePtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/liblinetab003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/liblinetab003.c deleted file mode 100644 index 2df94602200..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/liblinetab003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "linetab003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/liblinetab003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/liblinetab003.cpp new file mode 100644 index 00000000000..ba913214372 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/liblinetab003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "linetab003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/linetab003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/linetab003.c deleted file mode 100644 index 5b8c5be37ed..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/linetab003.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_linetab003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_linetab003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_linetab003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_line_numbers) { - printf("Warning: GetLineNumberTable is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetLineNumberTable_linetab003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jint entryCount; - jvmtiLineNumberEntry *table; - int i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_get_line_numbers) { - return result; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "meth", "()I"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> source does not include line nubmers check ...\n"); - } - err = (*jvmti)->GetLineNumberTable(jvmti, mid, &entryCount, &table); - if (err != JVMTI_ERROR_ABSENT_INFORMATION) { - result = STATUS_FAILED; - printf("Error expected: JVMTI_ERROR_ABSENT_INFORMATION,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - printf(" meth() line number table (%d entries):%s\n", - entryCount, (entryCount==0 ? " empty" : "")); - for (i = 0; i < entryCount; i++) { - printf(" start_location = 0x%x%08x,", - (jint)(table[i].start_location >> 32), - (jint)table[i].start_location); - printf(" line_number = %d\n", table[i].line_number); - } - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/linetab003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/linetab003.cpp new file mode 100644 index 00000000000..be466a75c53 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLineNumberTable/linetab003/linetab003.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_linetab003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_linetab003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_linetab003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_line_numbers) { + printf("Warning: GetLineNumberTable is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetLineNumberTable_linetab003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jint entryCount; + jvmtiLineNumberEntry *table; + int i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_get_line_numbers) { + return result; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "meth", "()I"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> source does not include line nubmers check ...\n"); + } + err = jvmti->GetLineNumberTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_ABSENT_INFORMATION) { + result = STATUS_FAILED; + printf("Error expected: JVMTI_ERROR_ABSENT_INFORMATION,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + printf(" meth() line number table (%d entries):%s\n", + entryCount, (entryCount==0 ? " empty" : "")); + for (i = 0; i < entryCount; i++) { + printf(" start_location = 0x%x%08x,", + (jint)(table[i].start_location >> 32), + (jint)table[i].start_location); + printf(" line_number = %d\n", table[i].line_number); + } + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/libloadedclss001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/libloadedclss001.c deleted file mode 100644 index 9c4842a4629..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/libloadedclss001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "loadedclss001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/libloadedclss001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/libloadedclss001.cpp new file mode 100644 index 00000000000..395db9001e6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/libloadedclss001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "loadedclss001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/loadedclss001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/loadedclss001.c deleted file mode 100644 index 01a88125f77..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/loadedclss001.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_loadedclss001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_loadedclss001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_loadedclss001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetLoadedClasses_loadedclss001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jclass *classes; - jint classCount; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (classCountPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetLoadedClasses(jvmti, NULL, &classes); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (classesPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetLoadedClasses(jvmti, &classCount, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/loadedclss001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/loadedclss001.cpp new file mode 100644 index 00000000000..5ea659a7004 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss001/loadedclss001.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_loadedclss001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_loadedclss001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_loadedclss001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetLoadedClasses_loadedclss001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jclass *classes; + jint classCount; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (classCountPtr) null pointer check ...\n"); + } + err = jvmti->GetLoadedClasses(NULL, &classes); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (classesPtr) null pointer check ...\n"); + } + err = jvmti->GetLoadedClasses(&classCount, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/libloadedclss002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/libloadedclss002.c deleted file mode 100644 index da88418b6c6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/libloadedclss002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "loadedclss002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/libloadedclss002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/libloadedclss002.cpp new file mode 100644 index 00000000000..5e05c0789c3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/libloadedclss002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "loadedclss002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/loadedclss002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/loadedclss002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/loadedclss002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLoadedClasses/loadedclss002/loadedclss002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/getlocal001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/getlocal001.c deleted file mode 100644 index 967082393d1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/getlocal001.c +++ /dev/null @@ -1,531 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#define JNI_EARG(x) -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#define JNI_EARG(x) x -#endif - -#endif - -#ifndef JNI_EARG - -#ifdef __cplusplus -#define JNI_EARG(x) -#else -#define JNI_EARG(x) x -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID mid1, mid2, mid3, mid4; -static jfloat fval; -static jdouble dval; - -void check1(jvmtiEnv *jvmti_env, jthread thr, jint depth, - jvmtiLocalVariableEntry *table, jint count) { - jvmtiError err; - jlong l = 0; - jfloat f = 0.0; - jdouble d = 0.0; - int i; - - for (i = 0; i < count; i++) { - if (strcmp(table[i].name, "l") == 0) { - err = (*jvmti_env)->GetLocalLong(jvmti_env, thr, depth, table[i].slot, &l); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalLong#1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "f") == 0) { - err = (*jvmti_env)->GetLocalFloat(jvmti_env, thr, depth, table[i].slot, &f); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalFloat#1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "d") == 0) { - err = (*jvmti_env)->GetLocalDouble(jvmti_env, thr, depth, table[i].slot, &d); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalDouble#1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - if ((l != 22) || (f != 6.0) || (d != 7.0)) { - result = STATUS_FAILED; - printf("One of values retrieved by GetLocal is wrong (hook):\n"); - printf(" actual: long = 0x%08x%08x, float = %f, double = %f\n", - (jint)(l >> 32), (jint)l, f, d); - printf(" expected: long = 0x%08x%08x, float = %f, double = %f\n", - (jint)0, (jint)22, (double)6.0, (double)7.0); - } -} - -void check2(jvmtiEnv *jvmti_env, jthread thr, jint depth, - jvmtiLocalVariableEntry *table, jint count) { - jvmtiError err; - jint i1 = 0, i2 = 0, i3 = 0, i4 = 0, i5 = JNI_FALSE; - int i; - - for (i = 0; i < count; i++) { - if (strcmp(table[i].name, "i1") == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, depth, table[i].slot, &i1); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#2i1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i2") == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, depth, table[i].slot, &i2); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#2i2) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i3") == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, depth, table[i].slot, &i3); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#2i3) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i4") == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, depth, table[i].slot, &i4); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#2i4) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i5") == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, depth, table[i].slot, &i5); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#2i5) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - if ((i1 != 1) || (i2 != 1) || (i3 != 1) || (i4 != 1) || (i5 != JNI_TRUE)) { - result = STATUS_FAILED; - printf("One of values retrieved by GetLocal is wrong (locals):\n"); - printf(" actual: int=%d, short=%d, char=%d, byte=%d, boolean=%d\n", - i1, i2, i3, i4, i5); - printf(" expected: int=%d, short=%d, char=%d, byte=%d, boolean=%d\n", - 1, 1, 1, 1, JNI_TRUE); - } -} - -void check3(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jint depth, - jvmtiLocalVariableEntry *table, jint count, jmethodID mid) { - jvmtiError err; - jobject ob1 = NULL, ob2 = NULL; - jclass cls; - jfieldID fid; - jint fldVal = 0; - jint arr[10]; - int i; - - for (i = 0; i < count; i++) { - if (strcmp(table[i].name, "ob1") == 0) { - err = (*jvmti_env)->GetLocalObject(jvmti_env, thr, depth, - table[i].slot, &ob1); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalObject#1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, mid, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), - "fld", "I"); - if (fid == NULL) { - printf("Cannot find ID for \"fld\" field of meth03\n"); - JNI_ENV_PTR(env)->ExceptionClear(JNI_EARG(env)); - result = STATUS_FAILED; - continue; - } - fldVal = JNI_ENV_PTR(env)->GetIntField(JNI_ENV_ARG(env, ob1), fid); - } else if (strcmp(table[i].name, "ob2") == 0) { - err = (*jvmti_env)->GetLocalObject(jvmti_env, thr, depth, - table[i].slot, &ob2); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalObject#2) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - JNI_ENV_PTR(env)->GetIntArrayRegion(JNI_ENV_ARG(env, ob2), - 0, 10, arr); - } - } - if ((fldVal != 17) || (arr[2] != 8)) { - result = STATUS_FAILED; - printf("One of objects retrieved by GetLocal contains wrong value:\n"); - printf(" actual: fldVal = %d, int.arr[2] = %d\n", fldVal, arr[2]); - printf(" expected: fldVal = %d, int.arr[2] = %d\n", 17, 8); - } -} - -void check4(jvmtiEnv *jvmti_env, jthread thr, jint depth, - jvmtiLocalVariableEntry *table, jint count) { - jvmtiError err; - jint i1 = 0, i2 = 0, i3 = 0, i4 = 0, b = JNI_FALSE; - jlong l, lval = -100; - jfloat f = 0.0; - jdouble d = 0.0; - int i; - - for (i = 0; i < count; i++) { - if (strcmp(table[i].name, "i1") == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, depth, table[i].slot, &i1); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#4i1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i2") == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, depth, table[i].slot, &i2); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#4i2) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i3") == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, depth, table[i].slot, &i3); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#4i3) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i4") == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, depth, table[i].slot, &i4); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#4i4) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "b") == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, depth, table[i].slot, &b); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#4b) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "l") == 0) { - err = (*jvmti_env)->GetLocalLong(jvmti_env, thr, depth, table[i].slot, &l); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalLong#4) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "f") == 0) { - err = (*jvmti_env)->GetLocalFloat(jvmti_env, thr, depth, table[i].slot, &f); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalFloat#4) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "d") == 0) { - err = (*jvmti_env)->GetLocalDouble(jvmti_env, thr, depth, table[i].slot, &d); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalDouble#4) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - if ((i1 != 1) || (i2 != 2) || (i3 != 3) || (i4 != 4) || (b != JNI_TRUE) || - (l != lval) || (f != fval) || (d != dval)) { - result = STATUS_FAILED; - printf("One of values retrieved by GetLocal is wrong (params):\n"); - printf(" actual: int=%d, short=%d, char=%d, byte=%d, boolean=%d\n", - i1, i2, i3, i4, b); - printf(" long = 0x%08x%08x, float = %f, double = %f\n", - (jint)(l >> 32), (jint)l, f, d); - printf(" expected: int=%d, short=%d, char=%d, byte=%d, boolean=%d\n", - 1, 2, 3, 4, JNI_TRUE); - printf(" long = 0x%08x%08x, float = %f, double = %f\n", - (jint)(lval >> 32), (jint)lval, fval, dval); - } -} - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID mid, - jboolean was_poped_by_exception, jvalue return_value) { - jvmtiError err; - jvmtiLocalVariableEntry *table = NULL; - jint entryCount = 0; - int i; - - if (mid == mid1 || mid == mid2 || mid == mid3 || mid == mid4) { - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, - &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable#1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (mid == mid1) { - if (printdump == JNI_TRUE) { - printf(">>> exit: meth01\n"); - } - check1(jvmti_env, thr, 0, table, entryCount); - } else if (mid == mid2) { - if (printdump == JNI_TRUE) { - printf(">>> exit: meth02\n"); - } - check2(jvmti_env, thr, 0, table, entryCount); - mid2 = NULL; - } else if (mid == mid3) { - if (printdump == JNI_TRUE) { - printf(">>> exit: meth03\n"); - } - check3(jvmti_env, (JNIEnv *)env, thr, 0, table, entryCount, mid); - } else if (mid == mid4) { - if (printdump == JNI_TRUE) { - printf(">>> exit: meth04\n"); - } - check4(jvmti_env, thr, 0, table, entryCount); - } - } - if (table != NULL) { - for (i = 0; i < entryCount; i++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table[i].name); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table[i].signature); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table); - } -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - jvmtiError err; - jvmtiLocalVariableEntry *table = NULL; - jint entryCount = 0; - jmethodID mid; - jlocation loc; - int i; - - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thr, 1, &mid, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable#2) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (mid == mid1) { - if (printdump == JNI_TRUE) { - printf(">>> bp: meth01\n"); - } - check1(jvmti_env, thr, 1, table, entryCount); - } else if (mid == mid2) { - if (printdump == JNI_TRUE) { - printf(">>> bp: meth02\n"); - } - check2(jvmti_env, thr, 1, table, entryCount); - } else if (mid == mid3) { - if (printdump == JNI_TRUE) { - printf(">>> bp: meth03\n"); - } - check3(jvmti_env, (JNIEnv *)env, thr, 1, table, entryCount, mid); - } else if (mid == mid4) { - if (printdump == JNI_TRUE) { - printf(">>> bp: meth04\n"); - } - check4(jvmti_env, thr, 1, table, entryCount); - } else { - printf("ERROR: didn't know where we got called from"); - result = STATUS_FAILED; - } - if (table != NULL) { - for (i = 0; i < entryCount; i++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table[i].name); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table[i].signature); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getlocal001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getlocal001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getlocal001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_access_local_variables) { - printf("Warning: Access to local variables is not implemented\n"); - } else if (caps.can_generate_breakpoint_events && - caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or MethodExit event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetLocalVariable_getlocal001_getMeth(JNIEnv *env, jclass cls, - jdouble d, jfloat f) { - jvmtiError err; - jmethodID mid; - - if (!caps.can_access_local_variables || - !caps.can_generate_breakpoint_events || - !caps.can_generate_method_exit_events) return; - - fval = f; - dval = d; - mid1 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "meth01", "()D"); - mid2 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "meth02", "(I)V"); - mid3 = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "meth03", "(Lnsk/jvmti/GetLocalVariable/getlocal001;)V"); - mid4 = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "meth04", "(IJSDCFBZ)V"); - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (mid == 0 || mid1 == 0 || mid2 == 0 || mid3 == 0 || mid4 == 0) { - printf("Cannot find Method ID for a method\n"); - JNI_ENV_PTR(env)->ExceptionDescribe(JNI_EARG(env)); - JNI_ENV_PTR(env)->ExceptionClear(JNI_EARG(env)); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to SetBreakpoint: err = %d\n", err); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetLocalVariable_getlocal001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/getlocal001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/getlocal001.cpp new file mode 100644 index 00000000000..7fbc942ec75 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/getlocal001.cpp @@ -0,0 +1,531 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#define JNI_EARG(x) +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#define JNI_EARG(x) x +#endif + +#endif + +#ifndef JNI_EARG + +#ifdef __cplusplus +#define JNI_EARG(x) +#else +#define JNI_EARG(x) x +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID mid1, mid2, mid3, mid4; +static jfloat fval; +static jdouble dval; + +void check1(jvmtiEnv *jvmti_env, jthread thr, jint depth, + jvmtiLocalVariableEntry *table, jint count) { + jvmtiError err; + jlong l = 0; + jfloat f = 0.0; + jdouble d = 0.0; + int i; + + for (i = 0; i < count; i++) { + if (strcmp(table[i].name, "l") == 0) { + err = jvmti_env->GetLocalLong(thr, depth, table[i].slot, &l); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalLong#1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "f") == 0) { + err = jvmti_env->GetLocalFloat(thr, depth, table[i].slot, &f); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalFloat#1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "d") == 0) { + err = jvmti_env->GetLocalDouble(thr, depth, table[i].slot, &d); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalDouble#1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + if ((l != 22) || (f != 6.0) || (d != 7.0)) { + result = STATUS_FAILED; + printf("One of values retrieved by GetLocal is wrong (hook):\n"); + printf(" actual: long = 0x%08x%08x, float = %f, double = %f\n", + (jint)(l >> 32), (jint)l, f, d); + printf(" expected: long = 0x%08x%08x, float = %f, double = %f\n", + (jint)0, (jint)22, (double)6.0, (double)7.0); + } +} + +void check2(jvmtiEnv *jvmti_env, jthread thr, jint depth, + jvmtiLocalVariableEntry *table, jint count) { + jvmtiError err; + jint i1 = 0, i2 = 0, i3 = 0, i4 = 0, i5 = JNI_FALSE; + int i; + + for (i = 0; i < count; i++) { + if (strcmp(table[i].name, "i1") == 0) { + err = jvmti_env->GetLocalInt(thr, depth, table[i].slot, &i1); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#2i1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i2") == 0) { + err = jvmti_env->GetLocalInt(thr, depth, table[i].slot, &i2); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#2i2) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i3") == 0) { + err = jvmti_env->GetLocalInt(thr, depth, table[i].slot, &i3); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#2i3) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i4") == 0) { + err = jvmti_env->GetLocalInt(thr, depth, table[i].slot, &i4); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#2i4) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i5") == 0) { + err = jvmti_env->GetLocalInt(thr, depth, table[i].slot, &i5); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#2i5) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + if ((i1 != 1) || (i2 != 1) || (i3 != 1) || (i4 != 1) || (i5 != JNI_TRUE)) { + result = STATUS_FAILED; + printf("One of values retrieved by GetLocal is wrong (locals):\n"); + printf(" actual: int=%d, short=%d, char=%d, byte=%d, boolean=%d\n", + i1, i2, i3, i4, i5); + printf(" expected: int=%d, short=%d, char=%d, byte=%d, boolean=%d\n", + 1, 1, 1, 1, JNI_TRUE); + } +} + +void check3(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jint depth, + jvmtiLocalVariableEntry *table, jint count, jmethodID mid) { + jvmtiError err; + jobject ob1 = NULL, ob2 = NULL; + jclass cls; + jfieldID fid; + jint fldVal = 0; + jint arr[10]; + int i; + + for (i = 0; i < count; i++) { + if (strcmp(table[i].name, "ob1") == 0) { + err = jvmti_env->GetLocalObject(thr, depth, + table[i].slot, &ob1); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalObject#1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti_env->GetMethodDeclaringClass(mid, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), + "fld", "I"); + if (fid == NULL) { + printf("Cannot find ID for \"fld\" field of meth03\n"); + JNI_ENV_PTR(env)->ExceptionClear(JNI_EARG(env)); + result = STATUS_FAILED; + continue; + } + fldVal = JNI_ENV_PTR(env)->GetIntField(JNI_ENV_ARG(env, ob1), fid); + } else if (strcmp(table[i].name, "ob2") == 0) { + err = jvmti_env->GetLocalObject(thr, depth, + table[i].slot, &ob2); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalObject#2) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + JNI_ENV_PTR(env)->GetIntArrayRegion(JNI_ENV_ARG(env, (jintArray) ob2), + 0, 10, arr); + } + } + if ((fldVal != 17) || (arr[2] != 8)) { + result = STATUS_FAILED; + printf("One of objects retrieved by GetLocal contains wrong value:\n"); + printf(" actual: fldVal = %d, int.arr[2] = %d\n", fldVal, arr[2]); + printf(" expected: fldVal = %d, int.arr[2] = %d\n", 17, 8); + } +} + +void check4(jvmtiEnv *jvmti_env, jthread thr, jint depth, + jvmtiLocalVariableEntry *table, jint count) { + jvmtiError err; + jint i1 = 0, i2 = 0, i3 = 0, i4 = 0, b = JNI_FALSE; + jlong l, lval = -100; + jfloat f = 0.0; + jdouble d = 0.0; + int i; + + for (i = 0; i < count; i++) { + if (strcmp(table[i].name, "i1") == 0) { + err = jvmti_env->GetLocalInt(thr, depth, table[i].slot, &i1); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#4i1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i2") == 0) { + err = jvmti_env->GetLocalInt(thr, depth, table[i].slot, &i2); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#4i2) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i3") == 0) { + err = jvmti_env->GetLocalInt(thr, depth, table[i].slot, &i3); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#4i3) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i4") == 0) { + err = jvmti_env->GetLocalInt(thr, depth, table[i].slot, &i4); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#4i4) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "b") == 0) { + err = jvmti_env->GetLocalInt(thr, depth, table[i].slot, &b); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#4b) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "l") == 0) { + err = jvmti_env->GetLocalLong(thr, depth, table[i].slot, &l); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalLong#4) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "f") == 0) { + err = jvmti_env->GetLocalFloat(thr, depth, table[i].slot, &f); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalFloat#4) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "d") == 0) { + err = jvmti_env->GetLocalDouble(thr, depth, table[i].slot, &d); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalDouble#4) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + if ((i1 != 1) || (i2 != 2) || (i3 != 3) || (i4 != 4) || (b != JNI_TRUE) || + (l != lval) || (f != fval) || (d != dval)) { + result = STATUS_FAILED; + printf("One of values retrieved by GetLocal is wrong (params):\n"); + printf(" actual: int=%d, short=%d, char=%d, byte=%d, boolean=%d\n", + i1, i2, i3, i4, b); + printf(" long = 0x%08x%08x, float = %f, double = %f\n", + (jint)(l >> 32), (jint)l, f, d); + printf(" expected: int=%d, short=%d, char=%d, byte=%d, boolean=%d\n", + 1, 2, 3, 4, JNI_TRUE); + printf(" long = 0x%08x%08x, float = %f, double = %f\n", + (jint)(lval >> 32), (jint)lval, fval, dval); + } +} + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID mid, + jboolean was_poped_by_exception, jvalue return_value) { + jvmtiError err; + jvmtiLocalVariableEntry *table = NULL; + jint entryCount = 0; + int i; + + if (mid == mid1 || mid == mid2 || mid == mid3 || mid == mid4) { + err = jvmti_env->GetLocalVariableTable(mid, + &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable#1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (mid == mid1) { + if (printdump == JNI_TRUE) { + printf(">>> exit: meth01\n"); + } + check1(jvmti_env, thr, 0, table, entryCount); + } else if (mid == mid2) { + if (printdump == JNI_TRUE) { + printf(">>> exit: meth02\n"); + } + check2(jvmti_env, thr, 0, table, entryCount); + mid2 = NULL; + } else if (mid == mid3) { + if (printdump == JNI_TRUE) { + printf(">>> exit: meth03\n"); + } + check3(jvmti_env, (JNIEnv *)env, thr, 0, table, entryCount, mid); + } else if (mid == mid4) { + if (printdump == JNI_TRUE) { + printf(">>> exit: meth04\n"); + } + check4(jvmti_env, thr, 0, table, entryCount); + } + } + if (table != NULL) { + for (i = 0; i < entryCount; i++) { + jvmti_env->Deallocate((unsigned char*)table[i].name); + jvmti_env->Deallocate((unsigned char*)table[i].signature); + } + jvmti_env->Deallocate((unsigned char*)table); + } +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + jvmtiError err; + jvmtiLocalVariableEntry *table = NULL; + jint entryCount = 0; + jmethodID mid; + jlocation loc; + int i; + + err = jvmti_env->GetFrameLocation(thr, 1, &mid, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable#2) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (mid == mid1) { + if (printdump == JNI_TRUE) { + printf(">>> bp: meth01\n"); + } + check1(jvmti_env, thr, 1, table, entryCount); + } else if (mid == mid2) { + if (printdump == JNI_TRUE) { + printf(">>> bp: meth02\n"); + } + check2(jvmti_env, thr, 1, table, entryCount); + } else if (mid == mid3) { + if (printdump == JNI_TRUE) { + printf(">>> bp: meth03\n"); + } + check3(jvmti_env, (JNIEnv *)env, thr, 1, table, entryCount, mid); + } else if (mid == mid4) { + if (printdump == JNI_TRUE) { + printf(">>> bp: meth04\n"); + } + check4(jvmti_env, thr, 1, table, entryCount); + } else { + printf("ERROR: didn't know where we got called from"); + result = STATUS_FAILED; + } + if (table != NULL) { + for (i = 0; i < entryCount; i++) { + jvmti_env->Deallocate((unsigned char*)table[i].name); + jvmti_env->Deallocate((unsigned char*)table[i].signature); + } + jvmti_env->Deallocate((unsigned char*)table); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getlocal001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getlocal001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getlocal001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_access_local_variables) { + printf("Warning: Access to local variables is not implemented\n"); + } else if (caps.can_generate_breakpoint_events && + caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or MethodExit event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetLocalVariable_getlocal001_getMeth(JNIEnv *env, jclass cls, + jdouble d, jfloat f) { + jvmtiError err; + jmethodID mid; + + if (!caps.can_access_local_variables || + !caps.can_generate_breakpoint_events || + !caps.can_generate_method_exit_events) return; + + fval = f; + dval = d; + mid1 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "meth01", "()D"); + mid2 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "meth02", "(I)V"); + mid3 = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "meth03", "(Lnsk/jvmti/GetLocalVariable/getlocal001;)V"); + mid4 = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "meth04", "(IJSDCFBZ)V"); + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (mid == 0 || mid1 == 0 || mid2 == 0 || mid3 == 0 || mid4 == 0) { + printf("Cannot find Method ID for a method\n"); + JNI_ENV_PTR(env)->ExceptionDescribe(JNI_EARG(env)); + JNI_ENV_PTR(env)->ExceptionClear(JNI_EARG(env)); + result = STATUS_FAILED; + return; + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to SetBreakpoint: err = %d\n", err); + result = STATUS_FAILED; + return; + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetLocalVariable_getlocal001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/libgetlocal001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/libgetlocal001.c deleted file mode 100644 index e57947c2833..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/libgetlocal001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getlocal001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/libgetlocal001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/libgetlocal001.cpp new file mode 100644 index 00000000000..e05633c7e7a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal001/libgetlocal001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getlocal001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/getlocal002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/getlocal002.c deleted file mode 100644 index 538091ba15c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/getlocal002.c +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID mid = NULL; - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jboolean was_poped_by_exception, jvalue return_value) { - jvmtiError err; - jint entryCount, i; - jvmtiLocalVariableEntry *table; - jint intVal; - jfloat floatVal; - jdouble doubleVal; - - if (mid == method) { - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_EXIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable metod exit event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->GetLocalVariableTable(jvmti, mid, - &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - for (i = 0; i < entryCount; i++) { - if (strcmp(table[i].name, "f") == 0) { - if (printdump == JNI_TRUE) { - printf(">>> (float/int) type mismatch check ...\n"); - } - err = (*jvmti)->GetLocalInt(jvmti, thr, 0, table[i].slot, &intVal); - if (err != JVMTI_ERROR_TYPE_MISMATCH) { - printf("Error expected: JVMTI_ERROR_TYPE_MISMATCH,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> (float/double) type mismatch check ...\n"); - } - err = (*jvmti)->GetLocalDouble(jvmti, thr, 0, table[i].slot, &doubleVal); - if (err != JVMTI_ERROR_TYPE_MISMATCH) { - printf("Error expected: JVMTI_ERROR_TYPE_MISMATCH,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> invalid slot check ...\n"); - } - err = (*jvmti)->GetLocalFloat(jvmti, thr, 0, 10, &floatVal); - if (err != JVMTI_ERROR_INVALID_SLOT) { - printf("Error expected: JVMTI_ERROR_INVALID_SLOT,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetLocalFloat(jvmti, thr, 0, table[i].slot, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - for (i = 0; i < entryCount; i++) { - (*jvmti)->Deallocate(jvmti, (unsigned char*)table[i].name); - (*jvmti)->Deallocate(jvmti, (unsigned char*)table[i].signature); - } - (*jvmti)->Deallocate(jvmti, (unsigned char*)table); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getlocal002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getlocal002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getlocal002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_access_local_variables) { - printf("Warning: Access to local variables is not implemented\n"); - } else if (caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: MethodExit event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetLocalVariable_getlocal002_getMeth(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_access_local_variables || - !caps.can_generate_method_exit_events) return; - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "meth01", "()D"); - if (mid == NULL) { - printf("Cannot find Method ID for meth01\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable metod exit event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetLocalVariable_getlocal002_checkLoc(JNIEnv *env, - jclass cls, jthread thr) { - jvmtiError err; - jvmtiLocalVariableEntry *table; - jint entryCount, i; - jmethodID mid; - jint i1; - - if (jvmti == NULL) { - return; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "meth02", "()V"); - if (mid == NULL) { - printf("Cannot find Method ID for meth02\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetLocalVariableTable(jvmti, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - for (i = 0; i < entryCount; i++) { - if (strcmp(table[i].name, "i1") == 0) { - if (printdump == JNI_TRUE) { - printf(">>> invalid thread check ...\n"); - } - err = (*jvmti)->GetLocalInt(jvmti, cls, 0, table[i].slot, &i1); - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> invalid depth check ...\n"); - } - err = (*jvmti)->GetLocalInt(jvmti, thr, -1, table[i].slot, &i1); - if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { - printf("Error expected: JVMTI_ERROR_ILLEGAL_ARGUMENT,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> opaque frame check ...\n"); - } - err = (*jvmti)->GetLocalInt(jvmti, thr, 0, table[i].slot, &i1); - if (err != JVMTI_ERROR_OPAQUE_FRAME) { - printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetLocalVariable_getlocal002_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/getlocal002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/getlocal002.cpp new file mode 100644 index 00000000000..bcfbf02c71d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/getlocal002.cpp @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID mid = NULL; + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jboolean was_poped_by_exception, jvalue return_value) { + jvmtiError err; + jint entryCount, i; + jvmtiLocalVariableEntry *table; + jint intVal; + jfloat floatVal; + jdouble doubleVal; + + if (mid == method) { + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_EXIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable metod exit event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->GetLocalVariableTable(mid, + &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + for (i = 0; i < entryCount; i++) { + if (strcmp(table[i].name, "f") == 0) { + if (printdump == JNI_TRUE) { + printf(">>> (float/int) type mismatch check ...\n"); + } + err = jvmti->GetLocalInt(thr, 0, table[i].slot, &intVal); + if (err != JVMTI_ERROR_TYPE_MISMATCH) { + printf("Error expected: JVMTI_ERROR_TYPE_MISMATCH,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> (float/double) type mismatch check ...\n"); + } + err = jvmti->GetLocalDouble(thr, 0, table[i].slot, &doubleVal); + if (err != JVMTI_ERROR_TYPE_MISMATCH) { + printf("Error expected: JVMTI_ERROR_TYPE_MISMATCH,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> invalid slot check ...\n"); + } + err = jvmti->GetLocalFloat(thr, 0, 10, &floatVal); + if (err != JVMTI_ERROR_INVALID_SLOT) { + printf("Error expected: JVMTI_ERROR_INVALID_SLOT,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetLocalFloat(thr, 0, table[i].slot, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + for (i = 0; i < entryCount; i++) { + jvmti->Deallocate((unsigned char*)table[i].name); + jvmti->Deallocate((unsigned char*)table[i].signature); + } + jvmti->Deallocate((unsigned char*)table); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getlocal002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getlocal002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getlocal002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_access_local_variables) { + printf("Warning: Access to local variables is not implemented\n"); + } else if (caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: MethodExit event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetLocalVariable_getlocal002_getMeth(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_access_local_variables || + !caps.can_generate_method_exit_events) return; + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "meth01", "()D"); + if (mid == NULL) { + printf("Cannot find Method ID for meth01\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable metod exit event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetLocalVariable_getlocal002_checkLoc(JNIEnv *env, + jclass cls, jthread thr) { + jvmtiError err; + jvmtiLocalVariableEntry *table; + jint entryCount, i; + jmethodID mid; + jint i1; + + if (jvmti == NULL) { + return; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "meth02", "()V"); + if (mid == NULL) { + printf("Cannot find Method ID for meth02\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + for (i = 0; i < entryCount; i++) { + if (strcmp(table[i].name, "i1") == 0) { + if (printdump == JNI_TRUE) { + printf(">>> invalid thread check ...\n"); + } + err = jvmti->GetLocalInt(cls, 0, table[i].slot, &i1); + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> invalid depth check ...\n"); + } + err = jvmti->GetLocalInt(thr, -1, table[i].slot, &i1); + if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { + printf("Error expected: JVMTI_ERROR_ILLEGAL_ARGUMENT,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> opaque frame check ...\n"); + } + err = jvmti->GetLocalInt(thr, 0, table[i].slot, &i1); + if (err != JVMTI_ERROR_OPAQUE_FRAME) { + printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetLocalVariable_getlocal002_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/libgetlocal002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/libgetlocal002.c deleted file mode 100644 index 541bf11be73..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/libgetlocal002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getlocal002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/libgetlocal002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/libgetlocal002.cpp new file mode 100644 index 00000000000..8d305d8ef77 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariable/getlocal002/libgetlocal002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getlocal002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/liblocaltab001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/liblocaltab001.c deleted file mode 100644 index 6ea50f2acfc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/liblocaltab001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "localtab001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/liblocaltab001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/liblocaltab001.cpp new file mode 100644 index 00000000000..40fdd4a7459 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/liblocaltab001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "localtab001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/localtab001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/localtab001.c deleted file mode 100644 index 3c0f67413bb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/localtab001.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - int count; - jvmtiLocalVariableEntry *table; -} info; - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jvmtiLocalVariableEntry m1[] = { - {0, 21, "this", "Lnsk/jvmti/GetLocalVariableTable/localtab001;", NULL, 0}, - {4, 17, "l", "J", NULL, 1}, - {7, 14, "f", "F", NULL, 2}, - {12, 9, "d", "D", NULL, 3} -}; -static jvmtiLocalVariableEntry m2[] = { - {0, 32, "this", "Lnsk/jvmti/GetLocalVariableTable/localtab001;", NULL, 0}, - {0, 32, "step", "I", NULL, 1}, - {2, 29, "i2", "S", NULL, 2}, - {4, 27, "i3", "C", NULL, 3}, - {7, 24, "i4", "B", NULL, 4}, - {10,21, "i5", "Z", NULL, 5}, - {13,18, "i1", "I", NULL, 6} -}; -static jvmtiLocalVariableEntry m3[] = { - {0, 70, "ob", "Lnsk/jvmti/GetLocalVariableTable/localtab001;", NULL, 0}, - {2, 67, "ob1", "Lnsk/jvmti/GetLocalVariableTable/localtab001;", NULL, 1}, - {56,13, "ob2", "[I", NULL, 2}, - {61, 0, "i", "I", NULL, 3}, - {64, 5, "e", "Ljava/lang/IndexOutOfBoundsException;", NULL, 4} -}; -static jvmtiLocalVariableEntry m4[] = { - {0, 33, "i1", "I", NULL, 0}, - {0, 33, "l", "J", NULL, 1}, - {0, 33, "i2", "S", NULL, 2}, - {0, 33, "d", "D", NULL, 3}, - {0, 33, "i3", "C", NULL, 4}, - {0, 33, "f", "F", NULL, 5}, - {0, 33, "i4", "B", NULL, 6}, - {0, 33, "b", "Z", NULL, 7} -}; -static jvmtiLocalVariableEntry m5[] = { - {0, 6, "this", "Lnsk/jvmti/GetLocalVariableTable/localtab001;", NULL, 0}, - {0, 6, "i", "I", NULL, 1}, - {2, 4, "i12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678", "I", NULL, 2} -}; -static jvmtiLocalVariableEntry m6[] = { - {0, 5, "this", "Lnsk/jvmti/GetLocalVariableTable/localtab001;", NULL, 0}, -}; -static info meth_tab[] = { - {0, NULL}, - {4, m1}, - {7, m2}, - {5, m3}, - {8, m4}, - {3, m5}, - {1, m6} -}; - -void checkMeth(JNIEnv *env, jclass cl, char *name, char *sig, - int stat, int meth_ind) { - jvmtiError err; - int i, j, flag, loc_err; - jmethodID mid; - jint count = -1; - jvmtiLocalVariableEntry *table; - int exp_count = meth_tab[meth_ind].count; - jvmtiLocalVariableEntry *exp_table = meth_tab[meth_ind].table; - - if (stat) { - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), name, sig); - } else { - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); - } - if (mid == NULL) { - printf("Name = %s, sig = %s: mid = NULL\n", name, sig); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->GetLocalVariableTable(jvmti, mid, &count, &table); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_access_local_variables) { - /* It is OK */ - return; - } else if (err != JVMTI_ERROR_NONE) { - printf("Name = %s, sig = %s:\n", name, sig); - printf(" Failed get local variable table: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - if (count != exp_count) { - printf("Name = %s, sig = %s: number of entries expected: %d, got: %d\n", - name, sig, exp_count, count); - result = STATUS_FAILED; - } - - for (i = 0; i < exp_count; i++) { /* for each expected entry */ - flag = 0; - loc_err = 0; - for (j = 0; j < count; j++) { /* search returned table for the entry */ - if (strcmp(table[j].name, exp_table[i].name) == 0) { - flag = 1; - if (strcmp(table[j].signature, exp_table[i].signature) != 0) { - if (!loc_err) { - loc_err = 1; - printf("Name = %s, sig = %s, local %s:\n", - name, sig, table[j].name); - } - printf(" signature expected: \"%s\", got: \"%s\"\n", - exp_table[i].signature, table[j].signature); - result = STATUS_FAILED; - } - if (table[j].start_location != exp_table[i].start_location) { - if (!loc_err) { - loc_err = 1; - printf("Name = %s, sig = %s, local %s:\n", - name, sig, table[j].name); - } - printf(" start_location expected: 0x%x, got: 0x%08x%08x\n", - (jint)exp_table[i].start_location, - (jint)(table[j].start_location >> 32), - (jint)table[j].start_location); - result = STATUS_FAILED; - } - if (table[j].length != exp_table[i].length) { - if (!loc_err) { - loc_err = 1; - printf("Name = %s, sig = %s, local %s:\n", - name, sig, table[j].name); - } - printf(" length expected: %d, got: %d\n", - exp_table[i].length, table[j].length); - result = STATUS_FAILED; - } - break; - } - } - if (!flag) { - printf("Name = %s, sig = %s: no local: %s\n", - name, sig, exp_table[i].name); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_localtab001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_localtab001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_localtab001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_access_local_variables) { - printf("Warning: Access to local variables is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetLocalVariableTable_localtab001_check(JNIEnv *env, jclass cls) { - checkMeth(env, cls, "meth00", "()V", 1, 0); - checkMeth(env, cls, "meth01", "()D", 0, 1); - checkMeth(env, cls, "meth02", "(I)V", 0, 2); - checkMeth(env, cls, "meth03", "(Lnsk/jvmti/GetLocalVariableTable/localtab001;)V", 1, 3); - checkMeth(env, cls, "meth04", "(IJSDCFBZ)D", 1, 4); - checkMeth(env, cls, "meth05", "(I)I", 0, 5); - checkMeth(env, cls, "", "()V", 0, 6); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetLocalVariableTable_localtab001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/localtab001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/localtab001.cpp new file mode 100644 index 00000000000..d7888896200 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab001/localtab001.cpp @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + int count; + jvmtiLocalVariableEntry *table; +} info; + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jvmtiLocalVariableEntry m1[] = { + {0, 21, (char*) "this", (char*) "Lnsk/jvmti/GetLocalVariableTable/localtab001;", NULL, 0}, + {4, 17, (char*) "l", (char*) "J", NULL, 1}, + {7, 14, (char*) "f", (char*) "F", NULL, 2}, + {12, 9, (char*) "d", (char*) "D", NULL, 3} +}; +static jvmtiLocalVariableEntry m2[] = { + {0, 32, (char*) "this", (char*) "Lnsk/jvmti/GetLocalVariableTable/localtab001;", NULL, 0}, + {0, 32, (char*) "step", (char*) "I", NULL, 1}, + {2, 29, (char*) "i2", (char*) "S", NULL, 2}, + {4, 27, (char*) "i3", (char*) "C", NULL, 3}, + {7, 24, (char*) "i4", (char*) "B", NULL, 4}, + {10,21, (char*) "i5", (char*) "Z", NULL, 5}, + {13,18, (char*) "i1", (char*) "I", NULL, 6} +}; +static jvmtiLocalVariableEntry m3[] = { + {0, 70, (char*) "ob", (char*) "Lnsk/jvmti/GetLocalVariableTable/localtab001;", NULL, 0}, + {2, 67, (char*) "ob1", (char*) "Lnsk/jvmti/GetLocalVariableTable/localtab001;", NULL, 1}, + {56,13, (char*) "ob2", (char*) "[I", NULL, 2}, + {61, 0, (char*) "i", (char*) "I", NULL, 3}, + {64, 5, (char*) "e", (char*) "Ljava/lang/IndexOutOfBoundsException;", NULL, 4} +}; +static jvmtiLocalVariableEntry m4[] = { + {0, 33, (char*) "i1", (char*) "I", NULL, 0}, + {0, 33, (char*) "l", (char*) "J", NULL, 1}, + {0, 33, (char*) "i2", (char*) "S", NULL, 2}, + {0, 33, (char*) "d", (char*) "D", NULL, 3}, + {0, 33, (char*) "i3", (char*) "C", NULL, 4}, + {0, 33, (char*) "f", (char*) "F", NULL, 5}, + {0, 33, (char*) "i4", (char*) "B", NULL, 6}, + {0, 33, (char*) "b", (char*) "Z", NULL, 7} +}; +static jvmtiLocalVariableEntry m5[] = { + {0, 6, (char*) "this", (char*) "Lnsk/jvmti/GetLocalVariableTable/localtab001;", NULL, 0}, + {0, 6, (char*) "i", (char*) "I", NULL, 1}, + {2, 4, (char*) "i12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678", (char*) "I", NULL, 2} +}; +static jvmtiLocalVariableEntry m6[] = { + {0, 5, (char*) "this", (char*) "Lnsk/jvmti/GetLocalVariableTable/localtab001;", NULL, 0}, +}; +static info meth_tab[] = { + {0, NULL}, + {4, m1}, + {7, m2}, + {5, m3}, + {8, m4}, + {3, m5}, + {1, m6} +}; + +void checkMeth(JNIEnv *env, jclass cl, const char *name, const char *sig, + int stat, int meth_ind) { + jvmtiError err; + int i, j, flag, loc_err; + jmethodID mid; + jint count = -1; + jvmtiLocalVariableEntry *table; + int exp_count = meth_tab[meth_ind].count; + jvmtiLocalVariableEntry *exp_table = meth_tab[meth_ind].table; + + if (stat) { + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), name, sig); + } else { + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); + } + if (mid == NULL) { + printf("Name = %s, sig = %s: mid = NULL\n", name, sig); + result = STATUS_FAILED; + return; + } + err = jvmti->GetLocalVariableTable(mid, &count, &table); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_access_local_variables) { + /* It is OK */ + return; + } else if (err != JVMTI_ERROR_NONE) { + printf("Name = %s, sig = %s:\n", name, sig); + printf(" Failed get local variable table: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + if (count != exp_count) { + printf("Name = %s, sig = %s: number of entries expected: %d, got: %d\n", + name, sig, exp_count, count); + result = STATUS_FAILED; + } + + for (i = 0; i < exp_count; i++) { /* for each expected entry */ + flag = 0; + loc_err = 0; + for (j = 0; j < count; j++) { /* search returned table for the entry */ + if (strcmp(table[j].name, exp_table[i].name) == 0) { + flag = 1; + if (strcmp(table[j].signature, exp_table[i].signature) != 0) { + if (!loc_err) { + loc_err = 1; + printf("Name = %s, sig = %s, local %s:\n", + name, sig, table[j].name); + } + printf(" signature expected: \"%s\", got: \"%s\"\n", + exp_table[i].signature, table[j].signature); + result = STATUS_FAILED; + } + if (table[j].start_location != exp_table[i].start_location) { + if (!loc_err) { + loc_err = 1; + printf("Name = %s, sig = %s, local %s:\n", + name, sig, table[j].name); + } + printf(" start_location expected: 0x%x, got: 0x%08x%08x\n", + (jint)exp_table[i].start_location, + (jint)(table[j].start_location >> 32), + (jint)table[j].start_location); + result = STATUS_FAILED; + } + if (table[j].length != exp_table[i].length) { + if (!loc_err) { + loc_err = 1; + printf("Name = %s, sig = %s, local %s:\n", + name, sig, table[j].name); + } + printf(" length expected: %d, got: %d\n", + exp_table[i].length, table[j].length); + result = STATUS_FAILED; + } + break; + } + } + if (!flag) { + printf("Name = %s, sig = %s: no local: %s\n", + name, sig, exp_table[i].name); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_localtab001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_localtab001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_localtab001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_access_local_variables) { + printf("Warning: Access to local variables is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetLocalVariableTable_localtab001_check(JNIEnv *env, jclass cls) { + checkMeth(env, cls, "meth00", "()V", 1, 0); + checkMeth(env, cls, "meth01", "()D", 0, 1); + checkMeth(env, cls, "meth02", "(I)V", 0, 2); + checkMeth(env, cls, "meth03", "(Lnsk/jvmti/GetLocalVariableTable/localtab001;)V", 1, 3); + checkMeth(env, cls, "meth04", "(IJSDCFBZ)D", 1, 4); + checkMeth(env, cls, "meth05", "(I)I", 0, 5); + checkMeth(env, cls, "", "()V", 0, 6); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetLocalVariableTable_localtab001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/liblocaltab002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/liblocaltab002.c deleted file mode 100644 index 3da1ed7a5e4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/liblocaltab002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "localtab002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/liblocaltab002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/liblocaltab002.cpp new file mode 100644 index 00000000000..75f1b003589 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/liblocaltab002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "localtab002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/localtab002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/localtab002.c deleted file mode 100644 index 1223cc81d74..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/localtab002.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_localtab002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_localtab002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_localtab002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_access_local_variables) { - printf("Warning: Access to local variables is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetLocalVariableTable_localtab002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jint entryCount; - jvmtiLocalVariableEntry *table; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_access_local_variables) return result; - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "", "()V"); - if (mid == NULL) { - printf("Cannot get method ID for \"\"!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->GetLocalVariableTable(jvmti, NULL, &entryCount, &table); - if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (entryCountPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetLocalVariableTable(jvmti, mid, NULL, &table); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (tablePtr) null pointer check ...\n"); - } - err = (*jvmti)->GetLocalVariableTable(jvmti, mid, &entryCount, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "check", "()I"); - if (mid == NULL) { - printf("Cannot get method ID for \"check\"!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> native method check ...\n"); - } - err = (*jvmti)->GetLocalVariableTable(jvmti, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NATIVE_METHOD) { - printf("Error expected: JVMTI_ERROR_NATIVE_METHOD,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/localtab002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/localtab002.cpp new file mode 100644 index 00000000000..bf57acd6f4c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab002/localtab002.cpp @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_localtab002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_localtab002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_localtab002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_access_local_variables) { + printf("Warning: Access to local variables is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetLocalVariableTable_localtab002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jint entryCount; + jvmtiLocalVariableEntry *table; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_access_local_variables) return result; + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "", "()V"); + if (mid == NULL) { + printf("Cannot get method ID for \"\"!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->GetLocalVariableTable(NULL, &entryCount, &table); + if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (entryCountPtr) null pointer check ...\n"); + } + err = jvmti->GetLocalVariableTable(mid, NULL, &table); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (tablePtr) null pointer check ...\n"); + } + err = jvmti->GetLocalVariableTable(mid, &entryCount, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "check", "()I"); + if (mid == NULL) { + printf("Cannot get method ID for \"check\"!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> native method check ...\n"); + } + err = jvmti->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NATIVE_METHOD) { + printf("Error expected: JVMTI_ERROR_NATIVE_METHOD,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/liblocaltab003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/liblocaltab003.c deleted file mode 100644 index 091c11127f4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/liblocaltab003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "localtab003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/liblocaltab003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/liblocaltab003.cpp new file mode 100644 index 00000000000..b01b754dab8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/liblocaltab003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "localtab003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/localtab003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/localtab003.c deleted file mode 100644 index 3806e7068b0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/localtab003.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_localtab003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_localtab003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_localtab003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_access_local_variables) { - printf("Warning: Access to local variables is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetLocalVariableTable_localtab003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jint entryCount; - jvmtiLocalVariableEntry *table; - int i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_access_local_variables) return result; - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "meth", "()I"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> try class which has not local variable info ...\n"); - } - err = (*jvmti)->GetLocalVariableTable(jvmti, mid, &entryCount, &table); - if (err != JVMTI_ERROR_ABSENT_INFORMATION) { - result = STATUS_FAILED; - printf("Error expected: JVMTI_ERROR_ABSENT_INFORMATION,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - printf(" meth() local variable table (%d entries):%s\n", - entryCount, (entryCount==0 ? " empty" : "")); - for (i = 0; i < entryCount; i++) { - printf(" name=\"%s\", sig=\"%s\"", - table[i].name, table[i].signature); - printf(", start_location=0x%x%08x", - (jint)(table[i].start_location >> 32), - (jint)table[i].start_location); - printf(", length=%d", table[i].length); - printf(", slot=%d\n", table[i].slot); - } - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/localtab003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/localtab003.cpp new file mode 100644 index 00000000000..c5110605c33 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab003/localtab003.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_localtab003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_localtab003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_localtab003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_access_local_variables) { + printf("Warning: Access to local variables is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetLocalVariableTable_localtab003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jint entryCount; + jvmtiLocalVariableEntry *table; + int i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_access_local_variables) return result; + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "meth", "()I"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> try class which has not local variable info ...\n"); + } + err = jvmti->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_ABSENT_INFORMATION) { + result = STATUS_FAILED; + printf("Error expected: JVMTI_ERROR_ABSENT_INFORMATION,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + printf(" meth() local variable table (%d entries):%s\n", + entryCount, (entryCount==0 ? " empty" : "")); + for (i = 0; i < entryCount; i++) { + printf(" name=\"%s\", sig=\"%s\"", + table[i].name, table[i].signature); + printf(", start_location=0x%x%08x", + (jint)(table[i].start_location >> 32), + (jint)table[i].start_location); + printf(", length=%d", table[i].length); + printf(", slot=%d\n", table[i].slot); + } + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/liblocaltab004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/liblocaltab004.c deleted file mode 100644 index 4af50f9b9fe..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/liblocaltab004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "localtab004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/liblocaltab004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/liblocaltab004.cpp new file mode 100644 index 00000000000..ccc5662b97a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/liblocaltab004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "localtab004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/localtab004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/localtab004.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/localtab004.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab004/localtab004.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/liblocaltab005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/liblocaltab005.c deleted file mode 100644 index 24f572398a5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/liblocaltab005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "localtab005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/liblocaltab005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/liblocaltab005.cpp new file mode 100644 index 00000000000..faa37a25ee4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/liblocaltab005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "localtab005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/localtab005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/localtab005.c deleted file mode 100644 index e35682265e5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetLocalVariableTable/localtab005/localtab005.c +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define METH_NUM 3 /* overall number of methods */ - -#define STATUS_FAILED 2 -#define PASSED 0 - -typedef struct { /* local variable info */ - char *v_name; /* a variable name */ - char *v_sign; /* JVM type signature */ - char *v_gen_sign; /* JVM type generic signature */ -} localVar; - -/* expected local variable info are below */ -static localVar constr_lv[] = { /* constructor's local variables */ - {"this", "Lnsk/jvmti/GetLocalVariableTable/localtab005a;", "NULL"}, - {"constr_b", "Lnsk/jvmti/GetLocalVariableTable/localtab005b;", - "Lnsk/jvmti/GetLocalVariableTable/localtab005b;"}, - {"constr_i", "I", "NULL"}, - {"constr_c", "Lnsk/jvmti/GetLocalVariableTable/localtab005c;", - "Lnsk/jvmti/GetLocalVariableTable/localtab005c;"}, - {"constr_f", "F", "NULL"}, - {"constr_ch", "C", "NULL"}, - {"constr_if", "Lnsk/jvmti/GetLocalVariableTable/localtab005if;", - "Lnsk/jvmti/GetLocalVariableTable/localtab005if;"} -}; - -static localVar insMeth_lv[] = { /* finMethod()'s local variables */ - {"this", "Lnsk/jvmti/GetLocalVariableTable/localtab005a;", "NULL"}, - {"ins_c", "C", "NULL"}, - {"ins_i", "J", "NULL"}, - {"ltab005d", "Lnsk/jvmti/GetLocalVariableTable/localtab005d;", - "Lnsk/jvmti/GetLocalVariableTable/localtab005d;"}, - {"ins_k", "J", "NULL"}, - {"ins_l", "J", "NULL"}, - {"ins_g", "Lnsk/jvmti/GetLocalVariableTable/localtab005g;", - "Lnsk/jvmti/GetLocalVariableTable/localtab005g;"} -}; - -static localVar statMeth_lv[] = { /* statMethod()'s local variables */ - {"stat_x", "I", "NULL"}, - {"stat_y", "I", "NULL"}, - {"stat_z", "I", "NULL"}, - {"stat_j", "D", "NULL"}, - {"stat_d", "Lnsk/jvmti/GetLocalVariableTable/localtab005d;", - "Lnsk/jvmti/GetLocalVariableTable/localtab005d;"} -}; - -typedef struct { /* local variables of a method */ - int inst; /* type of a method: 0- static; 1- instance */ - char *m_name; /* a method name */ - char *m_sign; /* JVM signature of a method */ - int vcount; /* overall number of local variables */ - localVar *vars; - jmethodID mid; /* JNI's method ID */ -} methodInfo; - -/* list of tested methods */ -static methodInfo methInfo[] = { - {1, (char*) "", (char*) "()V", 7, constr_lv, NULL}, - {1, (char*) "insMethod", (char*) "(CJLnsk/jvmti/GetLocalVariableTable/localtab005d;J)V", 7, insMeth_lv, NULL}, - {0, (char*) "statMethod", (char*) "(III)D", 5, statMeth_lv, NULL} -}; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; - -static int checkAttr(JNIEnv *jni_env, jclass testedCls) { - int i, j, k; - int totRes = PASSED; - jint count = -1; - jvmtiLocalVariableEntry *lv_table; - - for (i=0; i>> Checking vars in the LocalVariableTable of the %s method \"%s\",\ - signature \"%s\" ...\n\t%d local vars as expected\n", - methInfo[i].inst?"instance":"static", - methInfo[i].m_name, methInfo[i].m_sign, count); - - for (j=0; j +#include +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define METH_NUM 3 /* overall number of methods */ + +#define STATUS_FAILED 2 +#define PASSED 0 + +typedef struct { /* local variable info */ + const char *v_name; /* a variable name */ + const char *v_sign; /* JVM type signature */ + const char *v_gen_sign; /* JVM type generic signature */ +} localVar; + +/* expected local variable info are below */ +static localVar constr_lv[] = { /* constructor's local variables */ + {"this", "Lnsk/jvmti/GetLocalVariableTable/localtab005a;", "NULL"}, + {"constr_b", "Lnsk/jvmti/GetLocalVariableTable/localtab005b;", + "Lnsk/jvmti/GetLocalVariableTable/localtab005b;"}, + {"constr_i", "I", "NULL"}, + {"constr_c", "Lnsk/jvmti/GetLocalVariableTable/localtab005c;", + "Lnsk/jvmti/GetLocalVariableTable/localtab005c;"}, + {"constr_f", "F", "NULL"}, + {"constr_ch", "C", "NULL"}, + {"constr_if", "Lnsk/jvmti/GetLocalVariableTable/localtab005if;", + "Lnsk/jvmti/GetLocalVariableTable/localtab005if;"} +}; + +static localVar insMeth_lv[] = { /* finMethod()'s local variables */ + {"this", "Lnsk/jvmti/GetLocalVariableTable/localtab005a;", "NULL"}, + {"ins_c", "C", "NULL"}, + {"ins_i", "J", "NULL"}, + {"ltab005d", "Lnsk/jvmti/GetLocalVariableTable/localtab005d;", + "Lnsk/jvmti/GetLocalVariableTable/localtab005d;"}, + {"ins_k", "J", "NULL"}, + {"ins_l", "J", "NULL"}, + {"ins_g", "Lnsk/jvmti/GetLocalVariableTable/localtab005g;", + "Lnsk/jvmti/GetLocalVariableTable/localtab005g;"} +}; + +static localVar statMeth_lv[] = { /* statMethod()'s local variables */ + {"stat_x", "I", "NULL"}, + {"stat_y", "I", "NULL"}, + {"stat_z", "I", "NULL"}, + {"stat_j", "D", "NULL"}, + {"stat_d", "Lnsk/jvmti/GetLocalVariableTable/localtab005d;", + "Lnsk/jvmti/GetLocalVariableTable/localtab005d;"} +}; + +typedef struct { /* local variables of a method */ + int inst; /* type of a method: 0- static; 1- instance */ + char *m_name; /* a method name */ + char *m_sign; /* JVM signature of a method */ + int vcount; /* overall number of local variables */ + localVar *vars; + jmethodID mid; /* JNI's method ID */ +} methodInfo; + +/* list of tested methods */ +static methodInfo methInfo[] = { + {1, (char*) "", (char*) "()V", 7, constr_lv, NULL}, + {1, (char*) "insMethod", (char*) "(CJLnsk/jvmti/GetLocalVariableTable/localtab005d;J)V", 7, insMeth_lv, NULL}, + {0, (char*) "statMethod", (char*) "(III)D", 5, statMeth_lv, NULL} +}; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; + +static int checkAttr(JNIEnv *jni_env, jclass testedCls) { + int i, j, k; + int totRes = PASSED; + jint count = -1; + jvmtiLocalVariableEntry *lv_table; + + for (i=0; i>> Checking vars in the LocalVariableTable of the %s method \"%s\",\ + signature \"%s\" ...\n\t%d local vars as expected\n", + methInfo[i].inst?"instance":"static", + methInfo[i].m_name, methInfo[i].m_sign, count); + + for (j=0; j -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; - -void checkMeth(JNIEnv *env, jclass cl, char *name, char *sig, int stat, int max_loc) { - jvmtiError err; - jmethodID mid = NULL; - jint ret_loc; - - if (stat) { - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), name, sig); - } else { - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); - } - if (mid == NULL) { - printf("Name = %s, sig = %s: mid = 0\n", name, sig); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->GetMaxLocals(jvmti, mid, &ret_loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMaxLocals) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else if (ret_loc != max_loc) { - printf("Name = %s, sig = %s: max locals expected: %d, got: %d\n", name, sig, max_loc, ret_loc); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_maxloc001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_maxloc001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_maxloc001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetMaxLocals_maxloc001_check(JNIEnv *env, jclass cls) { - jclass clsId; - - checkMeth(env, cls, "", "()V", 0, 1); - checkMeth(env, cls, "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I", 1, 2); - checkMeth(env, cls, "meth_stat", "(ILjava/lang/String;)[F", 1, 3); - checkMeth(env, cls, "meth_1", "(C)C", 0, 4); - checkMeth(env, cls, "meth_2", "(FF)F", 0, 6); - clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/GetMaxLocals/maxloc001a")); - checkMeth(env, clsId, "meth_new", "()Lnsk/jvmti/GetMaxLocals/maxloc001;", 0, 3); - checkMeth(env, clsId, "meth_abs", "()V", 0, 0); - clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/GetMaxLocals/maxloc001$Inn")); - checkMeth(env, clsId, "meth_inn", "(Ljava/lang/String;)V", 0, 2); - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc001/maxloc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc001/maxloc001.cpp new file mode 100644 index 00000000000..5157151a160 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc001/maxloc001.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; + +void checkMeth(JNIEnv *env, jclass cl, const char *name, const char *sig, int stat, int max_loc) { + jvmtiError err; + jmethodID mid = NULL; + jint ret_loc; + + if (stat) { + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), name, sig); + } else { + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); + } + if (mid == NULL) { + printf("Name = %s, sig = %s: mid = 0\n", name, sig); + result = STATUS_FAILED; + return; + } + err = jvmti->GetMaxLocals(mid, &ret_loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMaxLocals) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else if (ret_loc != max_loc) { + printf("Name = %s, sig = %s: max locals expected: %d, got: %d\n", name, sig, max_loc, ret_loc); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_maxloc001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_maxloc001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_maxloc001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetMaxLocals_maxloc001_check(JNIEnv *env, jclass cls) { + jclass clsId; + + checkMeth(env, cls, "", "()V", 0, 1); + checkMeth(env, cls, "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I", 1, 2); + checkMeth(env, cls, "meth_stat", "(ILjava/lang/String;)[F", 1, 3); + checkMeth(env, cls, "meth_1", "(C)C", 0, 4); + checkMeth(env, cls, "meth_2", "(FF)F", 0, 6); + clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/GetMaxLocals/maxloc001a")); + checkMeth(env, clsId, "meth_new", "()Lnsk/jvmti/GetMaxLocals/maxloc001;", 0, 3); + checkMeth(env, clsId, "meth_abs", "()V", 0, 0); + clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/GetMaxLocals/maxloc001$Inn")); + checkMeth(env, clsId, "meth_inn", "(Ljava/lang/String;)V", 0, 2); + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/libmaxloc002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/libmaxloc002.c deleted file mode 100644 index 8421506f22e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/libmaxloc002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "maxloc002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/libmaxloc002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/libmaxloc002.cpp new file mode 100644 index 00000000000..1cb31261ac6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/libmaxloc002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "maxloc002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/maxloc002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/maxloc002.c deleted file mode 100644 index d1b2deca631..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/maxloc002.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_maxloc002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_maxloc002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_maxloc002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetMaxLocals_maxloc002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jint max; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "", "()V"); - if (mid == NULL) { - printf("Cannot get method ID for \"\"!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->GetMaxLocals(jvmti, NULL, &max); - if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetMaxLocals(jvmti, mid, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "check", "()I"); - if (mid == NULL) { - printf("Cannot get method ID for \"check\"!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> native method check ...\n"); - } - err = (*jvmti)->GetMaxLocals(jvmti, mid, &max); - if (err != JVMTI_ERROR_NATIVE_METHOD) { - printf("Error expected: JVMTI_ERROR_NATIVE_METHOD,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/maxloc002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/maxloc002.cpp new file mode 100644 index 00000000000..830c9056b66 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMaxLocals/maxloc002/maxloc002.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_maxloc002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_maxloc002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_maxloc002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetMaxLocals_maxloc002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jint max; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "", "()V"); + if (mid == NULL) { + printf("Cannot get method ID for \"\"!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->GetMaxLocals(NULL, &max); + if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetMaxLocals(mid, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "check", "()I"); + if (mid == NULL) { + printf("Cannot get method ID for \"check\"!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> native method check ...\n"); + } + err = jvmti->GetMaxLocals(mid, &max); + if (err != JVMTI_ERROR_NATIVE_METHOD) { + printf("Error expected: JVMTI_ERROR_NATIVE_METHOD,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/declcls001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/declcls001.c deleted file mode 100644 index 96eb0b9c0f8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/declcls001.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti; -static jint result = PASSED; - -void checkMeth(JNIEnv *env, char *cl_name, char *name, char *sig, - int stat, char *decl_cl_name) { - jvmtiError err; - jmethodID mid; - char *cl_sig, *generic; - jclass cl, ret_decl_cl; - - cl = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, cl_name)); - if (stat) { - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), - name, sig); - } else { - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); - } - if (mid == NULL) { - printf("%s.%s%s: mid = NULL\n", cl_name, name, sig); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetMethodDeclaringClass(jvmti, mid, &ret_decl_cl); - if (err != JVMTI_ERROR_NONE) { - printf("%s.%s%s: ", cl_name, name, sig); - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassSignature(jvmti, ret_decl_cl, &cl_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("%s.%s%s: ", cl_name, name, sig); - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (strcmp(decl_cl_name, cl_sig) != 0) { - result = STATUS_FAILED; - printf("%s.%s%s: ", cl_name, name, sig); - printf("declaring class expected: %s, got: %s\n", decl_cl_name, cl_sig); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_declcls001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_declcls001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_declcls001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetMethodDeclaringClass_declcls001_check(JNIEnv *env, jclass cls) { - checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001", "meth", - "(I)V", 1, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001;"); - checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001b", "meth", - "(I)V", 1, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001;"); - checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001i", "meth_i", - "()I", 0, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001i;"); - checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001i1", "meth_i", - "()I", 0, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001i;"); - checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001i1", "meth_i1", - "()I", 0, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001i1;"); - checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001i_a", "meth_i", - "()I", 0, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001i;"); - checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001i_a", "meth_i1", - "()I", 0, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001i_a;"); - checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001i_a", "meth_z", - "()I", 0, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001z;"); - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/declcls001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/declcls001.cpp new file mode 100644 index 00000000000..e82f632a073 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/declcls001.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti; +static jint result = PASSED; + +void checkMeth(JNIEnv *env, const char *cl_name, const char *name, const char *sig, + int stat, const char *decl_cl_name) { + jvmtiError err; + jmethodID mid; + char *cl_sig, *generic; + jclass cl, ret_decl_cl; + + cl = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, cl_name)); + if (stat) { + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), + name, sig); + } else { + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); + } + if (mid == NULL) { + printf("%s.%s%s: mid = NULL\n", cl_name, name, sig); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetMethodDeclaringClass(mid, &ret_decl_cl); + if (err != JVMTI_ERROR_NONE) { + printf("%s.%s%s: ", cl_name, name, sig); + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassSignature(ret_decl_cl, &cl_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("%s.%s%s: ", cl_name, name, sig); + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (strcmp(decl_cl_name, cl_sig) != 0) { + result = STATUS_FAILED; + printf("%s.%s%s: ", cl_name, name, sig); + printf("declaring class expected: %s, got: %s\n", decl_cl_name, cl_sig); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_declcls001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_declcls001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_declcls001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetMethodDeclaringClass_declcls001_check(JNIEnv *env, jclass cls) { + checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001", "meth", + "(I)V", 1, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001;"); + checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001b", "meth", + "(I)V", 1, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001;"); + checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001i", "meth_i", + "()I", 0, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001i;"); + checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001i1", "meth_i", + "()I", 0, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001i;"); + checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001i1", "meth_i1", + "()I", 0, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001i1;"); + checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001i_a", "meth_i", + "()I", 0, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001i;"); + checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001i_a", "meth_i1", + "()I", 0, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001i_a;"); + checkMeth(env, "nsk/jvmti/GetMethodDeclaringClass/declcls001i_a", "meth_z", + "()I", 0, "Lnsk/jvmti/GetMethodDeclaringClass/declcls001z;"); + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/libdeclcls001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/libdeclcls001.c deleted file mode 100644 index 0d0de4306b9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/libdeclcls001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "declcls001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/libdeclcls001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/libdeclcls001.cpp new file mode 100644 index 00000000000..73e1af58446 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls001/libdeclcls001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "declcls001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/declcls002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/declcls002.c deleted file mode 100644 index e21de1c36d2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/declcls002.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_declcls002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_declcls002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_declcls002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetMethodDeclaringClass_declcls002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jclass declaringClass; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "", "()V"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->GetMethodDeclaringClass(jvmti, NULL, &declaringClass); - if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetMethodDeclaringClass(jvmti, mid, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/declcls002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/declcls002.cpp new file mode 100644 index 00000000000..6817900a3ac --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/declcls002.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_declcls002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_declcls002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_declcls002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetMethodDeclaringClass_declcls002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jclass declaringClass; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "", "()V"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->GetMethodDeclaringClass(NULL, &declaringClass); + if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetMethodDeclaringClass(mid, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/libdeclcls002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/libdeclcls002.c deleted file mode 100644 index 1a432d39ffb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/libdeclcls002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "declcls002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/libdeclcls002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/libdeclcls002.cpp new file mode 100644 index 00000000000..8bb5453f439 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls002/libdeclcls002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "declcls002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/declcls003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/declcls003.c deleted file mode 100644 index 34a4554f2b8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/declcls003.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static char *exp_class_sig = "Ljava/lang/Object;"; -static char *arr_sigs[] = {"[B", "[C", "[D", "[F", "[I", "[J", "[S", "[Z", - "[Lnsk/jvmti/GetMethodDeclaringClass/declcls003;", - "[[Lnsk/jvmti/GetMethodDeclaringClass/declcls003;" -}; - -void do_check(JNIEnv *env, char *name, char *meth, char *sig) { - jvmtiError err; - jclass cl; - jclass ret_decl_cl; - jmethodID mid; - char *cl_sig, *generic; - - if (printdump == JNI_TRUE) { - printf(">>> checking: %s.%s%s\n", name, meth, sig); - } - - cl = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, name)); - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), meth, sig); - if (mid == NULL) { - printf("%s.%s%s: mid = NULL\n", name, meth, sig); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetMethodDeclaringClass(jvmti, mid, &ret_decl_cl); - if (err != JVMTI_ERROR_NONE) { - printf("%s.%s%s: ", name, meth, sig); - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassSignature(jvmti, ret_decl_cl, &cl_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("%s.%s%s: ", name, meth, sig); - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>>\tmethod declaring class: %s\n", cl_sig); - } - - if (strcmp(exp_class_sig, cl_sig) != 0) { - printf("%s.%s%s: ", name, meth, sig); - printf("declaring class expected: %s, actual: %s\n", - exp_class_sig, cl_sig); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_declcls003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_declcls003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_declcls003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetMethodDeclaringClass_declcls003_check(JNIEnv *env, jclass cls) { - size_t i; - - for (i = 0; i < sizeof(arr_sigs)/sizeof(char *); i++) { - do_check(env, arr_sigs[i], "clone", "()Ljava/lang/Object;"); - do_check(env, arr_sigs[i], "equals", "(Ljava/lang/Object;)Z"); - do_check(env, arr_sigs[i], "finalize", "()V"); - do_check(env, arr_sigs[i], "getClass", "()Ljava/lang/Class;"); - do_check(env, arr_sigs[i], "hashCode", "()I"); - do_check(env, arr_sigs[i], "notify", "()V"); - do_check(env, arr_sigs[i], "notifyAll", "()V"); - do_check(env, arr_sigs[i], "toString", "()Ljava/lang/String;"); - do_check(env, arr_sigs[i], "wait", "()V"); - do_check(env, arr_sigs[i], "wait", "(J)V"); - do_check(env, arr_sigs[i], "wait", "(JI)V"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/declcls003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/declcls003.cpp new file mode 100644 index 00000000000..118a31e76c0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/declcls003.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static const char *exp_class_sig = "Ljava/lang/Object;"; +static const char *arr_sigs[] = {"[B", "[C", "[D", "[F", "[I", "[J", "[S", "[Z", + "[Lnsk/jvmti/GetMethodDeclaringClass/declcls003;", + "[[Lnsk/jvmti/GetMethodDeclaringClass/declcls003;" +}; + +void do_check(JNIEnv *env, const char *name, const char *meth, const char *sig) { + jvmtiError err; + jclass cl; + jclass ret_decl_cl; + jmethodID mid; + char *cl_sig, *generic; + + if (printdump == JNI_TRUE) { + printf(">>> checking: %s.%s%s\n", name, meth, sig); + } + + cl = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, name)); + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), meth, sig); + if (mid == NULL) { + printf("%s.%s%s: mid = NULL\n", name, meth, sig); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetMethodDeclaringClass(mid, &ret_decl_cl); + if (err != JVMTI_ERROR_NONE) { + printf("%s.%s%s: ", name, meth, sig); + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassSignature(ret_decl_cl, &cl_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("%s.%s%s: ", name, meth, sig); + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>>\tmethod declaring class: %s\n", cl_sig); + } + + if (strcmp(exp_class_sig, cl_sig) != 0) { + printf("%s.%s%s: ", name, meth, sig); + printf("declaring class expected: %s, actual: %s\n", + exp_class_sig, cl_sig); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_declcls003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_declcls003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_declcls003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetMethodDeclaringClass_declcls003_check(JNIEnv *env, jclass cls) { + size_t i; + + for (i = 0; i < sizeof(arr_sigs)/sizeof(char *); i++) { + do_check(env, arr_sigs[i], "clone", "()Ljava/lang/Object;"); + do_check(env, arr_sigs[i], "equals", "(Ljava/lang/Object;)Z"); + do_check(env, arr_sigs[i], "finalize", "()V"); + do_check(env, arr_sigs[i], "getClass", "()Ljava/lang/Class;"); + do_check(env, arr_sigs[i], "hashCode", "()I"); + do_check(env, arr_sigs[i], "notify", "()V"); + do_check(env, arr_sigs[i], "notifyAll", "()V"); + do_check(env, arr_sigs[i], "toString", "()Ljava/lang/String;"); + do_check(env, arr_sigs[i], "wait", "()V"); + do_check(env, arr_sigs[i], "wait", "(J)V"); + do_check(env, arr_sigs[i], "wait", "(JI)V"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/libdeclcls003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/libdeclcls003.c deleted file mode 100644 index 98cef9f986c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/libdeclcls003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "declcls003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/libdeclcls003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/libdeclcls003.cpp new file mode 100644 index 00000000000..50fc8120a94 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodDeclaringClass/declcls003/libdeclcls003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "declcls003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/libmethloc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/libmethloc001.c deleted file mode 100644 index 7735b3289f0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/libmethloc001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "methloc001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/libmethloc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/libmethloc001.cpp new file mode 100644 index 00000000000..734049342b5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/libmethloc001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "methloc001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/methloc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/methloc001.c deleted file mode 100644 index a9220d9433d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/methloc001.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - jlocation start; - jlocation end; -} info; - -static jvmtiEnv *jvmti; -static jint result = PASSED; -static info meth_tab[] = { - {0, 4}, /* 0 */ - {0, 0}, /* 1 meth1 */ - {0, 5} /* 2 meth2 */ -}; - -void checkMeth(JNIEnv *env, jclass cl, char *name, char *sig, - int stat, int meth_ind) { - jvmtiError ans; - int err = 0; - jmethodID mid; - jlocation start; - jlocation end; - jlocation exp_start = meth_tab[meth_ind].start; - jlocation exp_end = meth_tab[meth_ind].end; - - if (stat) { - mid = JNI_ENV_PTR(env)-> - GetStaticMethodID(JNI_ENV_ARG(env, cl), name, sig); - } else { - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); - } - if (mid == NULL) { - printf("Name = %s, sig = %s: mid = NULL\n", name, sig); - result = STATUS_FAILED; - return; - } - ans = (*jvmti)->GetMethodLocation(jvmti, mid, &start, &end); - if (ans != JVMTI_ERROR_NONE) { - printf("Name = %s, sig = %s:\n", name, sig); - printf(" Failed get method location: err = %d\n", ans); - result = STATUS_FAILED; - return; - } - if (start != exp_start) { - result = STATUS_FAILED; - err = 1; - printf("Name = %s, sig = %s:\n", name, sig); - printf(" first location expected: 0x%x, got: 0x%08x%08x\n", - (jint)exp_start, (jint)(start >> 32), (jint)start); - } - if (end != exp_end) { - result = STATUS_FAILED; - if (!err) { - printf("Name = %s, sig = %s:\n", name, sig); - } - printf(" last location expected: 0x%x, got: 0x%08x%08x\n", - (jint)exp_end, (jint)(end >> 32), (jint)end); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_methloc001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_methloc001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_methloc001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_GetMethodLocation_methloc001_check(JNIEnv *env, jclass cls) { - checkMeth(env, cls, "", "()V", 0, 0); - checkMeth(env, cls, "meth1", "()V", 0, 1); - checkMeth(env, cls, "meth2", "(I)[F", 1, 2); - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/methloc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/methloc001.cpp new file mode 100644 index 00000000000..5ebb878f4f1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc001/methloc001.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + jlocation start; + jlocation end; +} info; + +static jvmtiEnv *jvmti; +static jint result = PASSED; +static info meth_tab[] = { + {0, 4}, /* 0 */ + {0, 0}, /* 1 meth1 */ + {0, 5} /* 2 meth2 */ +}; + +void checkMeth(JNIEnv *env, jclass cl, const char *name, const char *sig, + int stat, int meth_ind) { + jvmtiError ans; + int err = 0; + jmethodID mid; + jlocation start; + jlocation end; + jlocation exp_start = meth_tab[meth_ind].start; + jlocation exp_end = meth_tab[meth_ind].end; + + if (stat) { + mid = JNI_ENV_PTR(env)-> + GetStaticMethodID(JNI_ENV_ARG(env, cl), name, sig); + } else { + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); + } + if (mid == NULL) { + printf("Name = %s, sig = %s: mid = NULL\n", name, sig); + result = STATUS_FAILED; + return; + } + ans = jvmti->GetMethodLocation(mid, &start, &end); + if (ans != JVMTI_ERROR_NONE) { + printf("Name = %s, sig = %s:\n", name, sig); + printf(" Failed get method location: err = %d\n", ans); + result = STATUS_FAILED; + return; + } + if (start != exp_start) { + result = STATUS_FAILED; + err = 1; + printf("Name = %s, sig = %s:\n", name, sig); + printf(" first location expected: 0x%x, got: 0x%08x%08x\n", + (jint)exp_start, (jint)(start >> 32), (jint)start); + } + if (end != exp_end) { + result = STATUS_FAILED; + if (!err) { + printf("Name = %s, sig = %s:\n", name, sig); + } + printf(" last location expected: 0x%x, got: 0x%08x%08x\n", + (jint)exp_end, (jint)(end >> 32), (jint)end); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_methloc001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_methloc001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_methloc001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_GetMethodLocation_methloc001_check(JNIEnv *env, jclass cls) { + checkMeth(env, cls, "", "()V", 0, 0); + checkMeth(env, cls, "meth1", "()V", 0, 1); + checkMeth(env, cls, "meth2", "(I)[F", 1, 2); + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/libmethloc002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/libmethloc002.c deleted file mode 100644 index d693d6d7cb6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/libmethloc002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "methloc002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/libmethloc002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/libmethloc002.cpp new file mode 100644 index 00000000000..2116bd4b31a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/libmethloc002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "methloc002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/methloc002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/methloc002.c deleted file mode 100644 index 8e57f43e0a8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/methloc002.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_methloc002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_methloc002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_methloc002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetMethodLocation_methloc002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jlocation startLocation; - jlocation endLocation; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "", "()V"); - if (mid == NULL) { - printf("Cannot get method ID for \"\"!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->GetMethodLocation(jvmti, NULL, &startLocation, &endLocation); - if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (startLocationPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetMethodLocation(jvmti, mid, NULL, &endLocation); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(startLocationPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (endLocationPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetMethodLocation(jvmti, mid, &startLocation, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(endLocationPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "check", "()I"); - if (mid == NULL) { - printf("Cannot get method ID for \"check\"!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> native method check ...\n"); - } - err = (*jvmti)->GetMethodLocation(jvmti, mid, &startLocation, &endLocation); - if (err != JVMTI_ERROR_NATIVE_METHOD) { - printf("Error expected: JVMTI_ERROR_NATIVE_METHOD,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/methloc002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/methloc002.cpp new file mode 100644 index 00000000000..b6414a2842f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodLocation/methloc002/methloc002.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_methloc002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_methloc002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_methloc002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetMethodLocation_methloc002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jlocation startLocation; + jlocation endLocation; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), "", "()V"); + if (mid == NULL) { + printf("Cannot get method ID for \"\"!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->GetMethodLocation(NULL, &startLocation, &endLocation); + if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (startLocationPtr) null pointer check ...\n"); + } + err = jvmti->GetMethodLocation(mid, NULL, &endLocation); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(startLocationPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (endLocationPtr) null pointer check ...\n"); + } + err = jvmti->GetMethodLocation(mid, &startLocation, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(endLocationPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "check", "()I"); + if (mid == NULL) { + printf("Cannot get method ID for \"check\"!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> native method check ...\n"); + } + err = jvmti->GetMethodLocation(mid, &startLocation, &endLocation); + if (err != JVMTI_ERROR_NATIVE_METHOD) { + printf("Error expected: JVMTI_ERROR_NATIVE_METHOD,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/libmethmod001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/libmethmod001.c deleted file mode 100644 index 7e3d33a197e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/libmethmod001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "methmod001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/libmethmod001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/libmethmod001.cpp new file mode 100644 index 00000000000..85b8d315c57 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/libmethmod001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "methmod001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/methmod001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/methmod001.c deleted file mode 100644 index 3c353ba8ecd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/methmod001.c +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define ACC_PUBLIC 0x001 -#define ACC_PRIVATE 0x002 -#define ACC_PROTECTED 0x004 -#define ACC_STATIC 0x008 -#define ACC_FINAL 0x010 -#define ACC_SYNCHRONIZED 0x020 -#define ACC_NATIVE 0x100 -#define ACC_ABSTRACT 0x400 -#define ACC_STRICT 0x800 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -void printModifiers(jint mod) { - if (mod & ACC_PUBLIC) printf(" PUBLIC"); - if (mod & ACC_PRIVATE) printf(" PRIVATE"); - if (mod & ACC_PROTECTED) printf(" PROTECTED"); - if (mod & ACC_STATIC) printf(" STATIC"); - if (mod & ACC_FINAL) printf(" FINAL"); - if (mod & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED"); - if (mod & ACC_NATIVE) printf(" NATIVE"); - if (mod & ACC_ABSTRACT) printf(" ABSTRACT"); - if (mod & ACC_STRICT) printf(" STRICT"); - printf(" (0x%0x)\n", mod); -} - -void checkMeth(jvmtiEnv *jvmti_env, JNIEnv *env, jclass cl, - char *name, char *sig, int stat, int flags) { - jvmtiError err; - jmethodID mid; - jint modifiers; - - if (stat) { - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), - name, sig); - } else { - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); - } - if (mid == NULL) { - printf("Cannot find MethodID for \"%s%s\"\n", name, sig); - result = STATUS_FAILED; - return; - } - - err = (*jvmti_env)->GetMethodModifiers(jvmti_env, mid, &modifiers); - if (err != JVMTI_ERROR_NONE) { - printf("\"%s%s\"\n", name, sig); - printf("(GetClassModifiers) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %s%s" , name, sig); - printModifiers(modifiers); - } - - if (modifiers != flags) { - printf("\"%s%s\" access flags expected:", name, sig); - printModifiers(flags); - printf("\t actual:"); - printModifiers(modifiers); - result = STATUS_FAILED; - } -} - -void JNICALL -ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jclass cls) { - jvmtiError err; - char *sig, *generic; - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - return; - } - if (strcmp(sig, "Lnsk/jvmti/GetMethodModifiers/methmod001;") == 0) { - checkMeth(jvmti_env, (JNIEnv *)env, cls, - "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I", - 1, ACC_PUBLIC | ACC_STATIC); - checkMeth(jvmti_env, (JNIEnv *)env, cls, - "meth_stat", "(ILjava/lang/String;)[F", - 1, ACC_PROTECTED | ACC_STATIC | ACC_FINAL); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_methmod001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_methmod001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_methmod001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.ClassLoad = &ClassLoad; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_CLASS_LOAD, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable event JVMTI_EVENT_CLASS_LOAD: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_GetMethodModifiers_methmod001_check(JNIEnv *env, jclass cls) { - jclass clsId; - - checkMeth(jvmti, env, cls, "", "()V", 0, ACC_PUBLIC); - checkMeth(jvmti, env, cls, "meth_1", "(C)C", 0, ACC_PRIVATE); - checkMeth(jvmti, env, cls, "meth_2", "(FF)F", 0, ACC_STRICT); - checkMeth(jvmti, env, cls, "check", "()I", 1, ACC_NATIVE | ACC_STATIC); - clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/GetMethodModifiers/methmod001a")); - checkMeth(jvmti, env, clsId, "meth_new", - "()Lnsk/jvmti/GetMethodModifiers/methmod001;", 0, ACC_SYNCHRONIZED); - checkMeth(jvmti, env, clsId, "meth_abs", "()V", 0, ACC_ABSTRACT); - clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/GetMethodModifiers/methmod001$Inn")); - checkMeth(jvmti, env, clsId, "meth_inn", "(Ljava/lang/String;)V", - 0, ACC_PUBLIC | ACC_SYNCHRONIZED | ACC_FINAL); - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/methmod001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/methmod001.cpp new file mode 100644 index 00000000000..c7bfa02bb82 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod001/methmod001.cpp @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define ACC_PUBLIC 0x001 +#define ACC_PRIVATE 0x002 +#define ACC_PROTECTED 0x004 +#define ACC_STATIC 0x008 +#define ACC_FINAL 0x010 +#define ACC_SYNCHRONIZED 0x020 +#define ACC_NATIVE 0x100 +#define ACC_ABSTRACT 0x400 +#define ACC_STRICT 0x800 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +void printModifiers(jint mod) { + if (mod & ACC_PUBLIC) printf(" PUBLIC"); + if (mod & ACC_PRIVATE) printf(" PRIVATE"); + if (mod & ACC_PROTECTED) printf(" PROTECTED"); + if (mod & ACC_STATIC) printf(" STATIC"); + if (mod & ACC_FINAL) printf(" FINAL"); + if (mod & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED"); + if (mod & ACC_NATIVE) printf(" NATIVE"); + if (mod & ACC_ABSTRACT) printf(" ABSTRACT"); + if (mod & ACC_STRICT) printf(" STRICT"); + printf(" (0x%0x)\n", mod); +} + +void checkMeth(jvmtiEnv *jvmti_env, JNIEnv *env, jclass cl, + const char *name, const char *sig, int stat, int flags) { + jvmtiError err; + jmethodID mid; + jint modifiers; + + if (stat) { + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), + name, sig); + } else { + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); + } + if (mid == NULL) { + printf("Cannot find MethodID for \"%s%s\"\n", name, sig); + result = STATUS_FAILED; + return; + } + + err = jvmti_env->GetMethodModifiers(mid, &modifiers); + if (err != JVMTI_ERROR_NONE) { + printf("\"%s%s\"\n", name, sig); + printf("(GetClassModifiers) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %s%s" , name, sig); + printModifiers(modifiers); + } + + if (modifiers != flags) { + printf("\"%s%s\" access flags expected:", name, sig); + printModifiers(flags); + printf("\t actual:"); + printModifiers(modifiers); + result = STATUS_FAILED; + } +} + +void JNICALL +ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jclass cls) { + jvmtiError err; + char *sig, *generic; + + err = jvmti_env->GetClassSignature(cls, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + return; + } + if (strcmp(sig, "Lnsk/jvmti/GetMethodModifiers/methmod001;") == 0) { + checkMeth(jvmti_env, (JNIEnv *)env, cls, + "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I", + 1, ACC_PUBLIC | ACC_STATIC); + checkMeth(jvmti_env, (JNIEnv *)env, cls, + "meth_stat", "(ILjava/lang/String;)[F", + 1, ACC_PROTECTED | ACC_STATIC | ACC_FINAL); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_methmod001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_methmod001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_methmod001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.ClassLoad = &ClassLoad; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_CLASS_LOAD, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable event JVMTI_EVENT_CLASS_LOAD: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_GetMethodModifiers_methmod001_check(JNIEnv *env, jclass cls) { + jclass clsId; + + checkMeth(jvmti, env, cls, "", "()V", 0, ACC_PUBLIC); + checkMeth(jvmti, env, cls, "meth_1", "(C)C", 0, ACC_PRIVATE); + checkMeth(jvmti, env, cls, "meth_2", "(FF)F", 0, ACC_STRICT); + checkMeth(jvmti, env, cls, "check", "()I", 1, ACC_NATIVE | ACC_STATIC); + clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/GetMethodModifiers/methmod001a")); + checkMeth(jvmti, env, clsId, "meth_new", + "()Lnsk/jvmti/GetMethodModifiers/methmod001;", 0, ACC_SYNCHRONIZED); + checkMeth(jvmti, env, clsId, "meth_abs", "()V", 0, ACC_ABSTRACT); + clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/GetMethodModifiers/methmod001$Inn")); + checkMeth(jvmti, env, clsId, "meth_inn", "(Ljava/lang/String;)V", + 0, ACC_PUBLIC | ACC_SYNCHRONIZED | ACC_FINAL); + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/libmethmod002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/libmethmod002.c deleted file mode 100644 index ac06ba8eedf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/libmethmod002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "methmod002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/libmethmod002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/libmethmod002.cpp new file mode 100644 index 00000000000..ac414725670 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/libmethmod002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "methmod002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/methmod002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/methmod002.c deleted file mode 100644 index ebc2a5ed372..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/methmod002.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_methmod002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_methmod002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_methmod002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetMethodModifiers_methmod002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jint modifiers; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "", "()V"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->GetMethodModifiers(jvmti, NULL, &modifiers); - if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetMethodModifiers(jvmti, mid, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/methmod002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/methmod002.cpp new file mode 100644 index 00000000000..449d9699b0b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodModifiers/methmod002/methmod002.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_methmod002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_methmod002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_methmod002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetMethodModifiers_methmod002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jint modifiers; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "", "()V"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->GetMethodModifiers(NULL, &modifiers); + if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetMethodModifiers(mid, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/libmethname001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/libmethname001.c deleted file mode 100644 index 5cb2719f6b4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/libmethname001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "methname001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/libmethname001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/libmethname001.cpp new file mode 100644 index 00000000000..bbc2bd68519 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/libmethname001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "methname001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/methname001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/methname001.c deleted file mode 100644 index eaffe4b3fc6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/methname001.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int count = 0; - -void checkMeth(jvmtiEnv *jvmti_env, JNIEnv *env, jclass cl, - char *name, char *sig, int stat) { - jvmtiError err; - jmethodID mid; - char *ret_name, *ret_sig, *generic; - - if (stat) { - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), - name, sig); - } else { - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); - } - if (mid == NULL) { - printf("Cannot find MethodID for \"%s%s\"\n", name, sig); - result = STATUS_FAILED; - return; - } - - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, - &ret_name, &ret_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("\"%s%s\"\n", name, sig); - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %s%s, got: %s%s\n" , name, sig , ret_name, ret_sig); - } - - if (strcmp(ret_name, name) != 0) { - printf("Name = %s, sig = %s: wrong name: %s\n", name, sig, ret_name); - result = STATUS_FAILED; - } - if (strcmp(ret_sig, sig) != 0) { - printf("Name = %s, sig = %s: wrong sig: %s\n", name, sig, ret_sig); - result = STATUS_FAILED; - } - - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*) ret_name); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*) ret_sig); -} - -void JNICALL -ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jclass cls) { - jvmtiError err; - char *sig, *generic; - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - return; - } - if (strcmp(sig, "Lmethname001;") == 0) { - checkMeth(jvmti_env, (JNIEnv *)env, cls, - "meth_stat", "(ILjava/lang/String;)[F", 1); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_methname001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_methname001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_methname001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.ClassLoad = &ClassLoad; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_CLASS_LOAD, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable event JVMTI_EVENT_CLASS_LOAD: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetMethodName_methname001_check(JNIEnv *env, jclass cls) { - jclass clsId; - - checkMeth(jvmti, env, cls, "", "()V", 0); - checkMeth(jvmti, env, cls, "meth_1", "(C)C", 0); - checkMeth(jvmti, env, cls, "meth_1", "(CC)C", 0); - clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/GetMethodName/methname001a")); - checkMeth(jvmti, env, clsId, "meth_new", - "()Lnsk/jvmti/GetMethodName/methname001;", 0); - clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/GetMethodName/methname001$Inn")); - checkMeth(jvmti, env, clsId, "meth_inn", "(Ljava/lang/String;)V", 0); - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/methname001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/methname001.cpp new file mode 100644 index 00000000000..116d0c767c3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname001/methname001.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int count = 0; + +void checkMeth(jvmtiEnv *jvmti_env, JNIEnv *env, jclass cl, + const char *name, const char *sig, int stat) { + jvmtiError err; + jmethodID mid; + char *ret_name, *ret_sig, *generic; + + if (stat) { + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), + name, sig); + } else { + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); + } + if (mid == NULL) { + printf("Cannot find MethodID for \"%s%s\"\n", name, sig); + result = STATUS_FAILED; + return; + } + + err = jvmti_env->GetMethodName(mid, + &ret_name, &ret_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("\"%s%s\"\n", name, sig); + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %s%s, got: %s%s\n" , name, sig , ret_name, ret_sig); + } + + if (strcmp(ret_name, name) != 0) { + printf("Name = %s, sig = %s: wrong name: %s\n", name, sig, ret_name); + result = STATUS_FAILED; + } + if (strcmp(ret_sig, sig) != 0) { + printf("Name = %s, sig = %s: wrong sig: %s\n", name, sig, ret_sig); + result = STATUS_FAILED; + } + + jvmti_env->Deallocate((unsigned char*) ret_name); + jvmti_env->Deallocate((unsigned char*) ret_sig); +} + +void JNICALL +ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jclass cls) { + jvmtiError err; + char *sig, *generic; + + err = jvmti_env->GetClassSignature(cls, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + return; + } + if (strcmp(sig, "Lmethname001;") == 0) { + checkMeth(jvmti_env, (JNIEnv *)env, cls, + "meth_stat", "(ILjava/lang/String;)[F", 1); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_methname001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_methname001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_methname001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.ClassLoad = &ClassLoad; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_CLASS_LOAD, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable event JVMTI_EVENT_CLASS_LOAD: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetMethodName_methname001_check(JNIEnv *env, jclass cls) { + jclass clsId; + + checkMeth(jvmti, env, cls, "", "()V", 0); + checkMeth(jvmti, env, cls, "meth_1", "(C)C", 0); + checkMeth(jvmti, env, cls, "meth_1", "(CC)C", 0); + clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/GetMethodName/methname001a")); + checkMeth(jvmti, env, clsId, "meth_new", + "()Lnsk/jvmti/GetMethodName/methname001;", 0); + clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/GetMethodName/methname001$Inn")); + checkMeth(jvmti, env, clsId, "meth_inn", "(Ljava/lang/String;)V", 0); + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/libmethname002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/libmethname002.c deleted file mode 100644 index 82168b50e6d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/libmethname002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "methname002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/libmethname002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/libmethname002.cpp new file mode 100644 index 00000000000..be05e2cc76b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/libmethname002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "methname002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/methname002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/methname002.c deleted file mode 100644 index 00cc6c03abf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/methname002.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_methname002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_methname002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_methname002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetMethodName_methname002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - char *name, *sig, *generic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "", "()V"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->GetMethodName(jvmti, NULL, &name, &sig, &generic); - if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (namePtr) null pointer check ...\n"); - } - err = (*jvmti)->GetMethodName(jvmti, mid, NULL, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(namePtr) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - if (printdump == JNI_TRUE) { - printf(">>> sig = \"%s\", generic = \"%s\"\n", sig, generic); - } - if (sig == NULL || strcmp(sig, "()V") != 0) { - printf("Wrong field sig: \"%s\", expected: \"I\"\n", sig); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> (signaturePtr) null pointer check ...\n"); - } - err = (*jvmti)->GetMethodName(jvmti, mid, &name, NULL, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(signaturePtr) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - if (printdump == JNI_TRUE) { - printf(">>> name = \"%s\", generic = \"%s\"\n", name, generic); - } - if (name == NULL || strcmp(name, "") != 0) { - printf("Wrong field name: \"%s\", expected: \"fld\"\n", name); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> (genericPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetMethodName(jvmti, mid, &name, &sig, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(signaturePtr) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - if (printdump == JNI_TRUE) { - printf(">>> name = \"%s\", sig = \"%s\"\n", name, sig); - } - if (name == NULL || strcmp(name, "") != 0) { - printf("Wrong field name: \"%s\", expected: \"fld\"\n", name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, "()V") != 0) { - printf("Wrong field sig: \"%s\", expected: \"I\"\n", sig); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/methname002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/methname002.cpp new file mode 100644 index 00000000000..3f92d18b52e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname002/methname002.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_methname002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_methname002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_methname002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetMethodName_methname002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + char *name, *sig, *generic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "", "()V"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->GetMethodName(NULL, &name, &sig, &generic); + if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (namePtr) null pointer check ...\n"); + } + err = jvmti->GetMethodName(mid, NULL, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(namePtr) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + if (printdump == JNI_TRUE) { + printf(">>> sig = \"%s\", generic = \"%s\"\n", sig, generic); + } + if (sig == NULL || strcmp(sig, "()V") != 0) { + printf("Wrong field sig: \"%s\", expected: \"I\"\n", sig); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> (signaturePtr) null pointer check ...\n"); + } + err = jvmti->GetMethodName(mid, &name, NULL, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(signaturePtr) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + if (printdump == JNI_TRUE) { + printf(">>> name = \"%s\", generic = \"%s\"\n", name, generic); + } + if (name == NULL || strcmp(name, "") != 0) { + printf("Wrong field name: \"%s\", expected: \"fld\"\n", name); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> (genericPtr) null pointer check ...\n"); + } + err = jvmti->GetMethodName(mid, &name, &sig, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(signaturePtr) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + if (printdump == JNI_TRUE) { + printf(">>> name = \"%s\", sig = \"%s\"\n", name, sig); + } + if (name == NULL || strcmp(name, "") != 0) { + printf("Wrong field name: \"%s\", expected: \"fld\"\n", name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, "()V") != 0) { + printf("Wrong field sig: \"%s\", expected: \"I\"\n", sig); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/libmethname003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/libmethname003.c deleted file mode 100644 index 2aa70479618..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/libmethname003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "methname003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/libmethname003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/libmethname003.cpp new file mode 100644 index 00000000000..409a5fdef71 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/libmethname003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "methname003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/methname003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/methname003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/methname003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetMethodName/methname003/methname003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/libobjhashcode001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/libobjhashcode001.c deleted file mode 100644 index e60685cb90a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/libobjhashcode001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "objhashcode001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/libobjhashcode001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/libobjhashcode001.cpp new file mode 100644 index 00000000000..9493c1412cd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/libobjhashcode001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "objhashcode001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/objhashcode001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/objhashcode001.c deleted file mode 100644 index f72941408f7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/objhashcode001.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/GetObjectHashCode/objhashcode001" -#define OBJECT_CLASS_NAME "nsk/jvmti/GetObjectHashCode/objhashcode001TestedClass" -#define OBJECT_CLASS_SIG "L"OBJECT_CLASS_NAME";" -#define OBJECT_FIELD_NAME "testedObject" - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for object created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - jobject testedObject = NULL; - jint objectHashCode = 0; - - NSK_DISPLAY0(">>> Obtain tested object from a static field of debugee class\n"); - { - jclass debugeeClass = NULL; - jfieldID objectField = NULL; - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: %p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got fieldID: %p\n", (void*)objectField); - - NSK_DISPLAY1("Get object from static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (testedObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got object: %p\n", (void*)testedObject); - - NSK_DISPLAY1("Create global reference for object: %p\n", (void*)testedObject); - if (!NSK_JNI_VERIFY(jni, (testedObject = - NSK_CPP_STUB2(NewGlobalRef, jni, testedObject)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got reference: %p\n", (void*)testedObject); - } - - NSK_DISPLAY0(">>> Testcase #1: get initial hash code of the object\n"); - { - NSK_DISPLAY1("Get hashcode for object: %p\n", (void*)testedObject); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetObjectHashCode, jvmti, testedObject, &objectHashCode))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got hash code: %d\n", (int)objectHashCode); - } - - NSK_DISPLAY0(">>> Testcase #2: get hash code of not changed object and compare with initial\n"); - { - jint hashCode = 0; - - NSK_DISPLAY1("Get hashcode for object: %p\n", (void*)testedObject); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetObjectHashCode, jvmti, testedObject, &hashCode))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got hash code: %d\n", (int)hashCode); - - if (hashCode != objectHashCode) { - NSK_COMPLAIN2("Other call to GetObjectHasCode for not changed object returns different value\n" - "# got hash code: %d\n" - "# initial hash code: %d\n", - (int)hashCode, (int)objectHashCode); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY2("SUCCESS: Got hash code is equal to initial: %d = %d\n", - (int)hashCode, (int)objectHashCode); - } - } - - NSK_DISPLAY0(">>> Testcase #3: get hash code of changed object and compare with initial\n"); - { - jint hashCode = 0; - - NSK_DISPLAY0("Let debugee to change object data\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_DISPLAY1("Get hashcode for object: %p\n", (void*)testedObject); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetObjectHashCode, jvmti, testedObject, &hashCode))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got hash code: %d\n", (int)hashCode); - - if (hashCode != objectHashCode) { - NSK_COMPLAIN2("Other call to GetObjectHasCode for changed object returns different value\n" - "# got hash code: %d\n" - "# initial hash code: %d\n", - (int)hashCode, (int)objectHashCode); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY2("SUCCESS: Got hash code is equal to initial: %d = %d\n", - (int)hashCode, (int)objectHashCode); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - NSK_DISPLAY1("Delete object reference: %p\n", (void*)testedObject); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedObject)); - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_objhashcode001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_objhashcode001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_objhashcode001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/objhashcode001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/objhashcode001.cpp new file mode 100644 index 00000000000..61846e7174c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectHashCode/objhashcode001/objhashcode001.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/GetObjectHashCode/objhashcode001" +#define OBJECT_CLASS_NAME "nsk/jvmti/GetObjectHashCode/objhashcode001TestedClass" +#define OBJECT_CLASS_SIG "L" OBJECT_CLASS_NAME ";" +#define OBJECT_FIELD_NAME "testedObject" + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for object created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + jobject testedObject = NULL; + jint objectHashCode = 0; + + NSK_DISPLAY0(">>> Obtain tested object from a static field of debugee class\n"); + { + jclass debugeeClass = NULL; + jfieldID objectField = NULL; + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: %p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got fieldID: %p\n", (void*)objectField); + + NSK_DISPLAY1("Get object from static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (testedObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got object: %p\n", (void*)testedObject); + + NSK_DISPLAY1("Create global reference for object: %p\n", (void*)testedObject); + if (!NSK_JNI_VERIFY(jni, (testedObject = + NSK_CPP_STUB2(NewGlobalRef, jni, testedObject)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got reference: %p\n", (void*)testedObject); + } + + NSK_DISPLAY0(">>> Testcase #1: get initial hash code of the object\n"); + { + NSK_DISPLAY1("Get hashcode for object: %p\n", (void*)testedObject); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetObjectHashCode, jvmti, testedObject, &objectHashCode))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got hash code: %d\n", (int)objectHashCode); + } + + NSK_DISPLAY0(">>> Testcase #2: get hash code of not changed object and compare with initial\n"); + { + jint hashCode = 0; + + NSK_DISPLAY1("Get hashcode for object: %p\n", (void*)testedObject); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetObjectHashCode, jvmti, testedObject, &hashCode))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got hash code: %d\n", (int)hashCode); + + if (hashCode != objectHashCode) { + NSK_COMPLAIN2("Other call to GetObjectHasCode for not changed object returns different value\n" + "# got hash code: %d\n" + "# initial hash code: %d\n", + (int)hashCode, (int)objectHashCode); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY2("SUCCESS: Got hash code is equal to initial: %d = %d\n", + (int)hashCode, (int)objectHashCode); + } + } + + NSK_DISPLAY0(">>> Testcase #3: get hash code of changed object and compare with initial\n"); + { + jint hashCode = 0; + + NSK_DISPLAY0("Let debugee to change object data\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_DISPLAY1("Get hashcode for object: %p\n", (void*)testedObject); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetObjectHashCode, jvmti, testedObject, &hashCode))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got hash code: %d\n", (int)hashCode); + + if (hashCode != objectHashCode) { + NSK_COMPLAIN2("Other call to GetObjectHasCode for changed object returns different value\n" + "# got hash code: %d\n" + "# initial hash code: %d\n", + (int)hashCode, (int)objectHashCode); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY2("SUCCESS: Got hash code is equal to initial: %d = %d\n", + (int)hashCode, (int)objectHashCode); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + NSK_DISPLAY1("Delete object reference: %p\n", (void*)testedObject); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedObject)); + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_objhashcode001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_objhashcode001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_objhashcode001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/libobjmonusage001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/libobjmonusage001.c deleted file mode 100644 index 93c6797ff0c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/libobjmonusage001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "objmonusage001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/libobjmonusage001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/libobjmonusage001.cpp new file mode 100644 index 00000000000..a02eb6580cd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/libobjmonusage001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "objmonusage001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/objmonusage001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/objmonusage001.c deleted file mode 100644 index 7689e2524f0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/objmonusage001.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x,y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x,y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_objmonusage001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_objmonusage001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_objmonusage001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_monitor_info) { - printf("Warning: GetObjectMonitorUsage is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage001_check(JNIEnv *env, - jclass cls, jint i, jobject obj, - jthread owner, jint entryCount, jint waiterCount) { - jvmtiError err; - jvmtiMonitorUsage inf; - jvmtiThreadInfo tinf; - int j; - - if (result == STATUS_FAILED) { - return; - } - - err = (*jvmti)->GetObjectMonitorUsage(jvmti, obj, &inf); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_monitor_info) { - /* Ok, it's expected */ - return; - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetMonitorInfo#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - if (inf.owner == NULL) { - printf(">>> [%2d] owner: none (0x0)\n", i); - } else { - (*jvmti)->GetThreadInfo(jvmti, inf.owner, &tinf); - printf(">>> [%2d] owner: %s (0x%p)\n", - i, tinf.name, inf.owner); - } - printf(">>> entry_count: %d\n", inf.entry_count); - printf(">>> waiter_count: %d\n", inf.waiter_count); - if (inf.waiter_count > 0) { - printf(">>> waiters:\n"); - for (j = 0; j < inf.waiter_count; j++) { - (*jvmti)->GetThreadInfo(jvmti, inf.waiters[j], &tinf); - printf(">>> %2d: %s (0x%p)\n", - j, tinf.name, inf.waiters[j]); - } - } - printf(">>> notify_waiter_count: %d\n", inf.notify_waiter_count); - if (inf.notify_waiter_count > 0) { - printf(">>> notify_waiters:\n"); - for (j = 0; j < inf.notify_waiter_count; j++) { - (*jvmti)->GetThreadInfo(jvmti, inf.notify_waiters[j], &tinf); - printf(">>> %2d: %s (0x%p)\n", - j, tinf.name, inf.notify_waiters[j]); - } - } - } - - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, owner), - inf.owner) != JNI_TRUE) { - (*jvmti)->GetThreadInfo(jvmti, inf.owner, &tinf); - printf("(%d) unexpected owner: %s (0x%p)\n", i, tinf.name, inf.owner); - result = STATUS_FAILED; - } - - if (inf.entry_count != entryCount) { - printf("(%d) entry_count expected: %d, actually: %d\n", - i, entryCount, inf.entry_count); - result = STATUS_FAILED; - } - - if (inf.waiter_count != waiterCount) { - printf("(%d) waiter_count expected: %d, actually: %d\n", - i, waiterCount, inf.waiter_count); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage001_getResult(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/objmonusage001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/objmonusage001.cpp new file mode 100644 index 00000000000..609e62bf720 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/objmonusage001.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x,y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x,y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_objmonusage001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_objmonusage001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_objmonusage001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_monitor_info) { + printf("Warning: GetObjectMonitorUsage is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage001_check(JNIEnv *env, + jclass cls, jint i, jobject obj, + jthread owner, jint entryCount, jint waiterCount) { + jvmtiError err; + jvmtiMonitorUsage inf; + jvmtiThreadInfo tinf; + int j; + + if (result == STATUS_FAILED) { + return; + } + + err = jvmti->GetObjectMonitorUsage(obj, &inf); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_monitor_info) { + /* Ok, it's expected */ + return; + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetMonitorInfo#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + if (inf.owner == NULL) { + printf(">>> [%2d] owner: none (0x0)\n", i); + } else { + jvmti->GetThreadInfo(inf.owner, &tinf); + printf(">>> [%2d] owner: %s (0x%p)\n", + i, tinf.name, inf.owner); + } + printf(">>> entry_count: %d\n", inf.entry_count); + printf(">>> waiter_count: %d\n", inf.waiter_count); + if (inf.waiter_count > 0) { + printf(">>> waiters:\n"); + for (j = 0; j < inf.waiter_count; j++) { + jvmti->GetThreadInfo(inf.waiters[j], &tinf); + printf(">>> %2d: %s (0x%p)\n", + j, tinf.name, inf.waiters[j]); + } + } + printf(">>> notify_waiter_count: %d\n", inf.notify_waiter_count); + if (inf.notify_waiter_count > 0) { + printf(">>> notify_waiters:\n"); + for (j = 0; j < inf.notify_waiter_count; j++) { + jvmti->GetThreadInfo(inf.notify_waiters[j], &tinf); + printf(">>> %2d: %s (0x%p)\n", + j, tinf.name, inf.notify_waiters[j]); + } + } + } + + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, owner), + inf.owner) != JNI_TRUE) { + jvmti->GetThreadInfo(inf.owner, &tinf); + printf("(%d) unexpected owner: %s (0x%p)\n", i, tinf.name, inf.owner); + result = STATUS_FAILED; + } + + if (inf.entry_count != entryCount) { + printf("(%d) entry_count expected: %d, actually: %d\n", + i, entryCount, inf.entry_count); + result = STATUS_FAILED; + } + + if (inf.waiter_count != waiterCount) { + printf("(%d) waiter_count expected: %d, actually: %d\n", + i, waiterCount, inf.waiter_count); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage001_getResult(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/libobjmonusage002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/libobjmonusage002.c deleted file mode 100644 index 2a12a20fde3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/libobjmonusage002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "objmonusage002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/libobjmonusage002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/libobjmonusage002.cpp new file mode 100644 index 00000000000..e9f28434790 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/libobjmonusage002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "objmonusage002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/objmonusage002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/objmonusage002.c deleted file mode 100644 index ce01ed57d36..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/objmonusage002.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_objmonusage002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_objmonusage002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_objmonusage002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_monitor_info) { - printf("Warning: GetObjectMonitorUsage is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage002_check(JNIEnv *env, - jclass cls, jobject obj) { - jvmtiError err; - jvmtiMonitorUsage inf; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid object check ...\n"); - } - err = (*jvmti)->GetObjectMonitorUsage(jvmti, NULL, &inf); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_monitor_info) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_INVALID_OBJECT) { - printf("Error expected: JVMTI_ERROR_INVALID_OBJECT,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetObjectMonitorUsage(jvmti, obj, NULL); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_monitor_info) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/objmonusage002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/objmonusage002.cpp new file mode 100644 index 00000000000..8a674ff73a3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage002/objmonusage002.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_objmonusage002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_objmonusage002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_objmonusage002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_monitor_info) { + printf("Warning: GetObjectMonitorUsage is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage002_check(JNIEnv *env, + jclass cls, jobject obj) { + jvmtiError err; + jvmtiMonitorUsage inf; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid object check ...\n"); + } + err = jvmti->GetObjectMonitorUsage(NULL, &inf); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_monitor_info) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_INVALID_OBJECT) { + printf("Error expected: JVMTI_ERROR_INVALID_OBJECT,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetObjectMonitorUsage(obj, NULL); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_monitor_info) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/libobjmonusage003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/libobjmonusage003.c deleted file mode 100644 index b87bd54441a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/libobjmonusage003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "objmonusage003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/libobjmonusage003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/libobjmonusage003.cpp new file mode 100644 index 00000000000..855a62349d8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/libobjmonusage003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "objmonusage003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/objmonusage003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/objmonusage003.c deleted file mode 100644 index f9abba6ae6c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/objmonusage003.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int count = 0; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_objmonusage003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_objmonusage003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_objmonusage003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_monitor_info) { - printf("Warning: GetObjectMonitorUsage is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage003_check(JNIEnv *env, - jclass cls, jobject obj, jthread owner, - jint entryCount, jint waiterCount) { - jvmtiError err; - jvmtiMonitorUsage inf; - jvmtiThreadInfo tinf; - int j; - - count++; - - err = (*jvmti)->GetObjectMonitorUsage(jvmti, obj, &inf); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_monitor_info) { - /* Ok, it's expected */ - return; - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetMonitorInfo#%d) unexpected error: %s (%d)\n", - count, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - if (inf.owner == NULL) { - printf(">>> [%2d] owner: none (0x0)\n", count); - } else { - err = (*jvmti)->GetThreadInfo(jvmti, inf.owner, &tinf); - printf(">>> [%2d] owner: %s (0x%p)\n", - count, tinf.name, inf.owner); - } - printf(">>> entry_count: %d\n", inf.entry_count); - printf(">>> waiter_count: %d\n", inf.waiter_count); - if (inf.waiter_count > 0) { - printf(">>> waiters:\n"); - for (j = 0; j < inf.waiter_count; j++) { - err = (*jvmti)->GetThreadInfo(jvmti, inf.waiters[j], &tinf); - printf(">>> %2d: %s (0x%p)\n", - j, tinf.name, inf.waiters[j]); - } - } - } - - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, owner), - inf.owner) != JNI_TRUE) { - printf("(%d) unexpected owner: 0x%p\n", count, inf.owner); - result = STATUS_FAILED; - } - - if (inf.entry_count != entryCount) { - printf("(%d) entry_count expected: %d, actually: %d\n", - count, entryCount, inf.entry_count); - result = STATUS_FAILED; - } - - if (inf.waiter_count != waiterCount) { - printf("(%d) waiter_count expected: %d, actually: %d\n", - count, waiterCount, inf.waiter_count); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage003_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/objmonusage003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/objmonusage003.cpp new file mode 100644 index 00000000000..634fec991d5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/objmonusage003.cpp @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int count = 0; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_objmonusage003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_objmonusage003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_objmonusage003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_monitor_info) { + printf("Warning: GetObjectMonitorUsage is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage003_check(JNIEnv *env, + jclass cls, jobject obj, jthread owner, + jint entryCount, jint waiterCount) { + jvmtiError err; + jvmtiMonitorUsage inf; + jvmtiThreadInfo tinf; + int j; + + count++; + + err = jvmti->GetObjectMonitorUsage(obj, &inf); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_monitor_info) { + /* Ok, it's expected */ + return; + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetMonitorInfo#%d) unexpected error: %s (%d)\n", + count, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + if (inf.owner == NULL) { + printf(">>> [%2d] owner: none (0x0)\n", count); + } else { + err = jvmti->GetThreadInfo(inf.owner, &tinf); + printf(">>> [%2d] owner: %s (0x%p)\n", + count, tinf.name, inf.owner); + } + printf(">>> entry_count: %d\n", inf.entry_count); + printf(">>> waiter_count: %d\n", inf.waiter_count); + if (inf.waiter_count > 0) { + printf(">>> waiters:\n"); + for (j = 0; j < inf.waiter_count; j++) { + err = jvmti->GetThreadInfo(inf.waiters[j], &tinf); + printf(">>> %2d: %s (0x%p)\n", + j, tinf.name, inf.waiters[j]); + } + } + } + + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, owner), + inf.owner) != JNI_TRUE) { + printf("(%d) unexpected owner: 0x%p\n", count, inf.owner); + result = STATUS_FAILED; + } + + if (inf.entry_count != entryCount) { + printf("(%d) entry_count expected: %d, actually: %d\n", + count, entryCount, inf.entry_count); + result = STATUS_FAILED; + } + + if (inf.waiter_count != waiterCount) { + printf("(%d) waiter_count expected: %d, actually: %d\n", + count, waiterCount, inf.waiter_count); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage003_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/libobjmonusage004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/libobjmonusage004.c deleted file mode 100644 index 90c5adb2650..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/libobjmonusage004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "objmonusage004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/libobjmonusage004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/libobjmonusage004.cpp new file mode 100644 index 00000000000..89db02b67e6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/libobjmonusage004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "objmonusage004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/objmonusage004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/objmonusage004.c deleted file mode 100644 index 69a8e5b3394..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/objmonusage004.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int count = 0; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_objmonusage004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_objmonusage004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_objmonusage004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_monitor_info) { - printf("Warning: GetObjectMonitorUsage is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage004_check(JNIEnv *env, - jclass cls, jobject obj, jthread owner, - jint entryCount, jint waiterCount) { - jvmtiError err; - jvmtiMonitorUsage inf; - jvmtiThreadInfo tinf; - int j; - - count++; - - err = (*jvmti)->GetObjectMonitorUsage(jvmti, obj, &inf); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_monitor_info) { - /* Ok, it's expected */ - return; - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetMonitorInfo#%d) unexpected error: %s (%d)\n", - count, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - if (inf.owner == NULL) { - printf(">>> [%2d] owner: none (0x0)\n", count); - } else { - err = (*jvmti)->GetThreadInfo(jvmti, inf.owner, &tinf); - printf(">>> [%2d] owner: %s (0x%p)\n", - count, tinf.name, inf.owner); - } - printf(">>> entry_count: %d\n", inf.entry_count); - printf(">>> waiter_count: %d\n", inf.waiter_count); - if (inf.waiter_count > 0) { - printf(">>> waiters:\n"); - for (j = 0; j < inf.waiter_count; j++) { - err = (*jvmti)->GetThreadInfo(jvmti, inf.waiters[j], &tinf); - printf(">>> %2d: %s (0x%p)\n", - j, tinf.name, inf.waiters[j]); - } - } - } - - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, owner), - inf.owner) != JNI_TRUE) { - printf("(%d) unexpected owner: 0x%p\n", count, inf.owner); - result = STATUS_FAILED; - } - - if (inf.entry_count != entryCount) { - printf("(%d) entry_count expected: %d, actually: %d\n", - count, entryCount, inf.entry_count); - result = STATUS_FAILED; - } - - if (inf.waiter_count != waiterCount) { - printf("(%d) waiter_count expected: %d, actually: %d\n", - count, waiterCount, inf.waiter_count); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage004_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/objmonusage004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/objmonusage004.cpp new file mode 100644 index 00000000000..7723f2cc7dc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage004/objmonusage004.cpp @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int count = 0; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_objmonusage004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_objmonusage004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_objmonusage004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_monitor_info) { + printf("Warning: GetObjectMonitorUsage is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage004_check(JNIEnv *env, + jclass cls, jobject obj, jthread owner, + jint entryCount, jint waiterCount) { + jvmtiError err; + jvmtiMonitorUsage inf; + jvmtiThreadInfo tinf; + int j; + + count++; + + err = jvmti->GetObjectMonitorUsage(obj, &inf); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_monitor_info) { + /* Ok, it's expected */ + return; + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetMonitorInfo#%d) unexpected error: %s (%d)\n", + count, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + if (inf.owner == NULL) { + printf(">>> [%2d] owner: none (0x0)\n", count); + } else { + err = jvmti->GetThreadInfo(inf.owner, &tinf); + printf(">>> [%2d] owner: %s (0x%p)\n", + count, tinf.name, inf.owner); + } + printf(">>> entry_count: %d\n", inf.entry_count); + printf(">>> waiter_count: %d\n", inf.waiter_count); + if (inf.waiter_count > 0) { + printf(">>> waiters:\n"); + for (j = 0; j < inf.waiter_count; j++) { + err = jvmti->GetThreadInfo(inf.waiters[j], &tinf); + printf(">>> %2d: %s (0x%p)\n", + j, tinf.name, inf.waiters[j]); + } + } + } + + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, owner), + inf.owner) != JNI_TRUE) { + printf("(%d) unexpected owner: 0x%p\n", count, inf.owner); + result = STATUS_FAILED; + } + + if (inf.entry_count != entryCount) { + printf("(%d) entry_count expected: %d, actually: %d\n", + count, entryCount, inf.entry_count); + result = STATUS_FAILED; + } + + if (inf.waiter_count != waiterCount) { + printf("(%d) waiter_count expected: %d, actually: %d\n", + count, waiterCount, inf.waiter_count); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage004_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/libobjmonusage005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/libobjmonusage005.c deleted file mode 100644 index 9c72d0fa2b3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/libobjmonusage005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "objmonusage005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/libobjmonusage005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/libobjmonusage005.cpp new file mode 100644 index 00000000000..571671e32f1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/libobjmonusage005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "objmonusage005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/objmonusage005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/objmonusage005.c deleted file mode 100644 index 42c683dc2da..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/objmonusage005.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_objmonusage005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_objmonusage005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_objmonusage005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_monitor_info) { - printf("Warning: GetObjectMonitorUsage is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage005_check(JNIEnv *env, jclass cls, jobject obj) { - jvmtiError err; - jvmtiMonitorUsage inf; - - err = (*jvmti)->GetObjectMonitorUsage(jvmti, obj, &inf); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_monitor_info) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetObjectMonitorUsage) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage005_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/objmonusage005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/objmonusage005.cpp new file mode 100644 index 00000000000..db722bde79a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage005/objmonusage005.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_objmonusage005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_objmonusage005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_objmonusage005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_monitor_info) { + printf("Warning: GetObjectMonitorUsage is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage005_check(JNIEnv *env, jclass cls, jobject obj) { + jvmtiError err; + jvmtiMonitorUsage inf; + + err = jvmti->GetObjectMonitorUsage(obj, &inf); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_monitor_info) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetObjectMonitorUsage) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage005_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/libobjmonusage006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/libobjmonusage006.c deleted file mode 100644 index 519a09b30ff..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/libobjmonusage006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "objmonusage006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/libobjmonusage006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/libobjmonusage006.cpp new file mode 100644 index 00000000000..d31160deaee --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/libobjmonusage006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "objmonusage006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/objmonusage006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/objmonusage006.c deleted file mode 100644 index 4a33d880793..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/objmonusage006.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_objmonusage006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_objmonusage006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_objmonusage006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_monitor_info) { - printf("Warning: GetObjectMonitorUsage is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage006_check(JNIEnv *env, jclass cls, jobject obj) { - jvmtiError err; - jvmtiMonitorUsage inf; - - err = (*jvmti)->GetObjectMonitorUsage(jvmti, obj, &inf); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_monitor_info) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetObjectMonitorUsage) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage006_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/objmonusage006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/objmonusage006.cpp new file mode 100644 index 00000000000..9b12c711e88 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage006/objmonusage006.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_objmonusage006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_objmonusage006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_objmonusage006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_monitor_info) { + printf("Warning: GetObjectMonitorUsage is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage006_check(JNIEnv *env, jclass cls, jobject obj) { + jvmtiError err; + jvmtiMonitorUsage inf; + + err = jvmti->GetObjectMonitorUsage(obj, &inf); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_monitor_info) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetObjectMonitorUsage) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetObjectMonitorUsage_objmonusage006_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/libobjsize001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/libobjsize001.c deleted file mode 100644 index 42256afdc3e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/libobjsize001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "objsize001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/libobjsize001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/libobjsize001.cpp new file mode 100644 index 00000000000..58b400403cf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/libobjsize001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "objsize001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/objsize001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/objsize001.c deleted file mode 100644 index 63b61c957b6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/objsize001.c +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -static jlong timeout = 0; - -#define DEBUGEE_CLASS_NAME "nsk/jvmti/GetObjectSize/objsize001" -#define OBJECT_CLASS_NAME "nsk/jvmti/GetObjectSize/objsize001TestedClass" -#define OBJECT_CLASS_SIG "L"OBJECT_CLASS_NAME";" -#define OBJECT_FIELD_NAME "testedObject" - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for object created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - { - jobject testedObject = NULL; - jlong objectSize = 0; - - NSK_DISPLAY0(">>> Obtain tested object from a static field of debugee class\n"); - { - jclass debugeeClass = NULL; - jfieldID objectField = NULL; - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); - - NSK_DISPLAY1("Get object from static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (testedObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)testedObject); - - NSK_DISPLAY1("Create global reference for object: 0x%p\n", (void*)testedObject); - if (!NSK_JNI_VERIFY(jni, (testedObject = - NSK_CPP_STUB2(NewGlobalRef, jni, testedObject)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got reference: 0x%p\n", (void*)testedObject); - } - - NSK_DISPLAY0(">>> Testcase #1: get initial size of the object\n"); - { - NSK_DISPLAY1("Get size for object: 0x%p\n", (void*)testedObject); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetObjectSize, jvmti, testedObject, &objectSize))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got object size: %ld bytes\n", (long)objectSize); - - if (objectSize <= 0) { - NSK_COMPLAIN1("GetObjectSize() returned unexpected size of object: %ld bytes\n", - (long)objectSize); - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(">>> Testcase #2: get size of not changed object and compare with initial\n"); - { - jlong size = 0; - - NSK_DISPLAY1("Get size for object: 0x%p\n", (void*)testedObject); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetObjectSize, jvmti, testedObject, &size))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got object size: %ld\n bytes", (long)size); - - if (size != objectSize) { - NSK_DISPLAY2("# WARNING: Other call to GetObjectSize for not changed object returns different size:\n" - "# got object size: %ld\n" - "# initial size: %ld\n", - (long)size, (long)objectSize); - } else { - NSK_DISPLAY2("SUCCESS: Got object size is equal to initial: %ld = %ld\n", - (long)size, (long)objectSize); - } - } - - NSK_DISPLAY0(">>> Testcase #3: get size of changed object and compare with initial\n"); - { - jlong size = 0; - - NSK_DISPLAY0("Let debugee to change object data\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_DISPLAY1("Get size for object: 0x%p\n", (void*)testedObject); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetObjectSize, jvmti, testedObject, &size))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got object size: %ld\n", (long)size); - - if (size != objectSize) { - NSK_COMPLAIN2("# WARNING: Other call to GetObjectSize for changed object returns different size:\n" - "# got object size: %ld\n" - "# initial size: %ld\n", - (long)size, (long)objectSize); - } else { - NSK_DISPLAY2("SUCCESS: Got object size is equal to initial: %ld = %ld\n", - (long)size, (long)objectSize); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - NSK_DISPLAY1("Delete object reference: 0x%p\n", (void*)testedObject); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedObject)); - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_objsize001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_objsize001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_objsize001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/objsize001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/objsize001.cpp new file mode 100644 index 00000000000..f10106e920b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectSize/objsize001/objsize001.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jlong timeout = 0; + +#define DEBUGEE_CLASS_NAME "nsk/jvmti/GetObjectSize/objsize001" +#define OBJECT_CLASS_NAME "nsk/jvmti/GetObjectSize/objsize001TestedClass" +#define OBJECT_CLASS_SIG "L" OBJECT_CLASS_NAME ";" +#define OBJECT_FIELD_NAME "testedObject" + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for object created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + { + jobject testedObject = NULL; + jlong objectSize = 0; + + NSK_DISPLAY0(">>> Obtain tested object from a static field of debugee class\n"); + { + jclass debugeeClass = NULL; + jfieldID objectField = NULL; + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); + + NSK_DISPLAY1("Get object from static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (testedObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)testedObject); + + NSK_DISPLAY1("Create global reference for object: 0x%p\n", (void*)testedObject); + if (!NSK_JNI_VERIFY(jni, (testedObject = + NSK_CPP_STUB2(NewGlobalRef, jni, testedObject)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got reference: 0x%p\n", (void*)testedObject); + } + + NSK_DISPLAY0(">>> Testcase #1: get initial size of the object\n"); + { + NSK_DISPLAY1("Get size for object: 0x%p\n", (void*)testedObject); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetObjectSize, jvmti, testedObject, &objectSize))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got object size: %ld bytes\n", (long)objectSize); + + if (objectSize <= 0) { + NSK_COMPLAIN1("GetObjectSize() returned unexpected size of object: %ld bytes\n", + (long)objectSize); + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(">>> Testcase #2: get size of not changed object and compare with initial\n"); + { + jlong size = 0; + + NSK_DISPLAY1("Get size for object: 0x%p\n", (void*)testedObject); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetObjectSize, jvmti, testedObject, &size))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got object size: %ld\n bytes", (long)size); + + if (size != objectSize) { + NSK_DISPLAY2("# WARNING: Other call to GetObjectSize for not changed object returns different size:\n" + "# got object size: %ld\n" + "# initial size: %ld\n", + (long)size, (long)objectSize); + } else { + NSK_DISPLAY2("SUCCESS: Got object size is equal to initial: %ld = %ld\n", + (long)size, (long)objectSize); + } + } + + NSK_DISPLAY0(">>> Testcase #3: get size of changed object and compare with initial\n"); + { + jlong size = 0; + + NSK_DISPLAY0("Let debugee to change object data\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_DISPLAY1("Get size for object: 0x%p\n", (void*)testedObject); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetObjectSize, jvmti, testedObject, &size))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got object size: %ld\n", (long)size); + + if (size != objectSize) { + NSK_COMPLAIN2("# WARNING: Other call to GetObjectSize for changed object returns different size:\n" + "# got object size: %ld\n" + "# initial size: %ld\n", + (long)size, (long)objectSize); + } else { + NSK_DISPLAY2("SUCCESS: Got object size is equal to initial: %ld = %ld\n", + (long)size, (long)objectSize); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + NSK_DISPLAY1("Delete object reference: 0x%p\n", (void*)testedObject); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedObject)); + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_objsize001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_objsize001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_objsize001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/libobjwithtags001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/libobjwithtags001.c deleted file mode 100644 index 6b78f168321..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/libobjwithtags001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "objwithtags001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/libobjwithtags001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/libobjwithtags001.cpp new file mode 100644 index 00000000000..a3947c61ae2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/libobjwithtags001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "objwithtags001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/objwithtags001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/objwithtags001.c deleted file mode 100644 index 59cdb4de300..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/objwithtags001.c +++ /dev/null @@ -1,477 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/GetObjectsWithTags/objwithtags001" -#define OBJECT_CLASS_NAME "nsk/jvmti/GetObjectsWithTags/objwithtags001TestedClass" -#define OBJECT_CLASS_SIG "L"OBJECT_CLASS_NAME";" -#define OBJECTS_FIELD_NAME "objects" -#define OBJECTS_FIELD_SIG "["OBJECT_CLASS_SIG - -/* constants */ -#define DEFAULT_TAGS_COUNT 4 -#define DEFAULT_OBJECTS_COUNT 5 - -static int tagsCount = 0; -static int objectsCount = 0; - -/* 2-dim indexing for flat list */ -#define ITEM(list, i, j) (((list) + (i * objectsCount))[j]) - -/* ============================================================================= */ - -/** Obtain tested objects from static field of debugee class. */ -static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int tagsCount, int objectsCount, - jobject* *objects, jlong* *tags) { - jclass debugeeClass = NULL; - jfieldID objectField = NULL; - jobjectArray arrayObject = NULL; - int size = tagsCount * objectsCount; - - NSK_DISPLAY2("Allocate memory for lists: %d objects for %d tags\n", - objectsCount, tagsCount); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, (size * sizeof(jobject)), - (unsigned char**)objects))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... allocated objects list: 0x%p\n", (void*)objects); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, (tagsCount * sizeof(jlong)), - (unsigned char**)tags))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... allocated tags list: 0x%p\n", (void*)tags); - - { - int i, k; - for (k = 0; k < size; k++) { - (*objects)[k] = NULL; - } - - for (i = 0; i < tagsCount; i++) { - (*tags)[i] = 100 * (jlong)(i + 1); - } - } - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find static field: %s\n", OBJECTS_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECTS_FIELD_NAME, OBJECTS_FIELD_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); - - NSK_DISPLAY1("Get objects array from static field: %s\n", OBJECTS_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (arrayObject = (jobjectArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)arrayObject); - - { - jsize arrayLen = 0; - jsize k; - - if (!NSK_JNI_VERIFY(jni, (arrayLen = - NSK_CPP_STUB2(GetArrayLength, jni, arrayObject)) == size)) { - NSK_DISPLAY1(" ... got array length: %d\n", (int)size); - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array length: %d\n", (int)size); - - for (k = 0; k < size; k++) { - jobject object = NULL; - - if (!NSK_JNI_VERIFY(jni, (object = - NSK_CPP_STUB3(GetObjectArrayElement, jni, arrayObject, k)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - if (!NSK_JNI_VERIFY(jni, (object = - NSK_CPP_STUB2(NewGlobalRef, jni, object)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - (*objects)[k] = object; - } - } - NSK_DISPLAY1(" ... object references created: %d objects\n", size); - - return NSK_TRUE; -} - -/** Release references to the tested objects and free allocated memory. */ -static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int tagsCount, int objectsCount, - jobject *objects, jlong *tags) { - int size = tagsCount * objectsCount; - int k; - - if (objects == NULL) - return NSK_TRUE; - - NSK_DISPLAY1("Release objects references: %d objects\n", size); - for (k = 0; k < size; k++) { - if (objects[k] != NULL) { - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, objects[k])); - } - } - NSK_DISPLAY1(" ... object references released: %d objects\n", size); - - NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objects); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objects))) { - nsk_jvmti_setFailStatus(); - } - - if (tags == NULL) - return NSK_FALSE; - - NSK_DISPLAY1("Deallocate tags list: 0x%p\n", (void*)tags); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)tags))) { - nsk_jvmti_setFailStatus(); - } - - return NSK_TRUE; -} - -/** Get and check tagged objects. */ -static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int tagsCount, int objectsCount, - jlong tags[], jobject objects[], - const char kind[], int expectedCount) { - jint taggedObjectsCount = 0; - jobject* taggedObjectsList = NULL; - jlong* taggedObjectsTags = NULL; - jlong expectedTag = 0; - int k; - - NSK_DISPLAY1("Get tagged objects: %d tags\n", tagsCount); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB6(GetObjectsWithTags, jvmti, tagsCount, tags, - &taggedObjectsCount, &taggedObjectsList, &taggedObjectsTags))) { - nsk_jvmti_setFailStatus(); - return NSK_TRUE; - } - NSK_DISPLAY1(" ... got tagged objects: %d\n", (int)taggedObjectsCount); - - if (taggedObjectsCount != expectedCount) { - NSK_COMPLAIN3("GetObjectsWithTags() returns unexpected number of objects %s:\n" - "# got objects: %d\n" - "# expected: %d\n", - kind, (int)taggedObjectsCount, (int)expectedCount); - nsk_jvmti_setFailStatus(); - } - - if (taggedObjectsList == NULL && taggedObjectsCount > 0) { - NSK_COMPLAIN2("GetObjectsWithTags() returns NULL list of objects %s: 0x%p\n", - kind, (void*)taggedObjectsList); - nsk_jvmti_setFailStatus(); - return NSK_TRUE; - } - - if (taggedObjectsTags == NULL && taggedObjectsCount > 0) { - NSK_COMPLAIN2("GetObjectsWithTags() returns NULL list of tags for objects %s: 0x%p\n", - kind, (void*)taggedObjectsTags); - nsk_jvmti_setFailStatus(); - return NSK_TRUE; - } - - for (k = 0; k < taggedObjectsCount; k++) { - jobject object = taggedObjectsList[k]; - jlong tag = taggedObjectsTags[k]; - int objectsFound = 0; - int i, j, l; - - NSK_DISPLAY3(" #%d: object: 0x%p, tag: %ld\n", k, (void*)object, (long)tag); - - if (object == NULL) { - NSK_COMPLAIN3("GetObjectsWithTags() returns NULL for object #%d %s: 0x%p\n", - k, kind, (void*)object); - nsk_jvmti_setFailStatus(); - continue; - } - - objectsFound = 0; - for (l = k + 1; l < taggedObjectsCount; l++) { - if (object == taggedObjectsList[l]) - objectsFound++; - } - if (objectsFound > 0) { - NSK_COMPLAIN4("GetObjectsWithTags() returns %d duplicates for object #%d %s: 0x%p\n", - objectsFound, k, kind, (void*)object); - nsk_jvmti_setFailStatus(); - continue; - } - - objectsFound = 0; - for (i = 0; i < tagsCount; i++) { - for (j = 0; j < objectsCount; j++) { - jobject foundObject = ITEM(objects, i, j); - - if (NSK_CPP_STUB3(IsSameObject, jni, object, foundObject)) { - objectsFound++; - - if (expectedCount > 0) - expectedTag = tags[i]; - - if (tag != expectedTag) { - NSK_COMPLAIN6("GetObjectsWithTags() returns wrong tag for object #%d %s:\n" - "# got object: 0x%p\n" - "# original: 0x%p\n" - "# got tag: %ld\n" - "# original: %ld\n", - k, kind, - (void*)object, (void*)foundObject, - (long)tag, (long)expectedTag); - nsk_jvmti_setFailStatus(); - } - break; - } - } - - if (objectsFound > 0) - break; - } - - if (objectsFound <= 0) { - NSK_COMPLAIN4("GetObjectsWithTags() returns unexpected #%d object %s:\n" - "# got object: 0x%p\n" - "# got tag: %ld\n", - k, kind, - (void*)object, (long)tag); - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY1("Deallocate got objects list: 0x%p\n", (void*)taggedObjectsList); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)taggedObjectsList))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY1("Deallocate got tags list: 0x%p\n", (void*)taggedObjectsTags); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)taggedObjectsTags))) { - nsk_jvmti_setFailStatus(); - } - - return NSK_TRUE; -} - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for objects created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - int size = tagsCount * objectsCount; - jobject* objects = NULL; - jlong* tags = NULL; - - NSK_DISPLAY0(">>> Obtain tested objects list from a static field of debugee class\n"); - { - if (!NSK_VERIFY(getTestedObjects(jvmti, jni, tagsCount, objectsCount, - &objects, &tags))) - return; - } - - NSK_DISPLAY0(">>> Tagging tested objects with different tags\n"); - { - int i, j; - - for (i = 0; i < tagsCount; i++) { - NSK_DISPLAY2(" tagging with %ld: %d objects\n", (long)tags[i], objectsCount); - for (j = 0; j < objectsCount; j++) { - jobject object = ITEM(objects, i, j); - - NSK_DISPLAY3(" #%d: object: 0x%p, tag: %ld\n", - j, (void*)object, (long)tags[i]); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, object, tags[i]))) { - nsk_jvmti_setFailStatus(); - return; - } - } - } - NSK_DISPLAY1(" ... objects tagged: %d objects\n", (tagsCount * objectsCount)); - } - - NSK_DISPLAY0(">>> Testcase #1: get tagged objects before objects data changed\n"); - { - if (!NSK_VERIFY( - checkTestedObjects(jvmti, jni, tagsCount, objectsCount, - tags, objects, "before changed", size))) - return; - } - - NSK_DISPLAY0(">>> Let debugee to change object data\n"); - { - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - } - - NSK_DISPLAY0(">>> Testcase #2: get tagged objects after objects data are changed\n"); - { - if (!NSK_VERIFY( - checkTestedObjects(jvmti, jni, tagsCount, objectsCount, - tags, objects, "after changed", size))) - return; - } - - NSK_DISPLAY0(">>> Untagging all tested objects (i.e., tagging with zero tag)\n"); - { - jlong tag = 0; - int i, j; - - for (i = 0; i < tagsCount; i++) { - NSK_DISPLAY2(" tagging with %ld: %d objects\n", (long)tag, objectsCount); - for (j = 0; j < objectsCount; j++) { - jobject object = ITEM(objects, i , j); - - NSK_DISPLAY3(" #%d: object: 0x%p, tag: %ld\n", - j, (void*)object, (long)tag); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, object, tag))) { - nsk_jvmti_setFailStatus(); - return; - } - } - } - NSK_DISPLAY1(" ... objects untagged: %d objects\n", (tagsCount * objectsCount)); - } - - NSK_DISPLAY0(">>> Testcase #3: get tagged objects after objects untagged\n"); - { - if (!NSK_VERIFY( - checkTestedObjects(jvmti, jni, tagsCount, objectsCount, - tags, objects, "after untagged", 0))) - return; - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, tagsCount, objectsCount, - objects, tags))) - return; - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_objwithtags001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_objwithtags001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_objwithtags001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* get option values */ - tagsCount = nsk_jvmti_findOptionIntValue("tags", DEFAULT_TAGS_COUNT); - objectsCount = nsk_jvmti_findOptionIntValue("objects", DEFAULT_OBJECTS_COUNT); - if (!NSK_VERIFY(tagsCount > 0 && objectsCount > 0)) - return JNI_ERR; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* add required capabilities */ - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/objwithtags001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/objwithtags001.cpp new file mode 100644 index 00000000000..87ed6a9267f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetObjectsWithTags/objwithtags001/objwithtags001.cpp @@ -0,0 +1,477 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/GetObjectsWithTags/objwithtags001" +#define OBJECT_CLASS_NAME "nsk/jvmti/GetObjectsWithTags/objwithtags001TestedClass" +#define OBJECT_CLASS_SIG "L" OBJECT_CLASS_NAME ";" +#define OBJECTS_FIELD_NAME "objects" +#define OBJECTS_FIELD_SIG "[" OBJECT_CLASS_SIG + +/* constants */ +#define DEFAULT_TAGS_COUNT 4 +#define DEFAULT_OBJECTS_COUNT 5 + +static int tagsCount = 0; +static int objectsCount = 0; + +/* 2-dim indexing for flat list */ +#define ITEM(list, i, j) (((list) + (i * objectsCount))[j]) + +/* ============================================================================= */ + +/** Obtain tested objects from static field of debugee class. */ +static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int tagsCount, int objectsCount, + jobject* *objects, jlong* *tags) { + jclass debugeeClass = NULL; + jfieldID objectField = NULL; + jobjectArray arrayObject = NULL; + int size = tagsCount * objectsCount; + + NSK_DISPLAY2("Allocate memory for lists: %d objects for %d tags\n", + objectsCount, tagsCount); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, (size * sizeof(jobject)), + (unsigned char**)objects))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... allocated objects list: 0x%p\n", (void*)objects); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, (tagsCount * sizeof(jlong)), + (unsigned char**)tags))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... allocated tags list: 0x%p\n", (void*)tags); + + { + int i, k; + for (k = 0; k < size; k++) { + (*objects)[k] = NULL; + } + + for (i = 0; i < tagsCount; i++) { + (*tags)[i] = 100 * (jlong)(i + 1); + } + } + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find static field: %s\n", OBJECTS_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECTS_FIELD_NAME, OBJECTS_FIELD_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); + + NSK_DISPLAY1("Get objects array from static field: %s\n", OBJECTS_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (arrayObject = (jobjectArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array object: 0x%p\n", (void*)arrayObject); + + { + jsize arrayLen = 0; + jsize k; + + if (!NSK_JNI_VERIFY(jni, (arrayLen = + NSK_CPP_STUB2(GetArrayLength, jni, arrayObject)) == size)) { + NSK_DISPLAY1(" ... got array length: %d\n", (int)size); + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array length: %d\n", (int)size); + + for (k = 0; k < size; k++) { + jobject object = NULL; + + if (!NSK_JNI_VERIFY(jni, (object = + NSK_CPP_STUB3(GetObjectArrayElement, jni, arrayObject, k)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + if (!NSK_JNI_VERIFY(jni, (object = + NSK_CPP_STUB2(NewGlobalRef, jni, object)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + (*objects)[k] = object; + } + } + NSK_DISPLAY1(" ... object references created: %d objects\n", size); + + return NSK_TRUE; +} + +/** Release references to the tested objects and free allocated memory. */ +static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int tagsCount, int objectsCount, + jobject *objects, jlong *tags) { + int size = tagsCount * objectsCount; + int k; + + if (objects == NULL) + return NSK_TRUE; + + NSK_DISPLAY1("Release objects references: %d objects\n", size); + for (k = 0; k < size; k++) { + if (objects[k] != NULL) { + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, objects[k])); + } + } + NSK_DISPLAY1(" ... object references released: %d objects\n", size); + + NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objects); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objects))) { + nsk_jvmti_setFailStatus(); + } + + if (tags == NULL) + return NSK_FALSE; + + NSK_DISPLAY1("Deallocate tags list: 0x%p\n", (void*)tags); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)tags))) { + nsk_jvmti_setFailStatus(); + } + + return NSK_TRUE; +} + +/** Get and check tagged objects. */ +static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int tagsCount, int objectsCount, + jlong tags[], jobject objects[], + const char kind[], int expectedCount) { + jint taggedObjectsCount = 0; + jobject* taggedObjectsList = NULL; + jlong* taggedObjectsTags = NULL; + jlong expectedTag = 0; + int k; + + NSK_DISPLAY1("Get tagged objects: %d tags\n", tagsCount); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB6(GetObjectsWithTags, jvmti, tagsCount, tags, + &taggedObjectsCount, &taggedObjectsList, &taggedObjectsTags))) { + nsk_jvmti_setFailStatus(); + return NSK_TRUE; + } + NSK_DISPLAY1(" ... got tagged objects: %d\n", (int)taggedObjectsCount); + + if (taggedObjectsCount != expectedCount) { + NSK_COMPLAIN3("GetObjectsWithTags() returns unexpected number of objects %s:\n" + "# got objects: %d\n" + "# expected: %d\n", + kind, (int)taggedObjectsCount, (int)expectedCount); + nsk_jvmti_setFailStatus(); + } + + if (taggedObjectsList == NULL && taggedObjectsCount > 0) { + NSK_COMPLAIN2("GetObjectsWithTags() returns NULL list of objects %s: 0x%p\n", + kind, (void*)taggedObjectsList); + nsk_jvmti_setFailStatus(); + return NSK_TRUE; + } + + if (taggedObjectsTags == NULL && taggedObjectsCount > 0) { + NSK_COMPLAIN2("GetObjectsWithTags() returns NULL list of tags for objects %s: 0x%p\n", + kind, (void*)taggedObjectsTags); + nsk_jvmti_setFailStatus(); + return NSK_TRUE; + } + + for (k = 0; k < taggedObjectsCount; k++) { + jobject object = taggedObjectsList[k]; + jlong tag = taggedObjectsTags[k]; + int objectsFound = 0; + int i, j, l; + + NSK_DISPLAY3(" #%d: object: 0x%p, tag: %ld\n", k, (void*)object, (long)tag); + + if (object == NULL) { + NSK_COMPLAIN3("GetObjectsWithTags() returns NULL for object #%d %s: 0x%p\n", + k, kind, (void*)object); + nsk_jvmti_setFailStatus(); + continue; + } + + objectsFound = 0; + for (l = k + 1; l < taggedObjectsCount; l++) { + if (object == taggedObjectsList[l]) + objectsFound++; + } + if (objectsFound > 0) { + NSK_COMPLAIN4("GetObjectsWithTags() returns %d duplicates for object #%d %s: 0x%p\n", + objectsFound, k, kind, (void*)object); + nsk_jvmti_setFailStatus(); + continue; + } + + objectsFound = 0; + for (i = 0; i < tagsCount; i++) { + for (j = 0; j < objectsCount; j++) { + jobject foundObject = ITEM(objects, i, j); + + if (NSK_CPP_STUB3(IsSameObject, jni, object, foundObject)) { + objectsFound++; + + if (expectedCount > 0) + expectedTag = tags[i]; + + if (tag != expectedTag) { + NSK_COMPLAIN6("GetObjectsWithTags() returns wrong tag for object #%d %s:\n" + "# got object: 0x%p\n" + "# original: 0x%p\n" + "# got tag: %ld\n" + "# original: %ld\n", + k, kind, + (void*)object, (void*)foundObject, + (long)tag, (long)expectedTag); + nsk_jvmti_setFailStatus(); + } + break; + } + } + + if (objectsFound > 0) + break; + } + + if (objectsFound <= 0) { + NSK_COMPLAIN4("GetObjectsWithTags() returns unexpected #%d object %s:\n" + "# got object: 0x%p\n" + "# got tag: %ld\n", + k, kind, + (void*)object, (long)tag); + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY1("Deallocate got objects list: 0x%p\n", (void*)taggedObjectsList); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)taggedObjectsList))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY1("Deallocate got tags list: 0x%p\n", (void*)taggedObjectsTags); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)taggedObjectsTags))) { + nsk_jvmti_setFailStatus(); + } + + return NSK_TRUE; +} + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for objects created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + int size = tagsCount * objectsCount; + jobject* objects = NULL; + jlong* tags = NULL; + + NSK_DISPLAY0(">>> Obtain tested objects list from a static field of debugee class\n"); + { + if (!NSK_VERIFY(getTestedObjects(jvmti, jni, tagsCount, objectsCount, + &objects, &tags))) + return; + } + + NSK_DISPLAY0(">>> Tagging tested objects with different tags\n"); + { + int i, j; + + for (i = 0; i < tagsCount; i++) { + NSK_DISPLAY2(" tagging with %ld: %d objects\n", (long)tags[i], objectsCount); + for (j = 0; j < objectsCount; j++) { + jobject object = ITEM(objects, i, j); + + NSK_DISPLAY3(" #%d: object: 0x%p, tag: %ld\n", + j, (void*)object, (long)tags[i]); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, object, tags[i]))) { + nsk_jvmti_setFailStatus(); + return; + } + } + } + NSK_DISPLAY1(" ... objects tagged: %d objects\n", (tagsCount * objectsCount)); + } + + NSK_DISPLAY0(">>> Testcase #1: get tagged objects before objects data changed\n"); + { + if (!NSK_VERIFY( + checkTestedObjects(jvmti, jni, tagsCount, objectsCount, + tags, objects, "before changed", size))) + return; + } + + NSK_DISPLAY0(">>> Let debugee to change object data\n"); + { + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + } + + NSK_DISPLAY0(">>> Testcase #2: get tagged objects after objects data are changed\n"); + { + if (!NSK_VERIFY( + checkTestedObjects(jvmti, jni, tagsCount, objectsCount, + tags, objects, "after changed", size))) + return; + } + + NSK_DISPLAY0(">>> Untagging all tested objects (i.e., tagging with zero tag)\n"); + { + jlong tag = 0; + int i, j; + + for (i = 0; i < tagsCount; i++) { + NSK_DISPLAY2(" tagging with %ld: %d objects\n", (long)tag, objectsCount); + for (j = 0; j < objectsCount; j++) { + jobject object = ITEM(objects, i , j); + + NSK_DISPLAY3(" #%d: object: 0x%p, tag: %ld\n", + j, (void*)object, (long)tag); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, object, tag))) { + nsk_jvmti_setFailStatus(); + return; + } + } + } + NSK_DISPLAY1(" ... objects untagged: %d objects\n", (tagsCount * objectsCount)); + } + + NSK_DISPLAY0(">>> Testcase #3: get tagged objects after objects untagged\n"); + { + if (!NSK_VERIFY( + checkTestedObjects(jvmti, jni, tagsCount, objectsCount, + tags, objects, "after untagged", 0))) + return; + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, tagsCount, objectsCount, + objects, tags))) + return; + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_objwithtags001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_objwithtags001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_objwithtags001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* get option values */ + tagsCount = nsk_jvmti_findOptionIntValue("tags", DEFAULT_TAGS_COUNT); + objectsCount = nsk_jvmti_findOptionIntValue("objects", DEFAULT_OBJECTS_COUNT); + if (!NSK_VERIFY(tagsCount > 0 && objectsCount > 0)) + return JNI_ERR; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* add required capabilities */ + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/libownmoninf001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/libownmoninf001.c deleted file mode 100644 index 2f0cd92f398..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/libownmoninf001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ownmoninf001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/libownmoninf001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/libownmoninf001.cpp new file mode 100644 index 00000000000..1f3bb811341 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/libownmoninf001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ownmoninf001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/ownmoninf001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/ownmoninf001.c deleted file mode 100644 index e4c5f3a2f76..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/ownmoninf001.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ownmoninf001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ownmoninf001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ownmoninf001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_owned_monitor_info) { - printf("Warning: GetOwnedMonitorInfo is not implemented\n"); - } - - return JNI_OK; -} - -jobject *getInfo(JNIEnv *env, jint point, jthread thr, int count) { - jvmtiError err; - jint owned_monitor_count; - jobject *owned_monitors = NULL; - - err = (*jvmti)->GetOwnedMonitorInfo(jvmti, thr, - &owned_monitor_count, &owned_monitors); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_owned_monitor_info) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetOwnedMonitorInfo#%d) unexpected error: %s (%d)\n", - point, TranslateError(err), err); - result = STATUS_FAILED; - return NULL; - } else { - if (owned_monitor_count != count) { - result = STATUS_FAILED; - printf("Point %d: number of owned monitors expected: %d, got: %d\n", - point, count, owned_monitor_count); - return NULL; - } - } - return owned_monitors; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf001_checkMon0(JNIEnv *env, - jclass cls, jint point, jthread thr) { - getInfo(env, point, thr, 0); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf001_checkMon1(JNIEnv *env, - jclass cls, jint point, jthread thr, jobject lock) { - jobject *monitors; - if ((monitors = getInfo(env, point, thr, 1)) == NULL) { - return; - } - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, lock), monitors[0]) - == JNI_FALSE) { - result = STATUS_FAILED; - printf("Point %d: not expected monitor: 0x%p\n", point, monitors[0]); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf001_checkMon2(JNIEnv *env, - jclass cls, jint point, jthread thr, jobject lock1, jobject lock2) { - jobject *monitors; - if ((monitors = getInfo(env, point, thr, 2)) == NULL) { - return; - } - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, lock1), monitors[0]) - == JNI_FALSE && - JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, lock2), monitors[0]) - == JNI_FALSE) { - result = STATUS_FAILED; - printf("Point %d: not expected monitor: 0x%p\n", point, monitors[0]); - } - if ((JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, lock1), monitors[1]) - == JNI_FALSE && - JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, lock2), monitors[1]) - == JNI_FALSE) || - JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, monitors[0]), - monitors[1]) == JNI_TRUE) { - result = STATUS_FAILED; - printf("Point %d: not expected monitor: 0x%p\n", point, monitors[1]); - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/ownmoninf001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/ownmoninf001.cpp new file mode 100644 index 00000000000..2337dbcad79 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/ownmoninf001.cpp @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ownmoninf001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ownmoninf001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ownmoninf001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_owned_monitor_info) { + printf("Warning: GetOwnedMonitorInfo is not implemented\n"); + } + + return JNI_OK; +} + +jobject *getInfo(JNIEnv *env, jint point, jthread thr, int count) { + jvmtiError err; + jint owned_monitor_count; + jobject *owned_monitors = NULL; + + err = jvmti->GetOwnedMonitorInfo(thr, + &owned_monitor_count, &owned_monitors); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_owned_monitor_info) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetOwnedMonitorInfo#%d) unexpected error: %s (%d)\n", + point, TranslateError(err), err); + result = STATUS_FAILED; + return NULL; + } else { + if (owned_monitor_count != count) { + result = STATUS_FAILED; + printf("Point %d: number of owned monitors expected: %d, got: %d\n", + point, count, owned_monitor_count); + return NULL; + } + } + return owned_monitors; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf001_checkMon0(JNIEnv *env, + jclass cls, jint point, jthread thr) { + getInfo(env, point, thr, 0); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf001_checkMon1(JNIEnv *env, + jclass cls, jint point, jthread thr, jobject lock) { + jobject *monitors; + if ((monitors = getInfo(env, point, thr, 1)) == NULL) { + return; + } + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, lock), monitors[0]) + == JNI_FALSE) { + result = STATUS_FAILED; + printf("Point %d: not expected monitor: 0x%p\n", point, monitors[0]); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf001_checkMon2(JNIEnv *env, + jclass cls, jint point, jthread thr, jobject lock1, jobject lock2) { + jobject *monitors; + if ((monitors = getInfo(env, point, thr, 2)) == NULL) { + return; + } + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, lock1), monitors[0]) + == JNI_FALSE && + JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, lock2), monitors[0]) + == JNI_FALSE) { + result = STATUS_FAILED; + printf("Point %d: not expected monitor: 0x%p\n", point, monitors[0]); + } + if ((JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, lock1), monitors[1]) + == JNI_FALSE && + JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, lock2), monitors[1]) + == JNI_FALSE) || + JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, monitors[0]), + monitors[1]) == JNI_TRUE) { + result = STATUS_FAILED; + printf("Point %d: not expected monitor: 0x%p\n", point, monitors[1]); + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/libownmoninf002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/libownmoninf002.c deleted file mode 100644 index cbc20ed095d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/libownmoninf002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ownmoninf002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/libownmoninf002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/libownmoninf002.cpp new file mode 100644 index 00000000000..e38f6aa8f2e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/libownmoninf002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ownmoninf002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/ownmoninf002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/ownmoninf002.c deleted file mode 100644 index bc7a4478744..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/ownmoninf002.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ownmoninf002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ownmoninf002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ownmoninf002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_owned_monitor_info) { - printf("Warning: GetOwnedMonitorInfo is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf002_checkMon(JNIEnv *env, - jclass cls, jthread thr) { - jvmtiError err; - jint owned_monitor_count; - jobject *owned_monitors; - - err = (*jvmti)->GetOwnedMonitorInfo(jvmti, thr, - &owned_monitor_count, &owned_monitors); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_owned_monitor_info) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetOwnedMonitorInfo) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf002_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/ownmoninf002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/ownmoninf002.cpp new file mode 100644 index 00000000000..1387db23faa --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf002/ownmoninf002.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ownmoninf002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ownmoninf002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ownmoninf002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_owned_monitor_info) { + printf("Warning: GetOwnedMonitorInfo is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf002_checkMon(JNIEnv *env, + jclass cls, jthread thr) { + jvmtiError err; + jint owned_monitor_count; + jobject *owned_monitors; + + err = jvmti->GetOwnedMonitorInfo(thr, + &owned_monitor_count, &owned_monitors); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_owned_monitor_info) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetOwnedMonitorInfo) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf002_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/libownmoninf003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/libownmoninf003.c deleted file mode 100644 index e48d68a198b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/libownmoninf003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ownmoninf003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/libownmoninf003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/libownmoninf003.cpp new file mode 100644 index 00000000000..4ab35755522 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/libownmoninf003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ownmoninf003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/ownmoninf003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/ownmoninf003.c deleted file mode 100644 index bfb9c6429ae..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/ownmoninf003.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ownmoninf003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ownmoninf003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ownmoninf003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_owned_monitor_info) { - printf("Warning: GetOwnedMonitorInfo is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf003_check(JNIEnv *env, - jclass cls, jthread thr) { - jvmtiError err; - jint owned_monitor_count; - jobject *owned_monitors; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid thread check ...\n"); - } - err = (*jvmti)->GetOwnedMonitorInfo(jvmti, cls, - &owned_monitor_count, &owned_monitors); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_owned_monitor_info) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (owned_monitor_count_ptr) null pointer check ...\n"); - } - err = (*jvmti)->GetOwnedMonitorInfo(jvmti, thr, NULL, &owned_monitors); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_monitor_info) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (owned_monitors_ptr) null pointer check ...\n"); - } - err = (*jvmti)->GetOwnedMonitorInfo(jvmti, thr, &owned_monitor_count, NULL); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_monitor_info) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/ownmoninf003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/ownmoninf003.cpp new file mode 100644 index 00000000000..99afe2e200d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf003/ownmoninf003.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ownmoninf003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ownmoninf003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ownmoninf003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_owned_monitor_info) { + printf("Warning: GetOwnedMonitorInfo is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf003_check(JNIEnv *env, + jclass cls, jthread thr) { + jvmtiError err; + jint owned_monitor_count; + jobject *owned_monitors; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid thread check ...\n"); + } + err = jvmti->GetOwnedMonitorInfo(cls, + &owned_monitor_count, &owned_monitors); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_owned_monitor_info) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (owned_monitor_count_ptr) null pointer check ...\n"); + } + err = jvmti->GetOwnedMonitorInfo(thr, NULL, &owned_monitors); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_monitor_info) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (owned_monitors_ptr) null pointer check ...\n"); + } + err = jvmti->GetOwnedMonitorInfo(thr, &owned_monitor_count, NULL); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_monitor_info) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/getphase001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/getphase001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/getphase001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/getphase001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/libgetphase001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/libgetphase001.c deleted file mode 100644 index 00f2105c18d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/libgetphase001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getphase001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/libgetphase001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/libgetphase001.cpp new file mode 100644 index 00000000000..b6953217125 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase001/libgetphase001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getphase001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/getphase002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/getphase002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/getphase002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/getphase002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/libgetphase002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/libgetphase002.c deleted file mode 100644 index 4ee627b643e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/libgetphase002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getphase002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/libgetphase002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/libgetphase002.cpp new file mode 100644 index 00000000000..696898f5a5a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPhase/getphase002/libgetphase002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getphase002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/getpotcaps001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/getpotcaps001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/getpotcaps001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/getpotcaps001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/libgetpotcaps001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/libgetpotcaps001.c deleted file mode 100644 index 77c5352384e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/libgetpotcaps001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getpotcaps001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/libgetpotcaps001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/libgetpotcaps001.cpp new file mode 100644 index 00000000000..7dca53bb4f8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetPotentialCapabilities/getpotcaps001/libgetpotcaps001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getpotcaps001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/libsrcdebugex001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/libsrcdebugex001.c deleted file mode 100644 index ee426eedb33..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/libsrcdebugex001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "srcdebugex001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/libsrcdebugex001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/libsrcdebugex001.cpp new file mode 100644 index 00000000000..3a2e42f8bc4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/libsrcdebugex001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "srcdebugex001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/srcdebugex001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/srcdebugex001.c deleted file mode 100644 index c59be342905..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/srcdebugex001.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static int result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_srcdebugex001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_srcdebugex001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_srcdebugex001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_source_debug_extension) { - printf("Warning: GetSourceDebugExtension is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetSourceDebugExtension_srcdebugex001_getSrcDebugX(JNIEnv *env, - jclass cls, jboolean vrb) { - jvmtiError err; - char *srcDebugX = NULL; - - if (!caps.can_get_source_debug_extension) return result; - - err = (*jvmti)->GetSourceDebugExtension(jvmti, cls, &srcDebugX); - switch (err) { - case JVMTI_ERROR_NONE: - if (vrb == JNI_TRUE) { - printf("TEST PASSED: GetSourceDebugExtension() is successfully done\n"); - printf("\tthe debug extension information is \"%s\"", srcDebugX); - } - err = (*jvmti)->Deallocate(jvmti, (unsigned char *) srcDebugX); - if (err != JVMTI_ERROR_NONE) { - printf("(Deallocate) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - break; - case JVMTI_ERROR_ABSENT_INFORMATION: - if (vrb == JNI_TRUE) - printf("TEST PASSED: GetSourceDebugExtension() returned the expected error %s (%d)\n", - TranslateError(err), err); - break; - default: - printf("TEST FAILED: the function GetSourceDebugExtension() returned the error %s (%d)\n", - TranslateError(err), err); - printf("\tFor more info about this error please refer to the JVMTI spec.\n"); - result = STATUS_FAILED; - break; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/srcdebugex001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/srcdebugex001.cpp new file mode 100644 index 00000000000..19214b9af9c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex001/srcdebugex001.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static int result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_srcdebugex001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_srcdebugex001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_srcdebugex001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_source_debug_extension) { + printf("Warning: GetSourceDebugExtension is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetSourceDebugExtension_srcdebugex001_getSrcDebugX(JNIEnv *env, + jclass cls, jboolean vrb) { + jvmtiError err; + char *srcDebugX = NULL; + + if (!caps.can_get_source_debug_extension) return result; + + err = jvmti->GetSourceDebugExtension(cls, &srcDebugX); + switch (err) { + case JVMTI_ERROR_NONE: + if (vrb == JNI_TRUE) { + printf("TEST PASSED: GetSourceDebugExtension() is successfully done\n"); + printf("\tthe debug extension information is \"%s\"", srcDebugX); + } + err = jvmti->Deallocate((unsigned char *) srcDebugX); + if (err != JVMTI_ERROR_NONE) { + printf("(Deallocate) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + break; + case JVMTI_ERROR_ABSENT_INFORMATION: + if (vrb == JNI_TRUE) + printf("TEST PASSED: GetSourceDebugExtension() returned the expected error %s (%d)\n", + TranslateError(err), err); + break; + default: + printf("TEST FAILED: the function GetSourceDebugExtension() returned the error %s (%d)\n", + TranslateError(err), err); + printf("\tFor more info about this error please refer to the JVMTI spec.\n"); + result = STATUS_FAILED; + break; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/libsrcdebugex002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/libsrcdebugex002.c deleted file mode 100644 index e214b566826..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/libsrcdebugex002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "srcdebugex002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/libsrcdebugex002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/libsrcdebugex002.cpp new file mode 100644 index 00000000000..4761d076bb6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/libsrcdebugex002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "srcdebugex002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/srcdebugex002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/srcdebugex002.c deleted file mode 100644 index ad7c06c6657..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/srcdebugex002.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static int result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_srcdebugex002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_srcdebugex002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_srcdebugex002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_source_debug_extension) { - printf("Warning: GetSourceDebugExtension is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetSourceDebugExtension_srcdebugex002_getSrcDebugX(JNIEnv *env, - jclass cls, jint t_case) { - jvmtiError err; - char *srcDebugX = NULL; - jobject invalCls; /* used as invalid class */ - - if (!caps.can_get_source_debug_extension) return result; - - switch (t_case) { - case 1: /* NULL pointer in test debug mode */ - printf("\nInvoke GetSourceDebugExtension() with NULL pointer...\n"); - fflush(stdout); - // fallthrough - case 0: /* NULL pointer */ - err = (*jvmti)->GetSourceDebugExtension(jvmti, cls, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("TEST FAILED: the function GetSourceDebugExtension() returned the error %s (%d)\n", - TranslateError(err), err); - printf("\tBut it should return the error JVMTI_ERROR_NULL_POINTER.\n"); - result = STATUS_FAILED; - } - break; - case 3: /* invalid class in test debug mode */ - printf("\nInvoke GetSourceDebugExtension() for an invalid class...\n"); - fflush(stdout); - // fallthrough - case 2: /* invalid class */ - err = (*jvmti)->GetClassLoader(jvmti, cls, &invalCls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassLoader) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - err = (*jvmti)->GetSourceDebugExtension(jvmti, invalCls, &srcDebugX); - if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("TEST FAILED: the function GetSourceDebugExtension() returned the error %s (%d)\n", - TranslateError(err), err); - printf("\tBut it should return the error JVMTI_ERROR_INVALID_CLASS.\n"); - result = STATUS_FAILED; - } - } - break; - default: - break; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/srcdebugex002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/srcdebugex002.cpp new file mode 100644 index 00000000000..d66a41a098d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex002/srcdebugex002.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static int result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_srcdebugex002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_srcdebugex002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_srcdebugex002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_source_debug_extension) { + printf("Warning: GetSourceDebugExtension is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetSourceDebugExtension_srcdebugex002_getSrcDebugX(JNIEnv *env, + jclass cls, jint t_case) { + jvmtiError err; + char *srcDebugX = NULL; + jobject invalCls; /* used as invalid class */ + + if (!caps.can_get_source_debug_extension) return result; + + switch (t_case) { + case 1: /* NULL pointer in test debug mode */ + printf("\nInvoke GetSourceDebugExtension() with NULL pointer...\n"); + fflush(stdout); + // fallthrough + case 0: /* NULL pointer */ + err = jvmti->GetSourceDebugExtension(cls, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("TEST FAILED: the function GetSourceDebugExtension() returned the error %s (%d)\n", + TranslateError(err), err); + printf("\tBut it should return the error JVMTI_ERROR_NULL_POINTER.\n"); + result = STATUS_FAILED; + } + break; + case 3: /* invalid class in test debug mode */ + printf("\nInvoke GetSourceDebugExtension() for an invalid class...\n"); + fflush(stdout); + // fallthrough + case 2: /* invalid class */ + err = jvmti->GetClassLoader(cls, &invalCls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassLoader) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + err = jvmti->GetSourceDebugExtension((jclass) invalCls, &srcDebugX); + if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("TEST FAILED: the function GetSourceDebugExtension() returned the error %s (%d)\n", + TranslateError(err), err); + printf("\tBut it should return the error JVMTI_ERROR_INVALID_CLASS.\n"); + result = STATUS_FAILED; + } + } + break; + default: + break; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/libsrcdebugex003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/libsrcdebugex003.c deleted file mode 100644 index 8b919e3fc22..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/libsrcdebugex003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "srcdebugex003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/libsrcdebugex003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/libsrcdebugex003.cpp new file mode 100644 index 00000000000..39d750b5dad --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/libsrcdebugex003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "srcdebugex003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/srcdebugex003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/srcdebugex003.c deleted file mode 100644 index 42ca08bbdbc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/srcdebugex003.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -#define DEBUGXSTR "An expected attribute string" - -jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static int result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_srcdebugex003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_srcdebugex003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_srcdebugex003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_source_debug_extension) { - printf("Warning: GetSourceDebugExtension is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetSourceDebugExtension_srcdebugex003_getSrcDebugX(JNIEnv *env, - jclass cls, jboolean vrb) { - jvmtiError err; - char *srcDebugX = NULL; - - if (!caps.can_get_source_debug_extension) return result; - - if (vrb == JNI_TRUE) - printf(">>>>>>>> Invoking GetSourceDebugExtension()...\n"); - err = (*jvmti)->GetSourceDebugExtension(jvmti, cls, &srcDebugX); - if (err != JVMTI_ERROR_NONE) { - printf("%s: Failed to call GetSourceDebugExtension():\n", __FILE__); - printf("\tthe function returned the error: %s (%d)\n", - TranslateError(err), err); - printf("\tFor more info about this error please refer to the JVMTI spec.\n"); - return STATUS_FAILED; - } - if (vrb == JNI_TRUE) - printf("<<<<<<<< GetSourceDebugExtension() is successfully done\n"); - - if (strcmp(srcDebugX, DEBUGXSTR) != 0) { - printf("TEST FAILED: obtained SourceDebugExtension attribute is \"%s\"\n", - srcDebugX); - printf("\texpected: \"%s\"\n\n", DEBUGXSTR); - result = STATUS_FAILED; - } else { - if (vrb == JNI_TRUE) - printf("TEST PASSED: got the expected SourceDebugExtension attribute: \"%s\"\n\n", - srcDebugX); - result = PASSED; - } - - err = (*jvmti)->Deallocate(jvmti, (unsigned char*) srcDebugX); - if (err != JVMTI_ERROR_NONE) { - printf("TEST FAILED: the function Deallocate() returned the error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - return (result); -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/srcdebugex003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/srcdebugex003.cpp new file mode 100644 index 00000000000..6052f802c8c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceDebugExtension/srcdebugex003/srcdebugex003.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +#define DEBUGXSTR "An expected attribute string" + +jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static int result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_srcdebugex003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_srcdebugex003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_srcdebugex003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_source_debug_extension) { + printf("Warning: GetSourceDebugExtension is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetSourceDebugExtension_srcdebugex003_getSrcDebugX(JNIEnv *env, + jclass cls, jboolean vrb) { + jvmtiError err; + char *srcDebugX = NULL; + + if (!caps.can_get_source_debug_extension) return result; + + if (vrb == JNI_TRUE) + printf(">>>>>>>> Invoking GetSourceDebugExtension()...\n"); + err = jvmti->GetSourceDebugExtension(cls, &srcDebugX); + if (err != JVMTI_ERROR_NONE) { + printf("%s: Failed to call GetSourceDebugExtension():\n", __FILE__); + printf("\tthe function returned the error: %s (%d)\n", + TranslateError(err), err); + printf("\tFor more info about this error please refer to the JVMTI spec.\n"); + return STATUS_FAILED; + } + if (vrb == JNI_TRUE) + printf("<<<<<<<< GetSourceDebugExtension() is successfully done\n"); + + if (strcmp(srcDebugX, DEBUGXSTR) != 0) { + printf("TEST FAILED: obtained SourceDebugExtension attribute is \"%s\"\n", + srcDebugX); + printf("\texpected: \"%s\"\n\n", DEBUGXSTR); + result = STATUS_FAILED; + } else { + if (vrb == JNI_TRUE) + printf("TEST PASSED: got the expected SourceDebugExtension attribute: \"%s\"\n\n", + srcDebugX); + result = PASSED; + } + + err = jvmti->Deallocate((unsigned char*) srcDebugX); + if (err != JVMTI_ERROR_NONE) { + printf("TEST FAILED: the function Deallocate() returned the error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + return (result); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/getsrcfn004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/getsrcfn004.c deleted file mode 100644 index 0df94affe98..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/getsrcfn004.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jvmtiCapabilities caps; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getsrcfn004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getsrcfn004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getsrcfn004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - res = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (res != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(res), res); - return JNI_ERR; - } - - res = (*jvmti)->AddCapabilities(jvmti, &caps); - if (res != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(res), res); - return JNI_ERR; - } - - res = (*jvmti)->GetCapabilities(jvmti, &caps); - if (res != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(res), res); - return JNI_ERR; - } - - if (!caps.can_get_source_file_name) { - printf("Warning: Not implemented capability can_get_source_file_name\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetSourceFileName_getsrcfn004_check(JNIEnv *env, jclass cls) { - jvmtiError err; - char *name; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->GetSourceFileName(jvmti, NULL, &name); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && caps.can_get_source_file_name) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } else if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetSourceFileName(jvmti, cls, NULL); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && caps.can_get_source_file_name) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } else if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/getsrcfn004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/getsrcfn004.cpp new file mode 100644 index 00000000000..a2f8b42df0c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/getsrcfn004.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jvmtiCapabilities caps; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getsrcfn004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getsrcfn004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getsrcfn004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint code; + jvmtiError res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + code = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (code != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + res = jvmti->GetPotentialCapabilities(&caps); + if (res != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(res), res); + return JNI_ERR; + } + + res = jvmti->AddCapabilities(&caps); + if (res != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(res), res); + return JNI_ERR; + } + + res = jvmti->GetCapabilities(&caps); + if (res != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(res), res); + return JNI_ERR; + } + + if (!caps.can_get_source_file_name) { + printf("Warning: Not implemented capability can_get_source_file_name\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetSourceFileName_getsrcfn004_check(JNIEnv *env, jclass cls) { + jvmtiError err; + char *name; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->GetSourceFileName(NULL, &name); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && caps.can_get_source_file_name) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } else if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetSourceFileName(cls, NULL); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && caps.can_get_source_file_name) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } else if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/libgetsrcfn004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/libgetsrcfn004.c deleted file mode 100644 index 18b9812460a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/libgetsrcfn004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getsrcfn004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/libgetsrcfn004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/libgetsrcfn004.cpp new file mode 100644 index 00000000000..8f9afcf9859 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn004/libgetsrcfn004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getsrcfn004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/getsrcfn005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/getsrcfn005.c deleted file mode 100644 index 6275f34ad22..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/getsrcfn005.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jvmtiCapabilities caps; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getsrcfn005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getsrcfn005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getsrcfn005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - res = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (res != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(res), res); - return JNI_ERR; - } - - res = (*jvmti)->AddCapabilities(jvmti, &caps); - if (res != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(res), res); - return JNI_ERR; - } - - res = (*jvmti)->GetCapabilities(jvmti, &caps); - if (res != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(res), res); - return JNI_ERR; - } - - if (!caps.can_get_source_file_name) { - printf("Warning: Not implemented capability can_get_source_file_name\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetSourceFileName_getsrcfn005_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { - jvmtiError err; - char *name; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> trying #%d\n", i); - } - - err = (*jvmti)->GetSourceFileName(jvmti, clazz, &name); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && caps.can_get_source_file_name) { - printf("Error expected: JVMTI_ERROR_ABSENT_INFORMATION,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } else if (err != JVMTI_ERROR_ABSENT_INFORMATION) { - printf("(%d) error expected: JVMTI_ERROR_ABSENT_INFORMATION,\n", i); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL Java_nsk_jvmti_GetSourceFileName_getsrcfn005_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/getsrcfn005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/getsrcfn005.cpp new file mode 100644 index 00000000000..4bbe79d706d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/getsrcfn005.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jvmtiCapabilities caps; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getsrcfn005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getsrcfn005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getsrcfn005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError res; + jint code; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + code = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (code != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + res = jvmti->GetPotentialCapabilities(&caps); + if (res != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(res), res); + return JNI_ERR; + } + + res = jvmti->AddCapabilities(&caps); + if (res != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(res), res); + return JNI_ERR; + } + + res = jvmti->GetCapabilities(&caps); + if (res != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(res), res); + return JNI_ERR; + } + + if (!caps.can_get_source_file_name) { + printf("Warning: Not implemented capability can_get_source_file_name\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetSourceFileName_getsrcfn005_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { + jvmtiError err; + char *name; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> trying #%d\n", i); + } + + err = jvmti->GetSourceFileName(clazz, &name); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && caps.can_get_source_file_name) { + printf("Error expected: JVMTI_ERROR_ABSENT_INFORMATION,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } else if (err != JVMTI_ERROR_ABSENT_INFORMATION) { + printf("(%d) error expected: JVMTI_ERROR_ABSENT_INFORMATION,\n", i); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL Java_nsk_jvmti_GetSourceFileName_getsrcfn005_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/libgetsrcfn005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/libgetsrcfn005.c deleted file mode 100644 index e277816e14d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/libgetsrcfn005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getsrcfn005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/libgetsrcfn005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/libgetsrcfn005.cpp new file mode 100644 index 00000000000..e4d7f16c1d0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn005/libgetsrcfn005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getsrcfn005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/getsrcfn006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/getsrcfn006.c deleted file mode 100644 index 8165e0a6bc4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/getsrcfn006.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jvmtiCapabilities caps; -static const char *fnames[] = { - "getsrcfn006.java", - "getsrcfn006a.java", - "getsrcfn006b.java", - "getsrcfn006c.java" -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getsrcfn006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getsrcfn006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getsrcfn006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - res = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (res != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(res), res); - return JNI_ERR; - } - - res = (*jvmti)->AddCapabilities(jvmti, &caps); - if (res != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(res), res); - return JNI_ERR; - } - - res = (*jvmti)->GetCapabilities(jvmti, &caps); - if (res != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(res), res); - return JNI_ERR; - } - - if (!caps.can_get_source_file_name) { - printf("Warning: Not implemented capability can_get_source_file_name\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetSourceFileName_getsrcfn006_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { - jvmtiError err; - char *name; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetSourceFileName(jvmti, clazz, &name); - if (err != JVMTI_ERROR_NONE) { - printf("(GetSourceFileName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> %d: \"%s\"\n", i, name); - } - - if (strcmp(name, fnames[i]) != 0) { - printf("(%d) wrong source file name: \"%s\", expected: \"%s\"\n", - i, name, fnames[i]); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL Java_nsk_jvmti_GetSourceFileName_getsrcfn006_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/getsrcfn006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/getsrcfn006.cpp new file mode 100644 index 00000000000..867f40a557c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/getsrcfn006.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jvmtiCapabilities caps; +static const char *fnames[] = { + "getsrcfn006.java", + "getsrcfn006a.java", + "getsrcfn006b.java", + "getsrcfn006c.java" +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getsrcfn006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getsrcfn006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getsrcfn006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError res; + jint code; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + code = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (code != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + res = jvmti->GetPotentialCapabilities(&caps); + if (res != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(res), res); + return JNI_ERR; + } + + res = jvmti->AddCapabilities(&caps); + if (res != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(res), res); + return JNI_ERR; + } + + res = jvmti->GetCapabilities(&caps); + if (res != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(res), res); + return JNI_ERR; + } + + if (!caps.can_get_source_file_name) { + printf("Warning: Not implemented capability can_get_source_file_name\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetSourceFileName_getsrcfn006_check(JNIEnv *env, jclass cls, jint i, jclass clazz) { + jvmtiError err; + char *name; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetSourceFileName(clazz, &name); + if (err != JVMTI_ERROR_NONE) { + printf("(GetSourceFileName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> %d: \"%s\"\n", i, name); + } + + if (strcmp(name, fnames[i]) != 0) { + printf("(%d) wrong source file name: \"%s\", expected: \"%s\"\n", + i, name, fnames[i]); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL Java_nsk_jvmti_GetSourceFileName_getsrcfn006_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/libgetsrcfn006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/libgetsrcfn006.c deleted file mode 100644 index 3ada3ae85c7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/libgetsrcfn006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getsrcfn006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/libgetsrcfn006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/libgetsrcfn006.cpp new file mode 100644 index 00000000000..8745c560c22 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSourceFileName/getsrcfn006/libgetsrcfn006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getsrcfn006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/getstacktr001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/getstacktr001.c deleted file mode 100644 index b1c1551145f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/getstacktr001.c +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls; - char *name; - char *sig; -} frame_info; - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static frame_info frames[] = { - {"Lnsk/jvmti/GetStackTrace/getstacktr001;", "check", - "(Ljava/lang/Thread;)V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr001;", "dummy", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr001;", "chain", "()I"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr001;", "run", - "([Ljava/lang/String;Ljava/io/PrintStream;)I"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr001;", "main", - "([Ljava/lang/String;)V"} -}; - -#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getstacktr001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr001_chain(JNIEnv *env, jclass cls) { - jmethodID mid; - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "dummy", "()V"); - JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, cls), mid); - - return result; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr001_check(JNIEnv *env, jclass cls, jthread thread) { - jvmtiError err; - jvmtiFrameInfo f[NUMBER_OF_FRAMES + 1]; - jclass callerClass; - char *sigClass, *name, *sig, *generic; - jint i, count; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetStackTrace(jvmti, thread, 0, - NUMBER_OF_FRAMES + 1, f, &count); - if (err != JVMTI_ERROR_NONE) { - printf("(GetStackTrace) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - if (count != NUMBER_OF_FRAMES) { - printf("Wrong number of frames: %d, expected: %d\n", - count, NUMBER_OF_FRAMES); - result = STATUS_FAILED; - } - for (i = 0; i < count; i++) { - if (printdump == JNI_TRUE) { - printf(">>> checking frame#%d ...\n", i); - } - err = (*jvmti)->GetMethodDeclaringClass(jvmti, - f[i].method, &callerClass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti)->GetClassSignature(jvmti, callerClass, - &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti)->GetMethodName(jvmti, f[i].method, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", sigClass); - printf(">>> method: \"%s%s\"\n", name, sig); - printf(">>> %d ... done\n", i); - } - if (i < NUMBER_OF_FRAMES) { - if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) { - printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n", - i, sigClass, frames[i].cls); - result = STATUS_FAILED; - } - if (name == NULL || strcmp(name, frames[i].name) != 0) { - printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n", - i, name, frames[i].name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { - printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n", - i, sig, frames[i].sig); - result = STATUS_FAILED; - } - } - } -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/getstacktr001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/getstacktr001.cpp new file mode 100644 index 00000000000..bcf8b50c38e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/getstacktr001.cpp @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls; + const char *name; + const char *sig; +} frame_info; + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static frame_info frames[] = { + {"Lnsk/jvmti/GetStackTrace/getstacktr001;", "check", + "(Ljava/lang/Thread;)V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr001;", "dummy", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr001;", "chain", "()I"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr001;", "run", + "([Ljava/lang/String;Ljava/io/PrintStream;)I"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr001;", "main", + "([Ljava/lang/String;)V"} +}; + +#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getstacktr001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr001_chain(JNIEnv *env, jclass cls) { + jmethodID mid; + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "dummy", "()V"); + JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, cls), mid); + + return result; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr001_check(JNIEnv *env, jclass cls, jthread thread) { + jvmtiError err; + jvmtiFrameInfo f[NUMBER_OF_FRAMES + 1]; + jclass callerClass; + char *sigClass, *name, *sig, *generic; + jint i, count; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetStackTrace(thread, 0, + NUMBER_OF_FRAMES + 1, f, &count); + if (err != JVMTI_ERROR_NONE) { + printf("(GetStackTrace) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + if (count != NUMBER_OF_FRAMES) { + printf("Wrong number of frames: %d, expected: %d\n", + count, NUMBER_OF_FRAMES); + result = STATUS_FAILED; + } + for (i = 0; i < count; i++) { + if (printdump == JNI_TRUE) { + printf(">>> checking frame#%d ...\n", i); + } + err = jvmti->GetMethodDeclaringClass( + f[i].method, &callerClass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti->GetClassSignature(callerClass, + &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti->GetMethodName(f[i].method, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", sigClass); + printf(">>> method: \"%s%s\"\n", name, sig); + printf(">>> %d ... done\n", i); + } + if (i < NUMBER_OF_FRAMES) { + if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) { + printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n", + i, sigClass, frames[i].cls); + result = STATUS_FAILED; + } + if (name == NULL || strcmp(name, frames[i].name) != 0) { + printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n", + i, name, frames[i].name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { + printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n", + i, sig, frames[i].sig); + result = STATUS_FAILED; + } + } + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/libgetstacktr001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/libgetstacktr001.c deleted file mode 100644 index 765694aed19..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/libgetstacktr001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getstacktr001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/libgetstacktr001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/libgetstacktr001.cpp new file mode 100644 index 00000000000..b5931fc5b50 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/libgetstacktr001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getstacktr001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/getstacktr002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/getstacktr002.c deleted file mode 100644 index 070608f549d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/getstacktr002.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getstacktr002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr002_check(JNIEnv *env, jclass cls, jthread thread) { - jvmtiError err; - jvmtiFrameInfo frame; - jint count; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> Invalid thread check ...\n"); - } - err = (*jvmti)->GetStackTrace(jvmti, cls, 0, 1, &frame, &count); - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("Error expected: JVMTI_ERROR_INVALID_THREAD, got: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> Illegal max_count argument check ...\n"); - } - err = (*jvmti)->GetStackTrace(jvmti, thread, 0, -1, &frame, &count); - if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { - printf("Error expected: JVMTI_ERROR_ILLEGAL_ARGUMENT, got: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (stack_buffer) null pointer check ...\n"); - } - err = (*jvmti)->GetStackTrace(jvmti, thread, 0, 1, NULL, &count); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(stack_buffer) error expected: JVMTI_ERROR_NULL_POINTER,"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (count_ptr) null pointer check ...\n"); - } - err = (*jvmti)->GetStackTrace(jvmti, thread, 0, 1, &frame, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(count_ptr) error expected: JVMTI_ERROR_NULL_POINTER,"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/getstacktr002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/getstacktr002.cpp new file mode 100644 index 00000000000..2d7e5921fac --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/getstacktr002.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getstacktr002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr002_check(JNIEnv *env, jclass cls, jthread thread) { + jvmtiError err; + jvmtiFrameInfo frame; + jint count; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> Invalid thread check ...\n"); + } + err = jvmti->GetStackTrace(cls, 0, 1, &frame, &count); + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("Error expected: JVMTI_ERROR_INVALID_THREAD, got: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> Illegal max_count argument check ...\n"); + } + err = jvmti->GetStackTrace(thread, 0, -1, &frame, &count); + if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { + printf("Error expected: JVMTI_ERROR_ILLEGAL_ARGUMENT, got: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (stack_buffer) null pointer check ...\n"); + } + err = jvmti->GetStackTrace(thread, 0, 1, NULL, &count); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(stack_buffer) error expected: JVMTI_ERROR_NULL_POINTER,"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (count_ptr) null pointer check ...\n"); + } + err = jvmti->GetStackTrace(thread, 0, 1, &frame, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(count_ptr) error expected: JVMTI_ERROR_NULL_POINTER,"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/libgetstacktr002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/libgetstacktr002.c deleted file mode 100644 index 1f5c056803a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/libgetstacktr002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getstacktr002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/libgetstacktr002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/libgetstacktr002.cpp new file mode 100644 index 00000000000..40004b1b207 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/libgetstacktr002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getstacktr002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/getstacktr003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/getstacktr003.c deleted file mode 100644 index f86002e4410..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/getstacktr003.c +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls; - char *name; - char *sig; -} frame_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static frame_info frames[] = { - {"Ljava/lang/Object;", "wait", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr003;", "dummy", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr003;", "chain", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr003$TestThread;", "run", "()V"}, -}; - -#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) -#define MAX_NUMBER_OF_FRAMES 32 - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getstacktr003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_suspend) { - printf("Warning: suspend/resume is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr003_chain(JNIEnv *env, jclass cls) { - jmethodID mid; - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "dummy", "()V"); - if (mid == NULL) { - printf("Could not find method ID for dummy()V!\n"); - } else { - JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, cls), mid); - } - - return; -} - -JNIEXPORT int JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr003_check(JNIEnv *env, jclass cls, jthread thread) { - jvmtiError err; - jvmtiFrameInfo f[MAX_NUMBER_OF_FRAMES]; - jclass callerClass; - char *sigClass, *name, *sig, *generic; - jint i, count; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_suspend) { - return result; - } - - err = (*jvmti)->SuspendThread(jvmti, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(SuspendThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return result; - } - - err = (*jvmti)->GetStackTrace(jvmti, thread, - 0, MAX_NUMBER_OF_FRAMES, f, &count); - if (err != JVMTI_ERROR_NONE) { - printf("(GetStackTrace) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return result; - } - if (count < NUMBER_OF_FRAMES) { - printf("Number of frames: %d is less then expected: %d\n", - count, NUMBER_OF_FRAMES); - result = STATUS_FAILED; - } - for (i = 0; i < count; i++) { - if (printdump == JNI_TRUE) { - printf(">>> checking frame#%d ...\n", count-1-i); - } - err = (*jvmti)->GetMethodDeclaringClass(jvmti, f[count-1-i].method, - &callerClass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - count-1-i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti)->GetClassSignature(jvmti, callerClass, - &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - count-1-i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti)->GetMethodName(jvmti, f[count-1-i].method, - &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - count-1-i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", sigClass); - printf(">>> method: \"%s%s\"\n", name, sig); - printf(">>> %d ... done\n", i); - } - if (i < NUMBER_OF_FRAMES) { - if (sigClass == NULL || strcmp(sigClass, frames[NUMBER_OF_FRAMES-1-i].cls) != 0) { - printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n", - NUMBER_OF_FRAMES-1-i, sigClass, frames[NUMBER_OF_FRAMES-1-i].cls); - result = STATUS_FAILED; - } - if (name == NULL || strcmp(name, frames[NUMBER_OF_FRAMES-1-i].name) != 0) { - printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n", - NUMBER_OF_FRAMES-1-i, name, frames[NUMBER_OF_FRAMES-1-i].name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, frames[NUMBER_OF_FRAMES-1-i].sig) != 0) { - printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n", - NUMBER_OF_FRAMES-1-i, sig, frames[NUMBER_OF_FRAMES-1-i].sig); - result = STATUS_FAILED; - } - } - } - - err = (*jvmti)->ResumeThread(jvmti, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(ResumeThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/getstacktr003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/getstacktr003.cpp new file mode 100644 index 00000000000..0952564af23 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/getstacktr003.cpp @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls; + const char *name; + const char *sig; +} frame_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static frame_info frames[] = { + {"Ljava/lang/Object;", "wait", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr003;", "dummy", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr003;", "chain", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr003$TestThread;", "run", "()V"}, +}; + +#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) +#define MAX_NUMBER_OF_FRAMES 32 + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getstacktr003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_suspend) { + printf("Warning: suspend/resume is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr003_chain(JNIEnv *env, jclass cls) { + jmethodID mid; + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "dummy", "()V"); + if (mid == NULL) { + printf("Could not find method ID for dummy()V!\n"); + } else { + JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, cls), mid); + } + + return; +} + +JNIEXPORT int JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr003_check(JNIEnv *env, jclass cls, jthread thread) { + jvmtiError err; + jvmtiFrameInfo f[MAX_NUMBER_OF_FRAMES]; + jclass callerClass; + char *sigClass, *name, *sig, *generic; + jint i, count; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_suspend) { + return result; + } + + err = jvmti->SuspendThread(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(SuspendThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return result; + } + + err = jvmti->GetStackTrace(thread, + 0, MAX_NUMBER_OF_FRAMES, f, &count); + if (err != JVMTI_ERROR_NONE) { + printf("(GetStackTrace) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return result; + } + if (count < NUMBER_OF_FRAMES) { + printf("Number of frames: %d is less then expected: %d\n", + count, NUMBER_OF_FRAMES); + result = STATUS_FAILED; + } + for (i = 0; i < count; i++) { + if (printdump == JNI_TRUE) { + printf(">>> checking frame#%d ...\n", count-1-i); + } + err = jvmti->GetMethodDeclaringClass(f[count-1-i].method, + &callerClass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + count-1-i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti->GetClassSignature(callerClass, + &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + count-1-i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti->GetMethodName(f[count-1-i].method, + &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + count-1-i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", sigClass); + printf(">>> method: \"%s%s\"\n", name, sig); + printf(">>> %d ... done\n", i); + } + if (i < NUMBER_OF_FRAMES) { + if (sigClass == NULL || strcmp(sigClass, frames[NUMBER_OF_FRAMES-1-i].cls) != 0) { + printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n", + NUMBER_OF_FRAMES-1-i, sigClass, frames[NUMBER_OF_FRAMES-1-i].cls); + result = STATUS_FAILED; + } + if (name == NULL || strcmp(name, frames[NUMBER_OF_FRAMES-1-i].name) != 0) { + printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n", + NUMBER_OF_FRAMES-1-i, name, frames[NUMBER_OF_FRAMES-1-i].name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, frames[NUMBER_OF_FRAMES-1-i].sig) != 0) { + printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n", + NUMBER_OF_FRAMES-1-i, sig, frames[NUMBER_OF_FRAMES-1-i].sig); + result = STATUS_FAILED; + } + } + } + + err = jvmti->ResumeThread(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(ResumeThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/libgetstacktr003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/libgetstacktr003.c deleted file mode 100644 index b7c35f68624..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/libgetstacktr003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getstacktr003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/libgetstacktr003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/libgetstacktr003.cpp new file mode 100644 index 00000000000..34609f614dc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/libgetstacktr003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getstacktr003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/getstacktr004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/getstacktr004.c deleted file mode 100644 index cd817af29dd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/getstacktr004.c +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls; - char *name; - char *sig; -} frame_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID mid; -static frame_info frames[] = { - {"Lnsk/jvmti/GetStackTrace/getstacktr004$TestThread;", "checkPoint", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr004$TestThread;", "chain4", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr004$TestThread;", "chain3", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr004$TestThread;", "chain2", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr004$TestThread;", "chain1", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr004$TestThread;", "run", "()V"}, -}; - -#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) - -void check(jvmtiEnv *jvmti_env, jthread thr) { - jvmtiError err; - jvmtiFrameInfo f[NUMBER_OF_FRAMES + 1]; - jclass callerClass; - char *sigClass, *name, *sig, *generic; - jint i, count; - - err = (*jvmti_env)->GetStackTrace(jvmti_env, thr, - 0, NUMBER_OF_FRAMES + 1, f, &count); - if (err != JVMTI_ERROR_NONE) { - printf("(GetStackTrace) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - if (count != NUMBER_OF_FRAMES) { - printf("Wrong frame count, expected: %d, actual: %d\n", - NUMBER_OF_FRAMES, count); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> frame count: %d\n", count); - } - for (i = 0; i < count; i++) { - if (printdump == JNI_TRUE) { - printf(">>> checking frame#%d ...\n", i); - } - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, f[i].method, - &callerClass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, callerClass, - &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, f[i].method, - &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", sigClass); - printf(">>> method: \"%s%s\"\n", name, sig); - } - if (i < NUMBER_OF_FRAMES) { - if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) { - printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n", - i, sigClass, frames[i].cls); - result = STATUS_FAILED; - } - if (name == NULL || strcmp(name, frames[i].name) != 0) { - printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n", - i, name, frames[i].name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { - printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n", - i, sig, frames[i].sig); - result = STATUS_FAILED; - } - } - } -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - if (mid != method) { - printf("ERROR: didn't know where we got called from"); - result = STATUS_FAILED; - return; - } - check(jvmti_env, thr); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getstacktr004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr004_getReady(JNIEnv *env, jclass cls, jclass clazz) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_generate_breakpoint_events) { - return; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "checkPoint", "()V"); - if (mid == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr004_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/getstacktr004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/getstacktr004.cpp new file mode 100644 index 00000000000..dae33b3f040 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/getstacktr004.cpp @@ -0,0 +1,265 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls; + const char *name; + const char *sig; +} frame_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID mid; +static frame_info frames[] = { + {"Lnsk/jvmti/GetStackTrace/getstacktr004$TestThread;", "checkPoint", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr004$TestThread;", "chain4", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr004$TestThread;", "chain3", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr004$TestThread;", "chain2", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr004$TestThread;", "chain1", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr004$TestThread;", "run", "()V"}, +}; + +#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) + +void check(jvmtiEnv *jvmti_env, jthread thr) { + jvmtiError err; + jvmtiFrameInfo f[NUMBER_OF_FRAMES + 1]; + jclass callerClass; + char *sigClass, *name, *sig, *generic; + jint i, count; + + err = jvmti_env->GetStackTrace(thr, + 0, NUMBER_OF_FRAMES + 1, f, &count); + if (err != JVMTI_ERROR_NONE) { + printf("(GetStackTrace) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + if (count != NUMBER_OF_FRAMES) { + printf("Wrong frame count, expected: %d, actual: %d\n", + NUMBER_OF_FRAMES, count); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> frame count: %d\n", count); + } + for (i = 0; i < count; i++) { + if (printdump == JNI_TRUE) { + printf(">>> checking frame#%d ...\n", i); + } + err = jvmti_env->GetMethodDeclaringClass(f[i].method, + &callerClass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti_env->GetClassSignature(callerClass, + &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti_env->GetMethodName(f[i].method, + &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", sigClass); + printf(">>> method: \"%s%s\"\n", name, sig); + } + if (i < NUMBER_OF_FRAMES) { + if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) { + printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n", + i, sigClass, frames[i].cls); + result = STATUS_FAILED; + } + if (name == NULL || strcmp(name, frames[i].name) != 0) { + printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n", + i, name, frames[i].name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { + printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n", + i, sig, frames[i].sig); + result = STATUS_FAILED; + } + } + } +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + if (mid != method) { + printf("ERROR: didn't know where we got called from"); + result = STATUS_FAILED; + return; + } + check(jvmti_env, thr); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getstacktr004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr004_getReady(JNIEnv *env, jclass cls, jclass clazz) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_generate_breakpoint_events) { + return; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "checkPoint", "()V"); + if (mid == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + result = STATUS_FAILED; + return; + } + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr004_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/libgetstacktr004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/libgetstacktr004.c deleted file mode 100644 index 2e567a1f978..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/libgetstacktr004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getstacktr004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/libgetstacktr004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/libgetstacktr004.cpp new file mode 100644 index 00000000000..88c95348356 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/libgetstacktr004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getstacktr004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/getstacktr005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/getstacktr005.c deleted file mode 100644 index 48f6f1d1f25..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/getstacktr005.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls; - char *name; - char *sig; -} frame_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID mid; -static frame_info frames[] = { - {"Lnsk/jvmti/GetStackTrace/getstacktr005$TestThread;", "chain4", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr005$TestThread;", "chain3", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr005$TestThread;", "chain2", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr005$TestThread;", "chain1", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr005$TestThread;", "run", "()V"}, -}; - -#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) - -void check(jvmtiEnv *jvmti_env, jthread thr) { - jvmtiError err; - jvmtiFrameInfo f[NUMBER_OF_FRAMES + 1]; - jclass callerClass; - char *sigClass, *name, *sig, *generic; - jint i, count; - - err = (*jvmti_env)->GetStackTrace(jvmti_env, thr, - 0, NUMBER_OF_FRAMES + 1, f, &count); - if (err != JVMTI_ERROR_NONE) { - printf("(GetStackTrace) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - if (count != NUMBER_OF_FRAMES) { - printf("Wrong frame count, expected: %d, actual: %d\n", - NUMBER_OF_FRAMES, count); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> frame count: %d\n", count); - } - for (i = 0; i < count; i++) { - if (printdump == JNI_TRUE) { - printf(">>> checking frame#%d ...\n", i); - } - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, f[i].method, - &callerClass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, callerClass, - &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, f[i].method, - &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", sigClass); - printf(">>> method: \"%s%s\"\n", name, sig); - } - if (i < NUMBER_OF_FRAMES) { - if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) { - printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n", - i, sigClass, frames[i].cls); - result = STATUS_FAILED; - } - if (name == NULL || strcmp(name, frames[i].name) != 0) { - printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n", - i, name, frames[i].name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { - printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n", - i, sig, frames[i].sig); - result = STATUS_FAILED; - } - } - } -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - jvmtiError err; - jint frameCount = 0; - - if (mid != method) { - printf("ERROR: didn't know where we got called from"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> (bp) checking frame count ...\n"); - } - - err = (*jvmti)->GetFrameCount(jvmti, thr, &frameCount); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameCount#bp) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (frameCount != NUMBER_OF_FRAMES + 1) { - printf("(bp) wrong frame count, expected: %d, actual: %d\n", - NUMBER_OF_FRAMES + 1, frameCount); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (bp) frameCount: %d\n", frameCount); - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thr); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable step mode: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> stepping ...\n"); - } -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - jvmtiError err; - - check(jvmti_env, thr); - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thr); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable step mode: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getstacktr005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_single_step_events) { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or SingleStep event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr005_getReady(JNIEnv *env, jclass cls, jclass clazz) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_generate_breakpoint_events || - !caps.can_generate_single_step_events) { - return; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "checkPoint", "()V"); - if (mid == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr005_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/getstacktr005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/getstacktr005.cpp new file mode 100644 index 00000000000..b87d23810e1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/getstacktr005.cpp @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls; + const char *name; + const char *sig; +} frame_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID mid; +static frame_info frames[] = { + {"Lnsk/jvmti/GetStackTrace/getstacktr005$TestThread;", "chain4", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr005$TestThread;", "chain3", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr005$TestThread;", "chain2", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr005$TestThread;", "chain1", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr005$TestThread;", "run", "()V"}, +}; + +#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) + +void check(jvmtiEnv *jvmti_env, jthread thr) { + jvmtiError err; + jvmtiFrameInfo f[NUMBER_OF_FRAMES + 1]; + jclass callerClass; + char *sigClass, *name, *sig, *generic; + jint i, count; + + err = jvmti_env->GetStackTrace(thr, + 0, NUMBER_OF_FRAMES + 1, f, &count); + if (err != JVMTI_ERROR_NONE) { + printf("(GetStackTrace) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + if (count != NUMBER_OF_FRAMES) { + printf("Wrong frame count, expected: %d, actual: %d\n", + NUMBER_OF_FRAMES, count); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> frame count: %d\n", count); + } + for (i = 0; i < count; i++) { + if (printdump == JNI_TRUE) { + printf(">>> checking frame#%d ...\n", i); + } + err = jvmti_env->GetMethodDeclaringClass(f[i].method, + &callerClass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti_env->GetClassSignature(callerClass, + &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti_env->GetMethodName(f[i].method, + &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", sigClass); + printf(">>> method: \"%s%s\"\n", name, sig); + } + if (i < NUMBER_OF_FRAMES) { + if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) { + printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n", + i, sigClass, frames[i].cls); + result = STATUS_FAILED; + } + if (name == NULL || strcmp(name, frames[i].name) != 0) { + printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n", + i, name, frames[i].name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { + printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n", + i, sig, frames[i].sig); + result = STATUS_FAILED; + } + } + } +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + jvmtiError err; + jint frameCount = 0; + + if (mid != method) { + printf("ERROR: didn't know where we got called from"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> (bp) checking frame count ...\n"); + } + + err = jvmti->GetFrameCount(thr, &frameCount); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameCount#bp) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (frameCount != NUMBER_OF_FRAMES + 1) { + printf("(bp) wrong frame count, expected: %d, actual: %d\n", + NUMBER_OF_FRAMES + 1, frameCount); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (bp) frameCount: %d\n", frameCount); + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thr); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable step mode: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> stepping ...\n"); + } +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + jvmtiError err; + + check(jvmti_env, thr); + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thr); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable step mode: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getstacktr005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_single_step_events) { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or SingleStep event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr005_getReady(JNIEnv *env, jclass cls, jclass clazz) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_generate_breakpoint_events || + !caps.can_generate_single_step_events) { + return; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "checkPoint", "()V"); + if (mid == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + result = STATUS_FAILED; + return; + } + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr005_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/libgetstacktr005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/libgetstacktr005.c deleted file mode 100644 index c61d4d65057..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/libgetstacktr005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getstacktr005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/libgetstacktr005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/libgetstacktr005.cpp new file mode 100644 index 00000000000..5b6dc266727 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/libgetstacktr005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getstacktr005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/getstacktr006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/getstacktr006.c deleted file mode 100644 index 77086848121..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/getstacktr006.c +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls; - char *name; - char *sig; -} frame_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID mid; -static frame_info frames[] = { - {"Lnsk/jvmti/GetStackTrace/getstacktr006$TestThread;", "chain4", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr006$TestThread;", "chain3", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr006$TestThread;", "chain2", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr006$TestThread;", "chain1", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr006$TestThread;", "run", "()V"}, -}; - -#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) - -void check(jvmtiEnv *jvmti_env, jthread thr) { - jvmtiError err; - jvmtiFrameInfo f[NUMBER_OF_FRAMES + 1]; - jclass callerClass; - char *sigClass, *name, *sig, *generic; - jint i, count; - - err = (*jvmti_env)->GetStackTrace(jvmti_env, thr, - 0, NUMBER_OF_FRAMES + 1, f, &count); - if (err != JVMTI_ERROR_NONE) { - printf("(GetStackTrace) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - if (count != NUMBER_OF_FRAMES) { - printf("Wrong frame count, expected: %d, actual: %d\n", - NUMBER_OF_FRAMES, count); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> frame count: %d\n", count); - } - for (i = 0; i < count; i++) { - if (printdump == JNI_TRUE) { - printf(">>> checking frame#%d ...\n", i); - } - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, f[i].method, - &callerClass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, callerClass, - &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, f[i].method, - &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", sigClass); - printf(">>> method: \"%s%s\"\n", name, sig); - } - if (i < NUMBER_OF_FRAMES) { - if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) { - printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n", - i, sigClass, frames[i].cls); - result = STATUS_FAILED; - } - if (name == NULL || strcmp(name, frames[i].name) != 0) { - printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n", - i, name, frames[i].name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { - printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n", - i, sig, frames[i].sig); - result = STATUS_FAILED; - } - } - } -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - jvmtiError err; - - if (mid != method) { - printf("ERROR: didn't know where we got called from"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->ClearBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (!caps.can_pop_frame) { - printf("PopFrame is not implemented\n"); - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thr); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable step mode: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thr); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable step mode: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> popping frame ...\n"); - } - - err = (*jvmti)->PopFrame(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(PopFrame) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - jvmtiError err; - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thr); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable step mode: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - check(jvmti_env, thr); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getstacktr006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_single_step_events) { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or SingleStep event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr006_getReady(JNIEnv *env, jclass cls, jclass clazz) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_pop_frame || - !caps.can_generate_breakpoint_events || - !caps.can_generate_single_step_events) { - return; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "checkPoint", "()V"); - if (mid == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr006_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/getstacktr006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/getstacktr006.cpp new file mode 100644 index 00000000000..9244f032dce --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/getstacktr006.cpp @@ -0,0 +1,325 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls; + const char *name; + const char *sig; +} frame_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID mid; +static frame_info frames[] = { + {"Lnsk/jvmti/GetStackTrace/getstacktr006$TestThread;", "chain4", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr006$TestThread;", "chain3", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr006$TestThread;", "chain2", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr006$TestThread;", "chain1", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr006$TestThread;", "run", "()V"}, +}; + +#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) + +void check(jvmtiEnv *jvmti_env, jthread thr) { + jvmtiError err; + jvmtiFrameInfo f[NUMBER_OF_FRAMES + 1]; + jclass callerClass; + char *sigClass, *name, *sig, *generic; + jint i, count; + + err = jvmti_env->GetStackTrace(thr, + 0, NUMBER_OF_FRAMES + 1, f, &count); + if (err != JVMTI_ERROR_NONE) { + printf("(GetStackTrace) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + if (count != NUMBER_OF_FRAMES) { + printf("Wrong frame count, expected: %d, actual: %d\n", + NUMBER_OF_FRAMES, count); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> frame count: %d\n", count); + } + for (i = 0; i < count; i++) { + if (printdump == JNI_TRUE) { + printf(">>> checking frame#%d ...\n", i); + } + err = jvmti_env->GetMethodDeclaringClass(f[i].method, + &callerClass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti_env->GetClassSignature(callerClass, + &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti_env->GetMethodName(f[i].method, + &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", sigClass); + printf(">>> method: \"%s%s\"\n", name, sig); + } + if (i < NUMBER_OF_FRAMES) { + if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) { + printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n", + i, sigClass, frames[i].cls); + result = STATUS_FAILED; + } + if (name == NULL || strcmp(name, frames[i].name) != 0) { + printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n", + i, name, frames[i].name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { + printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n", + i, sig, frames[i].sig); + result = STATUS_FAILED; + } + } + } +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + jvmtiError err; + + if (mid != method) { + printf("ERROR: didn't know where we got called from"); + result = STATUS_FAILED; + return; + } + + err = jvmti->ClearBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (!caps.can_pop_frame) { + printf("PopFrame is not implemented\n"); + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thr); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable step mode: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thr); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable step mode: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> popping frame ...\n"); + } + + err = jvmti->PopFrame(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(PopFrame) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + jvmtiError err; + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thr); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable step mode: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + check(jvmti_env, thr); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getstacktr006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_single_step_events) { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or SingleStep event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr006_getReady(JNIEnv *env, jclass cls, jclass clazz) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_pop_frame || + !caps.can_generate_breakpoint_events || + !caps.can_generate_single_step_events) { + return; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "checkPoint", "()V"); + if (mid == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr006_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/libgetstacktr006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/libgetstacktr006.c deleted file mode 100644 index 871737dbf98..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/libgetstacktr006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getstacktr006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/libgetstacktr006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/libgetstacktr006.cpp new file mode 100644 index 00000000000..e2675650671 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/libgetstacktr006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getstacktr006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/getstacktr007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/getstacktr007.c deleted file mode 100644 index 2c13bd57f75..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/getstacktr007.c +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls; - char *name; - char *sig; -} frame_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID mid; -static jbyteArray classBytes; -static frame_info frames[] = { - {"Lnsk/jvmti/GetStackTrace/getstacktr007$TestThread;", "checkPoint", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr007$TestThread;", "chain4", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr007$TestThread;", "chain3", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr007$TestThread;", "chain2", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr007$TestThread;", "chain1", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr007$TestThread;", "run", "()V"}, -}; - -#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) - -void check(jvmtiEnv *jvmti_env, jthread thr) { - jvmtiError err; - jvmtiFrameInfo f[NUMBER_OF_FRAMES + 1]; - jclass callerClass; - char *sigClass, *name, *sig, *generic; - jint i, count; - - err = (*jvmti_env)->GetStackTrace(jvmti_env, thr, - 0, NUMBER_OF_FRAMES + 1, f, &count); - if (err != JVMTI_ERROR_NONE) { - printf("(GetStackTrace) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - if (count != NUMBER_OF_FRAMES) { - printf("Wrong frame count, expected: %d, actual: %d\n", - NUMBER_OF_FRAMES, count); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> frame count: %d\n", count); - } - for (i = 0; i < count; i++) { - if (printdump == JNI_TRUE) { - printf(">>> checking frame#%d ...\n", i); - } - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, f[i].method, - &callerClass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, callerClass, - &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, f[i].method, - &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", sigClass); - printf(">>> method: \"%s%s\"\n", name, sig); - } - if (i < NUMBER_OF_FRAMES) { - if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) { - printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n", - i, sigClass, frames[i].cls); - result = STATUS_FAILED; - } - if (name == NULL || strcmp(name, frames[i].name) != 0) { - printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n", - i, name, frames[i].name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { - printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n", - i, sig, frames[i].sig); - result = STATUS_FAILED; - } - } - } -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - jvmtiError err; - jclass klass; - jvmtiClassDefinition classDef; - - if (mid != method) { - printf("ERROR: don't know where we get called from"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_redefine_classes) { - printf("Redefine Classes is not implemented\n"); - return; - } - - if (classBytes == NULL) { - printf("ERROR: don't have any bytes"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetMethodDeclaringClass(jvmti, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass(bp) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> redefining class ...\n"); - } - - classDef.klass = klass; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes)); - classDef.class_bytes = (unsigned char*) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env, - classBytes), NULL); - - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err != JVMTI_ERROR_NONE) { - printf("(RedefineClasses) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - JNI_ENV_PTR(env)->DeleteGlobalRef(JNI_ENV_ARG((JNIEnv *)env, classBytes)); - classBytes = NULL; - - check(jvmti_env, thr); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getstacktr007(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr007_getReady(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_generate_breakpoint_events) { - return; - } - - classBytes = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "checkPoint", "()V"); - if (mid == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr007_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/getstacktr007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/getstacktr007.cpp new file mode 100644 index 00000000000..9d2945b9731 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/getstacktr007.cpp @@ -0,0 +1,315 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls; + const char *name; + const char *sig; +} frame_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID mid; +static jbyteArray classBytes; +static frame_info frames[] = { + {"Lnsk/jvmti/GetStackTrace/getstacktr007$TestThread;", "checkPoint", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr007$TestThread;", "chain4", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr007$TestThread;", "chain3", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr007$TestThread;", "chain2", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr007$TestThread;", "chain1", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr007$TestThread;", "run", "()V"}, +}; + +#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) + +void check(jvmtiEnv *jvmti_env, jthread thr) { + jvmtiError err; + jvmtiFrameInfo f[NUMBER_OF_FRAMES + 1]; + jclass callerClass; + char *sigClass, *name, *sig, *generic; + jint i, count; + + err = jvmti_env->GetStackTrace(thr, + 0, NUMBER_OF_FRAMES + 1, f, &count); + if (err != JVMTI_ERROR_NONE) { + printf("(GetStackTrace) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + if (count != NUMBER_OF_FRAMES) { + printf("Wrong frame count, expected: %d, actual: %d\n", + NUMBER_OF_FRAMES, count); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> frame count: %d\n", count); + } + for (i = 0; i < count; i++) { + if (printdump == JNI_TRUE) { + printf(">>> checking frame#%d ...\n", i); + } + err = jvmti_env->GetMethodDeclaringClass(f[i].method, + &callerClass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti_env->GetClassSignature(callerClass, + &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti_env->GetMethodName(f[i].method, + &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", sigClass); + printf(">>> method: \"%s%s\"\n", name, sig); + } + if (i < NUMBER_OF_FRAMES) { + if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) { + printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n", + i, sigClass, frames[i].cls); + result = STATUS_FAILED; + } + if (name == NULL || strcmp(name, frames[i].name) != 0) { + printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n", + i, name, frames[i].name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { + printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n", + i, sig, frames[i].sig); + result = STATUS_FAILED; + } + } + } +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + jvmtiError err; + jclass klass; + jvmtiClassDefinition classDef; + + if (mid != method) { + printf("ERROR: don't know where we get called from"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_redefine_classes) { + printf("Redefine Classes is not implemented\n"); + return; + } + + if (classBytes == NULL) { + printf("ERROR: don't have any bytes"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass(bp) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> redefining class ...\n"); + } + + classDef.klass = klass; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes)); + classDef.class_bytes = (unsigned char*) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env, + classBytes), NULL); + + err = jvmti->RedefineClasses(1, &classDef); + if (err != JVMTI_ERROR_NONE) { + printf("(RedefineClasses) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + JNI_ENV_PTR(env)->DeleteGlobalRef(JNI_ENV_ARG((JNIEnv *)env, classBytes)); + classBytes = NULL; + + check(jvmti_env, thr); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getstacktr007(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr007_getReady(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_generate_breakpoint_events) { + return; + } + + classBytes = (jbyteArray) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "checkPoint", "()V"); + if (mid == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr007_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/libgetstacktr007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/libgetstacktr007.c deleted file mode 100644 index ffa05b15b74..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/libgetstacktr007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getstacktr007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/libgetstacktr007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/libgetstacktr007.cpp new file mode 100644 index 00000000000..380b4e839b4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/libgetstacktr007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getstacktr007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/getstacktr008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/getstacktr008.c deleted file mode 100644 index 7007827483b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/getstacktr008.c +++ /dev/null @@ -1,411 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls; - char *name; - char *sig; -} frame_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jboolean wasFramePop = JNI_FALSE; -static jthread testedThread; -static jmethodID mid_checkPoint, mid_chain4; -static jbyteArray classBytes; -static frame_info frames[] = { - {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "checkPoint", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "chain5", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "chain4", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr008;", "nativeChain", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "chain3", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "chain2", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "chain1", "()V"}, - {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "run", "()V"}, -}; - -#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) - -void check(jvmtiEnv *jvmti_env, jthread thr, int offset, char *note) { - jvmtiError err; - jvmtiFrameInfo f[NUMBER_OF_FRAMES + 1]; - jclass callerClass; - char *sigClass, *name, *sig, *generic; - jint i, count; - - if (printdump == JNI_TRUE) { - printf(">>> checking stack frame for %s ...\n", note); - } - - err = (*jvmti_env)->GetStackTrace(jvmti_env, thr, - 0, NUMBER_OF_FRAMES + 1, f, &count); - if (err != JVMTI_ERROR_NONE) { - printf("(%s, GetStackTrace) unexpected error: %s (%d)\n", - note, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> frame count: %d\n", count); - } - - if (count != (jint)(NUMBER_OF_FRAMES - offset)) { - printf("(%s) wrong frame count, expected: %d, actual: %d\n", - note, NUMBER_OF_FRAMES, count); - result = STATUS_FAILED; - } - for (i = 0; i < count; i++) { - if (printdump == JNI_TRUE) { - printf(">>> checking frame#%d ...\n", i); - } - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, f[i].method, - &callerClass); - if (err != JVMTI_ERROR_NONE) { - printf("(%s, GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - note, i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, callerClass, - &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(%s, GetClassSignature#%d) unexpected error: %s (%d)\n", - note, i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - err = (*jvmti_env)->GetMethodName(jvmti_env, f[i].method, - &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(%s, GetMethodName#%d) unexpected error: %s (%d)\n", - note, i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", sigClass); - printf(">>> method: \"%s%s\"\n", name, sig); - } - if (i < NUMBER_OF_FRAMES) { - if (sigClass == NULL || - strcmp(sigClass, frames[i + offset].cls) != 0) { - printf("(%s, frame#%d) wrong class sig: \"%s\",\n", - note, i, sigClass); - printf(" expected: \"%s\"\n", frames[i + offset].cls); - result = STATUS_FAILED; - } - if (name == NULL || - strcmp(name, frames[i + offset].name) != 0) { - printf("(%s, frame#%d) wrong method name: \"%s\",", - note, i, name); - printf(" expected: \"%s\"\n", frames[i + offset].name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, frames[i + offset].sig) != 0) { - printf("(%s, frame#%d) wrong method sig: \"%s\",", - note, i, sig); - printf(" expected: \"%s\"\n", frames[i + offset].sig); - result = STATUS_FAILED; - } - } - } -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - jvmtiError err; - - if (mid_checkPoint != method) { - printf("ERROR: don't know where we get called from"); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->ClearBreakpoint(jvmti, mid_checkPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - check(jvmti_env, thr, 0, "bp"); - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thr); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable step mode: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> stepping ...\n"); - } -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - jclass klass; - jvmtiClassDefinition classDef; - - if (wasFramePop == JNI_FALSE) { - check(jvmti_env, thread, 1, "step"); - - if (!caps.can_pop_frame) { - printf("Pop Frame is not implemented\n"); - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable step mode: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - return; - } - if (printdump == JNI_TRUE) { - printf(">>> popping frame ...\n"); - } - err = (*jvmti)->PopFrame(jvmti, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(PopFrame) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - wasFramePop = JNI_TRUE; - } else { - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable step mode: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - check(jvmti_env, thread, 2, "pop"); - - if (!caps.can_redefine_classes) { - printf("Redefine Classes is not implemented\n"); - return; - } - if (classBytes == NULL) { - printf("ERROR: don't have any bytes"); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->GetMethodDeclaringClass(jvmti, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass(bp) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - if (printdump == JNI_TRUE) { - printf(">>> redefining class ...\n"); - } - classDef.klass = klass; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes)); - classDef.class_bytes = (unsigned char*) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env, - classBytes), NULL); - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err != JVMTI_ERROR_NONE) { - printf("(RedefineClasses) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - JNI_ENV_PTR(env)->DeleteGlobalRef(JNI_ENV_ARG((JNIEnv *)env, classBytes)); - classBytes = NULL; - check(jvmti_env, thread, 2, "swap"); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getstacktr008(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_single_step_events) { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or SingleStep event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr008_getReady(JNIEnv *env, jclass cls, - jthread thr, jbyteArray bytes) { - jvmtiError err; - jclass clazz; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - testedThread = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, thr)); - - if (!caps.can_generate_breakpoint_events || - !caps.can_generate_single_step_events) { - return; - } - - classBytes = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); - - clazz = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, thr)); - if (clazz == NULL) { - printf("Cannot get the class of thread object\n"); - result = STATUS_FAILED; - return; - } - - mid_checkPoint = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clazz), - "checkPoint", "()V"); - if (mid_checkPoint == NULL) { - printf("Cannot find Method ID for method \"checkPoint\"\n"); - result = STATUS_FAILED; - return; - } - - mid_chain4 = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clazz), - "chain4", "()V"); - if (mid_chain4 == NULL) { - printf("Cannot find Method ID for method \"chain4\"\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, mid_checkPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr008_nativeChain(JNIEnv *env, jclass cls) { - if (mid_chain4 != NULL) { - JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, cls), - mid_chain4); - } - check(jvmti, testedThread, 3, "native"); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr008_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/getstacktr008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/getstacktr008.cpp new file mode 100644 index 00000000000..993a8bafb74 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/getstacktr008.cpp @@ -0,0 +1,411 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls; + const char *name; + const char *sig; +} frame_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jboolean wasFramePop = JNI_FALSE; +static jthread testedThread; +static jmethodID mid_checkPoint, mid_chain4; +static jbyteArray classBytes; +static frame_info frames[] = { + {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "checkPoint", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "chain5", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "chain4", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr008;", "nativeChain", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "chain3", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "chain2", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "chain1", "()V"}, + {"Lnsk/jvmti/GetStackTrace/getstacktr008$TestThread;", "run", "()V"}, +}; + +#define NUMBER_OF_FRAMES ((int) (sizeof(frames)/sizeof(frame_info))) + +void check(jvmtiEnv *jvmti_env, jthread thr, int offset, const char *note) { + jvmtiError err; + jvmtiFrameInfo f[NUMBER_OF_FRAMES + 1]; + jclass callerClass; + char *sigClass, *name, *sig, *generic; + jint i, count; + + if (printdump == JNI_TRUE) { + printf(">>> checking stack frame for %s ...\n", note); + } + + err = jvmti_env->GetStackTrace(thr, + 0, NUMBER_OF_FRAMES + 1, f, &count); + if (err != JVMTI_ERROR_NONE) { + printf("(%s, GetStackTrace) unexpected error: %s (%d)\n", + note, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> frame count: %d\n", count); + } + + if (count != (jint)(NUMBER_OF_FRAMES - offset)) { + printf("(%s) wrong frame count, expected: %d, actual: %d\n", + note, NUMBER_OF_FRAMES, count); + result = STATUS_FAILED; + } + for (i = 0; i < count; i++) { + if (printdump == JNI_TRUE) { + printf(">>> checking frame#%d ...\n", i); + } + err = jvmti_env->GetMethodDeclaringClass(f[i].method, + &callerClass); + if (err != JVMTI_ERROR_NONE) { + printf("(%s, GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + note, i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti_env->GetClassSignature(callerClass, + &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(%s, GetClassSignature#%d) unexpected error: %s (%d)\n", + note, i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + err = jvmti_env->GetMethodName(f[i].method, + &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(%s, GetMethodName#%d) unexpected error: %s (%d)\n", + note, i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", sigClass); + printf(">>> method: \"%s%s\"\n", name, sig); + } + if (i < NUMBER_OF_FRAMES) { + if (sigClass == NULL || + strcmp(sigClass, frames[i + offset].cls) != 0) { + printf("(%s, frame#%d) wrong class sig: \"%s\",\n", + note, i, sigClass); + printf(" expected: \"%s\"\n", frames[i + offset].cls); + result = STATUS_FAILED; + } + if (name == NULL || + strcmp(name, frames[i + offset].name) != 0) { + printf("(%s, frame#%d) wrong method name: \"%s\",", + note, i, name); + printf(" expected: \"%s\"\n", frames[i + offset].name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, frames[i + offset].sig) != 0) { + printf("(%s, frame#%d) wrong method sig: \"%s\",", + note, i, sig); + printf(" expected: \"%s\"\n", frames[i + offset].sig); + result = STATUS_FAILED; + } + } + } +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + jvmtiError err; + + if (mid_checkPoint != method) { + printf("ERROR: don't know where we get called from"); + result = STATUS_FAILED; + return; + } + err = jvmti->ClearBreakpoint(mid_checkPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + check(jvmti_env, thr, 0, "bp"); + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thr); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable step mode: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> stepping ...\n"); + } +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + jclass klass; + jvmtiClassDefinition classDef; + + if (wasFramePop == JNI_FALSE) { + check(jvmti_env, thread, 1, "step"); + + if (!caps.can_pop_frame) { + printf("Pop Frame is not implemented\n"); + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable step mode: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + return; + } + if (printdump == JNI_TRUE) { + printf(">>> popping frame ...\n"); + } + err = jvmti->PopFrame(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(PopFrame) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + wasFramePop = JNI_TRUE; + } else { + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable step mode: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + check(jvmti_env, thread, 2, "pop"); + + if (!caps.can_redefine_classes) { + printf("Redefine Classes is not implemented\n"); + return; + } + if (classBytes == NULL) { + printf("ERROR: don't have any bytes"); + result = STATUS_FAILED; + return; + } + err = jvmti->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass(bp) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + if (printdump == JNI_TRUE) { + printf(">>> redefining class ...\n"); + } + classDef.klass = klass; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes)); + classDef.class_bytes = (unsigned char*) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env, + classBytes), NULL); + err = jvmti->RedefineClasses(1, &classDef); + if (err != JVMTI_ERROR_NONE) { + printf("(RedefineClasses) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + JNI_ENV_PTR(env)->DeleteGlobalRef(JNI_ENV_ARG((JNIEnv *)env, classBytes)); + classBytes = NULL; + check(jvmti_env, thread, 2, "swap"); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getstacktr008(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_single_step_events) { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or SingleStep event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr008_getReady(JNIEnv *env, jclass cls, + jthread thr, jbyteArray bytes) { + jvmtiError err; + jclass clazz; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + testedThread = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, thr)); + + if (!caps.can_generate_breakpoint_events || + !caps.can_generate_single_step_events) { + return; + } + + classBytes = (jbyteArray) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); + + clazz = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, thr)); + if (clazz == NULL) { + printf("Cannot get the class of thread object\n"); + result = STATUS_FAILED; + return; + } + + mid_checkPoint = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clazz), + "checkPoint", "()V"); + if (mid_checkPoint == NULL) { + printf("Cannot find Method ID for method \"checkPoint\"\n"); + result = STATUS_FAILED; + return; + } + + mid_chain4 = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clazz), + "chain4", "()V"); + if (mid_chain4 == NULL) { + printf("Cannot find Method ID for method \"chain4\"\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetBreakpoint(mid_checkPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr008_nativeChain(JNIEnv *env, jclass cls) { + if (mid_chain4 != NULL) { + JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, cls), + mid_chain4); + } + check(jvmti, testedThread, 3, "native"); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr008_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/libgetstacktr008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/libgetstacktr008.c deleted file mode 100644 index ca762ec6a32..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/libgetstacktr008.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getstacktr008.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/libgetstacktr008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/libgetstacktr008.cpp new file mode 100644 index 00000000000..e0219e2602d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/libgetstacktr008.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getstacktr008.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/getstacktr009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/getstacktr009.c deleted file mode 100644 index 7ccb5e35e0a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/getstacktr009.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr009(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr009(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getstacktr009(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetStackTrace_getstacktr009_check(JNIEnv *env, jclass cls, - jthread thread1, jthread thread2) { - jvmtiError err; - jvmtiFrameInfo frame; - jint count; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> Not yet started thread check ...\n"); - } - err = (*jvmti)->GetStackTrace(jvmti, thread1, 0, 1, &frame, &count); - if (err != JVMTI_ERROR_THREAD_NOT_ALIVE) { - printf("For not yet started thread:\n"); - printf("Error expected: JVMTI_ERROR_THREAD_NOT_ALIVE, got: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> Already finished thread check ...\n"); - } - err = (*jvmti)->GetStackTrace(jvmti, thread2, 0, 1, &frame, &count); - if (err != JVMTI_ERROR_THREAD_NOT_ALIVE) { - printf("For already finished thread:\n"); - printf("Error expected: JVMTI_ERROR_THREAD_NOT_ALIVE, got: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/getstacktr009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/getstacktr009.cpp new file mode 100644 index 00000000000..515a8dd66fb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/getstacktr009.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr009(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr009(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getstacktr009(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetStackTrace_getstacktr009_check(JNIEnv *env, jclass cls, + jthread thread1, jthread thread2) { + jvmtiError err; + jvmtiFrameInfo frame; + jint count; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> Not yet started thread check ...\n"); + } + err = jvmti->GetStackTrace(thread1, 0, 1, &frame, &count); + if (err != JVMTI_ERROR_THREAD_NOT_ALIVE) { + printf("For not yet started thread:\n"); + printf("Error expected: JVMTI_ERROR_THREAD_NOT_ALIVE, got: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> Already finished thread check ...\n"); + } + err = jvmti->GetStackTrace(thread2, 0, 1, &frame, &count); + if (err != JVMTI_ERROR_THREAD_NOT_ALIVE) { + printf("For already finished thread:\n"); + printf("Error expected: JVMTI_ERROR_THREAD_NOT_ALIVE, got: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/libgetstacktr009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/libgetstacktr009.c deleted file mode 100644 index 61422f42926..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/libgetstacktr009.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getstacktr009.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/libgetstacktr009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/libgetstacktr009.cpp new file mode 100644 index 00000000000..ba3db56ae83 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/libgetstacktr009.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getstacktr009.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/getsysprops001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/getsysprops001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/getsysprops001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/getsysprops001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/libgetsysprops001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/libgetsysprops001.c deleted file mode 100644 index 77cc7dce701..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/libgetsysprops001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getsysprops001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/libgetsysprops001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/libgetsysprops001.cpp new file mode 100644 index 00000000000..a7def1ee186 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops001/libgetsysprops001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getsysprops001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/getsysprops002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/getsysprops002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/getsysprops002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/getsysprops002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/libgetsysprops002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/libgetsysprops002.c deleted file mode 100644 index 9989627f588..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/libgetsysprops002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getsysprops002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/libgetsysprops002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/libgetsysprops002.cpp new file mode 100644 index 00000000000..9a25ed5dc0a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/libgetsysprops002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getsysprops002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/getsysprop001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/getsysprop001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/getsysprop001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/getsysprop001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/libgetsysprop001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/libgetsysprop001.c deleted file mode 100644 index fb493ed5263..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/libgetsysprop001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getsysprop001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/libgetsysprop001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/libgetsysprop001.cpp new file mode 100644 index 00000000000..1f195bbd584 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/libgetsysprop001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getsysprop001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/getsysprop002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/getsysprop002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/getsysprop002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/getsysprop002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/libgetsysprop002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/libgetsysprop002.c deleted file mode 100644 index 6f5292faa38..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/libgetsysprop002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getsysprop002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/libgetsysprop002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/libgetsysprop002.cpp new file mode 100644 index 00000000000..ebfc1ae02dc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/libgetsysprop002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getsysprop002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/gettag001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/gettag001.c deleted file mode 100644 index 80700d07372..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/gettag001.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/GetTag/gettag001" -#define OBJECT_CLASS_NAME "nsk/jvmti/GetTag/gettag001TestedClass" -#define OBJECT_CLASS_SIG "L"OBJECT_CLASS_NAME";" -#define OBJECT_FIELD_NAME "testedObject" - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for object created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - jobject testedObject = NULL; - jlong objectTag = 0; - - NSK_DISPLAY0(">>> Obtain tested object from a static field of debugee class\n"); - { - jclass debugeeClass = NULL; - jfieldID objectField = NULL; - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); - - NSK_DISPLAY1("Get object from static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (testedObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)testedObject); - - NSK_DISPLAY1("Create global reference for object: 0x%p\n", (void*)testedObject); - if (!NSK_JNI_VERIFY(jni, (testedObject = - NSK_CPP_STUB2(NewGlobalRef, jni, testedObject)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got reference: 0x%p\n", (void*)testedObject); - } - - NSK_DISPLAY0(">>> Testcase #1: Get tag of the object and check if it is zero\n"); - { - jlong objectTag = 100; - - NSK_DISPLAY1("Get tag for object: 0x%p\n", (void*)testedObject); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetTag, jvmti, testedObject, &objectTag))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got tag: %ld\n", (long)objectTag); - - if (objectTag != 0) { - NSK_COMPLAIN2("GetTag returns not zero tag for untagged object\n" - "# got tag: %ld\n" - "# expected: %ld\n", - (long)objectTag, (long)0); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY0("SUCCESS: Got tag is zero for untagged object\n"); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - NSK_DISPLAY1("Delete object reference: 0x%p\n", (void*)testedObject); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedObject)); - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_gettag001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_gettag001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_gettag001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* add required capabilities */ - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/gettag001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/gettag001.cpp new file mode 100644 index 00000000000..1acf96e1b57 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/gettag001.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/GetTag/gettag001" +#define OBJECT_CLASS_NAME "nsk/jvmti/GetTag/gettag001TestedClass" +#define OBJECT_CLASS_SIG "L" OBJECT_CLASS_NAME ";" +#define OBJECT_FIELD_NAME "testedObject" + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for object created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + jobject testedObject = NULL; + jlong objectTag = 0; + + NSK_DISPLAY0(">>> Obtain tested object from a static field of debugee class\n"); + { + jclass debugeeClass = NULL; + jfieldID objectField = NULL; + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); + + NSK_DISPLAY1("Get object from static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (testedObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)testedObject); + + NSK_DISPLAY1("Create global reference for object: 0x%p\n", (void*)testedObject); + if (!NSK_JNI_VERIFY(jni, (testedObject = + NSK_CPP_STUB2(NewGlobalRef, jni, testedObject)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got reference: 0x%p\n", (void*)testedObject); + } + + NSK_DISPLAY0(">>> Testcase #1: Get tag of the object and check if it is zero\n"); + { + jlong objectTag = 100; + + NSK_DISPLAY1("Get tag for object: 0x%p\n", (void*)testedObject); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetTag, jvmti, testedObject, &objectTag))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got tag: %ld\n", (long)objectTag); + + if (objectTag != 0) { + NSK_COMPLAIN2("GetTag returns not zero tag for untagged object\n" + "# got tag: %ld\n" + "# expected: %ld\n", + (long)objectTag, (long)0); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY0("SUCCESS: Got tag is zero for untagged object\n"); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + NSK_DISPLAY1("Delete object reference: 0x%p\n", (void*)testedObject); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedObject)); + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_gettag001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_gettag001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_gettag001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* add required capabilities */ + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/libgettag001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/libgettag001.c deleted file mode 100644 index c14875566e3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/libgettag001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "gettag001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/libgettag001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/libgettag001.cpp new file mode 100644 index 00000000000..0bd7affaddf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTag/gettag001/libgettag001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "gettag001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/libthrcputime001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/libthrcputime001.c deleted file mode 100644 index 7284d18c6fe..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/libthrcputime001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "thrcputime001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/libthrcputime001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/libthrcputime001.cpp new file mode 100644 index 00000000000..7f16b8887f2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/libthrcputime001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "thrcputime001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/thrcputime001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/thrcputime001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/thrcputime001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/thrcputime001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/libthrcputime002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/libthrcputime002.c deleted file mode 100644 index 09d5e447496..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/libthrcputime002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "thrcputime002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/libthrcputime002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/libthrcputime002.cpp new file mode 100644 index 00000000000..92b0885d85b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/libthrcputime002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "thrcputime002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/thrcputime002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/thrcputime002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/thrcputime002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/thrcputime002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/libthrtimerinfo001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/libthrtimerinfo001.c deleted file mode 100644 index 1e6208691ec..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/libthrtimerinfo001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "thrtimerinfo001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/libthrtimerinfo001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/libthrtimerinfo001.cpp new file mode 100644 index 00000000000..08e30136f43 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/libthrtimerinfo001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "thrtimerinfo001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/thrtimerinfo001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/thrtimerinfo001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/thrtimerinfo001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTimerInfo/thrtimerinfo001/thrtimerinfo001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/getthrdgrpchld001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/getthrdgrpchld001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/getthrdgrpchld001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/getthrdgrpchld001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/libgetthrdgrpchld001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/libgetthrdgrpchld001.c deleted file mode 100644 index 850fa48b1ce..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/libgetthrdgrpchld001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getthrdgrpchld001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/libgetthrdgrpchld001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/libgetthrdgrpchld001.cpp new file mode 100644 index 00000000000..4aee7a0e30c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/libgetthrdgrpchld001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getthrdgrpchld001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/libthrgrpinfo001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/libthrgrpinfo001.c deleted file mode 100644 index 7a0014f559e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/libthrgrpinfo001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "thrgrpinfo001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/libthrgrpinfo001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/libthrgrpinfo001.cpp new file mode 100644 index 00000000000..ae9eb41a612 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/libthrgrpinfo001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "thrgrpinfo001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/thrgrpinfo001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/thrgrpinfo001.c deleted file mode 100644 index 828d1c8d47f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/thrgrpinfo001.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jint stage = 0; -static const char *expName = "TestGroup"; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_thrgrpinfo001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_thrgrpinfo001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_thrgrpinfo001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetThreadGroupInfo_thrgrpinfo001_check(JNIEnv *env, jclass cls, jthreadGroup group, - jthreadGroup parent, jboolean daemon, jint pri) { - jvmtiError err; - jvmtiThreadGroupInfo inf; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - stage++; - - if (printdump == JNI_TRUE) { - printf(">>> (%d) getting thread group info ...\n", stage); - } - err = (*jvmti)->GetThreadGroupInfo(jvmti, group, &inf); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadGroupInfo#%d) unexpected error: %s (%d)\n", - stage, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> name: %s\n", inf.name); - printf(">>> parent: 0x%p\n", inf.parent); - printf(">>> max priority: %d\n", inf.max_priority); - printf(">>> is daemon: %s\n", - (inf.is_daemon == JNI_TRUE) ? "true" : "false"); - } - - if (inf.name == NULL || strcmp(inf.name, expName) != 0) { - printf("(%d) unexpected name: \"%s\",", stage, inf.name); - printf(" expected: \"%s\"\n", expName); - result = STATUS_FAILED; - } - - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, parent), - inf.parent) != JNI_TRUE) { - printf("(%d) parent is not the same\n", stage); - result = STATUS_FAILED; - } - - if (pri != inf.max_priority) { - printf("(%d) unexpected max_priority: %d,", stage, inf.max_priority); - printf(" expected: %d\n", pri); - result = STATUS_FAILED; - } - - if (daemon != inf.is_daemon) { - printf("(%d) unexpected is_daemon: %s,", stage, - (inf.is_daemon == JNI_TRUE) ? "true" : "false"); - printf(" expected: %s\n", (daemon == JNI_TRUE) ? "true" : "false"); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> done ...\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/thrgrpinfo001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/thrgrpinfo001.cpp new file mode 100644 index 00000000000..d444260a02e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/thrgrpinfo001.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jint stage = 0; +static const char *expName = "TestGroup"; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_thrgrpinfo001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_thrgrpinfo001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_thrgrpinfo001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetThreadGroupInfo_thrgrpinfo001_check(JNIEnv *env, jclass cls, jthreadGroup group, + jthreadGroup parent, jboolean daemon, jint pri) { + jvmtiError err; + jvmtiThreadGroupInfo inf; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + stage++; + + if (printdump == JNI_TRUE) { + printf(">>> (%d) getting thread group info ...\n", stage); + } + err = jvmti->GetThreadGroupInfo(group, &inf); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadGroupInfo#%d) unexpected error: %s (%d)\n", + stage, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> name: %s\n", inf.name); + printf(">>> parent: 0x%p\n", inf.parent); + printf(">>> max priority: %d\n", inf.max_priority); + printf(">>> is daemon: %s\n", + (inf.is_daemon == JNI_TRUE) ? "true" : "false"); + } + + if (inf.name == NULL || strcmp(inf.name, expName) != 0) { + printf("(%d) unexpected name: \"%s\",", stage, inf.name); + printf(" expected: \"%s\"\n", expName); + result = STATUS_FAILED; + } + + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, parent), + inf.parent) != JNI_TRUE) { + printf("(%d) parent is not the same\n", stage); + result = STATUS_FAILED; + } + + if (pri != inf.max_priority) { + printf("(%d) unexpected max_priority: %d,", stage, inf.max_priority); + printf(" expected: %d\n", pri); + result = STATUS_FAILED; + } + + if (daemon != inf.is_daemon) { + printf("(%d) unexpected is_daemon: %s,", stage, + (inf.is_daemon == JNI_TRUE) ? "true" : "false"); + printf(" expected: %s\n", (daemon == JNI_TRUE) ? "true" : "false"); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> done ...\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/libthrgrpinfo002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/libthrgrpinfo002.c deleted file mode 100644 index 5ec73835655..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/libthrgrpinfo002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "thrgrpinfo002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/libthrgrpinfo002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/libthrgrpinfo002.cpp new file mode 100644 index 00000000000..d62e59fb087 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/libthrgrpinfo002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "thrgrpinfo002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/thrgrpinfo002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/thrgrpinfo002.c deleted file mode 100644 index c56c5e85606..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/thrgrpinfo002.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_thrgrpinfo002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_thrgrpinfo002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_thrgrpinfo002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetThreadGroupInfo_thrgrpinfo002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jint groupCount; - jthreadGroup *groups; - jvmtiThreadGroupInfo inf; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> getting top thread group ...\n"); - } - err = (*jvmti)->GetTopThreadGroups(jvmti, &groupCount, &groups); - if (err != JVMTI_ERROR_NONE) { - printf("(GetTopThreadGroups) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid group check ...\n"); - } - err = (*jvmti)->GetThreadGroupInfo(jvmti, NULL, &inf); - if (err != JVMTI_ERROR_INVALID_THREAD_GROUP) { - printf("Error expected: JVMTI_ERROR_INVALID_THREAD_GROUP,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetThreadGroupInfo(jvmti, *groups, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/thrgrpinfo002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/thrgrpinfo002.cpp new file mode 100644 index 00000000000..6faa199e660 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/thrgrpinfo002.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_thrgrpinfo002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_thrgrpinfo002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_thrgrpinfo002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetThreadGroupInfo_thrgrpinfo002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jint groupCount; + jthreadGroup *groups; + jvmtiThreadGroupInfo inf; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> getting top thread group ...\n"); + } + err = jvmti->GetTopThreadGroups(&groupCount, &groups); + if (err != JVMTI_ERROR_NONE) { + printf("(GetTopThreadGroups) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid group check ...\n"); + } + err = jvmti->GetThreadGroupInfo(NULL, &inf); + if (err != JVMTI_ERROR_INVALID_THREAD_GROUP) { + printf("Error expected: JVMTI_ERROR_INVALID_THREAD_GROUP,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetThreadGroupInfo(*groups, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/libthrinfo001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/libthrinfo001.c deleted file mode 100644 index 6c8c921ad64..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/libthrinfo001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "thrinfo001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/libthrinfo001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/libthrinfo001.cpp new file mode 100644 index 00000000000..b823faa465a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/libthrinfo001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "thrinfo001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/thrinfo001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/thrinfo001.c deleted file mode 100644 index 535d59c04be..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/thrinfo001.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *name; - int priority; - int is_daemon; -} info; - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jvmtiThreadInfo inf; -static info threads[] = { - {"main", JVMTI_THREAD_NORM_PRIORITY, 0}, - {"thread1", JVMTI_THREAD_MIN_PRIORITY + 2, 1}, - {"Thread-", JVMTI_THREAD_MIN_PRIORITY, 1} -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_thrinfo001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_thrinfo001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_thrinfo001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_GetThreadInfo_thrinfo001_checkInfo(JNIEnv *env, jclass cls, - jthread thr, jthreadGroup group, jint ind) { - jvmtiError err; - - err = (*jvmti)->GetThreadInfo(jvmti, thr, &inf); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo#%d) unexpected error: %s (%d)\n", - ind, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (inf.name == NULL || - strstr(inf.name, threads[ind].name) != inf.name || - (ind < 2 && strlen(inf.name) != strlen(threads[ind].name))) { - printf("Thread %s: incorrect name: %s\n", threads[ind].name, inf.name); - result = STATUS_FAILED; - } - if (inf.priority != threads[ind].priority) { - printf("Thread %s: priority expected: %d, got: %d\n", - threads[ind].name, threads[ind].priority, inf.priority); - result = STATUS_FAILED; - } - if (inf.is_daemon != threads[ind].is_daemon) { - printf("Thread %s: is_daemon expected: %d, got: %d\n", - threads[ind].name, threads[ind].is_daemon, inf.is_daemon); - result = STATUS_FAILED; - } - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, group), - inf.thread_group) != JNI_TRUE) { - printf("Thread %s: invalid thread group\n", threads[ind].name); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_GetThreadInfo_thrinfo001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/thrinfo001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/thrinfo001.cpp new file mode 100644 index 00000000000..b95faccbd0b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/thrinfo001.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + int priority; + int is_daemon; +} info; + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jvmtiThreadInfo inf; +static info threads[] = { + {"main", JVMTI_THREAD_NORM_PRIORITY, 0}, + {"thread1", JVMTI_THREAD_MIN_PRIORITY + 2, 1}, + {"Thread-", JVMTI_THREAD_MIN_PRIORITY, 1} +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_thrinfo001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_thrinfo001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_thrinfo001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_GetThreadInfo_thrinfo001_checkInfo(JNIEnv *env, jclass cls, + jthread thr, jthreadGroup group, jint ind) { + jvmtiError err; + + err = jvmti->GetThreadInfo(thr, &inf); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo#%d) unexpected error: %s (%d)\n", + ind, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (inf.name == NULL || + strstr(inf.name, threads[ind].name) != inf.name || + (ind < 2 && strlen(inf.name) != strlen(threads[ind].name))) { + printf("Thread %s: incorrect name: %s\n", threads[ind].name, inf.name); + result = STATUS_FAILED; + } + if (inf.priority != threads[ind].priority) { + printf("Thread %s: priority expected: %d, got: %d\n", + threads[ind].name, threads[ind].priority, inf.priority); + result = STATUS_FAILED; + } + if (inf.is_daemon != threads[ind].is_daemon) { + printf("Thread %s: is_daemon expected: %d, got: %d\n", + threads[ind].name, threads[ind].is_daemon, inf.is_daemon); + result = STATUS_FAILED; + } + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, group), + inf.thread_group) != JNI_TRUE) { + printf("Thread %s: invalid thread group\n", threads[ind].name); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_GetThreadInfo_thrinfo001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/libthrinfo002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/libthrinfo002.c deleted file mode 100644 index 9dd398e1f41..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/libthrinfo002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "thrinfo002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/libthrinfo002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/libthrinfo002.cpp new file mode 100644 index 00000000000..7be0147e1e0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/libthrinfo002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "thrinfo002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/thrinfo002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/thrinfo002.c deleted file mode 100644 index dfbc4c9081d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/thrinfo002.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_thrinfo002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_thrinfo002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_thrinfo002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetThreadInfo_thrinfo002_check(JNIEnv *env, jclass cls, jthread thr, jthreadGroup group) { - jvmtiError err; - jvmtiThreadInfo inf; - - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid thread check ...\n"); - } - err = (*jvmti)->GetThreadInfo(jvmti, NULL, &inf); - if (err != JVMTI_ERROR_NONE) { - printf("Error expected: JVMTI_ERROR_NONE,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (inf.name == NULL || strcmp(inf.name, "main")) { - printf("Thread %s: incorrect name: %s\n", "main", inf.name); - result = STATUS_FAILED; - } - if (inf.priority != JVMTI_THREAD_NORM_PRIORITY) { - printf("Thread %s: priority expected: %d, got: %d\n", - "main", JVMTI_THREAD_NORM_PRIORITY, inf.priority); - result = STATUS_FAILED; - } - if (inf.is_daemon != 0) { - printf("Thread %s: is_daemon expected: %d, got: %d\n", - "main", 0, inf.is_daemon); - result = STATUS_FAILED; - } - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, group), - inf.thread_group) != JNI_TRUE) { - printf("Thread %s: invalid thread group\n", "main"); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetThreadInfo(jvmti, thr, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/thrinfo002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/thrinfo002.cpp new file mode 100644 index 00000000000..8cb4d281f52 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/thrinfo002.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_thrinfo002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_thrinfo002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_thrinfo002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetThreadInfo_thrinfo002_check(JNIEnv *env, jclass cls, jthread thr, jthreadGroup group) { + jvmtiError err; + jvmtiThreadInfo inf; + + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid thread check ...\n"); + } + err = jvmti->GetThreadInfo(NULL, &inf); + if (err != JVMTI_ERROR_NONE) { + printf("Error expected: JVMTI_ERROR_NONE,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (inf.name == NULL || strcmp(inf.name, "main")) { + printf("Thread %s: incorrect name: %s\n", "main", inf.name); + result = STATUS_FAILED; + } + if (inf.priority != JVMTI_THREAD_NORM_PRIORITY) { + printf("Thread %s: priority expected: %d, got: %d\n", + "main", JVMTI_THREAD_NORM_PRIORITY, inf.priority); + result = STATUS_FAILED; + } + if (inf.is_daemon != 0) { + printf("Thread %s: is_daemon expected: %d, got: %d\n", + "main", 0, inf.is_daemon); + result = STATUS_FAILED; + } + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, group), + inf.thread_group) != JNI_TRUE) { + printf("Thread %s: invalid thread group\n", "main"); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetThreadInfo(thr, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/getthrdstor001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/getthrdstor001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/getthrdstor001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/getthrdstor001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/libgetthrdstor001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/libgetthrdstor001.c deleted file mode 100644 index 9ea3092c360..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/libgetthrdstor001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getthrdstor001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/libgetthrdstor001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/libgetthrdstor001.cpp new file mode 100644 index 00000000000..01f9611e874 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/libgetthrdstor001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getthrdstor001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/libthrstat001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/libthrstat001.c deleted file mode 100644 index 1f7c15480aa..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/libthrstat001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "thrstat001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/libthrstat001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/libthrstat001.cpp new file mode 100644 index 00000000000..8205208a4d7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/libthrstat001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "thrstat001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/thrstat001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/thrstat001.c deleted file mode 100644 index 0f0dac83155..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/thrstat001.c +++ /dev/null @@ -1,442 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define WAIT_START 100 -#define WAIT_TIME (2*60*1000) - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jrawMonitorID access_lock; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jthread thr_ptr = NULL; -static jint state[] = { - JVMTI_THREAD_STATE_RUNNABLE, - JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER, - JVMTI_THREAD_STATE_IN_OBJECT_WAIT -}; - -static int entry_count = 0; -static int entry_error_count = 0; -static int exit_count = 0; -static int exit_error_count = 0; - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - jvmtiError err; - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_THREAD_START, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable THREAD_START event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (caps.can_generate_method_entry_events) { - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_ENTRY, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable METHOD_ENTRY event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (caps.can_generate_method_exit_events) { - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -void JNICALL -ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - jvmtiError err; - jvmtiThreadInfo thrInfo; - - err = (*jvmti_env)->RawMonitorEnter(jvmti_env, access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#TS) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetThreadInfo(jvmti_env, thread, &thrInfo); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo#TS) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (thrInfo.name != NULL && strcmp(thrInfo.name, "thr1") == 0) { - thr_ptr = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, thread)); - if (printdump == JNI_TRUE) { - printf(">>> ThreadStart: \"%s\", 0x%p\n", thrInfo.name, thr_ptr); - } - } - - err = (*jvmti_env)->RawMonitorExit(jvmti_env, access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#TS) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID mid) { - jvmtiError err; - jvmtiThreadInfo thrInfo; - jint thrState; - - err = (*jvmti_env)->RawMonitorEnter(jvmti_env, access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#ME) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - entry_count++; - err = (*jvmti_env)->GetThreadState(jvmti_env, thread, &thrState); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadState#ME) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if ((thrState & JVMTI_THREAD_STATE_RUNNABLE) == 0) { - if (entry_error_count == 0) { - err = (*jvmti_env)->GetThreadInfo(jvmti_env, thread, &thrInfo); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo#ME) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - printf("Wrong thread \"%s\" state on MethodEntry event:\n", - thrInfo.name); - printf(" expected: JVMTI_THREAD_STATE_RUNNABLE\n"); - printf(" got: %s (%d)\n", - TranslateState(thrState), thrState); - } - entry_error_count++; - result = STATUS_FAILED; - } - - err = (*jvmti_env)->RawMonitorExit(jvmti_env, access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#ME) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - -} - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID mid, - jboolean was_poped_by_exception, jvalue return_value) { - jvmtiError err; - jvmtiThreadInfo thrInfo; - jint thrState; - - err = (*jvmti_env)->RawMonitorEnter(jvmti_env, access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#MX) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - exit_count++; - err = (*jvmti_env)->GetThreadState(jvmti_env, thread, &thrState); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadState#MX) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if ((thrState & JVMTI_THREAD_STATE_RUNNABLE) == 0) { - if (exit_error_count == 0) { - err = (*jvmti_env)->GetThreadInfo(jvmti_env, thread, &thrInfo); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo#MX) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - printf("Wrong thread \"%s\" state on MethodExit event:\n", - thrInfo.name); - printf(" expected: JVMTI_THREAD_STATE_RUNNABLE\n"); - printf(" got: %s (%d)\n", - TranslateState(thrState), thrState); - } - exit_error_count++; - result = STATUS_FAILED; - } - - err = (*jvmti_env)->RawMonitorExit(jvmti_env, access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#MX) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_thrstat001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_thrstat001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_thrstat001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "_access_lock", &access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - callbacks.ThreadStart = &ThreadStart; - if (caps.can_generate_method_entry_events) { - callbacks.MethodEntry = &MethodEntry; - } else { - printf("Warning: MethodEntry event is not implemented\n"); - } - if (caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - } else { - printf("Warning: MethodExit event is not implemented\n"); - } - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable VM_INIT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetThreadState_thrstat001_checkStatus(JNIEnv *env, - jclass cls, jint statInd) { - jvmtiError err; - jrawMonitorID wait_lock; - jint thrState; - jint millis; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (thr_ptr == NULL) { - printf("Missing thread \"thr1\" start event\n"); - result = STATUS_FAILED; - return; - } - - /* wait until thread gets an expected state */ - err = (*jvmti)->CreateRawMonitor(jvmti, "_wait_lock", &wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - for (millis = WAIT_START; millis < WAIT_TIME; millis <<= 1) { - err = (*jvmti)->GetThreadState(jvmti, thr_ptr, &thrState); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadState#%d) unexpected error: %s (%d)\n", - statInd, TranslateError(err), err); - result = STATUS_FAILED; - } - if ((thrState & state[statInd]) != 0) { - break; - } - err = (*jvmti)->RawMonitorEnter(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorWait(jvmti, wait_lock, (jlong)millis); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorExit(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - err = (*jvmti)->DestroyRawMonitor(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> thread \"thr1\" (0x%p) state: %s (%d)\n", - thr_ptr, TranslateState(thrState), thrState); - } - - if ((thrState & state[statInd]) == 0) { - printf("Wrong thread \"thr1\" (0x%p) state:\n", thr_ptr); - printf(" expected: %s (%d)\n", - TranslateState(state[statInd]), state[statInd]); - printf(" actual: %s (%d)\n", - TranslateState(thrState), thrState); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetThreadState_thrstat001_getRes(JNIEnv *env, jclass cls) { - jvmtiError err; - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_THREAD_START, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable THREAD_START event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (caps.can_generate_method_entry_events) { - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_ENTRY, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable METHOD_ENTRY event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (caps.can_generate_method_exit_events) { - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_EXIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> total number of method entry events = %d\n", entry_count); - printf(">>> total number of method exit events = %d\n", exit_count); - } - - if (entry_error_count != 0) { - printf("Total number of errors on METHOD_ENTRY: %d of %d events\n", - entry_error_count, entry_count); - } - - if (exit_error_count != 0) { - printf("Total number of errors on METHOD_EXIT: %d of %d events\n", - exit_error_count, exit_count); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/thrstat001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/thrstat001.cpp new file mode 100644 index 00000000000..caf590ef0f7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat001/thrstat001.cpp @@ -0,0 +1,442 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define WAIT_START 100 +#define WAIT_TIME (2*60*1000) + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jrawMonitorID access_lock; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jthread thr_ptr = NULL; +static jint state[] = { + JVMTI_THREAD_STATE_RUNNABLE, + JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER, + JVMTI_THREAD_STATE_IN_OBJECT_WAIT +}; + +static int entry_count = 0; +static int entry_error_count = 0; +static int exit_count = 0; +static int exit_error_count = 0; + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + jvmtiError err; + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_THREAD_START, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable THREAD_START event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (caps.can_generate_method_entry_events) { + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_ENTRY, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable METHOD_ENTRY event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (caps.can_generate_method_exit_events) { + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +void JNICALL +ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + jvmtiError err; + jvmtiThreadInfo thrInfo; + + err = jvmti_env->RawMonitorEnter(access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#TS) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetThreadInfo(thread, &thrInfo); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo#TS) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (thrInfo.name != NULL && strcmp(thrInfo.name, "thr1") == 0) { + thr_ptr = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, thread)); + if (printdump == JNI_TRUE) { + printf(">>> ThreadStart: \"%s\", 0x%p\n", thrInfo.name, thr_ptr); + } + } + + err = jvmti_env->RawMonitorExit(access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#TS) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID mid) { + jvmtiError err; + jvmtiThreadInfo thrInfo; + jint thrState; + + err = jvmti_env->RawMonitorEnter(access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#ME) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + entry_count++; + err = jvmti_env->GetThreadState(thread, &thrState); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadState#ME) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if ((thrState & JVMTI_THREAD_STATE_RUNNABLE) == 0) { + if (entry_error_count == 0) { + err = jvmti_env->GetThreadInfo(thread, &thrInfo); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo#ME) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + printf("Wrong thread \"%s\" state on MethodEntry event:\n", + thrInfo.name); + printf(" expected: JVMTI_THREAD_STATE_RUNNABLE\n"); + printf(" got: %s (%d)\n", + TranslateState(thrState), thrState); + } + entry_error_count++; + result = STATUS_FAILED; + } + + err = jvmti_env->RawMonitorExit(access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#ME) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + +} + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID mid, + jboolean was_poped_by_exception, jvalue return_value) { + jvmtiError err; + jvmtiThreadInfo thrInfo; + jint thrState; + + err = jvmti_env->RawMonitorEnter(access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#MX) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + exit_count++; + err = jvmti_env->GetThreadState(thread, &thrState); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadState#MX) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if ((thrState & JVMTI_THREAD_STATE_RUNNABLE) == 0) { + if (exit_error_count == 0) { + err = jvmti_env->GetThreadInfo(thread, &thrInfo); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo#MX) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + printf("Wrong thread \"%s\" state on MethodExit event:\n", + thrInfo.name); + printf(" expected: JVMTI_THREAD_STATE_RUNNABLE\n"); + printf(" got: %s (%d)\n", + TranslateState(thrState), thrState); + } + exit_error_count++; + result = STATUS_FAILED; + } + + err = jvmti_env->RawMonitorExit(access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#MX) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_thrstat001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_thrstat001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_thrstat001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->CreateRawMonitor("_access_lock", &access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + callbacks.ThreadStart = &ThreadStart; + if (caps.can_generate_method_entry_events) { + callbacks.MethodEntry = &MethodEntry; + } else { + printf("Warning: MethodEntry event is not implemented\n"); + } + if (caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + } else { + printf("Warning: MethodExit event is not implemented\n"); + } + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable VM_INIT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetThreadState_thrstat001_checkStatus(JNIEnv *env, + jclass cls, jint statInd) { + jvmtiError err; + jrawMonitorID wait_lock; + jint thrState; + jint millis; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (thr_ptr == NULL) { + printf("Missing thread \"thr1\" start event\n"); + result = STATUS_FAILED; + return; + } + + /* wait until thread gets an expected state */ + err = jvmti->CreateRawMonitor("_wait_lock", &wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + for (millis = WAIT_START; millis < WAIT_TIME; millis <<= 1) { + err = jvmti->GetThreadState(thr_ptr, &thrState); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadState#%d) unexpected error: %s (%d)\n", + statInd, TranslateError(err), err); + result = STATUS_FAILED; + } + if ((thrState & state[statInd]) != 0) { + break; + } + err = jvmti->RawMonitorEnter(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorWait(wait_lock, (jlong)millis); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorExit(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + err = jvmti->DestroyRawMonitor(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> thread \"thr1\" (0x%p) state: %s (%d)\n", + thr_ptr, TranslateState(thrState), thrState); + } + + if ((thrState & state[statInd]) == 0) { + printf("Wrong thread \"thr1\" (0x%p) state:\n", thr_ptr); + printf(" expected: %s (%d)\n", + TranslateState(state[statInd]), state[statInd]); + printf(" actual: %s (%d)\n", + TranslateState(thrState), thrState); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetThreadState_thrstat001_getRes(JNIEnv *env, jclass cls) { + jvmtiError err; + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_THREAD_START, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable THREAD_START event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (caps.can_generate_method_entry_events) { + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_ENTRY, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable METHOD_ENTRY event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (caps.can_generate_method_exit_events) { + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_EXIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> total number of method entry events = %d\n", entry_count); + printf(">>> total number of method exit events = %d\n", exit_count); + } + + if (entry_error_count != 0) { + printf("Total number of errors on METHOD_ENTRY: %d of %d events\n", + entry_error_count, entry_count); + } + + if (exit_error_count != 0) { + printf("Total number of errors on METHOD_EXIT: %d of %d events\n", + exit_error_count, exit_count); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/libthrstat002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/libthrstat002.c deleted file mode 100644 index e4843ec6bdd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/libthrstat002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "thrstat002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/libthrstat002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/libthrstat002.cpp new file mode 100644 index 00000000000..7030190d49e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/libthrstat002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "thrstat002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/thrstat002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/thrstat002.c deleted file mode 100644 index ec7bf3a1586..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/thrstat002.c +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define WAIT_START 100 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jrawMonitorID access_lock, wait_lock; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jthread thr_ptr = NULL; -static jint wait_time = 0; -static jint state[] = { - JVMTI_THREAD_STATE_RUNNABLE, - JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER, - JVMTI_THREAD_STATE_IN_OBJECT_WAIT -}; - -void printStateFlags(jint flags) { - if (flags & JVMTI_THREAD_STATE_SUSPENDED) - printf(" JVMTI_THREAD_STATE_SUSPENDED"); - if (flags & JVMTI_THREAD_STATE_INTERRUPTED) - printf(" JVMTI_THREAD_STATE_INTERRUPTED"); - if (flags & JVMTI_THREAD_STATE_IN_NATIVE) - printf(" JVMTI_THREAD_STATE_IN_NATIVE"); - printf(" (0x%0x)\n", flags); -} - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - jvmtiError err; - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_THREAD_START, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable THREAD_START event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL -ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - jvmtiThreadInfo thrInfo; - jvmtiError err; - - err = (*jvmti_env)->RawMonitorEnter(jvmti_env, access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetThreadInfo(jvmti_env, thread, &thrInfo); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (thrInfo.name != NULL && strcmp(thrInfo.name, "thr1") == 0) { - thr_ptr = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, thread)); - if (printdump == JNI_TRUE) { - printf(">>> ThreadStart: \"%s\", 0x%p\n", thrInfo.name, thr_ptr); - } - } - - err = (*jvmti_env)->RawMonitorExit(jvmti_env, access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_thrstat002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_thrstat002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_thrstat002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_suspend) { - printf("Warning: suspend/resume is not implemented\n"); - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "_access_lock", &access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "_wait_lock", &wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - callbacks.ThreadStart = &ThreadStart; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable VM_INIT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetThreadState_thrstat002_init(JNIEnv *env, jclass cls, - jint waitTime) { - wait_time = waitTime * 60000; -} - -void wait_for(jint millis) { - jvmtiError err; - - err = (*jvmti)->RawMonitorEnter(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#check) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorWait(jvmti, wait_lock, (jlong)millis); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait#check) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorExit(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#check) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetThreadState_thrstat002_checkStatus(JNIEnv *env, jclass cls, - jint statInd, jboolean suspended) { - jint thrState; - jint suspState = -1; - jint right_stat = (suspended ? JVMTI_THREAD_STATE_SUSPENDED : 0); - jvmtiError right_ans = (suspended ? JVMTI_ERROR_THREAD_SUSPENDED : JVMTI_ERROR_NONE); - char *suspStr = (suspended ? ", suspended" : ""); - jvmtiError err; - jint millis; - jboolean timeout_is_reached; - unsigned int waited_millis; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (thr_ptr == NULL) { - printf("Missing thread \"thr1\" start event\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_suspend) { - return; - } - - printf( "START checkStatus for \"thr1\" (0x%p%s), check state: %s\n", - thr_ptr, suspStr, TranslateState(state[statInd]) ); - - timeout_is_reached = JNI_TRUE; - for (millis = WAIT_START, waited_millis=0; millis < wait_time; millis <<= 1) { - err = (*jvmti)->GetThreadState(jvmti, thr_ptr, &thrState); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadState#%d) unexpected error: %s (%d)\n", - statInd, TranslateError(err), err); - result = STATUS_FAILED; - timeout_is_reached = JNI_FALSE; - break; - } - suspState = thrState & JVMTI_THREAD_STATE_SUSPENDED; - if (suspended || (thrState & JVMTI_THREAD_STATE_RUNNABLE) == 0 || - (state[statInd] == JVMTI_THREAD_STATE_RUNNABLE)) { - timeout_is_reached = JNI_FALSE; - break; - } - - waited_millis += millis; - wait_for(millis); - } - - if (printdump == JNI_TRUE) { - printf(">>> thread \"thr1\" (0x%p) state: %s (%d)\n", - thr_ptr, TranslateState(thrState), thrState); - printf(">>>\tflags:"); - printStateFlags(suspState); - } - - if (timeout_is_reached == JNI_TRUE) { - printf("Error: timeout (%d secs) has been reached\n", waited_millis/1000); - } - if ((thrState & state[statInd]) == 0) { - printf("Wrong thread \"thr1\" (0x%p%s) state:\n", thr_ptr, suspStr); - printf(" expected: %s (%d)\n", - TranslateState(state[statInd]), state[statInd]); - printf(" actual: %s (%d)\n", - TranslateState(thrState), thrState); - result = STATUS_FAILED; - } - if (suspState != right_stat) { - printf("Wrong thread \"thr1\" (0x%p%s) state flags:\n", - thr_ptr, suspStr); - printf(" expected:"); - printStateFlags(right_stat); - printf(" actual:"); - printStateFlags(suspState); - result = STATUS_FAILED; - } - - err = (*jvmti)->SuspendThread(jvmti, thr_ptr); - if (err != right_ans) { - printf("Wrong result of SuspendThread() for \"thr1\" (0x%p%s):\n", - thr_ptr, suspStr); - printf(" expected: %s (%d), actual: %s (%d)\n", - TranslateError(right_ans), right_ans, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (!suspended) { - // wait till thread is not suspended - timeout_is_reached = JNI_TRUE; - for (millis = WAIT_START, waited_millis=0; millis < wait_time; millis <<= 1) { - waited_millis += millis; - wait_for(millis); - err = (*jvmti)->GetThreadState(jvmti, thr_ptr, &thrState); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadState#%d,after) unexpected error: %s (%d)\n", - statInd, TranslateError(err), err); - timeout_is_reached = JNI_FALSE; - result = STATUS_FAILED; - break; - } - suspState = thrState & JVMTI_THREAD_STATE_SUSPENDED; - if (suspState) { - timeout_is_reached = JNI_FALSE; - break; - } - } - - if (timeout_is_reached == JNI_TRUE) { - printf("Error: timeout (%d secs) has been reached\n", waited_millis/1000); - } - if ((thrState & state[statInd]) == 0) { - printf("Wrong thread \"thr1\" (0x%p) state after SuspendThread:\n", - thr_ptr); - printf(" expected: %s (%d)\n", - TranslateState(state[statInd]), state[statInd]); - printf(" actual: %s (%d)\n", - TranslateState(thrState), thrState); - result = STATUS_FAILED; - } - if (suspState != JVMTI_THREAD_STATE_SUSPENDED) { - printf("Wrong thread \"thr1\" (0x%p) state flags", thr_ptr); - printf(" after SuspendThread:\n"); - printf(" expected:"); - printStateFlags(JVMTI_THREAD_STATE_SUSPENDED); - printf(" actual:"); - printStateFlags(suspState); - result = STATUS_FAILED; - } - err = (*jvmti)->ResumeThread(jvmti, thr_ptr); - if (err != JVMTI_ERROR_NONE) { - printf("(ResumeThread#%d) unexpected error: %s (%d)\n", - statInd, TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetThreadState_thrstat002_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/thrstat002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/thrstat002.cpp new file mode 100644 index 00000000000..a55220d0990 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat002/thrstat002.cpp @@ -0,0 +1,381 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define WAIT_START 100 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jrawMonitorID access_lock, wait_lock; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jthread thr_ptr = NULL; +static jint wait_time = 0; +static jint state[] = { + JVMTI_THREAD_STATE_RUNNABLE, + JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER, + JVMTI_THREAD_STATE_IN_OBJECT_WAIT +}; + +void printStateFlags(jint flags) { + if (flags & JVMTI_THREAD_STATE_SUSPENDED) + printf(" JVMTI_THREAD_STATE_SUSPENDED"); + if (flags & JVMTI_THREAD_STATE_INTERRUPTED) + printf(" JVMTI_THREAD_STATE_INTERRUPTED"); + if (flags & JVMTI_THREAD_STATE_IN_NATIVE) + printf(" JVMTI_THREAD_STATE_IN_NATIVE"); + printf(" (0x%0x)\n", flags); +} + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + jvmtiError err; + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_THREAD_START, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable THREAD_START event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL +ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + jvmtiThreadInfo thrInfo; + jvmtiError err; + + err = jvmti_env->RawMonitorEnter(access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetThreadInfo(thread, &thrInfo); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (thrInfo.name != NULL && strcmp(thrInfo.name, "thr1") == 0) { + thr_ptr = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, thread)); + if (printdump == JNI_TRUE) { + printf(">>> ThreadStart: \"%s\", 0x%p\n", thrInfo.name, thr_ptr); + } + } + + err = jvmti_env->RawMonitorExit(access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_thrstat002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_thrstat002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_thrstat002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_suspend) { + printf("Warning: suspend/resume is not implemented\n"); + } + + err = jvmti->CreateRawMonitor("_access_lock", &access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->CreateRawMonitor("_wait_lock", &wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + callbacks.ThreadStart = &ThreadStart; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable VM_INIT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetThreadState_thrstat002_init(JNIEnv *env, jclass cls, + jint waitTime) { + wait_time = waitTime * 60000; +} + +void wait_for(jint millis) { + jvmtiError err; + + err = jvmti->RawMonitorEnter(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#check) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorWait(wait_lock, (jlong)millis); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait#check) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorExit(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#check) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetThreadState_thrstat002_checkStatus(JNIEnv *env, jclass cls, + jint statInd, jboolean suspended) { + jint thrState; + jint suspState = -1; + jint right_stat = (suspended ? JVMTI_THREAD_STATE_SUSPENDED : 0); + jvmtiError right_ans = (suspended ? JVMTI_ERROR_THREAD_SUSPENDED : JVMTI_ERROR_NONE); + const char *suspStr = (suspended ? ", suspended" : ""); + jvmtiError err; + jint millis; + jboolean timeout_is_reached; + unsigned int waited_millis; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (thr_ptr == NULL) { + printf("Missing thread \"thr1\" start event\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_suspend) { + return; + } + + printf( "START checkStatus for \"thr1\" (0x%p%s), check state: %s\n", + thr_ptr, suspStr, TranslateState(state[statInd]) ); + + timeout_is_reached = JNI_TRUE; + for (millis = WAIT_START, waited_millis=0; millis < wait_time; millis <<= 1) { + err = jvmti->GetThreadState(thr_ptr, &thrState); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadState#%d) unexpected error: %s (%d)\n", + statInd, TranslateError(err), err); + result = STATUS_FAILED; + timeout_is_reached = JNI_FALSE; + break; + } + suspState = thrState & JVMTI_THREAD_STATE_SUSPENDED; + if (suspended || (thrState & JVMTI_THREAD_STATE_RUNNABLE) == 0 || + (state[statInd] == JVMTI_THREAD_STATE_RUNNABLE)) { + timeout_is_reached = JNI_FALSE; + break; + } + + waited_millis += millis; + wait_for(millis); + } + + if (printdump == JNI_TRUE) { + printf(">>> thread \"thr1\" (0x%p) state: %s (%d)\n", + thr_ptr, TranslateState(thrState), thrState); + printf(">>>\tflags:"); + printStateFlags(suspState); + } + + if (timeout_is_reached == JNI_TRUE) { + printf("Error: timeout (%d secs) has been reached\n", waited_millis/1000); + } + if ((thrState & state[statInd]) == 0) { + printf("Wrong thread \"thr1\" (0x%p%s) state:\n", thr_ptr, suspStr); + printf(" expected: %s (%d)\n", + TranslateState(state[statInd]), state[statInd]); + printf(" actual: %s (%d)\n", + TranslateState(thrState), thrState); + result = STATUS_FAILED; + } + if (suspState != right_stat) { + printf("Wrong thread \"thr1\" (0x%p%s) state flags:\n", + thr_ptr, suspStr); + printf(" expected:"); + printStateFlags(right_stat); + printf(" actual:"); + printStateFlags(suspState); + result = STATUS_FAILED; + } + + err = jvmti->SuspendThread(thr_ptr); + if (err != right_ans) { + printf("Wrong result of SuspendThread() for \"thr1\" (0x%p%s):\n", + thr_ptr, suspStr); + printf(" expected: %s (%d), actual: %s (%d)\n", + TranslateError(right_ans), right_ans, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (!suspended) { + // wait till thread is not suspended + timeout_is_reached = JNI_TRUE; + for (millis = WAIT_START, waited_millis=0; millis < wait_time; millis <<= 1) { + waited_millis += millis; + wait_for(millis); + err = jvmti->GetThreadState(thr_ptr, &thrState); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadState#%d,after) unexpected error: %s (%d)\n", + statInd, TranslateError(err), err); + timeout_is_reached = JNI_FALSE; + result = STATUS_FAILED; + break; + } + suspState = thrState & JVMTI_THREAD_STATE_SUSPENDED; + if (suspState) { + timeout_is_reached = JNI_FALSE; + break; + } + } + + if (timeout_is_reached == JNI_TRUE) { + printf("Error: timeout (%d secs) has been reached\n", waited_millis/1000); + } + if ((thrState & state[statInd]) == 0) { + printf("Wrong thread \"thr1\" (0x%p) state after SuspendThread:\n", + thr_ptr); + printf(" expected: %s (%d)\n", + TranslateState(state[statInd]), state[statInd]); + printf(" actual: %s (%d)\n", + TranslateState(thrState), thrState); + result = STATUS_FAILED; + } + if (suspState != JVMTI_THREAD_STATE_SUSPENDED) { + printf("Wrong thread \"thr1\" (0x%p) state flags", thr_ptr); + printf(" after SuspendThread:\n"); + printf(" expected:"); + printStateFlags(JVMTI_THREAD_STATE_SUSPENDED); + printf(" actual:"); + printStateFlags(suspState); + result = STATUS_FAILED; + } + err = jvmti->ResumeThread(thr_ptr); + if (err != JVMTI_ERROR_NONE) { + printf("(ResumeThread#%d) unexpected error: %s (%d)\n", + statInd, TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetThreadState_thrstat002_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/libthrstat003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/libthrstat003.c deleted file mode 100644 index 588febbd638..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/libthrstat003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "thrstat003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/libthrstat003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/libthrstat003.cpp new file mode 100644 index 00000000000..f908b023d5c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/libthrstat003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "thrstat003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/thrstat003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/thrstat003.c deleted file mode 100644 index f15405d247f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/thrstat003.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define WAIT_START 100 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jint wait_time = 0; -static jint state[] = { - 0, /* JVMTI_THREAD_STATUS_NOT_STARTED, */ - JVMTI_THREAD_STATE_SLEEPING, - JVMTI_THREAD_STATE_TERMINATED /* JVMTI_THREAD_STATUS_ZOMBIE */ -}; - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetThreadState_thrstat003_init(JNIEnv *env, jclass cls, - jint waitTime) { - wait_time = waitTime * 60000; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_thrstat003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_thrstat003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_thrstat003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetThreadState_thrstat003_check(JNIEnv *env, jclass cls, - jthread thr, jint statInd) { - jvmtiError err; - jrawMonitorID wait_lock; - jint thrState; - jint i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "_wait_lock", &wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - statInd, TranslateError(err), err); - result = STATUS_FAILED; - } - - for (i = WAIT_START; i < wait_time; i <<= 1) { - err = (*jvmti)->GetThreadState(jvmti, thr, &thrState); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadState#%d) unexpected error: %s (%d)\n", - statInd, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> thread state: %s (%d)\n", - TranslateState(thrState), thrState); - } - - if ((thrState & JVMTI_THREAD_STATE_RUNNABLE) == 0) { - break; - } - - err = (*jvmti)->RawMonitorEnter(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorWait(jvmti, wait_lock, (jlong)i); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorExit(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - - err = (*jvmti)->DestroyRawMonitor(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", - statInd, TranslateError(err), err); - result = STATUS_FAILED; - } - - /* We expect that thread is NOT_STARTED if statInd == 0 */ - if (statInd == 0 && thrState != state[statInd]) { - result = STATUS_FAILED; - } else if (statInd != 0 && (thrState & state[statInd]) == 0) { - result = STATUS_FAILED; - } - if (result == STATUS_FAILED) { - printf("Wrong state: %s (%d)\n", TranslateState(thrState), thrState); - printf(" expected: %s (%d)\n", - TranslateState(state[statInd]), state[statInd]); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/thrstat003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/thrstat003.cpp new file mode 100644 index 00000000000..d99ab7ecc6e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat003/thrstat003.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define WAIT_START 100 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jint wait_time = 0; +static jint state[] = { + 0, /* JVMTI_THREAD_STATUS_NOT_STARTED, */ + JVMTI_THREAD_STATE_SLEEPING, + JVMTI_THREAD_STATE_TERMINATED /* JVMTI_THREAD_STATUS_ZOMBIE */ +}; + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetThreadState_thrstat003_init(JNIEnv *env, jclass cls, + jint waitTime) { + wait_time = waitTime * 60000; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_thrstat003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_thrstat003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_thrstat003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetThreadState_thrstat003_check(JNIEnv *env, jclass cls, + jthread thr, jint statInd) { + jvmtiError err; + jrawMonitorID wait_lock; + jint thrState; + jint i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->CreateRawMonitor("_wait_lock", &wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + statInd, TranslateError(err), err); + result = STATUS_FAILED; + } + + for (i = WAIT_START; i < wait_time; i <<= 1) { + err = jvmti->GetThreadState(thr, &thrState); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadState#%d) unexpected error: %s (%d)\n", + statInd, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> thread state: %s (%d)\n", + TranslateState(thrState), thrState); + } + + if ((thrState & JVMTI_THREAD_STATE_RUNNABLE) == 0) { + break; + } + + err = jvmti->RawMonitorEnter(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorWait(wait_lock, (jlong)i); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorExit(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + + err = jvmti->DestroyRawMonitor(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", + statInd, TranslateError(err), err); + result = STATUS_FAILED; + } + + /* We expect that thread is NOT_STARTED if statInd == 0 */ + if (statInd == 0 && thrState != state[statInd]) { + result = STATUS_FAILED; + } else if (statInd != 0 && (thrState & state[statInd]) == 0) { + result = STATUS_FAILED; + } + if (result == STATUS_FAILED) { + printf("Wrong state: %s (%d)\n", TranslateState(thrState), thrState); + printf(" expected: %s (%d)\n", + TranslateState(state[statInd]), state[statInd]); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/libthrstat004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/libthrstat004.c deleted file mode 100644 index 9536113db66..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/libthrstat004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "thrstat004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/libthrstat004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/libthrstat004.cpp new file mode 100644 index 00000000000..59f350ce599 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/libthrstat004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "thrstat004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/thrstat004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/thrstat004.c deleted file mode 100644 index 0cd17001331..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/thrstat004.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_thrstat004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_thrstat004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_thrstat004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetThreadState_thrstat004_check(JNIEnv *env, jclass cls, jthread thr) { - jvmtiError err; - jint thrState; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (threadStatePtr) null pointer check ...\n"); - } - err = (*jvmti)->GetThreadState(jvmti, thr, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(threadStatePtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid thread check ...\n"); - } - err = (*jvmti)->GetThreadState(jvmti, cls, &thrState); - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/thrstat004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/thrstat004.cpp new file mode 100644 index 00000000000..449aa4a86a6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat004/thrstat004.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_thrstat004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_thrstat004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_thrstat004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetThreadState_thrstat004_check(JNIEnv *env, jclass cls, jthread thr) { + jvmtiError err; + jint thrState; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (threadStatePtr) null pointer check ...\n"); + } + err = jvmti->GetThreadState(thr, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(threadStatePtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid thread check ...\n"); + } + err = jvmti->GetThreadState(cls, &thrState); + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/libthrstat005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/libthrstat005.c deleted file mode 100644 index 4c5fcb34261..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/libthrstat005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "thrstat005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/libthrstat005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/libthrstat005.cpp new file mode 100644 index 00000000000..8df523e9268 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/libthrstat005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "thrstat005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/thrstat005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/thrstat005.c deleted file mode 100644 index 11cd6bcba3e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/thrstat005.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" - -#ifndef STANDALONE -#include "JVMTITools.h" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define THREAD_STATE_MASK ~(JVMTI_THREAD_STATE_SUSPENDED \ - | JVMTI_THREAD_STATE_INTERRUPTED \ - | JVMTI_THREAD_STATE_IN_NATIVE \ - | JVMTI_THREAD_STATE_VENDOR_1 \ - | JVMTI_THREAD_STATE_VENDOR_2 \ - | JVMTI_THREAD_STATE_VENDOR_3) - -static int g_ThreadState[] = { - 0, /* TS_NEW */ - JVMTI_THREAD_STATE_TERMINATED, /* TS_TERMINATED */ - JVMTI_THREAD_STATE_ALIVE - | JVMTI_THREAD_STATE_RUNNABLE, /* TS_RUN_RUNNING */ - JVMTI_THREAD_STATE_ALIVE - | JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER, /* TS_RUN_BLOCKED */ - JVMTI_THREAD_STATE_ALIVE - | JVMTI_THREAD_STATE_IN_OBJECT_WAIT - | JVMTI_THREAD_STATE_WAITING - | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT, /* TS_RUN_WAIT_TIMED */ - JVMTI_THREAD_STATE_ALIVE - | JVMTI_THREAD_STATE_IN_OBJECT_WAIT - | JVMTI_THREAD_STATE_WAITING - | JVMTI_THREAD_STATE_WAITING_INDEFINITELY, /* TS_RUN_WAIT_INDEF */ - JVMTI_THREAD_STATE_ALIVE - | JVMTI_THREAD_STATE_PARKED - | JVMTI_THREAD_STATE_WAITING - | JVMTI_THREAD_STATE_WAITING_INDEFINITELY, /* TS_RUN_WAIT_PARKED_INDEF */ - JVMTI_THREAD_STATE_ALIVE - | JVMTI_THREAD_STATE_PARKED - | JVMTI_THREAD_STATE_WAITING - | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT, /* TS_RUN_WAIT_PARKED_TIMED */ - JVMTI_THREAD_STATE_ALIVE - | JVMTI_THREAD_STATE_SLEEPING - | JVMTI_THREAD_STATE_WAITING - | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT, /* TS_RUN_WAIT_SLEEPING */ -}; - -static jvmtiEnv * g_ppJvmtiEnv = NULL; -static int g_waitTime = 1000; -jrawMonitorID g_waitMon; /* Monitor is used just for sleeping */ - -void reportError(const char * szErr, int res) { -#ifndef STANDALONE - printf("%s (%d: %s)\n", szErr, res, TranslateError(res)); -#else - printf("%s (%d)\n", szErr, res); -#endif - fflush(stdout); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_thrstat005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_thrstat005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_thrstat005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &g_ppJvmtiEnv), JVMTI_VERSION_1_1); - if ( res != JNI_OK || ! g_ppJvmtiEnv ) { - printf("Agent_OnLoad: Error: GetEnv returned error or NULL\n"); - return JNI_ERR; - } - - res = (*g_ppJvmtiEnv)->CreateRawMonitor(g_ppJvmtiEnv, "beast", &g_waitMon); - if ( res != JVMTI_ERROR_NONE ) { - reportError("Agent_OnLoad: error creating raw monitor", res); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_GetThreadState_thrstat005_setWaitTime(JNIEnv * pEnv, jclass class, jint waitTime) { - g_waitTime = waitTime; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_GetThreadState_thrstat005_checkThreadState(JNIEnv * pEnv, jclass class, jthread thread, jint stateIdx) { - - jint thrState; - jint maskedThrState; - int waitTime = 10; - - /* Repeat querying status until waitTime < g_waitTime */ - do { - int res = (*g_ppJvmtiEnv)->GetThreadState(g_ppJvmtiEnv, thread, &thrState); - if (res != JVMTI_ERROR_NONE) { - reportError("GetThreadState: unexpected error", res); - return JNI_FALSE; - } - - maskedThrState = thrState & THREAD_STATE_MASK; - printf("GetThreadState = %x. Masked: %x. Must be: %x\n", thrState, maskedThrState, g_ThreadState[stateIdx]); - fflush(stdout); - - if ( maskedThrState == g_ThreadState[stateIdx] ) - return JNI_TRUE; - - printf("checkThreadState: wait %d ms\n", waitTime); - fflush(stdout); - if ( (res = (*g_ppJvmtiEnv)->RawMonitorEnter(g_ppJvmtiEnv, g_waitMon)) != JVMTI_ERROR_NONE - || (res = (*g_ppJvmtiEnv)->RawMonitorWait(g_ppJvmtiEnv, g_waitMon, waitTime)) != JVMTI_ERROR_NONE - || (res = (*g_ppJvmtiEnv)->RawMonitorExit(g_ppJvmtiEnv, g_waitMon)) != JVMTI_ERROR_NONE ) { - reportError("GetThreadState: unexpected error", res); - return JNI_FALSE; - } - - waitTime <<= 1; - - } while ( waitTime < g_waitTime ); - - return JNI_FALSE; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/thrstat005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/thrstat005.cpp new file mode 100644 index 00000000000..0bcb45bdf91 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadState/thrstat005/thrstat005.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" + +#ifndef STANDALONE +#include "JVMTITools.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define THREAD_STATE_MASK ~(JVMTI_THREAD_STATE_SUSPENDED \ + | JVMTI_THREAD_STATE_INTERRUPTED \ + | JVMTI_THREAD_STATE_IN_NATIVE \ + | JVMTI_THREAD_STATE_VENDOR_1 \ + | JVMTI_THREAD_STATE_VENDOR_2 \ + | JVMTI_THREAD_STATE_VENDOR_3) + +static int g_ThreadState[] = { + 0, /* TS_NEW */ + JVMTI_THREAD_STATE_TERMINATED, /* TS_TERMINATED */ + JVMTI_THREAD_STATE_ALIVE + | JVMTI_THREAD_STATE_RUNNABLE, /* TS_RUN_RUNNING */ + JVMTI_THREAD_STATE_ALIVE + | JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER, /* TS_RUN_BLOCKED */ + JVMTI_THREAD_STATE_ALIVE + | JVMTI_THREAD_STATE_IN_OBJECT_WAIT + | JVMTI_THREAD_STATE_WAITING + | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT, /* TS_RUN_WAIT_TIMED */ + JVMTI_THREAD_STATE_ALIVE + | JVMTI_THREAD_STATE_IN_OBJECT_WAIT + | JVMTI_THREAD_STATE_WAITING + | JVMTI_THREAD_STATE_WAITING_INDEFINITELY, /* TS_RUN_WAIT_INDEF */ + JVMTI_THREAD_STATE_ALIVE + | JVMTI_THREAD_STATE_PARKED + | JVMTI_THREAD_STATE_WAITING + | JVMTI_THREAD_STATE_WAITING_INDEFINITELY, /* TS_RUN_WAIT_PARKED_INDEF */ + JVMTI_THREAD_STATE_ALIVE + | JVMTI_THREAD_STATE_PARKED + | JVMTI_THREAD_STATE_WAITING + | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT, /* TS_RUN_WAIT_PARKED_TIMED */ + JVMTI_THREAD_STATE_ALIVE + | JVMTI_THREAD_STATE_SLEEPING + | JVMTI_THREAD_STATE_WAITING + | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT, /* TS_RUN_WAIT_SLEEPING */ +}; + +static jvmtiEnv * g_ppJvmtiEnv = NULL; +static int g_waitTime = 1000; +jrawMonitorID g_waitMon; /* Monitor is used just for sleeping */ + +void reportError(const char * szErr, jvmtiError res) { +#ifndef STANDALONE + printf("%s (%d: %s)\n", szErr, res, TranslateError(res)); +#else + printf("%s (%d)\n", szErr, res); +#endif + fflush(stdout); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_thrstat005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_thrstat005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_thrstat005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError error; + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &g_ppJvmtiEnv), JVMTI_VERSION_1_1); + if ( res != JNI_OK || ! g_ppJvmtiEnv ) { + printf("Agent_OnLoad: Error: GetEnv returned error or NULL\n"); + return JNI_ERR; + } + + error = g_ppJvmtiEnv->CreateRawMonitor("beast", &g_waitMon); + if ( error != JVMTI_ERROR_NONE ) { + reportError("Agent_OnLoad: error creating raw monitor", error); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_GetThreadState_thrstat005_setWaitTime(JNIEnv * pEnv, jclass klass, jint waitTime) { + g_waitTime = waitTime; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_GetThreadState_thrstat005_checkThreadState(JNIEnv * pEnv, jclass klass, jthread thread, jint stateIdx) { + + jint thrState; + jint maskedThrState; + int waitTime = 10; + + /* Repeat querying status until waitTime < g_waitTime */ + do { + jvmtiError res = g_ppJvmtiEnv->GetThreadState(thread, &thrState); + if (res != JVMTI_ERROR_NONE) { + reportError("GetThreadState: unexpected error", res); + return JNI_FALSE; + } + + maskedThrState = thrState & THREAD_STATE_MASK; + printf("GetThreadState = %x. Masked: %x. Must be: %x\n", thrState, maskedThrState, g_ThreadState[stateIdx]); + fflush(stdout); + + if ( maskedThrState == g_ThreadState[stateIdx] ) + return JNI_TRUE; + + printf("checkThreadState: wait %d ms\n", waitTime); + fflush(stdout); + if ( (res = g_ppJvmtiEnv->RawMonitorEnter(g_waitMon)) != JVMTI_ERROR_NONE + || (res = g_ppJvmtiEnv->RawMonitorWait(g_waitMon, waitTime)) != JVMTI_ERROR_NONE + || (res = g_ppJvmtiEnv->RawMonitorExit(g_waitMon)) != JVMTI_ERROR_NONE ) { + reportError("GetThreadState: unexpected error", res); + return JNI_FALSE; + } + + waitTime <<= 1; + + } while ( waitTime < g_waitTime ); + + return JNI_FALSE; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/gettime001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/gettime001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/gettime001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/gettime001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/libgettime001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/libgettime001.c deleted file mode 100644 index 80ef4ae9858..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/libgettime001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "gettime001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/libgettime001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/libgettime001.cpp new file mode 100644 index 00000000000..3895ee1e27b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTime/gettime001/libgettime001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "gettime001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/libtimerinfo001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/libtimerinfo001.c deleted file mode 100644 index f17a35b7e4b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/libtimerinfo001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "timerinfo001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/libtimerinfo001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/libtimerinfo001.cpp new file mode 100644 index 00000000000..9216f749f43 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/libtimerinfo001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "timerinfo001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/timerinfo001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/timerinfo001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/timerinfo001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/timerinfo001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/libtopthrgrp001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/libtopthrgrp001.c deleted file mode 100644 index d3ab4f82260..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/libtopthrgrp001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "topthrgrp001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/libtopthrgrp001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/libtopthrgrp001.cpp new file mode 100644 index 00000000000..7fdec456d04 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/libtopthrgrp001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "topthrgrp001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/topthrgrp001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/topthrgrp001.c deleted file mode 100644 index 7d87e245db6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/topthrgrp001.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_topthrgrp001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_topthrgrp001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_topthrgrp001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetTopThreadGroups_topthrgrp001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jint i, groupCount = 0; - jthreadGroup *groups = NULL; - jvmtiThreadGroupInfo inf; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> getting top thread groups list ...\n"); - } - err = (*jvmti)->GetTopThreadGroups(jvmti, &groupCount, &groups); - if (err != JVMTI_ERROR_NONE) { - printf("(GetTopThreadGroups) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> getting info about groups ...\n"); - } - for (i = 0; i < groupCount; i++) { - err = (*jvmti)->GetThreadGroupInfo(jvmti, groups[i], &inf); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadGroupInfo#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } else { - if (printdump == JNI_TRUE) { - printf(">>> group %d ----------------\n", i); - printf(">>> name: %s\n", inf.name); - printf(">>> parent: 0x%p\n", inf.parent); - printf(">>> max priority: %d\n", inf.max_priority); - printf(">>> is daemon: %s\n", - (inf.is_daemon==JNI_TRUE) ? "true" : "false"); - } - if (inf.parent != NULL) { - printf("ERROR: thread group is not parentless!\n"); - printf(" group name: %s\n", inf.name); - printf(" parent: 0x%p\n", inf.parent); - result = STATUS_FAILED; - } - } - } - - if (printdump == JNI_TRUE) { - printf(">>> done ...\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/topthrgrp001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/topthrgrp001.cpp new file mode 100644 index 00000000000..0bf4df61757 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/topthrgrp001.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_topthrgrp001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_topthrgrp001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_topthrgrp001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetTopThreadGroups_topthrgrp001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jint i, groupCount = 0; + jthreadGroup *groups = NULL; + jvmtiThreadGroupInfo inf; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> getting top thread groups list ...\n"); + } + err = jvmti->GetTopThreadGroups(&groupCount, &groups); + if (err != JVMTI_ERROR_NONE) { + printf("(GetTopThreadGroups) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> getting info about groups ...\n"); + } + for (i = 0; i < groupCount; i++) { + err = jvmti->GetThreadGroupInfo(groups[i], &inf); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadGroupInfo#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } else { + if (printdump == JNI_TRUE) { + printf(">>> group %d ----------------\n", i); + printf(">>> name: %s\n", inf.name); + printf(">>> parent: 0x%p\n", inf.parent); + printf(">>> max priority: %d\n", inf.max_priority); + printf(">>> is daemon: %s\n", + (inf.is_daemon==JNI_TRUE) ? "true" : "false"); + } + if (inf.parent != NULL) { + printf("ERROR: thread group is not parentless!\n"); + printf(" group name: %s\n", inf.name); + printf(" parent: 0x%p\n", inf.parent); + result = STATUS_FAILED; + } + } + } + + if (printdump == JNI_TRUE) { + printf(">>> done ...\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/libtopthrgrp002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/libtopthrgrp002.c deleted file mode 100644 index 0b1b1bda109..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/libtopthrgrp002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "topthrgrp002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/libtopthrgrp002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/libtopthrgrp002.cpp new file mode 100644 index 00000000000..40585862c79 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/libtopthrgrp002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "topthrgrp002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/topthrgrp002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/topthrgrp002.c deleted file mode 100644 index e378cef7d83..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/topthrgrp002.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_topthrgrp002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_topthrgrp002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_topthrgrp002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_GetTopThreadGroups_topthrgrp002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jint groupCount; - jthreadGroup *groups; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (groupCountPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetTopThreadGroups(jvmti, NULL, &groups); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(groupCountPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (groupsPtr) null pointer check ...\n"); - } - err = (*jvmti)->GetTopThreadGroups(jvmti, &groupCount, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("(groupsPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/topthrgrp002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/topthrgrp002.cpp new file mode 100644 index 00000000000..3b9159e4960 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp002/topthrgrp002.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_topthrgrp002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_topthrgrp002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_topthrgrp002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_GetTopThreadGroups_topthrgrp002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jint groupCount; + jthreadGroup *groups; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (groupCountPtr) null pointer check ...\n"); + } + err = jvmti->GetTopThreadGroups(NULL, &groups); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(groupCountPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (groupsPtr) null pointer check ...\n"); + } + err = jvmti->GetTopThreadGroups(&groupCount, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("(groupsPtr) error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/getvern001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/getvern001.c deleted file mode 100644 index 3f33bb4f0bc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/getvern001.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x,y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x,y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getvern001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getvern001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getvern001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_GetVersionNumber_getvern001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jint ver = 0; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> functional check ...\n"); - } - err = (*jvmti)->GetVersionNumber(jvmti, &ver); - if (err != JVMTI_ERROR_NONE) { - printf("(GetVersionNumber) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf("JVMTI version: %d.%d\n", (ver >> 16) & 0x0fff, ver & 0xffff); - printf(">>> ... done\n"); - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->GetVersionNumber(jvmti, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s\n", - TranslateError(err)); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/getvern001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/getvern001.cpp new file mode 100644 index 00000000000..c2bcdfde05e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/getvern001.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x,y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x,y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getvern001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getvern001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getvern001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_GetVersionNumber_getvern001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jint ver = 0; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> functional check ...\n"); + } + err = jvmti->GetVersionNumber(&ver); + if (err != JVMTI_ERROR_NONE) { + printf("(GetVersionNumber) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf("JVMTI version: %d.%d\n", (ver >> 16) & 0x0fff, ver & 0xffff); + printf(">>> ... done\n"); + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->GetVersionNumber(NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s\n", + TranslateError(err)); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/libgetvern001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/libgetvern001.c deleted file mode 100644 index 17f5d8b03e0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/libgetvern001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getvern001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/libgetvern001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/libgetvern001.cpp new file mode 100644 index 00000000000..8e1de13c947 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetVersionNumber/getvern001/libgetvern001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getvern001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/intrpthrd001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/intrpthrd001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/intrpthrd001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/intrpthrd001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/libintrpthrd001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/libintrpthrd001.c deleted file mode 100644 index 9642ce63ea8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/libintrpthrd001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "intrpthrd001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/libintrpthrd001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/libintrpthrd001.cpp new file mode 100644 index 00000000000..34a9e819d17 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd001/libintrpthrd001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "intrpthrd001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/intrpthrd002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/intrpthrd002.c deleted file mode 100644 index 5b5d88236aa..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/intrpthrd002.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static jint result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_intrpthrd002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_intrpthrd002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_intrpthrd002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_signal_thread) { - printf("Warning: InterruptThread is not implemented\n"); - } - - return JNI_OK; -} - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_InterruptThread_intrpthrd002_check (JNIEnv *env, jobject oobj, - jint ind, jthread thr) { - jvmtiError err; - - err = (*jvmti)->InterruptThread(jvmti, thr); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_signal_thread) { - /* It is OK */ - } else if (err != JVMTI_ERROR_THREAD_NOT_ALIVE) { - printf("(thr#%d) error expected: JVMTI_ERROR_THREAD_NOT_ALIVE,", ind); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_InterruptThread_intrpthrd002_getResult (JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/intrpthrd002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/intrpthrd002.cpp new file mode 100644 index 00000000000..0278bc30f8b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/intrpthrd002.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static jint result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_intrpthrd002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_intrpthrd002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_intrpthrd002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_signal_thread) { + printf("Warning: InterruptThread is not implemented\n"); + } + + return JNI_OK; +} + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_InterruptThread_intrpthrd002_check (JNIEnv *env, jobject oobj, + jint ind, jthread thr) { + jvmtiError err; + + err = jvmti->InterruptThread(thr); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_signal_thread) { + /* It is OK */ + } else if (err != JVMTI_ERROR_THREAD_NOT_ALIVE) { + printf("(thr#%d) error expected: JVMTI_ERROR_THREAD_NOT_ALIVE,", ind); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_InterruptThread_intrpthrd002_getResult (JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/libintrpthrd002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/libintrpthrd002.c deleted file mode 100644 index 66300b17079..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/libintrpthrd002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "intrpthrd002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/libintrpthrd002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/libintrpthrd002.cpp new file mode 100644 index 00000000000..f42325f2722 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd002/libintrpthrd002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "intrpthrd002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/intrpthrd003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/intrpthrd003.c deleted file mode 100644 index c089057cbbd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/intrpthrd003.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jvmtiError intrpthrd_err = JVMTI_ERROR_NONE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_intrpthrd003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_intrpthrd003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_intrpthrd003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_signal_thread) { - printf("Warning: InterruptThread is not implemented\n"); - } - - return JNI_OK; -} - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_InterruptThread_intrpthrd003_check (JNIEnv *env, jobject oobj, - jint ind, jthread thr) { - - intrpthrd_err = (*jvmti)->InterruptThread(jvmti, thr); - if (intrpthrd_err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_signal_thread) { - /* It is OK */ - } else { - switch (intrpthrd_err) { - case JVMTI_ERROR_NONE: - case JVMTI_ERROR_THREAD_NOT_ALIVE: - break; - - default: - printf("(thr#%d) error expected: JVMTI_ERROR_NONE or JVMTI_ERROR_THREAD_NOT_ALIVE,", ind); - printf(" got: %s (%d)\n", TranslateError(intrpthrd_err), intrpthrd_err); - result = STATUS_FAILED; - break; - } - } - - return result; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_InterruptThread_intrpthrd003_getResult (JNIEnv *env, jclass cls) { - return result; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_InterruptThread_intrpthrd003_isThreadNotAliveError(JNIEnv *env, jclass cls) { - if (intrpthrd_err == JVMTI_ERROR_THREAD_NOT_ALIVE) { - return JNI_TRUE; - } - return JNI_FALSE; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/intrpthrd003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/intrpthrd003.cpp new file mode 100644 index 00000000000..c92f683bdd8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/intrpthrd003.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jvmtiError intrpthrd_err = JVMTI_ERROR_NONE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_intrpthrd003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_intrpthrd003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_intrpthrd003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_signal_thread) { + printf("Warning: InterruptThread is not implemented\n"); + } + + return JNI_OK; +} + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_InterruptThread_intrpthrd003_check (JNIEnv *env, jobject oobj, + jint ind, jthread thr) { + + intrpthrd_err = jvmti->InterruptThread(thr); + if (intrpthrd_err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_signal_thread) { + /* It is OK */ + } else { + switch (intrpthrd_err) { + case JVMTI_ERROR_NONE: + case JVMTI_ERROR_THREAD_NOT_ALIVE: + break; + + default: + printf("(thr#%d) error expected: JVMTI_ERROR_NONE or JVMTI_ERROR_THREAD_NOT_ALIVE,", ind); + printf(" got: %s (%d)\n", TranslateError(intrpthrd_err), intrpthrd_err); + result = STATUS_FAILED; + break; + } + } + + return result; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_InterruptThread_intrpthrd003_getResult (JNIEnv *env, jclass cls) { + return result; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_InterruptThread_intrpthrd003_isThreadNotAliveError(JNIEnv *env, jclass cls) { + if (intrpthrd_err == JVMTI_ERROR_THREAD_NOT_ALIVE) { + return JNI_TRUE; + } + return JNI_FALSE; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/libintrpthrd003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/libintrpthrd003.c deleted file mode 100644 index fb55557d38a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/libintrpthrd003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "intrpthrd003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/libintrpthrd003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/libintrpthrd003.cpp new file mode 100644 index 00000000000..112ac569e4c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/InterruptThread/intrpthrd003/libintrpthrd003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "intrpthrd003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/isarray004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/isarray004.c deleted file mode 100644 index a2f65ffdb68..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/isarray004.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_isarray004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_isarray004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_isarray004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_IsArrayClass_isarray004_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jboolean isArrayClass; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->IsArrayClass(jvmti, NULL, &isArrayClass); - if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->IsArrayClass(jvmti, cls, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/isarray004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/isarray004.cpp new file mode 100644 index 00000000000..09f6625ebfa --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/isarray004.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_isarray004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_isarray004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_isarray004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_IsArrayClass_isarray004_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jboolean isArrayClass; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->IsArrayClass(NULL, &isArrayClass); + if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->IsArrayClass(cls, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/libisarray004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/libisarray004.c deleted file mode 100644 index d530c11ba1d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/libisarray004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "isarray004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/libisarray004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/libisarray004.cpp new file mode 100644 index 00000000000..5c544be1b54 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray004/libisarray004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "isarray004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/isarray005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/isarray005.c deleted file mode 100644 index f574bc807ce..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/isarray005.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_isarray005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_isarray005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_isarray005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -char const *jbooleanToString(jboolean flag) { - return ((flag == JNI_TRUE) ? "true" : "false"); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_IsArrayClass_isarray005_check(JNIEnv *env, - jclass cls, jclass clazz, jboolean flag) { - jvmtiError err; - jboolean isArrayClass; - char *sig, *generic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassSignature(jvmti, clazz, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->IsArrayClass(jvmti, clazz, &isArrayClass); - if (err != JVMTI_ERROR_NONE) { - printf("(IsArrayClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> %s - %s\n", sig, jbooleanToString(isArrayClass)); - } - - if (isArrayClass != flag) { - printf("(%s) wrong isArrayClass value: %s, expected: %s\n", - sig, jbooleanToString(isArrayClass), jbooleanToString(flag)); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL -Java_nsk_jvmti_IsArrayClass_isarray005_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/isarray005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/isarray005.cpp new file mode 100644 index 00000000000..9d6586ecc96 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/isarray005.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_isarray005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_isarray005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_isarray005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +char const *jbooleanToString(jboolean flag) { + return ((flag == JNI_TRUE) ? "true" : "false"); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_IsArrayClass_isarray005_check(JNIEnv *env, + jclass cls, jclass clazz, jboolean flag) { + jvmtiError err; + jboolean isArrayClass; + char *sig, *generic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassSignature(clazz, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->IsArrayClass(clazz, &isArrayClass); + if (err != JVMTI_ERROR_NONE) { + printf("(IsArrayClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> %s - %s\n", sig, jbooleanToString(isArrayClass)); + } + + if (isArrayClass != flag) { + printf("(%s) wrong isArrayClass value: %s, expected: %s\n", + sig, jbooleanToString(isArrayClass), jbooleanToString(flag)); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL +Java_nsk_jvmti_IsArrayClass_isarray005_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/libisarray005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/libisarray005.c deleted file mode 100644 index c880dc05a95..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/libisarray005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "isarray005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/libisarray005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/libisarray005.cpp new file mode 100644 index 00000000000..da48b3d3ace --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsArrayClass/isarray005/libisarray005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "isarray005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/isfldsin002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/isfldsin002.c deleted file mode 100644 index fad0aa45f78..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/isfldsin002.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_isfldsin002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_isfldsin002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_isfldsin002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_synthetic_attribute) { - printf("Warning: IsFieldSynthetic is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_IsFieldSynthetic_isfldsin002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jfieldID fid; - jboolean isSynthetic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld", "I"); - if (fid == NULL) { - printf("Cannot get field ID!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->IsFieldSynthetic(jvmti, NULL, fid, &isSynthetic); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_synthetic_attribute) { - /* It is OK */ - } else if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid field check ...\n"); - } - err = (*jvmti)->IsFieldSynthetic(jvmti, cls, NULL, &isSynthetic); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_synthetic_attribute) { - /* It is OK */ - } else if (err != JVMTI_ERROR_INVALID_FIELDID) { - printf("Error expected: JVMTI_ERROR_INVALID_FIELDID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->IsFieldSynthetic(jvmti, cls, fid, NULL); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_synthetic_attribute) { - /* It is OK */ - } else if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/isfldsin002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/isfldsin002.cpp new file mode 100644 index 00000000000..c3caf50cfc1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/isfldsin002.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_isfldsin002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_isfldsin002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_isfldsin002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_synthetic_attribute) { + printf("Warning: IsFieldSynthetic is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_IsFieldSynthetic_isfldsin002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jfieldID fid; + jboolean isSynthetic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld", "I"); + if (fid == NULL) { + printf("Cannot get field ID!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->IsFieldSynthetic(NULL, fid, &isSynthetic); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_synthetic_attribute) { + /* It is OK */ + } else if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid field check ...\n"); + } + err = jvmti->IsFieldSynthetic(cls, NULL, &isSynthetic); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_synthetic_attribute) { + /* It is OK */ + } else if (err != JVMTI_ERROR_INVALID_FIELDID) { + printf("Error expected: JVMTI_ERROR_INVALID_FIELDID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->IsFieldSynthetic(cls, fid, NULL); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_synthetic_attribute) { + /* It is OK */ + } else if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/libisfldsin002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/libisfldsin002.c deleted file mode 100644 index 472c9928743..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/libisfldsin002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "isfldsin002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/libisfldsin002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/libisfldsin002.cpp new file mode 100644 index 00000000000..db335bedbd0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin002/libisfldsin002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "isfldsin002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/isfldsin003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/isfldsin003.c deleted file mode 100644 index d4a6a59b938..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/isfldsin003.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *name; - char *sig; - jboolean is_synthetic; -} field_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static field_info fields[] = { - { "fld", "I", JNI_FALSE }, - { "this$0", "Lnsk/jvmti/IsFieldSynthetic/isfldsin003a;", JNI_TRUE } -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_isfldsin003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_isfldsin003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_isfldsin003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_synthetic_attribute) { - printf("Warning: IsFieldSynthetic is not implemented\n"); - } - - return JNI_OK; -} - -char const *jbooleanToString(jboolean flag) { - return ((flag == JNI_TRUE) ? "true" : "false"); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_IsFieldSynthetic_isfldsin003a_check(JNIEnv *env, - jclass cls, jclass clazz) { - jvmtiError err; - jfieldID fid; - jboolean isSynthetic; - size_t i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - for (i = 0; i < sizeof(fields) / sizeof(field_info); i++) { - fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, clazz), - fields[i].name, fields[i].sig); - if (fid == NULL) { - printf("(%" PRIuPTR ") cannot get field ID for %s:\"%s\"\n", - i, fields[i].name, fields[i].sig); - result = STATUS_FAILED; - continue; - } - - err = (*jvmti)->IsFieldSynthetic(jvmti, clazz, fid, &isSynthetic); - if (err != JVMTI_ERROR_NONE) { - printf("(IsFieldSynthetic#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> %s:\"%s\", isSynthetic: %s\n", - fields[i].name, fields[i].sig, - jbooleanToString(isSynthetic)); - } - - if (isSynthetic != fields[i].is_synthetic) { - printf("%s:\"%s\"\n\t - isSynthetic expected: %s, actual: %s\n", - fields[i].name, fields[i].sig, - jbooleanToString(fields[i].is_synthetic), - jbooleanToString(isSynthetic)); - result = STATUS_FAILED; - } - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/isfldsin003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/isfldsin003.cpp new file mode 100644 index 00000000000..424d09cada0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/isfldsin003.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + const char *sig; + jboolean is_synthetic; +} field_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static field_info fields[] = { + { "fld", "I", JNI_FALSE }, + { "this$0", "Lnsk/jvmti/IsFieldSynthetic/isfldsin003a;", JNI_TRUE } +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_isfldsin003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_isfldsin003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_isfldsin003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_synthetic_attribute) { + printf("Warning: IsFieldSynthetic is not implemented\n"); + } + + return JNI_OK; +} + +char const *jbooleanToString(jboolean flag) { + return ((flag == JNI_TRUE) ? "true" : "false"); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_IsFieldSynthetic_isfldsin003a_check(JNIEnv *env, + jclass cls, jclass clazz) { + jvmtiError err; + jfieldID fid; + jboolean isSynthetic; + size_t i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + for (i = 0; i < sizeof(fields) / sizeof(field_info); i++) { + fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, clazz), + fields[i].name, fields[i].sig); + if (fid == NULL) { + printf("(%" PRIuPTR ") cannot get field ID for %s:\"%s\"\n", + i, fields[i].name, fields[i].sig); + result = STATUS_FAILED; + continue; + } + + err = jvmti->IsFieldSynthetic(clazz, fid, &isSynthetic); + if (err != JVMTI_ERROR_NONE) { + printf("(IsFieldSynthetic#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> %s:\"%s\", isSynthetic: %s\n", + fields[i].name, fields[i].sig, + jbooleanToString(isSynthetic)); + } + + if (isSynthetic != fields[i].is_synthetic) { + printf("%s:\"%s\"\n\t - isSynthetic expected: %s, actual: %s\n", + fields[i].name, fields[i].sig, + jbooleanToString(fields[i].is_synthetic), + jbooleanToString(isSynthetic)); + result = STATUS_FAILED; + } + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/libisfldsin003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/libisfldsin003.c deleted file mode 100644 index a352ebcfbdd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/libisfldsin003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "isfldsin003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/libisfldsin003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/libisfldsin003.cpp new file mode 100644 index 00000000000..e8561797ea6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsFieldSynthetic/isfldsin003/libisfldsin003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "isfldsin003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/isintrf004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/isintrf004.c deleted file mode 100644 index 7a8da967eb5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/isintrf004.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_isintrf004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_isintrf004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_isintrf004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_IsInterface_isintrf004_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jboolean isInterface; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->IsInterface(jvmti, NULL, &isInterface); - if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->IsInterface(jvmti, cls, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/isintrf004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/isintrf004.cpp new file mode 100644 index 00000000000..16ae804e2f9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/isintrf004.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_isintrf004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_isintrf004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_isintrf004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_IsInterface_isintrf004_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jboolean isInterface; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->IsInterface(NULL, &isInterface); + if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->IsInterface(cls, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/libisintrf004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/libisintrf004.c deleted file mode 100644 index e94f93ab69f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/libisintrf004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "isintrf004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/libisintrf004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/libisintrf004.cpp new file mode 100644 index 00000000000..9921d1d21e3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf004/libisintrf004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "isintrf004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/isintrf005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/isintrf005.c deleted file mode 100644 index fdb0b68f0ef..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/isintrf005.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_isintrf005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_isintrf005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_isintrf005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -char const *jbooleanToString(jboolean flag) { - return ((flag == JNI_TRUE) ? "true" : "false"); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_IsInterface_isintrf005_check(JNIEnv *env, jclass cls, jclass clazz, jboolean flag) { - jvmtiError err; - jboolean isInterface; - char *sig, *generic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetClassSignature(jvmti, clazz, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->IsInterface(jvmti, clazz, &isInterface); - if (err != JVMTI_ERROR_NONE) { - printf("(IsInterface) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> %s - %s\n", sig, jbooleanToString(isInterface)); - } - - if (isInterface != flag) { - printf("(%s) wrong isInterface value: %s, expected: %s\n", - sig, jbooleanToString(isInterface), jbooleanToString(flag)); - result = STATUS_FAILED; - } -} - -JNIEXPORT int JNICALL Java_nsk_jvmti_IsInterface_isintrf005_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/isintrf005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/isintrf005.cpp new file mode 100644 index 00000000000..f5c8325e9bd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/isintrf005.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_isintrf005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_isintrf005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_isintrf005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +char const *jbooleanToString(jboolean flag) { + return ((flag == JNI_TRUE) ? "true" : "false"); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_IsInterface_isintrf005_check(JNIEnv *env, jclass cls, jclass clazz, jboolean flag) { + jvmtiError err; + jboolean isInterface; + char *sig, *generic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetClassSignature(clazz, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->IsInterface(clazz, &isInterface); + if (err != JVMTI_ERROR_NONE) { + printf("(IsInterface) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> %s - %s\n", sig, jbooleanToString(isInterface)); + } + + if (isInterface != flag) { + printf("(%s) wrong isInterface value: %s, expected: %s\n", + sig, jbooleanToString(isInterface), jbooleanToString(flag)); + result = STATUS_FAILED; + } +} + +JNIEXPORT int JNICALL Java_nsk_jvmti_IsInterface_isintrf005_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/libisintrf005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/libisintrf005.c deleted file mode 100644 index d05dfff8667..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/libisintrf005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "isintrf005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/libisintrf005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/libisintrf005.cpp new file mode 100644 index 00000000000..8920de001d5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsInterface/isintrf005/libisintrf005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "isintrf005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/isnative001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/isnative001.c deleted file mode 100644 index 5196ae16348..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/isnative001.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_isnative001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_isnative001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_isnative001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -char const *jbooleanToString(jboolean flag) { - return ((flag == JNI_TRUE) ? "true" : "false"); -} - -void checkMeth(JNIEnv *env, jclass cl, - char *name, char *sig, int stat, jboolean flag) { - jvmtiError err; - jmethodID mid; - jboolean is_native; - - if (stat) { - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), name, sig); - } else { - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); - } - if (mid == NULL) { - printf("Cannot find MethodID for \"%s%s\"\n", name, sig); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->IsMethodNative(jvmti, mid, &is_native); - if (err != JVMTI_ERROR_NONE) { - printf("(IsMethodNative) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> %s%s - %s\n", name, sig, jbooleanToString(is_native)); - } - - if (is_native != flag) { - printf("(%s%s) wrong is_native value: %s, expected: %s\n", - name, sig, jbooleanToString(is_native), jbooleanToString(flag)); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_IsMethodNative_isnative001_check(JNIEnv *env, jclass cls) { - jclass clsId; - - checkMeth(env, cls, "", "()V", 0, JNI_FALSE); - checkMeth(env, cls, "run", - "([Ljava/lang/String;Ljava/io/PrintStream;)I", 1, JNI_FALSE); - checkMeth(env, cls, "meth_stat", "(ILjava/lang/String;)[F", 1, JNI_FALSE); - checkMeth(env, cls, "meth_1", "(CCC)C", 0, JNI_FALSE); - checkMeth(env, cls, "nmeth", "()V", 0, JNI_TRUE); - checkMeth(env, cls, "check", "()I", 1, JNI_TRUE); - - clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/IsMethodNative/isnative001$Inn")); - if (clsId == NULL) { - printf("Cannot find nsk.jvmti.IsMethodNative.isnative001$Inn class!\n"); - return STATUS_FAILED; - } - - checkMeth(env, clsId, "meth_inn", "(Ljava/lang/String;J)V", 0, JNI_FALSE); - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/isnative001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/isnative001.cpp new file mode 100644 index 00000000000..a4e6690a354 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/isnative001.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_isnative001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_isnative001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_isnative001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +char const *jbooleanToString(jboolean flag) { + return ((flag == JNI_TRUE) ? "true" : "false"); +} + +void checkMeth(JNIEnv *env, jclass cl, + const char *name, const char *sig, int stat, jboolean flag) { + jvmtiError err; + jmethodID mid; + jboolean is_native; + + if (stat) { + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), name, sig); + } else { + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), name, sig); + } + if (mid == NULL) { + printf("Cannot find MethodID for \"%s%s\"\n", name, sig); + result = STATUS_FAILED; + return; + } + + err = jvmti->IsMethodNative(mid, &is_native); + if (err != JVMTI_ERROR_NONE) { + printf("(IsMethodNative) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> %s%s - %s\n", name, sig, jbooleanToString(is_native)); + } + + if (is_native != flag) { + printf("(%s%s) wrong is_native value: %s, expected: %s\n", + name, sig, jbooleanToString(is_native), jbooleanToString(flag)); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_IsMethodNative_isnative001_check(JNIEnv *env, jclass cls) { + jclass clsId; + + checkMeth(env, cls, "", "()V", 0, JNI_FALSE); + checkMeth(env, cls, "run", + "([Ljava/lang/String;Ljava/io/PrintStream;)I", 1, JNI_FALSE); + checkMeth(env, cls, "meth_stat", "(ILjava/lang/String;)[F", 1, JNI_FALSE); + checkMeth(env, cls, "meth_1", "(CCC)C", 0, JNI_FALSE); + checkMeth(env, cls, "nmeth", "()V", 0, JNI_TRUE); + checkMeth(env, cls, "check", "()I", 1, JNI_TRUE); + + clsId = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/IsMethodNative/isnative001$Inn")); + if (clsId == NULL) { + printf("Cannot find nsk.jvmti.IsMethodNative.isnative001$Inn class!\n"); + return STATUS_FAILED; + } + + checkMeth(env, clsId, "meth_inn", "(Ljava/lang/String;J)V", 0, JNI_FALSE); + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/libisnative001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/libisnative001.c deleted file mode 100644 index 3439ed52ac3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/libisnative001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "isnative001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/libisnative001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/libisnative001.cpp new file mode 100644 index 00000000000..3b030f215b6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative001/libisnative001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "isnative001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/isnative002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/isnative002.c deleted file mode 100644 index beb775c2860..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/isnative002.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_isnative002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_isnative002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_isnative002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_IsMethodNative_isnative002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jboolean isNative; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "", "()V"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->IsMethodNative(jvmti, NULL, &isNative); - if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->IsMethodNative(jvmti, mid, NULL); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/isnative002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/isnative002.cpp new file mode 100644 index 00000000000..d5d7228a458 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/isnative002.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_isnative002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_isnative002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_isnative002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_IsMethodNative_isnative002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jboolean isNative; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "", "()V"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->IsMethodNative(NULL, &isNative); + if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->IsMethodNative(mid, NULL); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/libisnative002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/libisnative002.c deleted file mode 100644 index dc3ff5d1ede..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/libisnative002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "isnative002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/libisnative002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/libisnative002.cpp new file mode 100644 index 00000000000..de92491c3b2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodNative/isnative002/libisnative002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "isnative002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/isobsolete001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/isobsolete001.c deleted file mode 100644 index 544401c3e23..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/isobsolete001.c +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/IsMethodObsolete/isobsolete001" -#define TESTED_CLASS_NAME "nsk/jvmti/IsMethodObsolete/isobsolete001r" -#define TESTED_CLASS_SIG "L"TESTED_CLASS_NAME";" -#define TESTED_THREAD_NAME "testedThread" -#define CLASSFILE_FIELD_NAME "classfileBytes" -#define CLASSFILE_FIELD_SIG "[B" - -#define STATIC_METHOD_NAME "testedStaticMethod" -#define STATIC_METHOD_SIG "(I"TESTED_CLASS_SIG")I" -#define INSTANCE_METHOD_NAME "testedInstanceMethod" -#define INSTANCE_METHOD_SIG "(I)I" - -/* constants */ -#define MAX_STACK_DEPTH 64 - -/* ============================================================================= */ - -/** Check is method obsolete is as expected. */ -static void checkMethodObsolete(jvmtiEnv* jvmti, jmethodID method, const char name[], - const char kind[], jboolean expected) { - - jboolean obsolete = JNI_FALSE; - - NSK_DISPLAY3("Call IsObsolete() for %s method: %p (%s)\n", kind, (void*)method, name); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(IsMethodObsolete, jvmti, method, &obsolete))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY1(" ... got obsolete: %d\n", (int)obsolete); - if (obsolete != expected) { - NSK_COMPLAIN4("IsObsolete() returns unexpected value for %s method: %s\n" - "# return value: %d\n" - "# expected: %d\n", - kind, name, - (int)obsolete, (int)expected); - nsk_jvmti_setFailStatus(); - } -} - -/** Check is obsolete for methods on the stack are as expected. */ -static void checkStackMethodsObsolete(jvmtiEnv* jvmti, jthread thread, - const char kind[], jboolean expected) { - - jvmtiFrameInfo frameStack[MAX_STACK_DEPTH]; - jint frameCount = 0; - - NSK_DISPLAY1("Get stack frames for thread: %p\n", (void*)thread); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB6(GetStackTrace, jvmti, thread, 0, MAX_STACK_DEPTH, - frameStack, &frameCount))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got frames: %d\n", (int)frameCount); - - NSK_DISPLAY1("Check methods of each frame: %d frames\n", (int)frameCount); - { - int found = 0; - int i; - - for (i = 0; i < frameCount; i++) { - char* name = NULL; - char* signature = NULL; - char* generic = NULL; - char* kind = NULL; - - NSK_DISPLAY1(" frame #%i:\n", i); - NSK_DISPLAY1(" methodID: %p\n", (void*)frameStack[i].method); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(GetMethodName, jvmti, frameStack[i].method, - &name, &signature, &generic))) { - nsk_jvmti_setFailStatus(); - continue; - } - NSK_DISPLAY1(" name: %s\n", nsk_null_string(name)); - NSK_DISPLAY1(" signature: %s\n", nsk_null_string(signature)); - NSK_DISPLAY1(" generic: %s\n", nsk_null_string(generic)); - if (name != NULL - && (strcmp(STATIC_METHOD_NAME, name) == 0 - || strcmp(INSTANCE_METHOD_NAME, name) == 0)) { - found++; - NSK_DISPLAY1("SUCCESS: found redefined method on stack: %s\n", name); - checkMethodObsolete(jvmti, frameStack[i].method, name, - "obsolete redefined", expected); - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)name))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)signature))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)generic))) { - nsk_jvmti_setFailStatus(); - } - } - - if (found < 2) { - NSK_COMPLAIN3("Not all %s methods found on stack:\n" - "# found methods: %d\n" - "# expected: %d\n", - kind, found, 2); - nsk_jvmti_setFailStatus(); - } - } -} - -/** Redefine class with given bytecode. */ -static int redefineClass(jvmtiEnv* jvmti, jclass klass, const char className[], - jint size, unsigned char bytes[]) { - jvmtiClassDefinition classDef; - - classDef.klass = klass; - classDef.class_byte_count = size; - classDef.class_bytes = bytes; - - NSK_DISPLAY1("Redefine class: %s\n", className); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &classDef))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... redefined with classfile: %d bytes\n", (int)size); - - return NSK_TRUE; -} - -/** Get classfile bytes to redefine. */ -static int getClassfileBytes(JNIEnv* jni, jvmtiEnv* jvmti, - jint* size, unsigned char* *bytes) { - jclass debugeeClass = NULL; - jfieldID fieldID = NULL; - jbyteArray array = NULL; - jbyte* elements; - int i; - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: %p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find static field: %s\n", CLASSFILE_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - CLASSFILE_FIELD_NAME, CLASSFILE_FIELD_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: %p\n", (void*)fieldID); - - NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", CLASSFILE_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - fieldID)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array object: %p\n", (void*)array); - - if (!NSK_JNI_VERIFY(jni, (*size = - NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); - - { - jboolean isCopy; - if (!NSK_JNI_VERIFY(jni, (elements = - NSK_CPP_STUB3(GetByteArrayElements, jni, array, - &isCopy)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - NSK_DISPLAY1(" ... got elements list: %p\n", (void*)elements); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... created bytes array: %p\n", (void*)*bytes); - - for (i = 0; i < *size; i++) { - (*bytes)[i] = (unsigned char)elements[i]; - } - NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); - - NSK_DISPLAY1("Release elements list: %p\n", (void*)elements); - NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); - NSK_DISPLAY0(" ... released\n"); - - return NSK_TRUE; -} - - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for tested methods to run\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - jclass testedClass = NULL; - jobject testedThread = NULL; - jmethodID staticMethodID = NULL; - jmethodID instanceMethodID = NULL; - unsigned char* classfileBytes = NULL; - jint classfileSize = 0; - - NSK_DISPLAY0(">>> Obtain bytes for class file redefinition\n"); - { - if (!NSK_VERIFY(getClassfileBytes(jni, jvmti, &classfileSize, &classfileBytes))) - return; - } - - NSK_DISPLAY0(">>> Find tested methods and running thread\n"); - { - NSK_DISPLAY1("Find tested class: %s\n", TESTED_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(FindClass, jni, TESTED_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: %p\n", (void*)testedClass); - - NSK_DISPLAY1("Make global reference for class object: %p\n", (void*)testedClass); - if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass) - NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got reference: %p\n", (void*)testedClass); - - NSK_DISPLAY1("Get static methodID: %s\n", STATIC_METHOD_NAME); - if (!NSK_JNI_VERIFY(jni, (staticMethodID = - NSK_CPP_STUB4(GetStaticMethodID, jni, testedClass, - STATIC_METHOD_NAME, STATIC_METHOD_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got methodID: %p\n", (void*)staticMethodID); - - NSK_DISPLAY1("Get instance methodID: %s\n", INSTANCE_METHOD_NAME); - if (!NSK_JNI_VERIFY(jni, (instanceMethodID = - NSK_CPP_STUB4(GetMethodID, jni, testedClass, - INSTANCE_METHOD_NAME, INSTANCE_METHOD_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got methodID: %p\n", (void*)instanceMethodID); - - NSK_DISPLAY1("Find thread with running methods by name: %s\n", TESTED_THREAD_NAME); - if (!NSK_VERIFY((testedThread = - nsk_jvmti_threadByName(TESTED_THREAD_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got thread reference: %p\n", (void*)testedThread); - } - - NSK_DISPLAY0(">>> Testcase #1: check IsObsolete() for methods before class redefinition\n"); - { - checkMethodObsolete(jvmti, staticMethodID, STATIC_METHOD_NAME, - "not yet redefined", JNI_FALSE); - checkMethodObsolete(jvmti, instanceMethodID, INSTANCE_METHOD_NAME, - "not yet redefined", JNI_FALSE); - } - - NSK_DISPLAY0(">>> Testcase #2: check IsObsolete() for methods on stack before class redefinition\n"); - { - checkStackMethodsObsolete(jvmti, testedThread, "not yet redefined", JNI_FALSE); - } - - NSK_DISPLAY0(">>> Redefine class while methods are on the stack\n"); - { - if (!NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, - classfileSize, classfileBytes))) - return; - } - - NSK_DISPLAY0(">>> Testcase #3: check IsObsolete() for methods after class redefinition\n"); - { - checkMethodObsolete(jvmti, staticMethodID, STATIC_METHOD_NAME, - "redefined", JNI_FALSE); - checkMethodObsolete(jvmti, instanceMethodID, INSTANCE_METHOD_NAME, - "redefined", JNI_FALSE); - } - - NSK_DISPLAY0(">>> Testcase #4: check IsObsolete() for obsoleted methods on stack after class redefinition\n"); - { - checkStackMethodsObsolete(jvmti, testedThread, "obsolete redefined", JNI_TRUE); - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - NSK_DISPLAY1("Deallocate classfile bytes array: %p\n", (void*)classfileBytes); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, classfileBytes))) { - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY1("Delete global eference to thread: %p\n", (void*)testedThread); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedThread)); - - NSK_DISPLAY1("Delete global reference to class: %p\n", (void*)testedClass); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_isobsolete001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_isobsolete001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_isobsolete001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* add required capabilities */ - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/isobsolete001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/isobsolete001.cpp new file mode 100644 index 00000000000..3d7efbce1d3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/isobsolete001.cpp @@ -0,0 +1,415 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/IsMethodObsolete/isobsolete001" +#define TESTED_CLASS_NAME "nsk/jvmti/IsMethodObsolete/isobsolete001r" +#define TESTED_CLASS_SIG "L" TESTED_CLASS_NAME ";" +#define TESTED_THREAD_NAME "testedThread" +#define CLASSFILE_FIELD_NAME "classfileBytes" +#define CLASSFILE_FIELD_SIG "[B" + +#define STATIC_METHOD_NAME "testedStaticMethod" +#define STATIC_METHOD_SIG "(I" TESTED_CLASS_SIG ")I" +#define INSTANCE_METHOD_NAME "testedInstanceMethod" +#define INSTANCE_METHOD_SIG "(I)I" + +/* constants */ +#define MAX_STACK_DEPTH 64 + +/* ============================================================================= */ + +/** Check is method obsolete is as expected. */ +static void checkMethodObsolete(jvmtiEnv* jvmti, jmethodID method, const char name[], + const char kind[], jboolean expected) { + + jboolean obsolete = JNI_FALSE; + + NSK_DISPLAY3("Call IsObsolete() for %s method: %p (%s)\n", kind, (void*)method, name); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(IsMethodObsolete, jvmti, method, &obsolete))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY1(" ... got obsolete: %d\n", (int)obsolete); + if (obsolete != expected) { + NSK_COMPLAIN4("IsObsolete() returns unexpected value for %s method: %s\n" + "# return value: %d\n" + "# expected: %d\n", + kind, name, + (int)obsolete, (int)expected); + nsk_jvmti_setFailStatus(); + } +} + +/** Check is obsolete for methods on the stack are as expected. */ +static void checkStackMethodsObsolete(jvmtiEnv* jvmti, jthread thread, + const char kind[], jboolean expected) { + + jvmtiFrameInfo frameStack[MAX_STACK_DEPTH]; + jint frameCount = 0; + + NSK_DISPLAY1("Get stack frames for thread: %p\n", (void*)thread); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB6(GetStackTrace, jvmti, thread, 0, MAX_STACK_DEPTH, + frameStack, &frameCount))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got frames: %d\n", (int)frameCount); + + NSK_DISPLAY1("Check methods of each frame: %d frames\n", (int)frameCount); + { + int found = 0; + int i; + + for (i = 0; i < frameCount; i++) { + char* name = NULL; + char* signature = NULL; + char* generic = NULL; + char* kind = NULL; + + NSK_DISPLAY1(" frame #%i:\n", i); + NSK_DISPLAY1(" methodID: %p\n", (void*)frameStack[i].method); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(GetMethodName, jvmti, frameStack[i].method, + &name, &signature, &generic))) { + nsk_jvmti_setFailStatus(); + continue; + } + NSK_DISPLAY1(" name: %s\n", nsk_null_string(name)); + NSK_DISPLAY1(" signature: %s\n", nsk_null_string(signature)); + NSK_DISPLAY1(" generic: %s\n", nsk_null_string(generic)); + if (name != NULL + && (strcmp(STATIC_METHOD_NAME, name) == 0 + || strcmp(INSTANCE_METHOD_NAME, name) == 0)) { + found++; + NSK_DISPLAY1("SUCCESS: found redefined method on stack: %s\n", name); + checkMethodObsolete(jvmti, frameStack[i].method, name, + "obsolete redefined", expected); + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)name))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)signature))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)generic))) { + nsk_jvmti_setFailStatus(); + } + } + + if (found < 2) { + NSK_COMPLAIN3("Not all %s methods found on stack:\n" + "# found methods: %d\n" + "# expected: %d\n", + kind, found, 2); + nsk_jvmti_setFailStatus(); + } + } +} + +/** Redefine class with given bytecode. */ +static int redefineClass(jvmtiEnv* jvmti, jclass klass, const char className[], + jint size, unsigned char bytes[]) { + jvmtiClassDefinition classDef; + + classDef.klass = klass; + classDef.class_byte_count = size; + classDef.class_bytes = bytes; + + NSK_DISPLAY1("Redefine class: %s\n", className); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &classDef))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... redefined with classfile: %d bytes\n", (int)size); + + return NSK_TRUE; +} + +/** Get classfile bytes to redefine. */ +static int getClassfileBytes(JNIEnv* jni, jvmtiEnv* jvmti, + jint* size, unsigned char* *bytes) { + jclass debugeeClass = NULL; + jfieldID fieldID = NULL; + jbyteArray array = NULL; + jbyte* elements; + int i; + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: %p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find static field: %s\n", CLASSFILE_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + CLASSFILE_FIELD_NAME, CLASSFILE_FIELD_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: %p\n", (void*)fieldID); + + NSK_DISPLAY1("Get classfile bytes array from static field: %s\n", CLASSFILE_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (array = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + fieldID)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array object: %p\n", (void*)array); + + if (!NSK_JNI_VERIFY(jni, (*size = + NSK_CPP_STUB2(GetArrayLength, jni, array)) > 0)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got array size: %d bytes\n", (int)*size); + + { + jboolean isCopy; + if (!NSK_JNI_VERIFY(jni, (elements = + NSK_CPP_STUB3(GetByteArrayElements, jni, array, + &isCopy)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + NSK_DISPLAY1(" ... got elements list: %p\n", (void*)elements); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, *size, bytes))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... created bytes array: %p\n", (void*)*bytes); + + for (i = 0; i < *size; i++) { + (*bytes)[i] = (unsigned char)elements[i]; + } + NSK_DISPLAY1(" ... copied bytecode: %d bytes\n", (int)*size); + + NSK_DISPLAY1("Release elements list: %p\n", (void*)elements); + NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni, array, elements, JNI_ABORT)); + NSK_DISPLAY0(" ... released\n"); + + return NSK_TRUE; +} + + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for tested methods to run\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + jclass testedClass = NULL; + jobject testedThread = NULL; + jmethodID staticMethodID = NULL; + jmethodID instanceMethodID = NULL; + unsigned char* classfileBytes = NULL; + jint classfileSize = 0; + + NSK_DISPLAY0(">>> Obtain bytes for class file redefinition\n"); + { + if (!NSK_VERIFY(getClassfileBytes(jni, jvmti, &classfileSize, &classfileBytes))) + return; + } + + NSK_DISPLAY0(">>> Find tested methods and running thread\n"); + { + NSK_DISPLAY1("Find tested class: %s\n", TESTED_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (testedClass = + NSK_CPP_STUB2(FindClass, jni, TESTED_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: %p\n", (void*)testedClass); + + NSK_DISPLAY1("Make global reference for class object: %p\n", (void*)testedClass); + if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got reference: %p\n", (void*)testedClass); + + NSK_DISPLAY1("Get static methodID: %s\n", STATIC_METHOD_NAME); + if (!NSK_JNI_VERIFY(jni, (staticMethodID = + NSK_CPP_STUB4(GetStaticMethodID, jni, testedClass, + STATIC_METHOD_NAME, STATIC_METHOD_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got methodID: %p\n", (void*)staticMethodID); + + NSK_DISPLAY1("Get instance methodID: %s\n", INSTANCE_METHOD_NAME); + if (!NSK_JNI_VERIFY(jni, (instanceMethodID = + NSK_CPP_STUB4(GetMethodID, jni, testedClass, + INSTANCE_METHOD_NAME, INSTANCE_METHOD_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got methodID: %p\n", (void*)instanceMethodID); + + NSK_DISPLAY1("Find thread with running methods by name: %s\n", TESTED_THREAD_NAME); + if (!NSK_VERIFY((testedThread = + nsk_jvmti_threadByName(TESTED_THREAD_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got thread reference: %p\n", (void*)testedThread); + } + + NSK_DISPLAY0(">>> Testcase #1: check IsObsolete() for methods before class redefinition\n"); + { + checkMethodObsolete(jvmti, staticMethodID, STATIC_METHOD_NAME, + "not yet redefined", JNI_FALSE); + checkMethodObsolete(jvmti, instanceMethodID, INSTANCE_METHOD_NAME, + "not yet redefined", JNI_FALSE); + } + + NSK_DISPLAY0(">>> Testcase #2: check IsObsolete() for methods on stack before class redefinition\n"); + { + checkStackMethodsObsolete(jvmti, testedThread, "not yet redefined", JNI_FALSE); + } + + NSK_DISPLAY0(">>> Redefine class while methods are on the stack\n"); + { + if (!NSK_VERIFY(redefineClass(jvmti, testedClass, TESTED_CLASS_NAME, + classfileSize, classfileBytes))) + return; + } + + NSK_DISPLAY0(">>> Testcase #3: check IsObsolete() for methods after class redefinition\n"); + { + checkMethodObsolete(jvmti, staticMethodID, STATIC_METHOD_NAME, + "redefined", JNI_FALSE); + checkMethodObsolete(jvmti, instanceMethodID, INSTANCE_METHOD_NAME, + "redefined", JNI_FALSE); + } + + NSK_DISPLAY0(">>> Testcase #4: check IsObsolete() for obsoleted methods on stack after class redefinition\n"); + { + checkStackMethodsObsolete(jvmti, testedThread, "obsolete redefined", JNI_TRUE); + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + NSK_DISPLAY1("Deallocate classfile bytes array: %p\n", (void*)classfileBytes); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, classfileBytes))) { + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY1("Delete global eference to thread: %p\n", (void*)testedThread); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedThread)); + + NSK_DISPLAY1("Delete global reference to class: %p\n", (void*)testedClass); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_isobsolete001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_isobsolete001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_isobsolete001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* add required capabilities */ + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/libisobsolete001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/libisobsolete001.c deleted file mode 100644 index 51008e3cc4c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/libisobsolete001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "isobsolete001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/libisobsolete001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/libisobsolete001.cpp new file mode 100644 index 00000000000..26b77002a3d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodObsolete/isobsolete001/libisobsolete001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "isobsolete001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/issynth001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/issynth001.c deleted file mode 100644 index f0261693000..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/issynth001.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - int class_id; - char *name; - char *signature; - jboolean is_static; - jboolean is_synthetic; -} method_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static method_info methods[] = { - {1, "meth_stat", "(ILjava/lang/String;)[F", JNI_TRUE, JNI_FALSE}, - {1, "meth_1", "(CCC)C", JNI_FALSE, JNI_FALSE}, - {1, "class$", "(Ljava/lang/String;)Ljava/lang/Class;", JNI_TRUE, JNI_TRUE}, - {1, "access$000", - "(Lnsk/jvmti/IsMethodSynthetic/issynth001a;)I", JNI_TRUE, JNI_TRUE}, - {1, "nmeth", "()V", JNI_FALSE, JNI_FALSE}, - {1, "check", "(Ljava/lang/Class;Ljava/lang/Class;)I", JNI_TRUE, JNI_FALSE}, - - {2, "", "()V", JNI_FALSE, JNI_FALSE}, - {2, "run", - "([Ljava/lang/String;Ljava/io/PrintStream;)I", JNI_TRUE, JNI_FALSE}, - - {3, "meth_inn", "(Ljava/lang/String;J)V", JNI_FALSE, JNI_FALSE}, -}; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_issynth001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_issynth001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_issynth001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_synthetic_attribute) { - printf("Warning: IsMethodSynthetic is not implemented\n"); - } - - return JNI_OK; -} - -char const *jbooleanToString(jboolean flag) { - return ((flag == JNI_TRUE) ? "true" : "false"); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_IsMethodSynthetic_issynth001a_check(JNIEnv *env, - jclass cls1, jclass cls2, jclass cls3) { - jvmtiError err; - jclass cl; - jmethodID mid; - jboolean is_synthetic; - size_t i; - - if (!caps.can_get_synthetic_attribute) { - return result; - } - - for (i = 0; i < sizeof(methods)/sizeof(method_info); i++) { - cl = ((methods[i].class_id == 1) ? cls1 : - ((methods[i].class_id == 2) ? cls2 : cls3)); - if (methods[i].is_static == JNI_TRUE) { - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), - methods[i].name, methods[i].signature); - } else { - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), - methods[i].name, methods[i].signature); - } - if (mid == NULL) { - printf("Cannot find MethodID for \"%s%s\"\n", - methods[i].name, methods[i].signature); - result = STATUS_FAILED; - continue; - } - - err = (*jvmti)->IsMethodSynthetic(jvmti, mid, &is_synthetic); - if (err != JVMTI_ERROR_NONE) { - printf("(IsMethodSynthetic) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> %s%s - %s\n", methods[i].name, methods[i].signature, - jbooleanToString(is_synthetic)); - } - - if (is_synthetic != methods[i].is_synthetic) { - printf("(%s%s) wrong is_synthetic value: %s, expected: %s\n", - methods[i].name, methods[i].signature, - jbooleanToString(is_synthetic), - jbooleanToString(methods[i].is_synthetic)); - result = STATUS_FAILED; - } - } - - return result; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_IsMethodSynthetic_issynth001a_nmeth(JNIEnv *env, jclass cls) { -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/issynth001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/issynth001.cpp new file mode 100644 index 00000000000..973b5001046 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/issynth001.cpp @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + int class_id; + const char *name; + const char *signature; + jboolean is_static; + jboolean is_synthetic; +} method_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static method_info methods[] = { + {1, "meth_stat", "(ILjava/lang/String;)[F", JNI_TRUE, JNI_FALSE}, + {1, "meth_1", "(CCC)C", JNI_FALSE, JNI_FALSE}, + {1, "class$", "(Ljava/lang/String;)Ljava/lang/Class;", JNI_TRUE, JNI_TRUE}, + {1, "access$000", + "(Lnsk/jvmti/IsMethodSynthetic/issynth001a;)I", JNI_TRUE, JNI_TRUE}, + {1, "nmeth", "()V", JNI_FALSE, JNI_FALSE}, + {1, "check", "(Ljava/lang/Class;Ljava/lang/Class;)I", JNI_TRUE, JNI_FALSE}, + + {2, "", "()V", JNI_FALSE, JNI_FALSE}, + {2, "run", + "([Ljava/lang/String;Ljava/io/PrintStream;)I", JNI_TRUE, JNI_FALSE}, + + {3, "meth_inn", "(Ljava/lang/String;J)V", JNI_FALSE, JNI_FALSE}, +}; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_issynth001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_issynth001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_issynth001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_synthetic_attribute) { + printf("Warning: IsMethodSynthetic is not implemented\n"); + } + + return JNI_OK; +} + +char const *jbooleanToString(jboolean flag) { + return ((flag == JNI_TRUE) ? "true" : "false"); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_IsMethodSynthetic_issynth001a_check(JNIEnv *env, + jclass cls1, jclass cls2, jclass cls3) { + jvmtiError err; + jclass cl; + jmethodID mid; + jboolean is_synthetic; + size_t i; + + if (!caps.can_get_synthetic_attribute) { + return result; + } + + for (i = 0; i < sizeof(methods)/sizeof(method_info); i++) { + cl = ((methods[i].class_id == 1) ? cls1 : + ((methods[i].class_id == 2) ? cls2 : cls3)); + if (methods[i].is_static == JNI_TRUE) { + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cl), + methods[i].name, methods[i].signature); + } else { + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), + methods[i].name, methods[i].signature); + } + if (mid == NULL) { + printf("Cannot find MethodID for \"%s%s\"\n", + methods[i].name, methods[i].signature); + result = STATUS_FAILED; + continue; + } + + err = jvmti->IsMethodSynthetic(mid, &is_synthetic); + if (err != JVMTI_ERROR_NONE) { + printf("(IsMethodSynthetic) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> %s%s - %s\n", methods[i].name, methods[i].signature, + jbooleanToString(is_synthetic)); + } + + if (is_synthetic != methods[i].is_synthetic) { + printf("(%s%s) wrong is_synthetic value: %s, expected: %s\n", + methods[i].name, methods[i].signature, + jbooleanToString(is_synthetic), + jbooleanToString(methods[i].is_synthetic)); + result = STATUS_FAILED; + } + } + + return result; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_IsMethodSynthetic_issynth001a_nmeth(JNIEnv *env, jclass cls) { +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/libIsMethodSyntheticIssynth001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/libIsMethodSyntheticIssynth001.c deleted file mode 100644 index 5f9835f19ec..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/libIsMethodSyntheticIssynth001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "issynth001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/libIsMethodSyntheticIssynth001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/libIsMethodSyntheticIssynth001.cpp new file mode 100644 index 00000000000..f98c51e27da --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth001/libIsMethodSyntheticIssynth001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "issynth001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/issynth002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/issynth002.c deleted file mode 100644 index f33aa42e127..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/issynth002.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_issynth002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_issynth002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_issynth002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_synthetic_attribute) { - printf("Warning: IsMethodSynthetic is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_IsMethodSynthetic_issynth002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jboolean isSynthetic; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "", "()V"); - if (mid == NULL) { - printf("Cannot find method \"()V\"!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->IsMethodSynthetic(jvmti, NULL, &isSynthetic); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_synthetic_attribute) { - /* It is OK */ - } else if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->IsMethodSynthetic(jvmti, mid, NULL); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_get_synthetic_attribute) { - /* It is OK */ - } else if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/issynth002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/issynth002.cpp new file mode 100644 index 00000000000..bd4780fc56d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/issynth002.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_issynth002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_issynth002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_issynth002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_synthetic_attribute) { + printf("Warning: IsMethodSynthetic is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_IsMethodSynthetic_issynth002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jboolean isSynthetic; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "", "()V"); + if (mid == NULL) { + printf("Cannot find method \"()V\"!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->IsMethodSynthetic(NULL, &isSynthetic); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_synthetic_attribute) { + /* It is OK */ + } else if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->IsMethodSynthetic(mid, NULL); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_get_synthetic_attribute) { + /* It is OK */ + } else if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/libissynth002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/libissynth002.c deleted file mode 100644 index e5d50ffc1ce..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/libissynth002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "issynth002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/libissynth002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/libissynth002.cpp new file mode 100644 index 00000000000..d079ab30ece --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IsMethodSynthetic/issynth002/libissynth002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "issynth002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/iterheap001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/iterheap001.c deleted file mode 100644 index 7d75b96288b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/iterheap001.c +++ /dev/null @@ -1,572 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -static jlong timeout = 0; - -#define INFO_NONE 0x00 -#define INFO_ALL 0xFF -#define INFO_OBJREF 0x01 -#define INFO_STACKREF 0x02 -#define INFO_HEAPROOT 0x04 -#define INFO_HEAPOBJ 0x08 -#define INFO_TAGGED 0x10 - -static unsigned int info = INFO_NONE; - -#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap001" -#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap001RootTestedClass" -#define ROOT_OBJECT_CLASS_SIG "L"ROOT_OBJECT_CLASS_NAME";" -#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap001TestedClass" -#define CHAIN_OBJECT_CLASS_SIG "L"CHAIN_OBJECT_CLASS_NAME";" - -#define OBJECT_FIELD_NAME "object" -#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" -#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" -#define TAIL_FIELD_NAME "tail" - -#define DEFAULT_CHAIN_LENGTH 4 - -typedef struct ObjectDescStruct { - jlong tag; - jint found; - int collected; -} ObjectDesc; - -static int chainLength = 0; -static int objectsCount = 0; - -static ObjectDesc* objectDescList = NULL; - -static volatile int foundUntagged = 0; - -static int fakeUserData = 0; -static int userDataError = 0; - -/* ============================================================================= */ - -/** Obtain chain of tested objects and tag them recursively. */ -static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, - jfieldID firstField, const char firstFieldName[], - jfieldID nextField, const char nextFieldName[], - int count, ObjectDesc objectDescList[], - jlong tag, int reachable) { - - int success = NSK_TRUE; - jobject obj = NULL; - jlong objTag = (!reachable ? -tag : (tag % 2 != 0) ? tag : (jlong)0); - - if (count <= 0) - return NSK_TRUE; - - count--; - tag++; - - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - objectDescList[count].tag = objTag; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); - - if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, - nextField, nextFieldName, - count, objectDescList, tag, reachable)) { - return NSK_FALSE; - } - - NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); - return success; -} - -/** Obtain all tested objects from debugee class and tag them recursively. */ -static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - int *objectsCount, ObjectDesc* *objectDescList) { - jclass debugeeClass = NULL; - jclass rootObjectClass = NULL; - jclass chainObjectClass = NULL; - - jfieldID objectField = NULL; - jfieldID reachableChainField = NULL; - jfieldID unreachableChainField = NULL; - jfieldID tailField = NULL; - - jobject rootObject = NULL; - - jlong chainObjectTag = 100; - - *objectsCount = 2 * chainLength; - - NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), - (unsigned char**)objectDescList))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); - - { - int k; - for (k = 0; k < *objectsCount; k++) { - (*objectDescList)[k].tag = 0; - (*objectDescList)[k].found = 0; - (*objectDescList)[k].collected = 0; - } - } - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObjectClass = - NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); - - NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (chainObjectClass = - NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); - - NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (reachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (unreachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); - - NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (tailField = - NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, - TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); - - NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); - - NSK_DISPLAY0("Obtain and tag chain objects:\n"); - - NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - reachableChainField, REACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList, - chainObjectTag, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList + chainLength, - chainObjectTag, NSK_FALSE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/** Check if tagged objects were iterated. */ -static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, - int chainLength, ObjectDesc objectDescList[]) { - int success = NSK_TRUE; - int expectedUntagged = 0; - int i; - - NSK_DISPLAY0("Following tagged/untagged objects were iterated:\n"); - - NSK_DISPLAY0(" reachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY2(" tag=%-5ld iterated=%d times\n", - (long)objectDescList[i].tag, objectDescList[i].found); - - if (objectDescList[i].found <= 0 - && objectDescList[i].tag != 0) { - NSK_COMPLAIN2("Reachable tagged object was not iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i].tag, - objectDescList[i].found); - nsk_jvmti_setFailStatus(); - } - - if (objectDescList[i].tag == 0) { - expectedUntagged++; - } - } - - NSK_DISPLAY0(" unreachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY3(" tag=%-5ld iterated=%-3d collected=%d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found, - objectDescList[i + chainLength].collected); - - if (objectDescList[i + chainLength].found <= 0 - && objectDescList[i + chainLength].collected <= 0) { - NSK_COMPLAIN2("Not collected unreachable tagged object was not iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found); - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(" untagged objects:\n"); - NSK_DISPLAY2(" minimum=%-3d iterated=%d objects\n", - expectedUntagged, foundUntagged); - if (foundUntagged < expectedUntagged) { - NSK_COMPLAIN2("Unexpected number of untagged objects were iterated:\n" - "# iterated untagged objects: %d\n" - "# expected at least: %d\n", - foundUntagged, expectedUntagged); - nsk_jvmti_setFailStatus(); - } - - return NSK_TRUE; -} - -/** Release references to the tested objects and free allocated memory. */ -static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - ObjectDesc* objectDescList) { - if (objectDescList != NULL) { - NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { - nsk_jvmti_setFailStatus(); - } - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** heapRootCallback for heap iterator. */ -jvmtiIterationControl JNICALL -heapObjectCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { - - if (info & INFO_HEAPOBJ) { - NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", - (long)class_tag, (long)size, - (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); - } else if ((info & INFO_TAGGED) != 0 && - tag_ptr != NULL && *tag_ptr != 0) { - NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", - (long)class_tag, (long)size, - (long)*tag_ptr); - } - - if (class_tag != 0) { - NSK_COMPLAIN3("Unexpected class_tag passed to heapObjectCallback:\n" - "# object tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr == NULL) { - NSK_COMPLAIN3("NULL tag_ptr is passed to heapObjectCallback:\n" - "# tag_ptr: 0x%p\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (void*)tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } else { - if (*tag_ptr == 0) { - foundUntagged++; - } else { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - break; - } - } - - if (found <= 0) { - NSK_COMPLAIN3("Unknown tagged object passed to heapObjectCallback:\n" - "# tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed to heapObjectCallback:\n" - "# expected: 0x%p\n" - "# actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for tested objects created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - { - NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); - { - if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, - &objectsCount, &objectDescList))) - return; - } - - NSK_DISPLAY0(">>> Enable OBJECT_FREE event and let debugee to clean links to unreachable objects\n"); - { - jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - } - - NSK_DISPLAY0(">>> Iterate over all object in heap with filter JVMTI_HEAP_OBJECT_EITHER\n"); - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_EITHER, heapObjectCallback, - &fakeUserData))) { - nsk_jvmti_setFailStatus(); - return; - } - } - - NSK_DISPLAY0(">>> Disable OBJECT_FREE event and check if tagged/untagged objects were iterated:\n"); - { - jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) - return; - - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, objectDescList))) - return; - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -JNIEXPORT void JNICALL -callbackObjectFree(jvmtiEnv* jvmti, jlong tag) { - int i; - - if (info & INFO_HEAPOBJ) { - NSK_DISPLAY1(" : tag=%-5ld\n", tag); - } - - if (tag != 0) { - for (i = 0; i < objectsCount; i++) { - if (tag == objectDescList[i].tag) { - objectDescList[i].collected++; - break; - } - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_iterheap001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_iterheap001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_iterheap001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - { - const char* infoOpt = nsk_jvmti_findOptionValue("info"); - if (infoOpt != NULL) { - if (strcmp(infoOpt, "none") == 0) - info = INFO_NONE; - else if (strcmp(infoOpt, "all") == 0) - info = INFO_ALL; - else if (strcmp(infoOpt, "objref") == 0) - info = INFO_OBJREF; - else if (strcmp(infoOpt, "stackref") == 0) - info = INFO_STACKREF; - else if (strcmp(infoOpt, "heaproot") == 0) - info = INFO_HEAPROOT; - else if (strcmp(infoOpt, "heapobj") == 0) - info = INFO_HEAPOBJ; - else if (strcmp(infoOpt, "tagged") == 0) - info = INFO_TAGGED; - else { - NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); - return JNI_ERR; - } - } - } - - chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); - if (!NSK_VERIFY(chainLength > 0)) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - caps.can_generate_object_free_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ObjectFree = callbackObjectFree; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/iterheap001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/iterheap001.cpp new file mode 100644 index 00000000000..1eca543138e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/iterheap001.cpp @@ -0,0 +1,572 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jlong timeout = 0; + +#define INFO_NONE 0x00 +#define INFO_ALL 0xFF +#define INFO_OBJREF 0x01 +#define INFO_STACKREF 0x02 +#define INFO_HEAPROOT 0x04 +#define INFO_HEAPOBJ 0x08 +#define INFO_TAGGED 0x10 + +static unsigned int info = INFO_NONE; + +#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap001" +#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap001RootTestedClass" +#define ROOT_OBJECT_CLASS_SIG "L" ROOT_OBJECT_CLASS_NAME ";" +#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap001TestedClass" +#define CHAIN_OBJECT_CLASS_SIG "L" CHAIN_OBJECT_CLASS_NAME ";" + +#define OBJECT_FIELD_NAME "object" +#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" +#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" +#define TAIL_FIELD_NAME "tail" + +#define DEFAULT_CHAIN_LENGTH 4 + +typedef struct ObjectDescStruct { + jlong tag; + jint found; + int collected; +} ObjectDesc; + +static int chainLength = 0; +static int objectsCount = 0; + +static ObjectDesc* objectDescList = NULL; + +static volatile int foundUntagged = 0; + +static int fakeUserData = 0; +static int userDataError = 0; + +/* ============================================================================= */ + +/** Obtain chain of tested objects and tag them recursively. */ +static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, + jfieldID firstField, const char firstFieldName[], + jfieldID nextField, const char nextFieldName[], + int count, ObjectDesc objectDescList[], + jlong tag, int reachable) { + + int success = NSK_TRUE; + jobject obj = NULL; + jlong objTag = (!reachable ? -tag : (tag % 2 != 0) ? tag : (jlong)0); + + if (count <= 0) + return NSK_TRUE; + + count--; + tag++; + + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + objectDescList[count].tag = objTag; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); + + if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, + nextField, nextFieldName, + count, objectDescList, tag, reachable)) { + return NSK_FALSE; + } + + NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); + return success; +} + +/** Obtain all tested objects from debugee class and tag them recursively. */ +static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + int *objectsCount, ObjectDesc* *objectDescList) { + jclass debugeeClass = NULL; + jclass rootObjectClass = NULL; + jclass chainObjectClass = NULL; + + jfieldID objectField = NULL; + jfieldID reachableChainField = NULL; + jfieldID unreachableChainField = NULL; + jfieldID tailField = NULL; + + jobject rootObject = NULL; + + jlong chainObjectTag = 100; + + *objectsCount = 2 * chainLength; + + NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), + (unsigned char**)objectDescList))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); + + { + int k; + for (k = 0; k < *objectsCount; k++) { + (*objectDescList)[k].tag = 0; + (*objectDescList)[k].found = 0; + (*objectDescList)[k].collected = 0; + } + } + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObjectClass = + NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); + + NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (chainObjectClass = + NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); + + NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (reachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (unreachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); + + NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (tailField = + NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, + TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); + + NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); + + NSK_DISPLAY0("Obtain and tag chain objects:\n"); + + NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + reachableChainField, REACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList, + chainObjectTag, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList + chainLength, + chainObjectTag, NSK_FALSE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/** Check if tagged objects were iterated. */ +static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, + int chainLength, ObjectDesc objectDescList[]) { + int success = NSK_TRUE; + int expectedUntagged = 0; + int i; + + NSK_DISPLAY0("Following tagged/untagged objects were iterated:\n"); + + NSK_DISPLAY0(" reachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY2(" tag=%-5ld iterated=%d times\n", + (long)objectDescList[i].tag, objectDescList[i].found); + + if (objectDescList[i].found <= 0 + && objectDescList[i].tag != 0) { + NSK_COMPLAIN2("Reachable tagged object was not iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i].tag, + objectDescList[i].found); + nsk_jvmti_setFailStatus(); + } + + if (objectDescList[i].tag == 0) { + expectedUntagged++; + } + } + + NSK_DISPLAY0(" unreachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY3(" tag=%-5ld iterated=%-3d collected=%d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found, + objectDescList[i + chainLength].collected); + + if (objectDescList[i + chainLength].found <= 0 + && objectDescList[i + chainLength].collected <= 0) { + NSK_COMPLAIN2("Not collected unreachable tagged object was not iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found); + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(" untagged objects:\n"); + NSK_DISPLAY2(" minimum=%-3d iterated=%d objects\n", + expectedUntagged, foundUntagged); + if (foundUntagged < expectedUntagged) { + NSK_COMPLAIN2("Unexpected number of untagged objects were iterated:\n" + "# iterated untagged objects: %d\n" + "# expected at least: %d\n", + foundUntagged, expectedUntagged); + nsk_jvmti_setFailStatus(); + } + + return NSK_TRUE; +} + +/** Release references to the tested objects and free allocated memory. */ +static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + ObjectDesc* objectDescList) { + if (objectDescList != NULL) { + NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { + nsk_jvmti_setFailStatus(); + } + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** heapRootCallback for heap iterator. */ +jvmtiIterationControl JNICALL +heapObjectCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { + + if (info & INFO_HEAPOBJ) { + NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", + (long)class_tag, (long)size, + (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); + } else if ((info & INFO_TAGGED) != 0 && + tag_ptr != NULL && *tag_ptr != 0) { + NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", + (long)class_tag, (long)size, + (long)*tag_ptr); + } + + if (class_tag != 0) { + NSK_COMPLAIN3("Unexpected class_tag passed to heapObjectCallback:\n" + "# object tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr == NULL) { + NSK_COMPLAIN3("NULL tag_ptr is passed to heapObjectCallback:\n" + "# tag_ptr: 0x%p\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (void*)tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } else { + if (*tag_ptr == 0) { + foundUntagged++; + } else { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + break; + } + } + + if (found <= 0) { + NSK_COMPLAIN3("Unknown tagged object passed to heapObjectCallback:\n" + "# tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed to heapObjectCallback:\n" + "# expected: 0x%p\n" + "# actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for tested objects created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + { + NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); + { + if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, + &objectsCount, &objectDescList))) + return; + } + + NSK_DISPLAY0(">>> Enable OBJECT_FREE event and let debugee to clean links to unreachable objects\n"); + { + jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + } + + NSK_DISPLAY0(">>> Iterate over all object in heap with filter JVMTI_HEAP_OBJECT_EITHER\n"); + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_EITHER, heapObjectCallback, + &fakeUserData))) { + nsk_jvmti_setFailStatus(); + return; + } + } + + NSK_DISPLAY0(">>> Disable OBJECT_FREE event and check if tagged/untagged objects were iterated:\n"); + { + jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) + return; + + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, objectDescList))) + return; + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +JNIEXPORT void JNICALL +callbackObjectFree(jvmtiEnv* jvmti, jlong tag) { + int i; + + if (info & INFO_HEAPOBJ) { + NSK_DISPLAY1(" : tag=%-5ld\n", tag); + } + + if (tag != 0) { + for (i = 0; i < objectsCount; i++) { + if (tag == objectDescList[i].tag) { + objectDescList[i].collected++; + break; + } + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_iterheap001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_iterheap001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_iterheap001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + { + const char* infoOpt = nsk_jvmti_findOptionValue("info"); + if (infoOpt != NULL) { + if (strcmp(infoOpt, "none") == 0) + info = INFO_NONE; + else if (strcmp(infoOpt, "all") == 0) + info = INFO_ALL; + else if (strcmp(infoOpt, "objref") == 0) + info = INFO_OBJREF; + else if (strcmp(infoOpt, "stackref") == 0) + info = INFO_STACKREF; + else if (strcmp(infoOpt, "heaproot") == 0) + info = INFO_HEAPROOT; + else if (strcmp(infoOpt, "heapobj") == 0) + info = INFO_HEAPOBJ; + else if (strcmp(infoOpt, "tagged") == 0) + info = INFO_TAGGED; + else { + NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); + return JNI_ERR; + } + } + } + + chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); + if (!NSK_VERIFY(chainLength > 0)) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + caps.can_generate_object_free_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ObjectFree = callbackObjectFree; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/libiterheap001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/libiterheap001.c deleted file mode 100644 index 15e8ab25ea5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/libiterheap001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterheap001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/libiterheap001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/libiterheap001.cpp new file mode 100644 index 00000000000..96da3d8d968 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap001/libiterheap001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterheap001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/iterheap002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/iterheap002.c deleted file mode 100644 index 4192e17bfdc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/iterheap002.c +++ /dev/null @@ -1,580 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -static jlong timeout = 0; - -#define INFO_NONE 0x00 -#define INFO_ALL 0xFF -#define INFO_OBJREF 0x01 -#define INFO_STACKREF 0x02 -#define INFO_HEAPROOT 0x04 -#define INFO_HEAPOBJ 0x08 -#define INFO_TAGGED 0x10 - -static unsigned int info = INFO_NONE; - -#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap002" -#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap002RootTestedClass" -#define ROOT_OBJECT_CLASS_SIG "L"ROOT_OBJECT_CLASS_NAME";" -#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap002TestedClass" -#define CHAIN_OBJECT_CLASS_SIG "L"CHAIN_OBJECT_CLASS_NAME";" - -#define OBJECT_FIELD_NAME "object" -#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" -#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" -#define TAIL_FIELD_NAME "tail" - -#define DEFAULT_CHAIN_LENGTH 4 - -typedef struct ObjectDescStruct { - jlong tag; - jint found; - int collected; -} ObjectDesc; - -static int chainLength = 0; -static int objectsCount = 0; - -static ObjectDesc* objectDescList = NULL; - -static volatile int foundUntagged = 0; - -static int fakeUserData = 0; -static int userDataError = 0; - -/* ============================================================================= */ - -/** Obtain chain of tested objects and tag them recursively. */ -static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, - jfieldID firstField, const char firstFieldName[], - jfieldID nextField, const char nextFieldName[], - int count, ObjectDesc objectDescList[], - jlong tag, int reachable) { - - int success = NSK_TRUE; - jobject obj = NULL; - jlong objTag = (!reachable ? -tag : (tag % 2 != 0) ? tag : (jlong)0); - - if (count <= 0) - return NSK_TRUE; - - count--; - tag++; - - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - objectDescList[count].tag = objTag; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); - - if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, - nextField, nextFieldName, - count, objectDescList, tag, reachable)) { - return NSK_FALSE; - } - - NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); - return success; -} - -/** Obtain all tested objects from debugee class and tag them recursively. */ -static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - int *objectsCount, ObjectDesc* *objectDescList) { - jclass debugeeClass = NULL; - jclass rootObjectClass = NULL; - jclass chainObjectClass = NULL; - - jfieldID objectField = NULL; - jfieldID reachableChainField = NULL; - jfieldID unreachableChainField = NULL; - jfieldID tailField = NULL; - - jobject rootObject = NULL; - - jlong chainObjectTag = 100; - - *objectsCount = 2 * chainLength; - - NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), - (unsigned char**)objectDescList))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); - - { - int k; - for (k = 0; k < *objectsCount; k++) { - (*objectDescList)[k].tag = 0; - (*objectDescList)[k].found = 0; - (*objectDescList)[k].collected = 0; - } - } - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObjectClass = - NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); - - NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (chainObjectClass = - NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); - - NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (reachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (unreachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); - - NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (tailField = - NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, - TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); - - NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); - - NSK_DISPLAY0("Obtain and tag chain objects:\n"); - - NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - reachableChainField, REACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList, - chainObjectTag, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList + chainLength, - chainObjectTag, NSK_FALSE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/** Check if tagged objects were iterated. */ -static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, - int chainLength, ObjectDesc objectDescList[]) { - int success = NSK_TRUE; - int expectedUntagged = 0; - int i; - - NSK_DISPLAY0("Following tagged/untagged objects were iterated:\n"); - - NSK_DISPLAY0(" reachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY2(" tag=%-5ld iterated=%d times\n", - (long)objectDescList[i].tag, objectDescList[i].found); - - if (objectDescList[i].found <= 0 - && objectDescList[i].tag != 0) { - NSK_COMPLAIN2("Reachable tagged object was not iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i].tag, - objectDescList[i].found); - nsk_jvmti_setFailStatus(); - } - - if (objectDescList[i].tag == 0) { - expectedUntagged++; - } - } - - NSK_DISPLAY0(" unreachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY3(" tag=%-5ld iterated=%-3d collected=%d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found, - objectDescList[i + chainLength].collected); - - if (objectDescList[i + chainLength].found <= 0 - && objectDescList[i + chainLength].collected <= 0) { - NSK_COMPLAIN2("Not collected unreachable tagged object was not iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found); - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(" untagged objects:\n"); - NSK_DISPLAY2(" minimum=%-3d iterated=%d objects\n", - expectedUntagged, foundUntagged); - if (foundUntagged > 0) { - NSK_COMPLAIN2("A number of untagged objects were iterated:\n" - "# iterated untagged objects: %d\n" - "# untagged objects at least: %d\n", - foundUntagged, expectedUntagged); - nsk_jvmti_setFailStatus(); - } - - return NSK_TRUE; -} - -/** Release references to the tested objects and free allocated memory. */ -static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - ObjectDesc* objectDescList) { - if (objectDescList != NULL) { - NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { - nsk_jvmti_setFailStatus(); - } - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** heapRootCallback for heap iterator. */ -jvmtiIterationControl JNICALL -heapObjectCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { - - if (info & INFO_HEAPOBJ) { - NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", - (long)class_tag, (long)size, - (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); - } else if ((info & INFO_TAGGED) != 0 && - tag_ptr != NULL && *tag_ptr != 0) { - NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", - (long)class_tag, (long)size, - (long)*tag_ptr); - } - - if (class_tag != 0) { - NSK_COMPLAIN3("Unexpected class_tag passed to heapObjectCallback:\n" - "# object tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr == NULL) { - NSK_COMPLAIN3("NULL tag_ptr is passed to heapObjectCallback:\n" - "# tag_ptr: 0x%p\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (void*)tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } else { - if (*tag_ptr == 0) { - foundUntagged++; - NSK_COMPLAIN3("Untagged object passed to heapObjectCallback:\n" - "# tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } else { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - break; - } - } - - if (found <= 0) { - NSK_COMPLAIN3("Unknown tagged object passed to heapObjectCallback:\n" - "# tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed to heapObjectCallback:\n" - "# expected: 0x%p\n" - "# actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for tested objects created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - { - NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); - { - if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, - &objectsCount, &objectDescList))) - return; - } - - NSK_DISPLAY0(">>> Enable OBJECT_FREE event and let debugee to clean links to unreachable objects\n"); - { - jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - } - - NSK_DISPLAY0(">>> Iterate over all object in heap with filter JVMTI_HEAP_OBJECT_TAGGED\n"); - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_TAGGED, heapObjectCallback, - &fakeUserData))) { - nsk_jvmti_setFailStatus(); - return; - } - } - - NSK_DISPLAY0(">>> Disable OBJECT_FREE event and check if tagged objects were iterated:\n"); - { - jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) - return; - - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, objectDescList))) - return; - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -JNIEXPORT void JNICALL -callbackObjectFree(jvmtiEnv* jvmti, jlong tag) { - int i; - - if (info & INFO_HEAPOBJ) { - NSK_DISPLAY1(" : tag=%-5ld\n", tag); - } - - if (tag != 0) { - for (i = 0; i < objectsCount; i++) { - if (tag == objectDescList[i].tag) { - objectDescList[i].collected++; - break; - } - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_iterheap002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_iterheap002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_iterheap002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - { - const char* infoOpt = nsk_jvmti_findOptionValue("info"); - if (infoOpt != NULL) { - if (strcmp(infoOpt, "none") == 0) - info = INFO_NONE; - else if (strcmp(infoOpt, "all") == 0) - info = INFO_ALL; - else if (strcmp(infoOpt, "objref") == 0) - info = INFO_OBJREF; - else if (strcmp(infoOpt, "stackref") == 0) - info = INFO_STACKREF; - else if (strcmp(infoOpt, "heaproot") == 0) - info = INFO_HEAPROOT; - else if (strcmp(infoOpt, "heapobj") == 0) - info = INFO_HEAPOBJ; - else if (strcmp(infoOpt, "tagged") == 0) - info = INFO_TAGGED; - else { - NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); - return JNI_ERR; - } - } - } - - chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); - if (!NSK_VERIFY(chainLength > 0)) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - caps.can_generate_object_free_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ObjectFree = callbackObjectFree; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/iterheap002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/iterheap002.cpp new file mode 100644 index 00000000000..192168c919a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/iterheap002.cpp @@ -0,0 +1,580 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jlong timeout = 0; + +#define INFO_NONE 0x00 +#define INFO_ALL 0xFF +#define INFO_OBJREF 0x01 +#define INFO_STACKREF 0x02 +#define INFO_HEAPROOT 0x04 +#define INFO_HEAPOBJ 0x08 +#define INFO_TAGGED 0x10 + +static unsigned int info = INFO_NONE; + +#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap002" +#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap002RootTestedClass" +#define ROOT_OBJECT_CLASS_SIG "L" ROOT_OBJECT_CLASS_NAME ";" +#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap002TestedClass" +#define CHAIN_OBJECT_CLASS_SIG "L" CHAIN_OBJECT_CLASS_NAME ";" + +#define OBJECT_FIELD_NAME "object" +#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" +#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" +#define TAIL_FIELD_NAME "tail" + +#define DEFAULT_CHAIN_LENGTH 4 + +typedef struct ObjectDescStruct { + jlong tag; + jint found; + int collected; +} ObjectDesc; + +static int chainLength = 0; +static int objectsCount = 0; + +static ObjectDesc* objectDescList = NULL; + +static volatile int foundUntagged = 0; + +static int fakeUserData = 0; +static int userDataError = 0; + +/* ============================================================================= */ + +/** Obtain chain of tested objects and tag them recursively. */ +static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, + jfieldID firstField, const char firstFieldName[], + jfieldID nextField, const char nextFieldName[], + int count, ObjectDesc objectDescList[], + jlong tag, int reachable) { + + int success = NSK_TRUE; + jobject obj = NULL; + jlong objTag = (!reachable ? -tag : (tag % 2 != 0) ? tag : (jlong)0); + + if (count <= 0) + return NSK_TRUE; + + count--; + tag++; + + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + objectDescList[count].tag = objTag; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); + + if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, + nextField, nextFieldName, + count, objectDescList, tag, reachable)) { + return NSK_FALSE; + } + + NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); + return success; +} + +/** Obtain all tested objects from debugee class and tag them recursively. */ +static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + int *objectsCount, ObjectDesc* *objectDescList) { + jclass debugeeClass = NULL; + jclass rootObjectClass = NULL; + jclass chainObjectClass = NULL; + + jfieldID objectField = NULL; + jfieldID reachableChainField = NULL; + jfieldID unreachableChainField = NULL; + jfieldID tailField = NULL; + + jobject rootObject = NULL; + + jlong chainObjectTag = 100; + + *objectsCount = 2 * chainLength; + + NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), + (unsigned char**)objectDescList))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); + + { + int k; + for (k = 0; k < *objectsCount; k++) { + (*objectDescList)[k].tag = 0; + (*objectDescList)[k].found = 0; + (*objectDescList)[k].collected = 0; + } + } + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObjectClass = + NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); + + NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (chainObjectClass = + NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); + + NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (reachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (unreachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); + + NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (tailField = + NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, + TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); + + NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); + + NSK_DISPLAY0("Obtain and tag chain objects:\n"); + + NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + reachableChainField, REACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList, + chainObjectTag, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList + chainLength, + chainObjectTag, NSK_FALSE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/** Check if tagged objects were iterated. */ +static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, + int chainLength, ObjectDesc objectDescList[]) { + int success = NSK_TRUE; + int expectedUntagged = 0; + int i; + + NSK_DISPLAY0("Following tagged/untagged objects were iterated:\n"); + + NSK_DISPLAY0(" reachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY2(" tag=%-5ld iterated=%d times\n", + (long)objectDescList[i].tag, objectDescList[i].found); + + if (objectDescList[i].found <= 0 + && objectDescList[i].tag != 0) { + NSK_COMPLAIN2("Reachable tagged object was not iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i].tag, + objectDescList[i].found); + nsk_jvmti_setFailStatus(); + } + + if (objectDescList[i].tag == 0) { + expectedUntagged++; + } + } + + NSK_DISPLAY0(" unreachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY3(" tag=%-5ld iterated=%-3d collected=%d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found, + objectDescList[i + chainLength].collected); + + if (objectDescList[i + chainLength].found <= 0 + && objectDescList[i + chainLength].collected <= 0) { + NSK_COMPLAIN2("Not collected unreachable tagged object was not iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found); + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(" untagged objects:\n"); + NSK_DISPLAY2(" minimum=%-3d iterated=%d objects\n", + expectedUntagged, foundUntagged); + if (foundUntagged > 0) { + NSK_COMPLAIN2("A number of untagged objects were iterated:\n" + "# iterated untagged objects: %d\n" + "# untagged objects at least: %d\n", + foundUntagged, expectedUntagged); + nsk_jvmti_setFailStatus(); + } + + return NSK_TRUE; +} + +/** Release references to the tested objects and free allocated memory. */ +static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + ObjectDesc* objectDescList) { + if (objectDescList != NULL) { + NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { + nsk_jvmti_setFailStatus(); + } + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** heapRootCallback for heap iterator. */ +jvmtiIterationControl JNICALL +heapObjectCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { + + if (info & INFO_HEAPOBJ) { + NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", + (long)class_tag, (long)size, + (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); + } else if ((info & INFO_TAGGED) != 0 && + tag_ptr != NULL && *tag_ptr != 0) { + NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", + (long)class_tag, (long)size, + (long)*tag_ptr); + } + + if (class_tag != 0) { + NSK_COMPLAIN3("Unexpected class_tag passed to heapObjectCallback:\n" + "# object tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr == NULL) { + NSK_COMPLAIN3("NULL tag_ptr is passed to heapObjectCallback:\n" + "# tag_ptr: 0x%p\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (void*)tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } else { + if (*tag_ptr == 0) { + foundUntagged++; + NSK_COMPLAIN3("Untagged object passed to heapObjectCallback:\n" + "# tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } else { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + break; + } + } + + if (found <= 0) { + NSK_COMPLAIN3("Unknown tagged object passed to heapObjectCallback:\n" + "# tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed to heapObjectCallback:\n" + "# expected: 0x%p\n" + "# actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for tested objects created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + { + NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); + { + if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, + &objectsCount, &objectDescList))) + return; + } + + NSK_DISPLAY0(">>> Enable OBJECT_FREE event and let debugee to clean links to unreachable objects\n"); + { + jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + } + + NSK_DISPLAY0(">>> Iterate over all object in heap with filter JVMTI_HEAP_OBJECT_TAGGED\n"); + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_TAGGED, heapObjectCallback, + &fakeUserData))) { + nsk_jvmti_setFailStatus(); + return; + } + } + + NSK_DISPLAY0(">>> Disable OBJECT_FREE event and check if tagged objects were iterated:\n"); + { + jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) + return; + + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, objectDescList))) + return; + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +JNIEXPORT void JNICALL +callbackObjectFree(jvmtiEnv* jvmti, jlong tag) { + int i; + + if (info & INFO_HEAPOBJ) { + NSK_DISPLAY1(" : tag=%-5ld\n", tag); + } + + if (tag != 0) { + for (i = 0; i < objectsCount; i++) { + if (tag == objectDescList[i].tag) { + objectDescList[i].collected++; + break; + } + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_iterheap002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_iterheap002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_iterheap002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + { + const char* infoOpt = nsk_jvmti_findOptionValue("info"); + if (infoOpt != NULL) { + if (strcmp(infoOpt, "none") == 0) + info = INFO_NONE; + else if (strcmp(infoOpt, "all") == 0) + info = INFO_ALL; + else if (strcmp(infoOpt, "objref") == 0) + info = INFO_OBJREF; + else if (strcmp(infoOpt, "stackref") == 0) + info = INFO_STACKREF; + else if (strcmp(infoOpt, "heaproot") == 0) + info = INFO_HEAPROOT; + else if (strcmp(infoOpt, "heapobj") == 0) + info = INFO_HEAPOBJ; + else if (strcmp(infoOpt, "tagged") == 0) + info = INFO_TAGGED; + else { + NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); + return JNI_ERR; + } + } + } + + chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); + if (!NSK_VERIFY(chainLength > 0)) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + caps.can_generate_object_free_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ObjectFree = callbackObjectFree; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/libiterheap002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/libiterheap002.c deleted file mode 100644 index 65de3884335..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/libiterheap002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterheap002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/libiterheap002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/libiterheap002.cpp new file mode 100644 index 00000000000..bde2edbb361 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap002/libiterheap002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterheap002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/iterheap003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/iterheap003.c deleted file mode 100644 index 26f6f1b2b78..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/iterheap003.c +++ /dev/null @@ -1,581 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -static jlong timeout = 0; - -#define INFO_NONE 0x00 -#define INFO_ALL 0xFF -#define INFO_OBJREF 0x01 -#define INFO_STACKREF 0x02 -#define INFO_HEAPROOT 0x04 -#define INFO_HEAPOBJ 0x08 -#define INFO_TAGGED 0x10 - -static unsigned int info = INFO_NONE; - -#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap003" -#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap003RootTestedClass" -#define ROOT_OBJECT_CLASS_SIG "L"ROOT_OBJECT_CLASS_NAME";" -#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap003TestedClass" -#define CHAIN_OBJECT_CLASS_SIG "L"CHAIN_OBJECT_CLASS_NAME";" - -#define OBJECT_FIELD_NAME "object" -#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" -#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" -#define TAIL_FIELD_NAME "tail" - -#define DEFAULT_CHAIN_LENGTH 4 - -typedef struct ObjectDescStruct { - jlong tag; - jint found; - int collected; -} ObjectDesc; - -static int chainLength = 0; -static int objectsCount = 0; - -static ObjectDesc* objectDescList = NULL; - -static volatile int foundUntagged = 0; - -static int fakeUserData = 0; -static int userDataError = 0; - -/* ============================================================================= */ - -/** Obtain chain of tested objects and tag them recursively. */ -static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, - jfieldID firstField, const char firstFieldName[], - jfieldID nextField, const char nextFieldName[], - int count, ObjectDesc objectDescList[], - jlong tag, int reachable) { - - int success = NSK_TRUE; - jobject obj = NULL; - jlong objTag = (!reachable ? -tag : (tag % 2 != 0) ? tag : (jlong)0); - - if (count <= 0) - return NSK_TRUE; - - count--; - tag++; - - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - objectDescList[count].tag = objTag; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); - - if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, - nextField, nextFieldName, - count, objectDescList, tag, reachable)) { - return NSK_FALSE; - } - - NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); - return success; -} - -/** Obtain all tested objects from debugee class and tag them recursively. */ -static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - int *objectsCount, ObjectDesc* *objectDescList) { - jclass debugeeClass = NULL; - jclass rootObjectClass = NULL; - jclass chainObjectClass = NULL; - - jfieldID objectField = NULL; - jfieldID reachableChainField = NULL; - jfieldID unreachableChainField = NULL; - jfieldID tailField = NULL; - - jobject rootObject = NULL; - - jlong chainObjectTag = 100; - - *objectsCount = 2 * chainLength; - - NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), - (unsigned char**)objectDescList))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); - - { - int k; - for (k = 0; k < *objectsCount; k++) { - (*objectDescList)[k].tag = 0; - (*objectDescList)[k].found = 0; - (*objectDescList)[k].collected = 0; - } - } - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObjectClass = - NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); - - NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (chainObjectClass = - NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); - - NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (reachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (unreachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); - - NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (tailField = - NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, - TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); - - NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); - - NSK_DISPLAY0("Obtain and tag chain objects:\n"); - - NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - reachableChainField, REACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList, - chainObjectTag, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList + chainLength, - chainObjectTag, NSK_FALSE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/** Check if tagged objects were iterated. */ -static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, - int chainLength, ObjectDesc objectDescList[]) { - int success = NSK_TRUE; - int expectedUntagged = 0; - int i; - - NSK_DISPLAY0("Following tagged/untagged objects were iterated:\n"); - - NSK_DISPLAY0(" reachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY2(" tag=%-5ld iterated=%d times\n", - (long)objectDescList[i].tag, objectDescList[i].found); - - if (objectDescList[i].found > 0 - && objectDescList[i].tag != 0) { - NSK_COMPLAIN2("Reachable tagged object was iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i].tag, - objectDescList[i].found); - nsk_jvmti_setFailStatus(); - } - - if (objectDescList[i].tag == 0) { - expectedUntagged++; - } - } - - NSK_DISPLAY0(" unreachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY3(" tag=%-5ld iterated=%-3d collected=%d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found, - objectDescList[i + chainLength].collected); - - if (objectDescList[i + chainLength].found > 0 - && objectDescList[i + chainLength].collected <= 0) { - NSK_COMPLAIN2("Not collected unreachable tagged object was iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found); - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(" untagged objects:\n"); - NSK_DISPLAY2(" minimum=%-3d iterated=%d objects\n", - expectedUntagged, foundUntagged); - if (foundUntagged <= expectedUntagged) { - NSK_COMPLAIN2("Unexpected number of untagged objects were iterated:\n" - "# iterated untagged objects: %d\n" - "# expected at least: %d\n", - foundUntagged, expectedUntagged); - nsk_jvmti_setFailStatus(); - } - - return NSK_TRUE; -} - -/** Release references to the tested objects and free allocated memory. */ -static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - ObjectDesc* objectDescList) { - if (objectDescList != NULL) { - NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { - nsk_jvmti_setFailStatus(); - } - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** heapRootCallback for heap iterator. */ -jvmtiIterationControl JNICALL -heapObjectCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { - - if (info & INFO_HEAPOBJ) { - NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", - (long)class_tag, (long)size, - (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); - } else if ((info & INFO_TAGGED) != 0 && - tag_ptr != NULL && *tag_ptr != 0) { - NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", - (long)class_tag, (long)size, - (long)*tag_ptr); - } - - if (class_tag != 0) { - NSK_COMPLAIN3("Unexpected class_tag passed to heapObjectCallback:\n" - "# object tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr == NULL) { - NSK_COMPLAIN3("NULL tag_ptr is passed to heapObjectCallback:\n" - "# tag_ptr: 0x%p\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (void*)tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } else { - if (*tag_ptr == 0) { - foundUntagged++; - } else { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - break; - } - } - - if (found <= 0) { - NSK_COMPLAIN3("Unknown tagged object passed to heapObjectCallback:\n" - "# tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } else { - NSK_COMPLAIN3("Known tagged object passed to heapObjectCallback:\n" - "# tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed to heapObjectCallback:\n" - "# expected: 0x%p\n" - "# actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for tested objects created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - { - NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); - { - if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, - &objectsCount, &objectDescList))) - return; - } - - NSK_DISPLAY0(">>> Enable OBJECT_FREE event and let debugee to clean links to unreachable objects\n"); - { - jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - } - - NSK_DISPLAY0(">>> Iterate over all object in heap with filter JVMTI_HEAP_OBJECT_UNTAGGED\n"); - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_UNTAGGED, heapObjectCallback, - &fakeUserData))) { - nsk_jvmti_setFailStatus(); - return; - } - } - - NSK_DISPLAY0(">>> Disable OBJECT_FREE event and check if untagged objects were iterated:\n"); - { - jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) - return; - - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, objectDescList))) - return; - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -JNIEXPORT void JNICALL -callbackObjectFree(jvmtiEnv* jvmti, jlong tag) { - int i; - - if (info & INFO_HEAPOBJ) { - NSK_DISPLAY1(" : tag=%-5ld\n", tag); - } - - if (tag > 0) { - for (i = 0; i < objectsCount; i++) { - if (tag == objectDescList[i].tag) { - objectDescList[i].collected++; - break; - } - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_iterheap003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_iterheap003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_iterheap003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - { - const char* infoOpt = nsk_jvmti_findOptionValue("info"); - if (infoOpt != NULL) { - if (strcmp(infoOpt, "none") == 0) - info = INFO_NONE; - else if (strcmp(infoOpt, "all") == 0) - info = INFO_ALL; - else if (strcmp(infoOpt, "objref") == 0) - info = INFO_OBJREF; - else if (strcmp(infoOpt, "stackref") == 0) - info = INFO_STACKREF; - else if (strcmp(infoOpt, "heaproot") == 0) - info = INFO_HEAPROOT; - else if (strcmp(infoOpt, "heapobj") == 0) - info = INFO_HEAPOBJ; - else if (strcmp(infoOpt, "tagged") == 0) - info = INFO_TAGGED; - else { - NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); - return JNI_ERR; - } - } - } - - chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); - if (!NSK_VERIFY(chainLength > 0)) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - caps.can_generate_object_free_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ObjectFree = callbackObjectFree; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/iterheap003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/iterheap003.cpp new file mode 100644 index 00000000000..c93340009d2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/iterheap003.cpp @@ -0,0 +1,581 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jlong timeout = 0; + +#define INFO_NONE 0x00 +#define INFO_ALL 0xFF +#define INFO_OBJREF 0x01 +#define INFO_STACKREF 0x02 +#define INFO_HEAPROOT 0x04 +#define INFO_HEAPOBJ 0x08 +#define INFO_TAGGED 0x10 + +static unsigned int info = INFO_NONE; + +#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap003" +#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap003RootTestedClass" +#define ROOT_OBJECT_CLASS_SIG "L" ROOT_OBJECT_CLASS_NAME ";" +#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverHeap/iterheap003TestedClass" +#define CHAIN_OBJECT_CLASS_SIG "L" CHAIN_OBJECT_CLASS_NAME ";" + +#define OBJECT_FIELD_NAME "object" +#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" +#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" +#define TAIL_FIELD_NAME "tail" + +#define DEFAULT_CHAIN_LENGTH 4 + +typedef struct ObjectDescStruct { + jlong tag; + jint found; + int collected; +} ObjectDesc; + +static int chainLength = 0; +static int objectsCount = 0; + +static ObjectDesc* objectDescList = NULL; + +static volatile int foundUntagged = 0; + +static int fakeUserData = 0; +static int userDataError = 0; + +/* ============================================================================= */ + +/** Obtain chain of tested objects and tag them recursively. */ +static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, + jfieldID firstField, const char firstFieldName[], + jfieldID nextField, const char nextFieldName[], + int count, ObjectDesc objectDescList[], + jlong tag, int reachable) { + + int success = NSK_TRUE; + jobject obj = NULL; + jlong objTag = (!reachable ? -tag : (tag % 2 != 0) ? tag : (jlong)0); + + if (count <= 0) + return NSK_TRUE; + + count--; + tag++; + + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + objectDescList[count].tag = objTag; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); + + if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, + nextField, nextFieldName, + count, objectDescList, tag, reachable)) { + return NSK_FALSE; + } + + NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); + return success; +} + +/** Obtain all tested objects from debugee class and tag them recursively. */ +static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + int *objectsCount, ObjectDesc* *objectDescList) { + jclass debugeeClass = NULL; + jclass rootObjectClass = NULL; + jclass chainObjectClass = NULL; + + jfieldID objectField = NULL; + jfieldID reachableChainField = NULL; + jfieldID unreachableChainField = NULL; + jfieldID tailField = NULL; + + jobject rootObject = NULL; + + jlong chainObjectTag = 100; + + *objectsCount = 2 * chainLength; + + NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), + (unsigned char**)objectDescList))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); + + { + int k; + for (k = 0; k < *objectsCount; k++) { + (*objectDescList)[k].tag = 0; + (*objectDescList)[k].found = 0; + (*objectDescList)[k].collected = 0; + } + } + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObjectClass = + NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); + + NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (chainObjectClass = + NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); + + NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (reachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (unreachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); + + NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (tailField = + NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, + TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); + + NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); + + NSK_DISPLAY0("Obtain and tag chain objects:\n"); + + NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + reachableChainField, REACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList, + chainObjectTag, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList + chainLength, + chainObjectTag, NSK_FALSE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/** Check if tagged objects were iterated. */ +static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, + int chainLength, ObjectDesc objectDescList[]) { + int success = NSK_TRUE; + int expectedUntagged = 0; + int i; + + NSK_DISPLAY0("Following tagged/untagged objects were iterated:\n"); + + NSK_DISPLAY0(" reachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY2(" tag=%-5ld iterated=%d times\n", + (long)objectDescList[i].tag, objectDescList[i].found); + + if (objectDescList[i].found > 0 + && objectDescList[i].tag != 0) { + NSK_COMPLAIN2("Reachable tagged object was iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i].tag, + objectDescList[i].found); + nsk_jvmti_setFailStatus(); + } + + if (objectDescList[i].tag == 0) { + expectedUntagged++; + } + } + + NSK_DISPLAY0(" unreachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY3(" tag=%-5ld iterated=%-3d collected=%d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found, + objectDescList[i + chainLength].collected); + + if (objectDescList[i + chainLength].found > 0 + && objectDescList[i + chainLength].collected <= 0) { + NSK_COMPLAIN2("Not collected unreachable tagged object was iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found); + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(" untagged objects:\n"); + NSK_DISPLAY2(" minimum=%-3d iterated=%d objects\n", + expectedUntagged, foundUntagged); + if (foundUntagged <= expectedUntagged) { + NSK_COMPLAIN2("Unexpected number of untagged objects were iterated:\n" + "# iterated untagged objects: %d\n" + "# expected at least: %d\n", + foundUntagged, expectedUntagged); + nsk_jvmti_setFailStatus(); + } + + return NSK_TRUE; +} + +/** Release references to the tested objects and free allocated memory. */ +static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + ObjectDesc* objectDescList) { + if (objectDescList != NULL) { + NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { + nsk_jvmti_setFailStatus(); + } + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** heapRootCallback for heap iterator. */ +jvmtiIterationControl JNICALL +heapObjectCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { + + if (info & INFO_HEAPOBJ) { + NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", + (long)class_tag, (long)size, + (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); + } else if ((info & INFO_TAGGED) != 0 && + tag_ptr != NULL && *tag_ptr != 0) { + NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", + (long)class_tag, (long)size, + (long)*tag_ptr); + } + + if (class_tag != 0) { + NSK_COMPLAIN3("Unexpected class_tag passed to heapObjectCallback:\n" + "# object tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr == NULL) { + NSK_COMPLAIN3("NULL tag_ptr is passed to heapObjectCallback:\n" + "# tag_ptr: 0x%p\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (void*)tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } else { + if (*tag_ptr == 0) { + foundUntagged++; + } else { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + break; + } + } + + if (found <= 0) { + NSK_COMPLAIN3("Unknown tagged object passed to heapObjectCallback:\n" + "# tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } else { + NSK_COMPLAIN3("Known tagged object passed to heapObjectCallback:\n" + "# tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed to heapObjectCallback:\n" + "# expected: 0x%p\n" + "# actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for tested objects created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + { + NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); + { + if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, + &objectsCount, &objectDescList))) + return; + } + + NSK_DISPLAY0(">>> Enable OBJECT_FREE event and let debugee to clean links to unreachable objects\n"); + { + jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + } + + NSK_DISPLAY0(">>> Iterate over all object in heap with filter JVMTI_HEAP_OBJECT_UNTAGGED\n"); + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_UNTAGGED, heapObjectCallback, + &fakeUserData))) { + nsk_jvmti_setFailStatus(); + return; + } + } + + NSK_DISPLAY0(">>> Disable OBJECT_FREE event and check if untagged objects were iterated:\n"); + { + jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) + return; + + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, objectDescList))) + return; + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +JNIEXPORT void JNICALL +callbackObjectFree(jvmtiEnv* jvmti, jlong tag) { + int i; + + if (info & INFO_HEAPOBJ) { + NSK_DISPLAY1(" : tag=%-5ld\n", tag); + } + + if (tag > 0) { + for (i = 0; i < objectsCount; i++) { + if (tag == objectDescList[i].tag) { + objectDescList[i].collected++; + break; + } + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_iterheap003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_iterheap003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_iterheap003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + { + const char* infoOpt = nsk_jvmti_findOptionValue("info"); + if (infoOpt != NULL) { + if (strcmp(infoOpt, "none") == 0) + info = INFO_NONE; + else if (strcmp(infoOpt, "all") == 0) + info = INFO_ALL; + else if (strcmp(infoOpt, "objref") == 0) + info = INFO_OBJREF; + else if (strcmp(infoOpt, "stackref") == 0) + info = INFO_STACKREF; + else if (strcmp(infoOpt, "heaproot") == 0) + info = INFO_HEAPROOT; + else if (strcmp(infoOpt, "heapobj") == 0) + info = INFO_HEAPOBJ; + else if (strcmp(infoOpt, "tagged") == 0) + info = INFO_TAGGED; + else { + NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); + return JNI_ERR; + } + } + } + + chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); + if (!NSK_VERIFY(chainLength > 0)) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + caps.can_generate_object_free_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ObjectFree = callbackObjectFree; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/libiterheap003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/libiterheap003.c deleted file mode 100644 index 7640aa8769f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/libiterheap003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterheap003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/libiterheap003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/libiterheap003.cpp new file mode 100644 index 00000000000..06f7d1e5c02 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap003/libiterheap003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterheap003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/iterheap004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/iterheap004.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/iterheap004.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/iterheap004.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/libiterheap004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/libiterheap004.c deleted file mode 100644 index 667e71f83ec..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/libiterheap004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterheap004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/libiterheap004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/libiterheap004.cpp new file mode 100644 index 00000000000..b02d8922aaf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap004/libiterheap004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterheap004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/iterheap005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/iterheap005.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/iterheap005.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/iterheap005.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/libiterheap005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/libiterheap005.c deleted file mode 100644 index fced6cadcbf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/libiterheap005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterheap005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/libiterheap005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/libiterheap005.cpp new file mode 100644 index 00000000000..812d9ebb084 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap005/libiterheap005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterheap005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/iterheap006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/iterheap006.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/iterheap006.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/iterheap006.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/libiterheap006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/libiterheap006.c deleted file mode 100644 index 9724b182ef1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/libiterheap006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterheap006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/libiterheap006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/libiterheap006.cpp new file mode 100644 index 00000000000..172c003be5e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap006/libiterheap006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterheap006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/iterheap007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/iterheap007.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/iterheap007.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/iterheap007.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/libiterheap007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/libiterheap007.c deleted file mode 100644 index 48f85d476f0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/libiterheap007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterheap007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/libiterheap007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/libiterheap007.cpp new file mode 100644 index 00000000000..162f96ddc1c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverHeap/iterheap007/libiterheap007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterheap007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/iterinstcls001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/iterinstcls001.c deleted file mode 100644 index fc1d913372c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/iterinstcls001.c +++ /dev/null @@ -1,591 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -static jlong timeout = 0; - -#define INFO_NONE 0x00 -#define INFO_ALL 0xFF -#define INFO_OBJREF 0x01 -#define INFO_STACKREF 0x02 -#define INFO_HEAPROOT 0x04 -#define INFO_HEAPOBJ 0x08 -#define INFO_HEAPOBJ 0x08 - -static unsigned int info = INFO_NONE; - -#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001" -#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001RootTestedClass" -#define ROOT_OBJECT_CLASS_SIG "L"ROOT_OBJECT_CLASS_NAME";" -#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001TestedClass" -#define CHAIN_OBJECT_CLASS_SIG "L"CHAIN_OBJECT_CLASS_NAME";" - -#define OBJECT_FIELD_NAME "object" -#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" -#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" -#define TAIL_FIELD_NAME "tail" - -#define DEFAULT_CHAIN_LENGTH 4 - -typedef struct ObjectDescStruct { - jlong tag; - jint found; - int collected; -} ObjectDesc; - -static int chainLength = 0; -static int objectsCount = 0; - -static ObjectDesc* objectDescList = NULL; - -static volatile int foundUntagged = 0; - -static int fakeUserData = 0; -static int userDataError = 0; - -/* ============================================================================= */ - -/** Obtain chain of tested objects and tag them recursively. */ -static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, - jfieldID firstField, const char firstFieldName[], - jfieldID nextField, const char nextFieldName[], - int count, ObjectDesc objectDescList[], - jlong tag, int reachable) { - - int success = NSK_TRUE; - jobject obj = NULL; - jlong objTag = (!reachable ? -tag : (tag % 2 != 0) ? tag : (jlong)0); - - if (count <= 0) - return NSK_TRUE; - - count--; - tag++; - - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - objectDescList[count].tag = objTag; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); - - if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, - nextField, nextFieldName, - count, objectDescList, tag, reachable)) { - return NSK_FALSE; - } - - NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); - return success; -} - -/** Obtain all tested objects from debugee class and tag them recursively. */ -static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - int *objectsCount, ObjectDesc* *objectDescList, - jclass *testedClass) { - jclass debugeeClass = NULL; - jclass rootObjectClass = NULL; - jclass chainObjectClass = NULL; - - jfieldID objectField = NULL; - jfieldID reachableChainField = NULL; - jfieldID unreachableChainField = NULL; - jfieldID tailField = NULL; - - jobject rootObject = NULL; - - jlong testedClassTag = 1; - jlong chainObjectTag = 100; - - *objectsCount = 2 * chainLength; - - NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), - (unsigned char**)objectDescList))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); - - { - int k; - for (k = 0; k < *objectsCount; k++) { - (*objectDescList)[k].tag = 0; - (*objectDescList)[k].found = 0; - (*objectDescList)[k].collected = 0; - } - } - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObjectClass = - NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); - - NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (chainObjectClass = - NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); - - NSK_DISPLAY1("Create global ref to tested class: 0x%p\n", chainObjectClass); - if (!NSK_JNI_VERIFY(jni, (*testedClass = (jclass) - NSK_CPP_STUB2(NewGlobalRef, jni, chainObjectClass)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... global ref: 0x%p\n", (void*)*testedClass); - - NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (reachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (unreachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); - - NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (tailField = - NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, - TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); - - NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); - - NSK_DISPLAY0("Obtain and tag chain objects:\n"); - - NSK_DISPLAY0(" tested class object:\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, *testedClass, testedClassTag))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)testedClassTag, (void*)*testedClass); - - NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - reachableChainField, REACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList, - chainObjectTag, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList + chainLength, - chainObjectTag, NSK_FALSE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/** Check if tagged objects were iterated. */ -static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, - int chainLength, ObjectDesc objectDescList[]) { - int success = NSK_TRUE; - int expectedUntagged = 0; - int i; - - NSK_DISPLAY0("Following tagged/untagged objects were iterated:\n"); - - NSK_DISPLAY0(" reachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY2(" tag=%-5ld iterated=%d times\n", - (long)objectDescList[i].tag, objectDescList[i].found); - - if (objectDescList[i].found <= 0 - && objectDescList[i].tag != 0) { - NSK_COMPLAIN2("Reachable tagged object was not iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i].tag, - objectDescList[i].found); - nsk_jvmti_setFailStatus(); - } - - if (objectDescList[i].tag == 0) { - expectedUntagged++; - } - } - - NSK_DISPLAY0(" unreachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY3(" tag=%-5ld iterated=%-3d collected=%d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found, - objectDescList[i + chainLength].collected); - - if (objectDescList[i + chainLength].found <= 0 - && objectDescList[i + chainLength].collected <= 0) { - NSK_COMPLAIN2("Not collected unreachable tagged object was not iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found); - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(" untagged objects:\n"); - NSK_DISPLAY2(" total=%-3d iterated=%d objects\n", - expectedUntagged, foundUntagged); - if (foundUntagged != expectedUntagged) { - NSK_COMPLAIN2("Unexpected number of untagged objects were iterated:\n" - "# iterated untagged objects: %d\n" - "# expected: %d\n", - foundUntagged, expectedUntagged); - nsk_jvmti_setFailStatus(); - } - - return NSK_TRUE; -} - -/** Release references to the tested objects and free allocated memory. */ -static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - ObjectDesc* objectDescList, jclass testedClass) { - if (testedClass != NULL) { - NSK_DISPLAY1("Release object reference to tested class: 0x%p\n", testedClass); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); - } - - if (objectDescList != NULL) { - NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { - nsk_jvmti_setFailStatus(); - } - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** heapRootCallback for heap iterator. */ -jvmtiIterationControl JNICALL -heapObjectCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { - - if (info & INFO_HEAPOBJ) { - NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", - (long)class_tag, (long)size, - (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); - } - - if (class_tag != 1) { - NSK_COMPLAIN3("Unexpected class_tag passed to heapObjectCallback:\n" - "# object tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr == NULL) { - NSK_COMPLAIN3("NULL tag_ptr is passed to heapObjectCallback:\n" - "# tag_ptr: 0x%p\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (void*)tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } else { - if (*tag_ptr == 0) { - foundUntagged++; - } else { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - break; - } - } - - if (found <= 0) { - NSK_COMPLAIN3("Unknown tagged object passed to heapObjectCallback:\n" - "# tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed to heapObjectCallback:\n" - "# expected: 0x%p\n" - "# actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for tested objects created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - { - jclass testedClass = NULL; - - NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); - { - if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, - &objectsCount, &objectDescList, &testedClass))) - return; - } - - NSK_DISPLAY0(">>> Enable OBJECT_FREE event and let debugee to clean links to unreachable objects\n"); - { - jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - } - - NSK_DISPLAY0(">>> Iterate over instances of tested class with filter JVMTI_HEAP_OBJECT_EITHER\n"); - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - testedClass, JVMTI_HEAP_OBJECT_EITHER, - heapObjectCallback, &fakeUserData))) { - nsk_jvmti_setFailStatus(); - return; - } - } - - NSK_DISPLAY0(">>> Disable OBJECT_FREE event and check if tagged/untagged objects were iterated:\n"); - { - jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) - return; - - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, - objectDescList, testedClass))) - return; - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -JNIEXPORT void JNICALL -callbackObjectFree(jvmtiEnv* jvmti, jlong tag) { - int i; - - if (info & INFO_HEAPOBJ) { - NSK_DISPLAY1(" : tag=%-5ld\n", tag); - } - - if (tag != 0) { - for (i = 0; i < objectsCount; i++) { - if (tag == objectDescList[i].tag) { - objectDescList[i].collected++; - break; - } - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_iterinstcls001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_iterinstcls001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_iterinstcls001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - { - const char* infoOpt = nsk_jvmti_findOptionValue("info"); - if (infoOpt != NULL) { - if (strcmp(infoOpt, "none") == 0) - info = INFO_NONE; - else if (strcmp(infoOpt, "all") == 0) - info = INFO_ALL; - else if (strcmp(infoOpt, "objref") == 0) - info = INFO_OBJREF; - else if (strcmp(infoOpt, "stackref") == 0) - info = INFO_STACKREF; - else if (strcmp(infoOpt, "heaproot") == 0) - info = INFO_HEAPROOT; - else if (strcmp(infoOpt, "heapobj") == 0) - info = INFO_HEAPOBJ; - else { - NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); - return JNI_ERR; - } - } - } - - chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); - if (!NSK_VERIFY(chainLength > 0)) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - caps.can_generate_object_free_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ObjectFree = callbackObjectFree; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/iterinstcls001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/iterinstcls001.cpp new file mode 100644 index 00000000000..62cf8d02338 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/iterinstcls001.cpp @@ -0,0 +1,591 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jlong timeout = 0; + +#define INFO_NONE 0x00 +#define INFO_ALL 0xFF +#define INFO_OBJREF 0x01 +#define INFO_STACKREF 0x02 +#define INFO_HEAPROOT 0x04 +#define INFO_HEAPOBJ 0x08 +#define INFO_HEAPOBJ 0x08 + +static unsigned int info = INFO_NONE; + +#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001" +#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001RootTestedClass" +#define ROOT_OBJECT_CLASS_SIG "L" ROOT_OBJECT_CLASS_NAME ";" +#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001TestedClass" +#define CHAIN_OBJECT_CLASS_SIG "L" CHAIN_OBJECT_CLASS_NAME ";" + +#define OBJECT_FIELD_NAME "object" +#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" +#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" +#define TAIL_FIELD_NAME "tail" + +#define DEFAULT_CHAIN_LENGTH 4 + +typedef struct ObjectDescStruct { + jlong tag; + jint found; + int collected; +} ObjectDesc; + +static int chainLength = 0; +static int objectsCount = 0; + +static ObjectDesc* objectDescList = NULL; + +static volatile int foundUntagged = 0; + +static int fakeUserData = 0; +static int userDataError = 0; + +/* ============================================================================= */ + +/** Obtain chain of tested objects and tag them recursively. */ +static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, + jfieldID firstField, const char firstFieldName[], + jfieldID nextField, const char nextFieldName[], + int count, ObjectDesc objectDescList[], + jlong tag, int reachable) { + + int success = NSK_TRUE; + jobject obj = NULL; + jlong objTag = (!reachable ? -tag : (tag % 2 != 0) ? tag : (jlong)0); + + if (count <= 0) + return NSK_TRUE; + + count--; + tag++; + + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + objectDescList[count].tag = objTag; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); + + if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, + nextField, nextFieldName, + count, objectDescList, tag, reachable)) { + return NSK_FALSE; + } + + NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); + return success; +} + +/** Obtain all tested objects from debugee class and tag them recursively. */ +static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + int *objectsCount, ObjectDesc* *objectDescList, + jclass *testedClass) { + jclass debugeeClass = NULL; + jclass rootObjectClass = NULL; + jclass chainObjectClass = NULL; + + jfieldID objectField = NULL; + jfieldID reachableChainField = NULL; + jfieldID unreachableChainField = NULL; + jfieldID tailField = NULL; + + jobject rootObject = NULL; + + jlong testedClassTag = 1; + jlong chainObjectTag = 100; + + *objectsCount = 2 * chainLength; + + NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), + (unsigned char**)objectDescList))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); + + { + int k; + for (k = 0; k < *objectsCount; k++) { + (*objectDescList)[k].tag = 0; + (*objectDescList)[k].found = 0; + (*objectDescList)[k].collected = 0; + } + } + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObjectClass = + NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); + + NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (chainObjectClass = + NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); + + NSK_DISPLAY1("Create global ref to tested class: 0x%p\n", chainObjectClass); + if (!NSK_JNI_VERIFY(jni, (*testedClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, chainObjectClass)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... global ref: 0x%p\n", (void*)*testedClass); + + NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (reachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (unreachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); + + NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (tailField = + NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, + TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); + + NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); + + NSK_DISPLAY0("Obtain and tag chain objects:\n"); + + NSK_DISPLAY0(" tested class object:\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, *testedClass, testedClassTag))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)testedClassTag, (void*)*testedClass); + + NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + reachableChainField, REACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList, + chainObjectTag, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList + chainLength, + chainObjectTag, NSK_FALSE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/** Check if tagged objects were iterated. */ +static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, + int chainLength, ObjectDesc objectDescList[]) { + int success = NSK_TRUE; + int expectedUntagged = 0; + int i; + + NSK_DISPLAY0("Following tagged/untagged objects were iterated:\n"); + + NSK_DISPLAY0(" reachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY2(" tag=%-5ld iterated=%d times\n", + (long)objectDescList[i].tag, objectDescList[i].found); + + if (objectDescList[i].found <= 0 + && objectDescList[i].tag != 0) { + NSK_COMPLAIN2("Reachable tagged object was not iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i].tag, + objectDescList[i].found); + nsk_jvmti_setFailStatus(); + } + + if (objectDescList[i].tag == 0) { + expectedUntagged++; + } + } + + NSK_DISPLAY0(" unreachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY3(" tag=%-5ld iterated=%-3d collected=%d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found, + objectDescList[i + chainLength].collected); + + if (objectDescList[i + chainLength].found <= 0 + && objectDescList[i + chainLength].collected <= 0) { + NSK_COMPLAIN2("Not collected unreachable tagged object was not iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found); + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(" untagged objects:\n"); + NSK_DISPLAY2(" total=%-3d iterated=%d objects\n", + expectedUntagged, foundUntagged); + if (foundUntagged != expectedUntagged) { + NSK_COMPLAIN2("Unexpected number of untagged objects were iterated:\n" + "# iterated untagged objects: %d\n" + "# expected: %d\n", + foundUntagged, expectedUntagged); + nsk_jvmti_setFailStatus(); + } + + return NSK_TRUE; +} + +/** Release references to the tested objects and free allocated memory. */ +static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + ObjectDesc* objectDescList, jclass testedClass) { + if (testedClass != NULL) { + NSK_DISPLAY1("Release object reference to tested class: 0x%p\n", testedClass); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); + } + + if (objectDescList != NULL) { + NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { + nsk_jvmti_setFailStatus(); + } + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** heapRootCallback for heap iterator. */ +jvmtiIterationControl JNICALL +heapObjectCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { + + if (info & INFO_HEAPOBJ) { + NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", + (long)class_tag, (long)size, + (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); + } + + if (class_tag != 1) { + NSK_COMPLAIN3("Unexpected class_tag passed to heapObjectCallback:\n" + "# object tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr == NULL) { + NSK_COMPLAIN3("NULL tag_ptr is passed to heapObjectCallback:\n" + "# tag_ptr: 0x%p\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (void*)tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } else { + if (*tag_ptr == 0) { + foundUntagged++; + } else { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + break; + } + } + + if (found <= 0) { + NSK_COMPLAIN3("Unknown tagged object passed to heapObjectCallback:\n" + "# tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed to heapObjectCallback:\n" + "# expected: 0x%p\n" + "# actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for tested objects created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + { + jclass testedClass = NULL; + + NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); + { + if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, + &objectsCount, &objectDescList, &testedClass))) + return; + } + + NSK_DISPLAY0(">>> Enable OBJECT_FREE event and let debugee to clean links to unreachable objects\n"); + { + jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + } + + NSK_DISPLAY0(">>> Iterate over instances of tested class with filter JVMTI_HEAP_OBJECT_EITHER\n"); + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + testedClass, JVMTI_HEAP_OBJECT_EITHER, + heapObjectCallback, &fakeUserData))) { + nsk_jvmti_setFailStatus(); + return; + } + } + + NSK_DISPLAY0(">>> Disable OBJECT_FREE event and check if tagged/untagged objects were iterated:\n"); + { + jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) + return; + + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, + objectDescList, testedClass))) + return; + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +JNIEXPORT void JNICALL +callbackObjectFree(jvmtiEnv* jvmti, jlong tag) { + int i; + + if (info & INFO_HEAPOBJ) { + NSK_DISPLAY1(" : tag=%-5ld\n", tag); + } + + if (tag != 0) { + for (i = 0; i < objectsCount; i++) { + if (tag == objectDescList[i].tag) { + objectDescList[i].collected++; + break; + } + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_iterinstcls001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_iterinstcls001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_iterinstcls001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + { + const char* infoOpt = nsk_jvmti_findOptionValue("info"); + if (infoOpt != NULL) { + if (strcmp(infoOpt, "none") == 0) + info = INFO_NONE; + else if (strcmp(infoOpt, "all") == 0) + info = INFO_ALL; + else if (strcmp(infoOpt, "objref") == 0) + info = INFO_OBJREF; + else if (strcmp(infoOpt, "stackref") == 0) + info = INFO_STACKREF; + else if (strcmp(infoOpt, "heaproot") == 0) + info = INFO_HEAPROOT; + else if (strcmp(infoOpt, "heapobj") == 0) + info = INFO_HEAPOBJ; + else { + NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); + return JNI_ERR; + } + } + } + + chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); + if (!NSK_VERIFY(chainLength > 0)) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + caps.can_generate_object_free_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ObjectFree = callbackObjectFree; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/libiterinstcls001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/libiterinstcls001.c deleted file mode 100644 index ef9a665836a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/libiterinstcls001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterinstcls001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/libiterinstcls001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/libiterinstcls001.cpp new file mode 100644 index 00000000000..0921d9fbc82 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls001/libiterinstcls001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterinstcls001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/iterinstcls002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/iterinstcls002.c deleted file mode 100644 index 9a2d6bcacaa..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/iterinstcls002.c +++ /dev/null @@ -1,599 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -static jlong timeout = 0; - -#define INFO_NONE 0x00 -#define INFO_ALL 0xFF -#define INFO_OBJREF 0x01 -#define INFO_STACKREF 0x02 -#define INFO_HEAPROOT 0x04 -#define INFO_HEAPOBJ 0x08 -#define INFO_HEAPOBJ 0x08 - -static unsigned int info = INFO_NONE; - -#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002" -#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002RootTestedClass" -#define ROOT_OBJECT_CLASS_SIG "L"ROOT_OBJECT_CLASS_NAME";" -#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002TestedClass" -#define CHAIN_OBJECT_CLASS_SIG "L"CHAIN_OBJECT_CLASS_NAME";" - -#define OBJECT_FIELD_NAME "object" -#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" -#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" -#define TAIL_FIELD_NAME "tail" - -#define DEFAULT_CHAIN_LENGTH 4 - -typedef struct ObjectDescStruct { - jlong tag; - jint found; - int collected; -} ObjectDesc; - -static int chainLength = 0; -static int objectsCount = 0; - -static ObjectDesc* objectDescList = NULL; - -static volatile int foundUntagged = 0; - -static int fakeUserData = 0; -static int userDataError = 0; - -/* ============================================================================= */ - -/** Obtain chain of tested objects and tag them recursively. */ -static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, - jfieldID firstField, const char firstFieldName[], - jfieldID nextField, const char nextFieldName[], - int count, ObjectDesc objectDescList[], - jlong tag, int reachable) { - - int success = NSK_TRUE; - jobject obj = NULL; - jlong objTag = (!reachable ? -tag : (tag % 2 != 0) ? tag : (jlong)0); - - if (count <= 0) - return NSK_TRUE; - - count--; - tag++; - - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - objectDescList[count].tag = objTag; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); - - if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, - nextField, nextFieldName, - count, objectDescList, tag, reachable)) { - return NSK_FALSE; - } - - NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); - return success; -} - -/** Obtain all tested objects from debugee class and tag them recursively. */ -static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - int *objectsCount, ObjectDesc* *objectDescList, - jclass *testedClass) { - jclass debugeeClass = NULL; - jclass rootObjectClass = NULL; - jclass chainObjectClass = NULL; - - jfieldID objectField = NULL; - jfieldID reachableChainField = NULL; - jfieldID unreachableChainField = NULL; - jfieldID tailField = NULL; - - jobject rootObject = NULL; - - jlong testedClassTag = 1; - jlong chainObjectTag = 100; - - *objectsCount = 2 * chainLength; - - NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), - (unsigned char**)objectDescList))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); - - { - int k; - for (k = 0; k < *objectsCount; k++) { - (*objectDescList)[k].tag = 0; - (*objectDescList)[k].found = 0; - (*objectDescList)[k].collected = 0; - } - } - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObjectClass = - NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); - - NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (chainObjectClass = - NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); - - NSK_DISPLAY1("Create global ref to tested class: 0x%p\n", chainObjectClass); - if (!NSK_JNI_VERIFY(jni, (*testedClass = (jclass) - NSK_CPP_STUB2(NewGlobalRef, jni, chainObjectClass)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... global ref: 0x%p\n", (void*)*testedClass); - - NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (reachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (unreachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); - - NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (tailField = - NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, - TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); - - NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); - - NSK_DISPLAY0("Obtain and tag chain objects:\n"); - - NSK_DISPLAY0(" tested class object:\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, *testedClass, testedClassTag))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)testedClassTag, (void*)*testedClass); - - NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - reachableChainField, REACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList, - chainObjectTag, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList + chainLength, - chainObjectTag, NSK_FALSE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/** Check if tagged objects were iterated. */ -static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, - int chainLength, ObjectDesc objectDescList[]) { - int success = NSK_TRUE; - int expectedUntagged = 0; - int i; - - NSK_DISPLAY0("Following tagged/untagged objects were iterated:\n"); - - NSK_DISPLAY0(" reachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY2(" tag=%-5ld iterated=%d times\n", - (long)objectDescList[i].tag, objectDescList[i].found); - - if (objectDescList[i].found <= 0 - && objectDescList[i].tag != 0) { - NSK_COMPLAIN2("Reachable tagged object was not iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i].tag, - objectDescList[i].found); - nsk_jvmti_setFailStatus(); - } - - if (objectDescList[i].tag == 0) { - expectedUntagged++; - } - } - - NSK_DISPLAY0(" unreachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY3(" tag=%-5ld iterated=%-3d collected=%d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found, - objectDescList[i + chainLength].collected); - - if (objectDescList[i + chainLength].found <= 0 - && objectDescList[i + chainLength].collected <= 0) { - NSK_COMPLAIN2("Not collected unreachable tagged object was not iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found); - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(" untagged objects:\n"); - NSK_DISPLAY2(" total=%-3d iterated=%d objects\n", - expectedUntagged, foundUntagged); - if (foundUntagged > 0) { - NSK_COMPLAIN2("A number of untagged objects were iterated:\n" - "# iterated untagged objects: %d\n" - "# total untagged objects: %d\n", - foundUntagged, expectedUntagged); - nsk_jvmti_setFailStatus(); - } - - return NSK_TRUE; -} - -/** Release references to the tested objects and free allocated memory. */ -static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - ObjectDesc* objectDescList, jclass testedClass) { - if (testedClass != NULL) { - NSK_DISPLAY1("Release object reference to tested class: 0x%p\n", testedClass); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); - } - - if (objectDescList != NULL) { - NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { - nsk_jvmti_setFailStatus(); - } - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** heapRootCallback for heap iterator. */ -jvmtiIterationControl JNICALL -heapObjectCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { - - if (info & INFO_HEAPOBJ) { - NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", - (long)class_tag, (long)size, - (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); - } - - if (class_tag != 1) { - NSK_COMPLAIN3("Unexpected class_tag passed to heapObjectCallback:\n" - "# object tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr == NULL) { - NSK_COMPLAIN3("NULL tag_ptr is passed to heapObjectCallback:\n" - "# tag_ptr: 0x%p\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (void*)tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } else { - if (*tag_ptr == 0) { - foundUntagged++; - NSK_COMPLAIN3("Untagged object passed to heapObjectCallback:\n" - "# tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } else { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - break; - } - } - - if (found <= 0) { - NSK_COMPLAIN3("Unknown tagged object passed to heapObjectCallback:\n" - "# tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed to heapObjectCallback:\n" - "# expected: 0x%p\n" - "# actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for tested objects created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - { - jclass testedClass = NULL; - - NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); - { - if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, - &objectsCount, &objectDescList, &testedClass))) - return; - } - - NSK_DISPLAY0(">>> Enable OBJECT_FREE event and let debugee to clean links to unreachable objects\n"); - { - jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - } - - NSK_DISPLAY0(">>> Iterate over instances of tested class with filter JVMTI_HEAP_OBJECT_TAGGED\n"); - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - testedClass, JVMTI_HEAP_OBJECT_TAGGED, - heapObjectCallback, &fakeUserData))) { - nsk_jvmti_setFailStatus(); - return; - } - } - - NSK_DISPLAY0(">>> Disable OBJECT_FREE event and check if tagged objects were iterated:\n"); - { - jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) - return; - - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, - objectDescList, testedClass))) - return; - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -JNIEXPORT void JNICALL -callbackObjectFree(jvmtiEnv* jvmti, jlong tag) { - int i; - - if (info & INFO_HEAPOBJ) { - NSK_DISPLAY1(" : tag=%-5ld\n", tag); - } - - if (tag != 0) { - for (i = 0; i < objectsCount; i++) { - if (tag == objectDescList[i].tag) { - objectDescList[i].collected++; - break; - } - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_iterinstcls002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_iterinstcls002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_iterinstcls002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - { - const char* infoOpt = nsk_jvmti_findOptionValue("info"); - if (infoOpt != NULL) { - if (strcmp(infoOpt, "none") == 0) - info = INFO_NONE; - else if (strcmp(infoOpt, "all") == 0) - info = INFO_ALL; - else if (strcmp(infoOpt, "objref") == 0) - info = INFO_OBJREF; - else if (strcmp(infoOpt, "stackref") == 0) - info = INFO_STACKREF; - else if (strcmp(infoOpt, "heaproot") == 0) - info = INFO_HEAPROOT; - else if (strcmp(infoOpt, "heapobj") == 0) - info = INFO_HEAPOBJ; - else { - NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); - return JNI_ERR; - } - } - } - - chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); - if (!NSK_VERIFY(chainLength > 0)) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - caps.can_generate_object_free_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ObjectFree = callbackObjectFree; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/iterinstcls002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/iterinstcls002.cpp new file mode 100644 index 00000000000..3daa0dee97c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/iterinstcls002.cpp @@ -0,0 +1,599 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jlong timeout = 0; + +#define INFO_NONE 0x00 +#define INFO_ALL 0xFF +#define INFO_OBJREF 0x01 +#define INFO_STACKREF 0x02 +#define INFO_HEAPROOT 0x04 +#define INFO_HEAPOBJ 0x08 +#define INFO_HEAPOBJ 0x08 + +static unsigned int info = INFO_NONE; + +#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002" +#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002RootTestedClass" +#define ROOT_OBJECT_CLASS_SIG "L" ROOT_OBJECT_CLASS_NAME ";" +#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002TestedClass" +#define CHAIN_OBJECT_CLASS_SIG "L" CHAIN_OBJECT_CLASS_NAME ";" + +#define OBJECT_FIELD_NAME "object" +#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" +#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" +#define TAIL_FIELD_NAME "tail" + +#define DEFAULT_CHAIN_LENGTH 4 + +typedef struct ObjectDescStruct { + jlong tag; + jint found; + int collected; +} ObjectDesc; + +static int chainLength = 0; +static int objectsCount = 0; + +static ObjectDesc* objectDescList = NULL; + +static volatile int foundUntagged = 0; + +static int fakeUserData = 0; +static int userDataError = 0; + +/* ============================================================================= */ + +/** Obtain chain of tested objects and tag them recursively. */ +static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, + jfieldID firstField, const char firstFieldName[], + jfieldID nextField, const char nextFieldName[], + int count, ObjectDesc objectDescList[], + jlong tag, int reachable) { + + int success = NSK_TRUE; + jobject obj = NULL; + jlong objTag = (!reachable ? -tag : (tag % 2 != 0) ? tag : (jlong)0); + + if (count <= 0) + return NSK_TRUE; + + count--; + tag++; + + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + objectDescList[count].tag = objTag; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); + + if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, + nextField, nextFieldName, + count, objectDescList, tag, reachable)) { + return NSK_FALSE; + } + + NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); + return success; +} + +/** Obtain all tested objects from debugee class and tag them recursively. */ +static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + int *objectsCount, ObjectDesc* *objectDescList, + jclass *testedClass) { + jclass debugeeClass = NULL; + jclass rootObjectClass = NULL; + jclass chainObjectClass = NULL; + + jfieldID objectField = NULL; + jfieldID reachableChainField = NULL; + jfieldID unreachableChainField = NULL; + jfieldID tailField = NULL; + + jobject rootObject = NULL; + + jlong testedClassTag = 1; + jlong chainObjectTag = 100; + + *objectsCount = 2 * chainLength; + + NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), + (unsigned char**)objectDescList))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); + + { + int k; + for (k = 0; k < *objectsCount; k++) { + (*objectDescList)[k].tag = 0; + (*objectDescList)[k].found = 0; + (*objectDescList)[k].collected = 0; + } + } + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObjectClass = + NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); + + NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (chainObjectClass = + NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); + + NSK_DISPLAY1("Create global ref to tested class: 0x%p\n", chainObjectClass); + if (!NSK_JNI_VERIFY(jni, (*testedClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, chainObjectClass)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... global ref: 0x%p\n", (void*)*testedClass); + + NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (reachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (unreachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); + + NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (tailField = + NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, + TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); + + NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); + + NSK_DISPLAY0("Obtain and tag chain objects:\n"); + + NSK_DISPLAY0(" tested class object:\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, *testedClass, testedClassTag))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)testedClassTag, (void*)*testedClass); + + NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + reachableChainField, REACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList, + chainObjectTag, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList + chainLength, + chainObjectTag, NSK_FALSE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/** Check if tagged objects were iterated. */ +static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, + int chainLength, ObjectDesc objectDescList[]) { + int success = NSK_TRUE; + int expectedUntagged = 0; + int i; + + NSK_DISPLAY0("Following tagged/untagged objects were iterated:\n"); + + NSK_DISPLAY0(" reachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY2(" tag=%-5ld iterated=%d times\n", + (long)objectDescList[i].tag, objectDescList[i].found); + + if (objectDescList[i].found <= 0 + && objectDescList[i].tag != 0) { + NSK_COMPLAIN2("Reachable tagged object was not iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i].tag, + objectDescList[i].found); + nsk_jvmti_setFailStatus(); + } + + if (objectDescList[i].tag == 0) { + expectedUntagged++; + } + } + + NSK_DISPLAY0(" unreachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY3(" tag=%-5ld iterated=%-3d collected=%d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found, + objectDescList[i + chainLength].collected); + + if (objectDescList[i + chainLength].found <= 0 + && objectDescList[i + chainLength].collected <= 0) { + NSK_COMPLAIN2("Not collected unreachable tagged object was not iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found); + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(" untagged objects:\n"); + NSK_DISPLAY2(" total=%-3d iterated=%d objects\n", + expectedUntagged, foundUntagged); + if (foundUntagged > 0) { + NSK_COMPLAIN2("A number of untagged objects were iterated:\n" + "# iterated untagged objects: %d\n" + "# total untagged objects: %d\n", + foundUntagged, expectedUntagged); + nsk_jvmti_setFailStatus(); + } + + return NSK_TRUE; +} + +/** Release references to the tested objects and free allocated memory. */ +static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + ObjectDesc* objectDescList, jclass testedClass) { + if (testedClass != NULL) { + NSK_DISPLAY1("Release object reference to tested class: 0x%p\n", testedClass); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); + } + + if (objectDescList != NULL) { + NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { + nsk_jvmti_setFailStatus(); + } + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** heapRootCallback for heap iterator. */ +jvmtiIterationControl JNICALL +heapObjectCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { + + if (info & INFO_HEAPOBJ) { + NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", + (long)class_tag, (long)size, + (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); + } + + if (class_tag != 1) { + NSK_COMPLAIN3("Unexpected class_tag passed to heapObjectCallback:\n" + "# object tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr == NULL) { + NSK_COMPLAIN3("NULL tag_ptr is passed to heapObjectCallback:\n" + "# tag_ptr: 0x%p\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (void*)tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } else { + if (*tag_ptr == 0) { + foundUntagged++; + NSK_COMPLAIN3("Untagged object passed to heapObjectCallback:\n" + "# tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } else { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + break; + } + } + + if (found <= 0) { + NSK_COMPLAIN3("Unknown tagged object passed to heapObjectCallback:\n" + "# tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed to heapObjectCallback:\n" + "# expected: 0x%p\n" + "# actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for tested objects created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + { + jclass testedClass = NULL; + + NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); + { + if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, + &objectsCount, &objectDescList, &testedClass))) + return; + } + + NSK_DISPLAY0(">>> Enable OBJECT_FREE event and let debugee to clean links to unreachable objects\n"); + { + jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + } + + NSK_DISPLAY0(">>> Iterate over instances of tested class with filter JVMTI_HEAP_OBJECT_TAGGED\n"); + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + testedClass, JVMTI_HEAP_OBJECT_TAGGED, + heapObjectCallback, &fakeUserData))) { + nsk_jvmti_setFailStatus(); + return; + } + } + + NSK_DISPLAY0(">>> Disable OBJECT_FREE event and check if tagged objects were iterated:\n"); + { + jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) + return; + + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, + objectDescList, testedClass))) + return; + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +JNIEXPORT void JNICALL +callbackObjectFree(jvmtiEnv* jvmti, jlong tag) { + int i; + + if (info & INFO_HEAPOBJ) { + NSK_DISPLAY1(" : tag=%-5ld\n", tag); + } + + if (tag != 0) { + for (i = 0; i < objectsCount; i++) { + if (tag == objectDescList[i].tag) { + objectDescList[i].collected++; + break; + } + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_iterinstcls002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_iterinstcls002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_iterinstcls002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + { + const char* infoOpt = nsk_jvmti_findOptionValue("info"); + if (infoOpt != NULL) { + if (strcmp(infoOpt, "none") == 0) + info = INFO_NONE; + else if (strcmp(infoOpt, "all") == 0) + info = INFO_ALL; + else if (strcmp(infoOpt, "objref") == 0) + info = INFO_OBJREF; + else if (strcmp(infoOpt, "stackref") == 0) + info = INFO_STACKREF; + else if (strcmp(infoOpt, "heaproot") == 0) + info = INFO_HEAPROOT; + else if (strcmp(infoOpt, "heapobj") == 0) + info = INFO_HEAPOBJ; + else { + NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); + return JNI_ERR; + } + } + } + + chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); + if (!NSK_VERIFY(chainLength > 0)) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + caps.can_generate_object_free_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ObjectFree = callbackObjectFree; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/libiterinstcls002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/libiterinstcls002.c deleted file mode 100644 index cbb080212f4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/libiterinstcls002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterinstcls002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/libiterinstcls002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/libiterinstcls002.cpp new file mode 100644 index 00000000000..edf00a40737 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls002/libiterinstcls002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterinstcls002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/iterinstcls003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/iterinstcls003.c deleted file mode 100644 index daa93df4da5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/iterinstcls003.c +++ /dev/null @@ -1,600 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -static jlong timeout = 0; - -#define INFO_NONE 0x00 -#define INFO_ALL 0xFF -#define INFO_OBJREF 0x01 -#define INFO_STACKREF 0x02 -#define INFO_HEAPROOT 0x04 -#define INFO_HEAPOBJ 0x08 -#define INFO_HEAPOBJ 0x08 - -static unsigned int info = INFO_NONE; - -#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003" -#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003RootTestedClass" -#define ROOT_OBJECT_CLASS_SIG "L"ROOT_OBJECT_CLASS_NAME";" -#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003TestedClass" -#define CHAIN_OBJECT_CLASS_SIG "L"CHAIN_OBJECT_CLASS_NAME";" - -#define OBJECT_FIELD_NAME "object" -#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" -#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" -#define TAIL_FIELD_NAME "tail" - -#define DEFAULT_CHAIN_LENGTH 4 - -typedef struct ObjectDescStruct { - jlong tag; - jint found; - int collected; -} ObjectDesc; - -static int chainLength = 0; -static int objectsCount = 0; - -static ObjectDesc* objectDescList = NULL; - -static volatile int foundUntagged = 0; - -static int fakeUserData = 0; -static int userDataError = 0; - -/* ============================================================================= */ - -/** Obtain chain of tested objects and tag them recursively. */ -static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, - jfieldID firstField, const char firstFieldName[], - jfieldID nextField, const char nextFieldName[], - int count, ObjectDesc objectDescList[], - jlong tag, int reachable) { - - int success = NSK_TRUE; - jobject obj = NULL; - jlong objTag = (!reachable ? -tag : (tag % 2 != 0) ? tag : (jlong)0); - - if (count <= 0) - return NSK_TRUE; - - count--; - tag++; - - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - objectDescList[count].tag = objTag; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); - - if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, - nextField, nextFieldName, - count, objectDescList, tag, reachable)) { - return NSK_FALSE; - } - - NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); - return success; -} - -/** Obtain all tested objects from debugee class and tag them recursively. */ -static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - int *objectsCount, ObjectDesc* *objectDescList, - jclass *testedClass) { - jclass debugeeClass = NULL; - jclass rootObjectClass = NULL; - jclass chainObjectClass = NULL; - - jfieldID objectField = NULL; - jfieldID reachableChainField = NULL; - jfieldID unreachableChainField = NULL; - jfieldID tailField = NULL; - - jobject rootObject = NULL; - - jlong testedClassTag = 1; - jlong chainObjectTag = 100; - - *objectsCount = 2 * chainLength; - - NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), - (unsigned char**)objectDescList))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); - - { - int k; - for (k = 0; k < *objectsCount; k++) { - (*objectDescList)[k].tag = 0; - (*objectDescList)[k].found = 0; - (*objectDescList)[k].collected = 0; - } - } - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObjectClass = - NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); - - NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (chainObjectClass = - NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); - - NSK_DISPLAY1("Create global ref to tested class: 0x%p\n", chainObjectClass); - if (!NSK_JNI_VERIFY(jni, (*testedClass = (jclass) - NSK_CPP_STUB2(NewGlobalRef, jni, chainObjectClass)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... global ref: 0x%p\n", (void*)*testedClass); - - NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (reachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (unreachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); - - NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (tailField = - NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, - TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); - - NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); - - NSK_DISPLAY0("Obtain and tag chain objects:\n"); - - NSK_DISPLAY0(" tested class object:\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, *testedClass, testedClassTag))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)testedClassTag, (void*)*testedClass); - - NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - reachableChainField, REACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList, - chainObjectTag, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList + chainLength, - chainObjectTag, NSK_FALSE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/** Check if tagged objects were iterated. */ -static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, - int chainLength, ObjectDesc objectDescList[]) { - int success = NSK_TRUE; - int expectedUntagged = 0; - int i; - - NSK_DISPLAY0("Following tagged/untagged objects were iterated:\n"); - - NSK_DISPLAY0(" reachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY2(" tag=%-5ld iterated=%d times\n", - (long)objectDescList[i].tag, objectDescList[i].found); - - if (objectDescList[i].found > 0 - && objectDescList[i].tag != 0) { - NSK_COMPLAIN2("Reachable tagged object was iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i].tag, - objectDescList[i].found); - nsk_jvmti_setFailStatus(); - } - - if (objectDescList[i].tag == 0) { - expectedUntagged++; - } - } - - NSK_DISPLAY0(" unreachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY3(" tag=%-5ld iterated=%-3d collected=%d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found, - objectDescList[i + chainLength].collected); - - if (objectDescList[i + chainLength].found <= 0 - && objectDescList[i + chainLength].collected > 0) { - NSK_COMPLAIN2("Not collected unreachable tagged object was iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found); - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(" untagged objects:\n"); - NSK_DISPLAY2(" total=%-3d iterated=%d objects\n", - expectedUntagged, foundUntagged); - if (foundUntagged > expectedUntagged) { - NSK_COMPLAIN2("Unexpected number of untagged objects were iterated:\n" - "# iterated untagged objects: %d\n" - "# expected: %d\n", - foundUntagged, expectedUntagged); - nsk_jvmti_setFailStatus(); - } - - return NSK_TRUE; -} - -/** Release references to the tested objects and free allocated memory. */ -static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - ObjectDesc* objectDescList, jclass testedClass) { - if (testedClass != NULL) { - NSK_DISPLAY1("Release object reference to tested class: 0x%p\n", testedClass); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); - } - - if (objectDescList != NULL) { - NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { - nsk_jvmti_setFailStatus(); - } - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** heapRootCallback for heap iterator. */ -jvmtiIterationControl JNICALL -heapObjectCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { - - if (info & INFO_HEAPOBJ) { - NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", - (long)class_tag, (long)size, - (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); - } - - if (class_tag != 1) { - NSK_COMPLAIN3("Unexpected class_tag passed to heapObjectCallback:\n" - "# object tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr == NULL) { - NSK_COMPLAIN3("NULL tag_ptr is passed to heapObjectCallback:\n" - "# tag_ptr: 0x%p\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (void*)tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } else { - if (*tag_ptr == 0) { - foundUntagged++; - } else { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - break; - } - } - - if (found <= 0) { - NSK_COMPLAIN3("Unknown tagged object passed to heapObjectCallback:\n" - "# tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } else { - NSK_COMPLAIN3("Known tagged object passed to heapObjectCallback:\n" - "# tag: %ld\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed to heapObjectCallback:\n" - "# expected: 0x%p\n" - "# actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for tested objects created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - { - jclass testedClass = NULL; - - NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); - { - if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, - &objectsCount, &objectDescList, &testedClass))) - return; - } - - NSK_DISPLAY0(">>> Enable OBJECT_FREE event and let debugee to clean links to unreachable objects\n"); - { - jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) - return; - - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - } - - NSK_DISPLAY0(">>> Iterate over instances of tested class with filter JVMTI_HEAP_OBJECT_UNTAGGED\n"); - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - testedClass, JVMTI_HEAP_OBJECT_UNTAGGED, - heapObjectCallback, &fakeUserData))) { - nsk_jvmti_setFailStatus(); - return; - } - } - - NSK_DISPLAY0(">>> Disable OBJECT_FREE event and check if untagged objects were iterated:\n"); - { - jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; - if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) - return; - - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, - objectDescList, testedClass))) - return; - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -JNIEXPORT void JNICALL -callbackObjectFree(jvmtiEnv* jvmti, jlong tag) { - int i; - - if (info & INFO_HEAPOBJ) { - NSK_DISPLAY1(" : tag=%-5ld\n", tag); - } - - if (tag > 0) { - for (i = 0; i < objectsCount; i++) { - if (tag == objectDescList[i].tag) { - objectDescList[i].collected++; - break; - } - } - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_iterinstcls003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_iterinstcls003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_iterinstcls003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - { - const char* infoOpt = nsk_jvmti_findOptionValue("info"); - if (infoOpt != NULL) { - if (strcmp(infoOpt, "none") == 0) - info = INFO_NONE; - else if (strcmp(infoOpt, "all") == 0) - info = INFO_ALL; - else if (strcmp(infoOpt, "objref") == 0) - info = INFO_OBJREF; - else if (strcmp(infoOpt, "stackref") == 0) - info = INFO_STACKREF; - else if (strcmp(infoOpt, "heaproot") == 0) - info = INFO_HEAPROOT; - else if (strcmp(infoOpt, "heapobj") == 0) - info = INFO_HEAPOBJ; - else { - NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); - return JNI_ERR; - } - } - } - - chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); - if (!NSK_VERIFY(chainLength > 0)) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - caps.can_generate_object_free_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ObjectFree = callbackObjectFree; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/iterinstcls003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/iterinstcls003.cpp new file mode 100644 index 00000000000..02a9779d2a4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/iterinstcls003.cpp @@ -0,0 +1,600 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jlong timeout = 0; + +#define INFO_NONE 0x00 +#define INFO_ALL 0xFF +#define INFO_OBJREF 0x01 +#define INFO_STACKREF 0x02 +#define INFO_HEAPROOT 0x04 +#define INFO_HEAPOBJ 0x08 +#define INFO_HEAPOBJ 0x08 + +static unsigned int info = INFO_NONE; + +#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003" +#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003RootTestedClass" +#define ROOT_OBJECT_CLASS_SIG "L" ROOT_OBJECT_CLASS_NAME ";" +#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003TestedClass" +#define CHAIN_OBJECT_CLASS_SIG "L" CHAIN_OBJECT_CLASS_NAME ";" + +#define OBJECT_FIELD_NAME "object" +#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" +#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" +#define TAIL_FIELD_NAME "tail" + +#define DEFAULT_CHAIN_LENGTH 4 + +typedef struct ObjectDescStruct { + jlong tag; + jint found; + int collected; +} ObjectDesc; + +static int chainLength = 0; +static int objectsCount = 0; + +static ObjectDesc* objectDescList = NULL; + +static volatile int foundUntagged = 0; + +static int fakeUserData = 0; +static int userDataError = 0; + +/* ============================================================================= */ + +/** Obtain chain of tested objects and tag them recursively. */ +static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, + jfieldID firstField, const char firstFieldName[], + jfieldID nextField, const char nextFieldName[], + int count, ObjectDesc objectDescList[], + jlong tag, int reachable) { + + int success = NSK_TRUE; + jobject obj = NULL; + jlong objTag = (!reachable ? -tag : (tag % 2 != 0) ? tag : (jlong)0); + + if (count <= 0) + return NSK_TRUE; + + count--; + tag++; + + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + objectDescList[count].tag = objTag; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); + + if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, + nextField, nextFieldName, + count, objectDescList, tag, reachable)) { + return NSK_FALSE; + } + + NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); + return success; +} + +/** Obtain all tested objects from debugee class and tag them recursively. */ +static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + int *objectsCount, ObjectDesc* *objectDescList, + jclass *testedClass) { + jclass debugeeClass = NULL; + jclass rootObjectClass = NULL; + jclass chainObjectClass = NULL; + + jfieldID objectField = NULL; + jfieldID reachableChainField = NULL; + jfieldID unreachableChainField = NULL; + jfieldID tailField = NULL; + + jobject rootObject = NULL; + + jlong testedClassTag = 1; + jlong chainObjectTag = 100; + + *objectsCount = 2 * chainLength; + + NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), + (unsigned char**)objectDescList))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); + + { + int k; + for (k = 0; k < *objectsCount; k++) { + (*objectDescList)[k].tag = 0; + (*objectDescList)[k].found = 0; + (*objectDescList)[k].collected = 0; + } + } + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObjectClass = + NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); + + NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (chainObjectClass = + NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); + + NSK_DISPLAY1("Create global ref to tested class: 0x%p\n", chainObjectClass); + if (!NSK_JNI_VERIFY(jni, (*testedClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, chainObjectClass)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... global ref: 0x%p\n", (void*)*testedClass); + + NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (reachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (unreachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); + + NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (tailField = + NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, + TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); + + NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); + + NSK_DISPLAY0("Obtain and tag chain objects:\n"); + + NSK_DISPLAY0(" tested class object:\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, *testedClass, testedClassTag))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)testedClassTag, (void*)*testedClass); + + NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + reachableChainField, REACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList, + chainObjectTag, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList + chainLength, + chainObjectTag, NSK_FALSE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/** Check if tagged objects were iterated. */ +static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, + int chainLength, ObjectDesc objectDescList[]) { + int success = NSK_TRUE; + int expectedUntagged = 0; + int i; + + NSK_DISPLAY0("Following tagged/untagged objects were iterated:\n"); + + NSK_DISPLAY0(" reachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY2(" tag=%-5ld iterated=%d times\n", + (long)objectDescList[i].tag, objectDescList[i].found); + + if (objectDescList[i].found > 0 + && objectDescList[i].tag != 0) { + NSK_COMPLAIN2("Reachable tagged object was iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i].tag, + objectDescList[i].found); + nsk_jvmti_setFailStatus(); + } + + if (objectDescList[i].tag == 0) { + expectedUntagged++; + } + } + + NSK_DISPLAY0(" unreachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY3(" tag=%-5ld iterated=%-3d collected=%d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found, + objectDescList[i + chainLength].collected); + + if (objectDescList[i + chainLength].found <= 0 + && objectDescList[i + chainLength].collected > 0) { + NSK_COMPLAIN2("Not collected unreachable tagged object was iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found); + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(" untagged objects:\n"); + NSK_DISPLAY2(" total=%-3d iterated=%d objects\n", + expectedUntagged, foundUntagged); + if (foundUntagged > expectedUntagged) { + NSK_COMPLAIN2("Unexpected number of untagged objects were iterated:\n" + "# iterated untagged objects: %d\n" + "# expected: %d\n", + foundUntagged, expectedUntagged); + nsk_jvmti_setFailStatus(); + } + + return NSK_TRUE; +} + +/** Release references to the tested objects and free allocated memory. */ +static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + ObjectDesc* objectDescList, jclass testedClass) { + if (testedClass != NULL) { + NSK_DISPLAY1("Release object reference to tested class: 0x%p\n", testedClass); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); + } + + if (objectDescList != NULL) { + NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { + nsk_jvmti_setFailStatus(); + } + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** heapRootCallback for heap iterator. */ +jvmtiIterationControl JNICALL +heapObjectCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { + + if (info & INFO_HEAPOBJ) { + NSK_DISPLAY3(" heapObjectCallback: class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", + (long)class_tag, (long)size, + (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); + } + + if (class_tag != 1) { + NSK_COMPLAIN3("Unexpected class_tag passed to heapObjectCallback:\n" + "# object tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr == NULL) { + NSK_COMPLAIN3("NULL tag_ptr is passed to heapObjectCallback:\n" + "# tag_ptr: 0x%p\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (void*)tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } else { + if (*tag_ptr == 0) { + foundUntagged++; + } else { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + break; + } + } + + if (found <= 0) { + NSK_COMPLAIN3("Unknown tagged object passed to heapObjectCallback:\n" + "# tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } else { + NSK_COMPLAIN3("Known tagged object passed to heapObjectCallback:\n" + "# tag: %ld\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed to heapObjectCallback:\n" + "# expected: 0x%p\n" + "# actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for tested objects created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + { + jclass testedClass = NULL; + + NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); + { + if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, + &objectsCount, &objectDescList, &testedClass))) + return; + } + + NSK_DISPLAY0(">>> Enable OBJECT_FREE event and let debugee to clean links to unreachable objects\n"); + { + jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_ENABLE, 1, &event, NULL))) + return; + + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + } + + NSK_DISPLAY0(">>> Iterate over instances of tested class with filter JVMTI_HEAP_OBJECT_UNTAGGED\n"); + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + testedClass, JVMTI_HEAP_OBJECT_UNTAGGED, + heapObjectCallback, &fakeUserData))) { + nsk_jvmti_setFailStatus(); + return; + } + } + + NSK_DISPLAY0(">>> Disable OBJECT_FREE event and check if untagged objects were iterated:\n"); + { + jvmtiEvent event = JVMTI_EVENT_OBJECT_FREE; + if (!NSK_VERIFY(nsk_jvmti_enableEvents(JVMTI_DISABLE, 1, &event, NULL))) + return; + + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, + objectDescList, testedClass))) + return; + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +JNIEXPORT void JNICALL +callbackObjectFree(jvmtiEnv* jvmti, jlong tag) { + int i; + + if (info & INFO_HEAPOBJ) { + NSK_DISPLAY1(" : tag=%-5ld\n", tag); + } + + if (tag > 0) { + for (i = 0; i < objectsCount; i++) { + if (tag == objectDescList[i].tag) { + objectDescList[i].collected++; + break; + } + } + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_iterinstcls003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_iterinstcls003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_iterinstcls003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + { + const char* infoOpt = nsk_jvmti_findOptionValue("info"); + if (infoOpt != NULL) { + if (strcmp(infoOpt, "none") == 0) + info = INFO_NONE; + else if (strcmp(infoOpt, "all") == 0) + info = INFO_ALL; + else if (strcmp(infoOpt, "objref") == 0) + info = INFO_OBJREF; + else if (strcmp(infoOpt, "stackref") == 0) + info = INFO_STACKREF; + else if (strcmp(infoOpt, "heaproot") == 0) + info = INFO_HEAPROOT; + else if (strcmp(infoOpt, "heapobj") == 0) + info = INFO_HEAPOBJ; + else { + NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); + return JNI_ERR; + } + } + } + + chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); + if (!NSK_VERIFY(chainLength > 0)) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + caps.can_generate_object_free_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ObjectFree = callbackObjectFree; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/libiterinstcls003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/libiterinstcls003.c deleted file mode 100644 index 6d190ab8ed7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/libiterinstcls003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterinstcls003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/libiterinstcls003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/libiterinstcls003.cpp new file mode 100644 index 00000000000..79b4224dbf8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls003/libiterinstcls003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterinstcls003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/iterinstcls004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/iterinstcls004.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/iterinstcls004.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/iterinstcls004.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/libiterinstcls004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/libiterinstcls004.c deleted file mode 100644 index acf795e3171..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/libiterinstcls004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterinstcls004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/libiterinstcls004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/libiterinstcls004.cpp new file mode 100644 index 00000000000..c55b0204968 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls004/libiterinstcls004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterinstcls004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/iterinstcls005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/iterinstcls005.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/iterinstcls005.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/iterinstcls005.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/libiterinstcls005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/libiterinstcls005.c deleted file mode 100644 index 419982bf758..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/libiterinstcls005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterinstcls005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/libiterinstcls005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/libiterinstcls005.cpp new file mode 100644 index 00000000000..9d20603bfd8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls005/libiterinstcls005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterinstcls005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/iterinstcls006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/iterinstcls006.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/iterinstcls006.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/iterinstcls006.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/libiterinstcls006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/libiterinstcls006.c deleted file mode 100644 index d23ca2b7933..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/libiterinstcls006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterinstcls006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/libiterinstcls006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/libiterinstcls006.cpp new file mode 100644 index 00000000000..b0fb3bdeefc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls006/libiterinstcls006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterinstcls006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/iterinstcls007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/iterinstcls007.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/iterinstcls007.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/iterinstcls007.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/libiterinstcls007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/libiterinstcls007.c deleted file mode 100644 index cd62c140292..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/libiterinstcls007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterinstcls007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/libiterinstcls007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/libiterinstcls007.cpp new file mode 100644 index 00000000000..a3cd2377ce7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverInstancesOfClass/iterinstcls007/libiterinstcls007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterinstcls007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/iterobjreachobj001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/iterobjreachobj001.c deleted file mode 100644 index b113b3f2dbb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/iterobjreachobj001.c +++ /dev/null @@ -1,550 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -static jlong timeout = 0; - -#define INFO_NONE 0x00 -#define INFO_ALL 0xFF -#define INFO_OBJREF 0x01 -#define INFO_STACKREF 0x02 -#define INFO_HEAPROOT 0x04 -#define INFO_HEAPOBJ 0x08 - -static unsigned int info = INFO_NONE; - -#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001" -#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001RootTestedClass" -#define ROOT_OBJECT_CLASS_SIG "L"ROOT_OBJECT_CLASS_NAME";" -#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001TestedClass" -#define CHAIN_OBJECT_CLASS_SIG "L"CHAIN_OBJECT_CLASS_NAME";" - -#define OBJECT_FIELD_NAME "object" -#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" -#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" -#define TAIL_FIELD_NAME "tail" - -#define DEFAULT_CHAIN_LENGTH 4 - -typedef struct ObjectDescStruct { - jlong tag; - jint found; -} ObjectDesc; - -static int chainLength = 0; -static int objectsCount = 0; - -static ObjectDesc* objectDescList = NULL; - -static int fakeUserData = 0; -static int userDataError = 0; - -/* ============================================================================= */ - -/** Obtain chain of tested objects and tag them recursively. */ -static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, - jfieldID firstField, const char firstFieldName[], - jfieldID nextField, const char nextFieldName[], - int count, ObjectDesc objectDescList[], - jlong tag, int reachable) { - jobject obj = NULL; - jlong objTag = (reachable ? tag : -tag); - - if (count <= 0) - return NSK_TRUE; - - count--; - tag++; - - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - objectDescList[count].tag = objTag; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); - - if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, - nextField, nextFieldName, - count, objectDescList, tag, reachable)) { - return NSK_FALSE; - } - - NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); - return NSK_TRUE; -} - -/** Obtain all tested objects from debugee class and tag them recursively. */ -static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - int *objectsCount, ObjectDesc* *objectDescList, - jobject* rootObject) { - jclass debugeeClass = NULL; - jclass rootObjectClass = NULL; - jclass chainObjectClass = NULL; - - jfieldID objectField = NULL; - jfieldID reachableChainField = NULL; - jfieldID unreachableChainField = NULL; - jfieldID tailField = NULL; - - jlong rootObjectTag = 1; - jlong chainObjectTag = 100; - - *objectsCount = 1 + 2 * chainLength; - - NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), - (unsigned char**)objectDescList))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); - - { - int k; - for (k = 0; k < *objectsCount; k++) { - (*objectDescList)[k].tag = 0; - (*objectDescList)[k].found = 0; - } - } - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObjectClass = - NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); - - NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (chainObjectClass = - NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); - - NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (reachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (unreachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); - - NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (tailField = - NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, - TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); - - NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (*rootObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)*rootObject); - - if (!NSK_JNI_VERIFY(jni, (*rootObject = - NSK_CPP_STUB2(NewGlobalRef, jni, *rootObject)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... global ref: 0x%p\n", (void*)*rootObject); - - NSK_DISPLAY0("Obtain and tag chain objects:\n"); - - NSK_DISPLAY0(" root tested object:\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, *rootObject, rootObjectTag))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)rootObjectTag, (void*)*rootObject); - - (*objectDescList)[0].tag = rootObjectTag; - - NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, *rootObject, - reachableChainField, REACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, (*objectDescList) + 1, - chainObjectTag, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, *rootObject, - unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, (*objectDescList) + 1 + chainLength, - chainObjectTag, NSK_FALSE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/** Check if tagged objects were iterated. */ -static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, - int chainLength, ObjectDesc objectDescList[]) { - int success = NSK_TRUE; - int i; - - NSK_DISPLAY0("Following tagged objects were iterated:\n"); - - NSK_DISPLAY0(" root tested object:\n"); - NSK_DISPLAY2(" tag=%-5ld found=%d times\n", - (long)objectDescList[0].tag, objectDescList[0].found); - - NSK_DISPLAY0(" reachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY2(" tag=%-5ld found=%d times\n", - (long)objectDescList[i + 1].tag, objectDescList[i + 1].found); - - if (objectDescList[i + 1].found <= 0) { - NSK_COMPLAIN2("Reachable object was not iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i + 1].tag, - objectDescList[i + 1].found); - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(" unreachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY2(" tag=%-5ld found=%d times\n", - (long)objectDescList[i + 1 + chainLength].tag, - objectDescList[i + 1 + chainLength].found); - - if (objectDescList[i + 1 + chainLength].found > 0) { - NSK_COMPLAIN2("Unreachable object was iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i + 1 + chainLength].tag, - objectDescList[i + 1 + chainLength].found); - nsk_jvmti_setFailStatus(); - } - } - - return NSK_TRUE; -} - -/** Release references to the tested objects and free allocated memory. */ -static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - ObjectDesc* objectDescList, jobject rootObject) { - if (rootObject != NULL) { - NSK_DISPLAY1("Release object reference to root tested object: 0x%p\n", rootObject); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, rootObject)); - } - - if (objectDescList != NULL) { - NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { - nsk_jvmti_setFailStatus(); - } - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** objectReferenceCallback for heap iterator. */ -jvmtiIterationControl JNICALL -objectReferenceCallback(jvmtiObjectReferenceKind reference_kind, - jlong class_tag, jlong size, jlong* tag_ptr, - jlong refferrer_tag, jint refferrer_index, - void* user_data) { - - if (info & INFO_OBJREF) { - NSK_DISPLAY6(" objectReferenceCallback: ref_kind=%1d class_tag=%-3ld size=%-3ld" - " *tag_ptr=%-5ld ref_tag=%-5ld ref_idx=%d\n", - (int)reference_kind, (long)class_tag, (long)size, - (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr), - (long)refferrer_tag, (int)refferrer_index); - } - - if (tag_ptr == NULL) { - NSK_COMPLAIN6("NULL tag_ptr is passed to objectReferenceCallback:\n" - "# tag_ptr: 0x%p\n" - "# reference_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n" - "# refferrer_tag: %ld\n" - "# refferrer_idx: %d\n", - (void*)tag_ptr, - (int)reference_kind, - (long)class_tag, - (long)size, - (long)refferrer_tag, - (int)refferrer_index); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr != NULL && *tag_ptr != 0) { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - - if (*tag_ptr < 0) { - NSK_COMPLAIN6("Unreachable tagged object is passed to objectReferenceCallback:\n" - "# tag: %ld\n" - "# reference_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n" - "# refferrer_tag: %ld\n" - "# refferrer_idx: %d\n", - (long)*tag_ptr, - (int)reference_kind, - (long)class_tag, - (long)size, - (long)refferrer_tag, - (int)refferrer_index); - nsk_jvmti_setFailStatus(); - } - break; - } - } - - if (found <= 0) { - NSK_COMPLAIN6("Unknown tagged object is passed to objectReferenceCallback:\n" - "# tag: %ld\n" - "# reference_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n" - "# refferrer_tag: %ld\n" - "# refferrer_idx: %d\n", - (long)*tag_ptr, - (int)reference_kind, - (long)class_tag, - (long)size, - (long)refferrer_tag, - (int)refferrer_index); - nsk_jvmti_setFailStatus(); - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed to objectReferenceCallback:\n" - "# expected: 0x%p\n" - "# actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - if (reference_kind == JVMTI_REFERENCE_CLASS) - return JVMTI_ITERATION_IGNORE; - - return JVMTI_ITERATION_CONTINUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for tested objects created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - { - jobject rootObject = NULL; - - NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); - { - if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, - &objectsCount, &objectDescList, &rootObject))) - return; - } - - NSK_DISPLAY0(">>> Let debugee to clean links to unreachable objects\n"); - { - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - } - - NSK_DISPLAY0(">>> Start iteration for root tested object\n"); - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverObjectsReachableFromObject, jvmti, - rootObject, objectReferenceCallback, &fakeUserData))) { - nsk_jvmti_setFailStatus(); - return; - } - } - - NSK_DISPLAY0(">>> Check if reachable objects were iterated:\n"); - { - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, - objectDescList, rootObject))) - return; - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_iterobjreachobj001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_iterobjreachobj001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_iterobjreachobj001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - { - const char* infoOpt = nsk_jvmti_findOptionValue("info"); - if (infoOpt != NULL) { - if (strcmp(infoOpt, "none") == 0) - info = INFO_NONE; - else if (strcmp(infoOpt, "all") == 0) - info = INFO_ALL; - else if (strcmp(infoOpt, "objref") == 0) - info = INFO_OBJREF; - else if (strcmp(infoOpt, "stackref") == 0) - info = INFO_STACKREF; - else if (strcmp(infoOpt, "heaproot") == 0) - info = INFO_HEAPROOT; - else if (strcmp(infoOpt, "heapobj") == 0) - info = INFO_HEAPOBJ; - else { - NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); - return JNI_ERR; - } - } - } - - chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); - if (!NSK_VERIFY(chainLength > 0)) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/iterobjreachobj001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/iterobjreachobj001.cpp new file mode 100644 index 00000000000..4e962e02b93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/iterobjreachobj001.cpp @@ -0,0 +1,550 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jlong timeout = 0; + +#define INFO_NONE 0x00 +#define INFO_ALL 0xFF +#define INFO_OBJREF 0x01 +#define INFO_STACKREF 0x02 +#define INFO_HEAPROOT 0x04 +#define INFO_HEAPOBJ 0x08 + +static unsigned int info = INFO_NONE; + +#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001" +#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001RootTestedClass" +#define ROOT_OBJECT_CLASS_SIG "L" ROOT_OBJECT_CLASS_NAME ";" +#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001TestedClass" +#define CHAIN_OBJECT_CLASS_SIG "L" CHAIN_OBJECT_CLASS_NAME ";" + +#define OBJECT_FIELD_NAME "object" +#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" +#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" +#define TAIL_FIELD_NAME "tail" + +#define DEFAULT_CHAIN_LENGTH 4 + +typedef struct ObjectDescStruct { + jlong tag; + jint found; +} ObjectDesc; + +static int chainLength = 0; +static int objectsCount = 0; + +static ObjectDesc* objectDescList = NULL; + +static int fakeUserData = 0; +static int userDataError = 0; + +/* ============================================================================= */ + +/** Obtain chain of tested objects and tag them recursively. */ +static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, + jfieldID firstField, const char firstFieldName[], + jfieldID nextField, const char nextFieldName[], + int count, ObjectDesc objectDescList[], + jlong tag, int reachable) { + jobject obj = NULL; + jlong objTag = (reachable ? tag : -tag); + + if (count <= 0) + return NSK_TRUE; + + count--; + tag++; + + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + objectDescList[count].tag = objTag; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); + + if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, + nextField, nextFieldName, + count, objectDescList, tag, reachable)) { + return NSK_FALSE; + } + + NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); + return NSK_TRUE; +} + +/** Obtain all tested objects from debugee class and tag them recursively. */ +static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + int *objectsCount, ObjectDesc* *objectDescList, + jobject* rootObject) { + jclass debugeeClass = NULL; + jclass rootObjectClass = NULL; + jclass chainObjectClass = NULL; + + jfieldID objectField = NULL; + jfieldID reachableChainField = NULL; + jfieldID unreachableChainField = NULL; + jfieldID tailField = NULL; + + jlong rootObjectTag = 1; + jlong chainObjectTag = 100; + + *objectsCount = 1 + 2 * chainLength; + + NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), + (unsigned char**)objectDescList))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); + + { + int k; + for (k = 0; k < *objectsCount; k++) { + (*objectDescList)[k].tag = 0; + (*objectDescList)[k].found = 0; + } + } + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObjectClass = + NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); + + NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (chainObjectClass = + NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); + + NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (reachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (unreachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); + + NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (tailField = + NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, + TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); + + NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (*rootObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)*rootObject); + + if (!NSK_JNI_VERIFY(jni, (*rootObject = + NSK_CPP_STUB2(NewGlobalRef, jni, *rootObject)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... global ref: 0x%p\n", (void*)*rootObject); + + NSK_DISPLAY0("Obtain and tag chain objects:\n"); + + NSK_DISPLAY0(" root tested object:\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, *rootObject, rootObjectTag))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)rootObjectTag, (void*)*rootObject); + + (*objectDescList)[0].tag = rootObjectTag; + + NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, *rootObject, + reachableChainField, REACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, (*objectDescList) + 1, + chainObjectTag, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, *rootObject, + unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, (*objectDescList) + 1 + chainLength, + chainObjectTag, NSK_FALSE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/** Check if tagged objects were iterated. */ +static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, + int chainLength, ObjectDesc objectDescList[]) { + int success = NSK_TRUE; + int i; + + NSK_DISPLAY0("Following tagged objects were iterated:\n"); + + NSK_DISPLAY0(" root tested object:\n"); + NSK_DISPLAY2(" tag=%-5ld found=%d times\n", + (long)objectDescList[0].tag, objectDescList[0].found); + + NSK_DISPLAY0(" reachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY2(" tag=%-5ld found=%d times\n", + (long)objectDescList[i + 1].tag, objectDescList[i + 1].found); + + if (objectDescList[i + 1].found <= 0) { + NSK_COMPLAIN2("Reachable object was not iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i + 1].tag, + objectDescList[i + 1].found); + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(" unreachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY2(" tag=%-5ld found=%d times\n", + (long)objectDescList[i + 1 + chainLength].tag, + objectDescList[i + 1 + chainLength].found); + + if (objectDescList[i + 1 + chainLength].found > 0) { + NSK_COMPLAIN2("Unreachable object was iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i + 1 + chainLength].tag, + objectDescList[i + 1 + chainLength].found); + nsk_jvmti_setFailStatus(); + } + } + + return NSK_TRUE; +} + +/** Release references to the tested objects and free allocated memory. */ +static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + ObjectDesc* objectDescList, jobject rootObject) { + if (rootObject != NULL) { + NSK_DISPLAY1("Release object reference to root tested object: 0x%p\n", rootObject); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, rootObject)); + } + + if (objectDescList != NULL) { + NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { + nsk_jvmti_setFailStatus(); + } + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** objectReferenceCallback for heap iterator. */ +jvmtiIterationControl JNICALL +objectReferenceCallback(jvmtiObjectReferenceKind reference_kind, + jlong class_tag, jlong size, jlong* tag_ptr, + jlong refferrer_tag, jint refferrer_index, + void* user_data) { + + if (info & INFO_OBJREF) { + NSK_DISPLAY6(" objectReferenceCallback: ref_kind=%1d class_tag=%-3ld size=%-3ld" + " *tag_ptr=%-5ld ref_tag=%-5ld ref_idx=%d\n", + (int)reference_kind, (long)class_tag, (long)size, + (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr), + (long)refferrer_tag, (int)refferrer_index); + } + + if (tag_ptr == NULL) { + NSK_COMPLAIN6("NULL tag_ptr is passed to objectReferenceCallback:\n" + "# tag_ptr: 0x%p\n" + "# reference_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n" + "# refferrer_tag: %ld\n" + "# refferrer_idx: %d\n", + (void*)tag_ptr, + (int)reference_kind, + (long)class_tag, + (long)size, + (long)refferrer_tag, + (int)refferrer_index); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr != NULL && *tag_ptr != 0) { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + + if (*tag_ptr < 0) { + NSK_COMPLAIN6("Unreachable tagged object is passed to objectReferenceCallback:\n" + "# tag: %ld\n" + "# reference_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n" + "# refferrer_tag: %ld\n" + "# refferrer_idx: %d\n", + (long)*tag_ptr, + (int)reference_kind, + (long)class_tag, + (long)size, + (long)refferrer_tag, + (int)refferrer_index); + nsk_jvmti_setFailStatus(); + } + break; + } + } + + if (found <= 0) { + NSK_COMPLAIN6("Unknown tagged object is passed to objectReferenceCallback:\n" + "# tag: %ld\n" + "# reference_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n" + "# refferrer_tag: %ld\n" + "# refferrer_idx: %d\n", + (long)*tag_ptr, + (int)reference_kind, + (long)class_tag, + (long)size, + (long)refferrer_tag, + (int)refferrer_index); + nsk_jvmti_setFailStatus(); + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed to objectReferenceCallback:\n" + "# expected: 0x%p\n" + "# actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + if (reference_kind == JVMTI_REFERENCE_CLASS) + return JVMTI_ITERATION_IGNORE; + + return JVMTI_ITERATION_CONTINUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for tested objects created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + { + jobject rootObject = NULL; + + NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); + { + if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, + &objectsCount, &objectDescList, &rootObject))) + return; + } + + NSK_DISPLAY0(">>> Let debugee to clean links to unreachable objects\n"); + { + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + } + + NSK_DISPLAY0(">>> Start iteration for root tested object\n"); + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverObjectsReachableFromObject, jvmti, + rootObject, objectReferenceCallback, &fakeUserData))) { + nsk_jvmti_setFailStatus(); + return; + } + } + + NSK_DISPLAY0(">>> Check if reachable objects were iterated:\n"); + { + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, + objectDescList, rootObject))) + return; + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_iterobjreachobj001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_iterobjreachobj001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_iterobjreachobj001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + { + const char* infoOpt = nsk_jvmti_findOptionValue("info"); + if (infoOpt != NULL) { + if (strcmp(infoOpt, "none") == 0) + info = INFO_NONE; + else if (strcmp(infoOpt, "all") == 0) + info = INFO_ALL; + else if (strcmp(infoOpt, "objref") == 0) + info = INFO_OBJREF; + else if (strcmp(infoOpt, "stackref") == 0) + info = INFO_STACKREF; + else if (strcmp(infoOpt, "heaproot") == 0) + info = INFO_HEAPROOT; + else if (strcmp(infoOpt, "heapobj") == 0) + info = INFO_HEAPOBJ; + else { + NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); + return JNI_ERR; + } + } + } + + chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); + if (!NSK_VERIFY(chainLength > 0)) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/libiterobjreachobj001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/libiterobjreachobj001.c deleted file mode 100644 index 6b2021504c4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/libiterobjreachobj001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterobjreachobj001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/libiterobjreachobj001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/libiterobjreachobj001.cpp new file mode 100644 index 00000000000..55d55b613ec --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj001/libiterobjreachobj001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterobjreachobj001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/iterobjreachobj002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/iterobjreachobj002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/iterobjreachobj002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/iterobjreachobj002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/libiterobjreachobj002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/libiterobjreachobj002.c deleted file mode 100644 index a8d032bb2b5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/libiterobjreachobj002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterobjreachobj002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/libiterobjreachobj002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/libiterobjreachobj002.cpp new file mode 100644 index 00000000000..761364d8f6c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj002/libiterobjreachobj002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterobjreachobj002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/iterobjreachobj003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/iterobjreachobj003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/iterobjreachobj003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/iterobjreachobj003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/libiterobjreachobj003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/libiterobjreachobj003.c deleted file mode 100644 index 3bb4da69f0d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/libiterobjreachobj003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterobjreachobj003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/libiterobjreachobj003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/libiterobjreachobj003.cpp new file mode 100644 index 00000000000..9784761821e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj003/libiterobjreachobj003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterobjreachobj003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/iterobjreachobj004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/iterobjreachobj004.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/iterobjreachobj004.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/iterobjreachobj004.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/libiterobjreachobj004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/libiterobjreachobj004.c deleted file mode 100644 index 201c124959c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/libiterobjreachobj004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterobjreachobj004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/libiterobjreachobj004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/libiterobjreachobj004.cpp new file mode 100644 index 00000000000..cb0d2d8154b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/libiterobjreachobj004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterobjreachobj004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/iterobjreachobj005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/iterobjreachobj005.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/iterobjreachobj005.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/iterobjreachobj005.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/libiterobjreachobj005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/libiterobjreachobj005.c deleted file mode 100644 index 2cb69f71ad7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/libiterobjreachobj005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterobjreachobj005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/libiterobjreachobj005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/libiterobjreachobj005.cpp new file mode 100644 index 00000000000..59e065d0d3a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj005/libiterobjreachobj005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterobjreachobj005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/iterreachobj001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/iterreachobj001.c deleted file mode 100644 index fe2e31ca969..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/iterreachobj001.c +++ /dev/null @@ -1,743 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -static jlong timeout = 0; - -#define INFO_NONE 0x00 -#define INFO_ALL 0xFF -#define INFO_OBJREF 0x01 -#define INFO_STACKREF 0x02 -#define INFO_HEAPROOT 0x04 -#define INFO_HEAPOBJ 0x08 - -static unsigned int info = INFO_NONE; - -#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverReachableObjects/iterreachobj001" -#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverReachableObjects/iterreachobj001RootTestedClass" -#define ROOT_OBJECT_CLASS_SIG "L"ROOT_OBJECT_CLASS_NAME";" -#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverReachableObjects/iterreachobj001TestedClass" -#define CHAIN_OBJECT_CLASS_SIG "L"CHAIN_OBJECT_CLASS_NAME";" - -#define OBJECT_FIELD_NAME "object" -#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" -#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" -#define TAIL_FIELD_NAME "tail" - -#define DEFAULT_CHAIN_LENGTH 4 - -typedef struct ObjectDescStruct { - jlong tag; - jint found; -} ObjectDesc; - -static int chainLength = 0; -static int objectsCount = 0; - -static ObjectDesc* objectDescList = NULL; - -static int fakeUserData = 0; -static int userDataError = 0; - -/* ============================================================================= */ - -/** Obtain chain of tested objects and tag them recursively. */ -static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, - jfieldID firstField, const char firstFieldName[], - jfieldID nextField, const char nextFieldName[], - int count, ObjectDesc objectDescList[], - jlong tag, int reachable) { - - int success = NSK_TRUE; - jobject obj = NULL; - jlong objTag = (reachable ? tag : -tag); - - if (count <= 0) - return NSK_TRUE; - - count--; - tag++; - - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - objectDescList[count].tag = objTag; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); - - if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, - nextField, nextFieldName, - count, objectDescList, tag, reachable)) { - return NSK_FALSE; - } - - NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); - return success; -} - -/** Obtain all tested objects from debugee class and tag them recursively. */ -static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - int *objectsCount, ObjectDesc* *objectDescList) { - jclass debugeeClass = NULL; - jclass rootObjectClass = NULL; - jclass chainObjectClass = NULL; - - jfieldID objectField = NULL; - jfieldID reachableChainField = NULL; - jfieldID unreachableChainField = NULL; - jfieldID tailField = NULL; - - jobject rootObject = NULL; - - jlong rootObjectTag = 1; - jlong chainObjectTag = 100; - - *objectsCount = 2 * chainLength; - - NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), - (unsigned char**)objectDescList))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); - - { - int k; - for (k = 0; k < *objectsCount; k++) { - (*objectDescList)[k].tag = 0; - (*objectDescList)[k].found = 0; - } - } - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObjectClass = - NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); - - NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (chainObjectClass = - NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); - - NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (reachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); - - NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (unreachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); - - NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (tailField = - NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, - TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); - - NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (rootObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); - - NSK_DISPLAY0("Obtain and tag chain objects:\n"); - - NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - reachableChainField, REACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList, - chainObjectTag, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, rootObject, - unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, *objectDescList + chainLength, - chainObjectTag, NSK_FALSE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/** Check if tagged objects were iterated. */ -static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, - int chainLength, ObjectDesc objectDescList[]) { - int success = NSK_TRUE; - int i; - - NSK_DISPLAY0("Following tagged objects were iterated:\n"); - - NSK_DISPLAY0(" reachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY2(" tag=%-5ld found=%d times\n", - (long)objectDescList[i].tag, objectDescList[i].found); - - if (objectDescList[i].found <= 0) { - NSK_COMPLAIN2("Reachable object was not iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i].tag, - objectDescList[i].found); - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(" unreachable objects:\n"); - for (i = 0; i < chainLength; i++) { - NSK_DISPLAY2(" tag=%-5ld found=%d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found); - - if (objectDescList[i + chainLength].found > 0) { - NSK_COMPLAIN2("Unreachable object was iterated:\n" - "# tag: %ld\n" - "# iterated: %d times\n", - (long)objectDescList[i + chainLength].tag, - objectDescList[i + chainLength].found); - nsk_jvmti_setFailStatus(); - } - } - - return NSK_TRUE; -} - -/** Release references to the tested objects and free allocated memory. */ -static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - ObjectDesc* objectDescList) { - if (objectDescList != NULL) { - NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { - nsk_jvmti_setFailStatus(); - } - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** heapRootCallback for heap iterator. */ -jvmtiIterationControl JNICALL -heapRootCallback(jvmtiHeapRootKind root_kind, - jlong class_tag, jlong size, jlong* tag_ptr, - void* user_data) { - - if (info & INFO_HEAPROOT) { - NSK_DISPLAY4(" heapRootCallback: root_kind=%2d class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", - (int)root_kind, (long)class_tag, (long)size, - (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); - } - - if (tag_ptr == NULL) { - NSK_COMPLAIN4("NULL tag_ptr is passed to heapRootCallback:\n" - "# tag_ptr: 0x%p\n" - "# root_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (void*)tag_ptr, - (int)root_kind, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr != NULL && *tag_ptr != 0) { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - - if (*tag_ptr < 0) { - NSK_COMPLAIN4("Unreachable tagged object passed to heapRootCallback:\n" - "# tag: %ld\n" - "# root_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (int)root_kind, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - - if (*tag_ptr > 0) { - NSK_COMPLAIN4("Not root reachable tagged object passed to heapRootCallback:\n" - "# tag: %ld\n" - "# root_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (int)root_kind, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - break; - } - } - - if (found <= 0) { - NSK_COMPLAIN4("Unknown tagged object passed to heapRootCallback:\n" - "# tag: %ld\n" - "# root_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n", - (long)*tag_ptr, - (int)root_kind, - (long)class_tag, - (long)size); - nsk_jvmti_setFailStatus(); - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed to heapRootCallback:\n" - "# expected: 0x%p\n" - "# actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - return JVMTI_ITERATION_CONTINUE; -} - -/** stackReferenceCallback for heap iterator. */ -jvmtiIterationControl JNICALL -stackReferenceCallback(jvmtiHeapRootKind root_kind, - jlong class_tag, jlong size, jlong* tag_ptr, - jlong thread_tag, jint depth, jmethodID method, - jint slot, void* user_data) { - - if (info & INFO_STACKREF) { - NSK_DISPLAY8(" stackReferenceCallback: root_kind=%1d class_tag=%-3ld size=%-3ld" - " *tag_ptr=%-5ld thread_tag=%-3ld depth=%3d method=0x%p slot=%d\n", - (int)root_kind, (long)class_tag, (long)size, - (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr), - (long)thread_tag, (int)depth, (void*)method, (int)slot); - } - - if (tag_ptr == NULL) { - NSK_COMPLAIN8("NULL tag_ptr is passed to stackReferenceCallback:\n" - "# tag_ptr: 0x%p\n" - "# root_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n" - "# thread_tag: %ld\n" - "# depth: %d\n" - "# method: 0x%p\n" - "# slot: %d\n", - (void*)tag_ptr, - (int)root_kind, - (long)class_tag, - (long)size, - (long)thread_tag, - (int)depth, - (void*)method, - (int)slot); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr != NULL && *tag_ptr != 0) { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - - if (*tag_ptr < 0) { - NSK_COMPLAIN8("Unreachable tagged object passed to stackReferenceCallback:\n" - "# tag: %ld\n" - "# root_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n" - "# thread_tag: %ld\n" - "# depth: %d\n" - "# method: 0x%p\n" - "# slot: %d\n", - (long)*tag_ptr, - (int)root_kind, - (long)class_tag, - (long)size, - (long)thread_tag, - (int)depth, - (void*)method, - (int)slot); - nsk_jvmti_setFailStatus(); - } - - if (*tag_ptr > 0) { - NSK_COMPLAIN8("Not stack reachable tagged object passed to stackReferenceCallback:\n" - "# tag: %ld\n" - "# root_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n" - "# thread_tag: %ld\n" - "# depth: %d\n" - "# method: 0x%p\n" - "# slot: %d\n", - (long)*tag_ptr, - (int)root_kind, - (long)class_tag, - (long)size, - (long)thread_tag, - (int)depth, - (void*)method, - (int)slot); - nsk_jvmti_setFailStatus(); - } - break; - } - } - - if (found <= 0) { - NSK_COMPLAIN8("Unknown tagged object passed to stackReferenceCallback:\n" - "# tag: %ld\n" - "# root_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n" - "# thread_tag: %ld\n" - "# depth: %d\n" - "# method: 0x%p\n" - "# slot: %d\n", - (long)*tag_ptr, - (int)root_kind, - (long)class_tag, - (long)size, - (long)thread_tag, - (int)depth, - (void*)method, - (int)slot); - nsk_jvmti_setFailStatus(); - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed to stackReferenceCallback:\n" - "# expected: 0x%p\n" - "# actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - return JVMTI_ITERATION_CONTINUE; -} - -/** objectReferenceCallback for heap iterator. */ -jvmtiIterationControl JNICALL -objectReferenceCallback(jvmtiObjectReferenceKind reference_kind, - jlong class_tag, jlong size, jlong* tag_ptr, - jlong refferrer_tag, jint refferrer_index, - void* user_data) { - - if (info & INFO_OBJREF) { - NSK_DISPLAY6(" objectReferenceCallback: ref_kind=%1d class_tag=%-3ld size=%-3ld" - " *tag_ptr=%-5ld ref_tag=%-5ld ref_idx=%d\n", - (int)reference_kind, (long)class_tag, (long)size, - (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr), - (long)refferrer_tag, (int)refferrer_index); - } - - if (tag_ptr == NULL) { - NSK_COMPLAIN6("NULL tag_ptr is passed to objectReferenceCallback:\n" - "# tag_ptr: 0x%p\n" - "# reference_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n" - "# refferrer_tag: %ld\n" - "# refferrer_idx: %d\n", - (void*)tag_ptr, - (int)reference_kind, - (long)class_tag, - (long)size, - (long)refferrer_tag, - (int)refferrer_index); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr != NULL && *tag_ptr != 0) { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - - if (*tag_ptr < 0) { - NSK_COMPLAIN6("Unreachable tagged object is passed to objectReferenceCallback:\n" - "# tag: %ld\n" - "# reference_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n" - "# refferrer_tag: %ld\n" - "# refferrer_idx: %d\n", - (long)*tag_ptr, - (int)reference_kind, - (long)class_tag, - (long)size, - (long)refferrer_tag, - (int)refferrer_index); - nsk_jvmti_setFailStatus(); - } - break; - } - } - - if (found <= 0) { - NSK_COMPLAIN6("Unknown tagged object is passed to ObjectReferenceCallback:\n" - "# tag: %ld\n" - "# reference_kind: %d\n" - "# class_tag: %ld\n" - "# size: %ld\n" - "# refferrer_tag: %ld\n" - "# refferrer_idx: %d\n", - (long)*tag_ptr, - (int)reference_kind, - (long)class_tag, - (long)size, - (long)refferrer_tag, - (int)refferrer_index); - nsk_jvmti_setFailStatus(); - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed to ObjectReferenceCallback:\n" - "# expected: 0x%p\n" - "# actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - if (reference_kind == JVMTI_REFERENCE_CLASS) - return JVMTI_ITERATION_IGNORE; - - return JVMTI_ITERATION_CONTINUE; -} - - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for tested objects created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - { - NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); - { - if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, &objectsCount, - &objectDescList))) - return; - } - - NSK_DISPLAY0(">>> Let debugee to clean links to unreachable objects\n"); - { - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - } - - NSK_DISPLAY0(">>> Start iteration over reachable objects\n"); - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverReachableObjects, jvmti, - heapRootCallback, stackReferenceCallback, - objectReferenceCallback, &fakeUserData))) { - nsk_jvmti_setFailStatus(); - return; - } - } - - NSK_DISPLAY0(">>> Check if reachable objects were iterated:\n"); - { - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, objectDescList))) - return; - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_iterreachobj001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_iterreachobj001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_iterreachobj001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - { - const char* infoOpt = nsk_jvmti_findOptionValue("info"); - if (infoOpt != NULL) { - if (strcmp(infoOpt, "none") == 0) - info = INFO_NONE; - else if (strcmp(infoOpt, "all") == 0) - info = INFO_ALL; - else if (strcmp(infoOpt, "objref") == 0) - info = INFO_OBJREF; - else if (strcmp(infoOpt, "stackref") == 0) - info = INFO_STACKREF; - else if (strcmp(infoOpt, "heaproot") == 0) - info = INFO_HEAPROOT; - else if (strcmp(infoOpt, "heapobj") == 0) - info = INFO_HEAPOBJ; - else { - NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); - return JNI_ERR; - } - } - } - - chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); - if (!NSK_VERIFY(chainLength > 0)) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/iterreachobj001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/iterreachobj001.cpp new file mode 100644 index 00000000000..c518e8d1fb0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/iterreachobj001.cpp @@ -0,0 +1,743 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jlong timeout = 0; + +#define INFO_NONE 0x00 +#define INFO_ALL 0xFF +#define INFO_OBJREF 0x01 +#define INFO_STACKREF 0x02 +#define INFO_HEAPROOT 0x04 +#define INFO_HEAPOBJ 0x08 + +static unsigned int info = INFO_NONE; + +#define DEBUGEE_CLASS_NAME "nsk/jvmti/IterateOverReachableObjects/iterreachobj001" +#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverReachableObjects/iterreachobj001RootTestedClass" +#define ROOT_OBJECT_CLASS_SIG "L" ROOT_OBJECT_CLASS_NAME ";" +#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/IterateOverReachableObjects/iterreachobj001TestedClass" +#define CHAIN_OBJECT_CLASS_SIG "L" CHAIN_OBJECT_CLASS_NAME ";" + +#define OBJECT_FIELD_NAME "object" +#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" +#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" +#define TAIL_FIELD_NAME "tail" + +#define DEFAULT_CHAIN_LENGTH 4 + +typedef struct ObjectDescStruct { + jlong tag; + jint found; +} ObjectDesc; + +static int chainLength = 0; +static int objectsCount = 0; + +static ObjectDesc* objectDescList = NULL; + +static int fakeUserData = 0; +static int userDataError = 0; + +/* ============================================================================= */ + +/** Obtain chain of tested objects and tag them recursively. */ +static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, + jfieldID firstField, const char firstFieldName[], + jfieldID nextField, const char nextFieldName[], + int count, ObjectDesc objectDescList[], + jlong tag, int reachable) { + + int success = NSK_TRUE; + jobject obj = NULL; + jlong objTag = (reachable ? tag : -tag); + + if (count <= 0) + return NSK_TRUE; + + count--; + tag++; + + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + objectDescList[count].tag = objTag; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY2(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); + + if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, + nextField, nextFieldName, + count, objectDescList, tag, reachable)) { + return NSK_FALSE; + } + + NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); + return success; +} + +/** Obtain all tested objects from debugee class and tag them recursively. */ +static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + int *objectsCount, ObjectDesc* *objectDescList) { + jclass debugeeClass = NULL; + jclass rootObjectClass = NULL; + jclass chainObjectClass = NULL; + + jfieldID objectField = NULL; + jfieldID reachableChainField = NULL; + jfieldID unreachableChainField = NULL; + jfieldID tailField = NULL; + + jobject rootObject = NULL; + + jlong rootObjectTag = 1; + jlong chainObjectTag = 100; + + *objectsCount = 2 * chainLength; + + NSK_DISPLAY1("Allocate memory for objects list: %d objects\n", *objectsCount); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), + (unsigned char**)objectDescList))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... allocated array: 0x%p\n", (void*)objectDescList); + + { + int k; + for (k = 0; k < *objectsCount; k++) { + (*objectDescList)[k].tag = 0; + (*objectDescList)[k].found = 0; + } + } + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObjectClass = + NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)rootObjectClass); + + NSK_DISPLAY1("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (chainObjectClass = + NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)chainObjectClass); + + NSK_DISPLAY1("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (reachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)reachableChainField); + + NSK_DISPLAY1("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (unreachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); + + NSK_DISPLAY1("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (tailField = + NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, + TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)tailField); + + NSK_DISPLAY1("Get root object from static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (rootObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)rootObject); + + NSK_DISPLAY0("Obtain and tag chain objects:\n"); + + NSK_DISPLAY1(" reachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + reachableChainField, REACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList, + chainObjectTag, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + NSK_DISPLAY1(" unreachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, rootObject, + unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, *objectDescList + chainLength, + chainObjectTag, NSK_FALSE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/** Check if tagged objects were iterated. */ +static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, + int chainLength, ObjectDesc objectDescList[]) { + int success = NSK_TRUE; + int i; + + NSK_DISPLAY0("Following tagged objects were iterated:\n"); + + NSK_DISPLAY0(" reachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY2(" tag=%-5ld found=%d times\n", + (long)objectDescList[i].tag, objectDescList[i].found); + + if (objectDescList[i].found <= 0) { + NSK_COMPLAIN2("Reachable object was not iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i].tag, + objectDescList[i].found); + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(" unreachable objects:\n"); + for (i = 0; i < chainLength; i++) { + NSK_DISPLAY2(" tag=%-5ld found=%d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found); + + if (objectDescList[i + chainLength].found > 0) { + NSK_COMPLAIN2("Unreachable object was iterated:\n" + "# tag: %ld\n" + "# iterated: %d times\n", + (long)objectDescList[i + chainLength].tag, + objectDescList[i + chainLength].found); + nsk_jvmti_setFailStatus(); + } + } + + return NSK_TRUE; +} + +/** Release references to the tested objects and free allocated memory. */ +static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + ObjectDesc* objectDescList) { + if (objectDescList != NULL) { + NSK_DISPLAY1("Deallocate objects list: 0x%p\n", (void*)objectDescList); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { + nsk_jvmti_setFailStatus(); + } + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** heapRootCallback for heap iterator. */ +jvmtiIterationControl JNICALL +heapRootCallback(jvmtiHeapRootKind root_kind, + jlong class_tag, jlong size, jlong* tag_ptr, + void* user_data) { + + if (info & INFO_HEAPROOT) { + NSK_DISPLAY4(" heapRootCallback: root_kind=%2d class_tag=%-3ld size=%-3ld *tag_ptr=%-5ld\n", + (int)root_kind, (long)class_tag, (long)size, + (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr)); + } + + if (tag_ptr == NULL) { + NSK_COMPLAIN4("NULL tag_ptr is passed to heapRootCallback:\n" + "# tag_ptr: 0x%p\n" + "# root_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (void*)tag_ptr, + (int)root_kind, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr != NULL && *tag_ptr != 0) { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + + if (*tag_ptr < 0) { + NSK_COMPLAIN4("Unreachable tagged object passed to heapRootCallback:\n" + "# tag: %ld\n" + "# root_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (int)root_kind, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + + if (*tag_ptr > 0) { + NSK_COMPLAIN4("Not root reachable tagged object passed to heapRootCallback:\n" + "# tag: %ld\n" + "# root_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (int)root_kind, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + break; + } + } + + if (found <= 0) { + NSK_COMPLAIN4("Unknown tagged object passed to heapRootCallback:\n" + "# tag: %ld\n" + "# root_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n", + (long)*tag_ptr, + (int)root_kind, + (long)class_tag, + (long)size); + nsk_jvmti_setFailStatus(); + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed to heapRootCallback:\n" + "# expected: 0x%p\n" + "# actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + return JVMTI_ITERATION_CONTINUE; +} + +/** stackReferenceCallback for heap iterator. */ +jvmtiIterationControl JNICALL +stackReferenceCallback(jvmtiHeapRootKind root_kind, + jlong class_tag, jlong size, jlong* tag_ptr, + jlong thread_tag, jint depth, jmethodID method, + jint slot, void* user_data) { + + if (info & INFO_STACKREF) { + NSK_DISPLAY8(" stackReferenceCallback: root_kind=%1d class_tag=%-3ld size=%-3ld" + " *tag_ptr=%-5ld thread_tag=%-3ld depth=%3d method=0x%p slot=%d\n", + (int)root_kind, (long)class_tag, (long)size, + (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr), + (long)thread_tag, (int)depth, (void*)method, (int)slot); + } + + if (tag_ptr == NULL) { + NSK_COMPLAIN8("NULL tag_ptr is passed to stackReferenceCallback:\n" + "# tag_ptr: 0x%p\n" + "# root_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n" + "# thread_tag: %ld\n" + "# depth: %d\n" + "# method: 0x%p\n" + "# slot: %d\n", + (void*)tag_ptr, + (int)root_kind, + (long)class_tag, + (long)size, + (long)thread_tag, + (int)depth, + (void*)method, + (int)slot); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr != NULL && *tag_ptr != 0) { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + + if (*tag_ptr < 0) { + NSK_COMPLAIN8("Unreachable tagged object passed to stackReferenceCallback:\n" + "# tag: %ld\n" + "# root_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n" + "# thread_tag: %ld\n" + "# depth: %d\n" + "# method: 0x%p\n" + "# slot: %d\n", + (long)*tag_ptr, + (int)root_kind, + (long)class_tag, + (long)size, + (long)thread_tag, + (int)depth, + (void*)method, + (int)slot); + nsk_jvmti_setFailStatus(); + } + + if (*tag_ptr > 0) { + NSK_COMPLAIN8("Not stack reachable tagged object passed to stackReferenceCallback:\n" + "# tag: %ld\n" + "# root_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n" + "# thread_tag: %ld\n" + "# depth: %d\n" + "# method: 0x%p\n" + "# slot: %d\n", + (long)*tag_ptr, + (int)root_kind, + (long)class_tag, + (long)size, + (long)thread_tag, + (int)depth, + (void*)method, + (int)slot); + nsk_jvmti_setFailStatus(); + } + break; + } + } + + if (found <= 0) { + NSK_COMPLAIN8("Unknown tagged object passed to stackReferenceCallback:\n" + "# tag: %ld\n" + "# root_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n" + "# thread_tag: %ld\n" + "# depth: %d\n" + "# method: 0x%p\n" + "# slot: %d\n", + (long)*tag_ptr, + (int)root_kind, + (long)class_tag, + (long)size, + (long)thread_tag, + (int)depth, + (void*)method, + (int)slot); + nsk_jvmti_setFailStatus(); + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed to stackReferenceCallback:\n" + "# expected: 0x%p\n" + "# actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + return JVMTI_ITERATION_CONTINUE; +} + +/** objectReferenceCallback for heap iterator. */ +jvmtiIterationControl JNICALL +objectReferenceCallback(jvmtiObjectReferenceKind reference_kind, + jlong class_tag, jlong size, jlong* tag_ptr, + jlong refferrer_tag, jint refferrer_index, + void* user_data) { + + if (info & INFO_OBJREF) { + NSK_DISPLAY6(" objectReferenceCallback: ref_kind=%1d class_tag=%-3ld size=%-3ld" + " *tag_ptr=%-5ld ref_tag=%-5ld ref_idx=%d\n", + (int)reference_kind, (long)class_tag, (long)size, + (long)(tag_ptr == NULL ? (jlong)0 : *tag_ptr), + (long)refferrer_tag, (int)refferrer_index); + } + + if (tag_ptr == NULL) { + NSK_COMPLAIN6("NULL tag_ptr is passed to objectReferenceCallback:\n" + "# tag_ptr: 0x%p\n" + "# reference_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n" + "# refferrer_tag: %ld\n" + "# refferrer_idx: %d\n", + (void*)tag_ptr, + (int)reference_kind, + (long)class_tag, + (long)size, + (long)refferrer_tag, + (int)refferrer_index); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr != NULL && *tag_ptr != 0) { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + + if (*tag_ptr < 0) { + NSK_COMPLAIN6("Unreachable tagged object is passed to objectReferenceCallback:\n" + "# tag: %ld\n" + "# reference_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n" + "# refferrer_tag: %ld\n" + "# refferrer_idx: %d\n", + (long)*tag_ptr, + (int)reference_kind, + (long)class_tag, + (long)size, + (long)refferrer_tag, + (int)refferrer_index); + nsk_jvmti_setFailStatus(); + } + break; + } + } + + if (found <= 0) { + NSK_COMPLAIN6("Unknown tagged object is passed to ObjectReferenceCallback:\n" + "# tag: %ld\n" + "# reference_kind: %d\n" + "# class_tag: %ld\n" + "# size: %ld\n" + "# refferrer_tag: %ld\n" + "# refferrer_idx: %d\n", + (long)*tag_ptr, + (int)reference_kind, + (long)class_tag, + (long)size, + (long)refferrer_tag, + (int)refferrer_index); + nsk_jvmti_setFailStatus(); + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed to ObjectReferenceCallback:\n" + "# expected: 0x%p\n" + "# actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + if (reference_kind == JVMTI_REFERENCE_CLASS) + return JVMTI_ITERATION_IGNORE; + + return JVMTI_ITERATION_CONTINUE; +} + + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for tested objects created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + { + NSK_DISPLAY0(">>> Obtain and tag tested objects from debugee class\n"); + { + if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, &objectsCount, + &objectDescList))) + return; + } + + NSK_DISPLAY0(">>> Let debugee to clean links to unreachable objects\n"); + { + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + } + + NSK_DISPLAY0(">>> Start iteration over reachable objects\n"); + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverReachableObjects, jvmti, + heapRootCallback, stackReferenceCallback, + objectReferenceCallback, &fakeUserData))) { + nsk_jvmti_setFailStatus(); + return; + } + } + + NSK_DISPLAY0(">>> Check if reachable objects were iterated:\n"); + { + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, objectDescList))) + return; + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_iterreachobj001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_iterreachobj001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_iterreachobj001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + { + const char* infoOpt = nsk_jvmti_findOptionValue("info"); + if (infoOpt != NULL) { + if (strcmp(infoOpt, "none") == 0) + info = INFO_NONE; + else if (strcmp(infoOpt, "all") == 0) + info = INFO_ALL; + else if (strcmp(infoOpt, "objref") == 0) + info = INFO_OBJREF; + else if (strcmp(infoOpt, "stackref") == 0) + info = INFO_STACKREF; + else if (strcmp(infoOpt, "heaproot") == 0) + info = INFO_HEAPROOT; + else if (strcmp(infoOpt, "heapobj") == 0) + info = INFO_HEAPOBJ; + else { + NSK_COMPLAIN1("Unknown option value: info=%s\n", infoOpt); + return JNI_ERR; + } + } + } + + chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); + if (!NSK_VERIFY(chainLength > 0)) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/libiterreachobj001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/libiterreachobj001.c deleted file mode 100644 index 168db5c6f36..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/libiterreachobj001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterreachobj001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/libiterreachobj001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/libiterreachobj001.cpp new file mode 100644 index 00000000000..37e9eaf9ce7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj001/libiterreachobj001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterreachobj001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/iterreachobj002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/iterreachobj002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/iterreachobj002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/iterreachobj002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/libiterreachobj002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/libiterreachobj002.c deleted file mode 100644 index 8d29a08f418..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/libiterreachobj002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterreachobj002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/libiterreachobj002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/libiterreachobj002.cpp new file mode 100644 index 00000000000..c2fa73e9703 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj002/libiterreachobj002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterreachobj002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/iterreachobj003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/iterreachobj003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/iterreachobj003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/iterreachobj003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/libiterreachobj003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/libiterreachobj003.c deleted file mode 100644 index b968fc6eb9f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/libiterreachobj003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterreachobj003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/libiterreachobj003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/libiterreachobj003.cpp new file mode 100644 index 00000000000..c11b8d6fc26 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj003/libiterreachobj003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterreachobj003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/iterreachobj004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/iterreachobj004.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/iterreachobj004.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/iterreachobj004.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/libiterreachobj004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/libiterreachobj004.c deleted file mode 100644 index 084ad0efd49..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/libiterreachobj004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterreachobj004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/libiterreachobj004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/libiterreachobj004.cpp new file mode 100644 index 00000000000..a9affe30805 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj004/libiterreachobj004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterreachobj004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/iterreachobj005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/iterreachobj005.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/iterreachobj005.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/iterreachobj005.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/libiterreachobj005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/libiterreachobj005.c deleted file mode 100644 index 0f3ff709158..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/libiterreachobj005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "iterreachobj005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/libiterreachobj005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/libiterreachobj005.cpp new file mode 100644 index 00000000000..f37c805f23d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverReachableObjects/iterreachobj005/libiterreachobj005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "iterreachobj005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/Abort.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/Abort.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/Abort.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/Abort.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/libAbort.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/libAbort.c deleted file mode 100644 index 20317af7d37..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/libAbort.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "Abort.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/libAbort.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/libAbort.cpp new file mode 100644 index 00000000000..8bdf3495194 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/abort/libAbort.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "Abort.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/callbacks/Callbacks.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/callbacks/Callbacks.c deleted file mode 100644 index 9de907b394a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/callbacks/Callbacks.c +++ /dev/null @@ -1,644 +0,0 @@ -/* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include - -#include "jvmti.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define STATIC_FIELD 0x0008 - -///amount of objects to be tagged -#define TEST_OBJECTS_COUNT 4 - -///expected amount of times object will bre ported by callbacks -#define PRIMITIVE_OCCURANCE_COUNT 1 -#define STRING_OCCURANCE_COUNT 2 -#define PRIMITIVE_ARRAY_OCCURANCE_COUNT 2 -#define NONPRIMITIVE_OCCURANCE_COUNT 1 - - -/** - tag format - - 63 35 32 16 0 - |1 |type|obj idx|field idx| - -*/ - -#define TAG_TYPE_PRIMITIVE 0 -#define TAG_TYPE_STRING 1 -#define TAG_TYPE_ARRAY 2 -#define TAG_TYPE_OBJECT 3 - -#define ENCODE_TAG(type,obj,fld) (0x8000000000000000ULL|(((jlong)type)<<32)|(((jlong)obj)<<16)|fld) - -#define DECODE_TYPE(tag) ((tag>>32)&0x0FFFF) -#define DECODE_OBJECT(tag) ((tag>>16)&0x0FFFF) -#define DECODE_FIELD(tag) (tag&0x0FFFF) - -///expected values -#define BOOLEAN JNI_FALSE -#define BYTE 0xB -#define CHAR 'z' -#define SHORT 0xB00 -#define INT ((int)0xDEADBEEF) -#define LONG 0xDEADBEEFDEADLL -#define FLOAT 3.1416f -#define DOUBLE 3.14159265 - -#define ARRAY_LENGTH 5 - -static wchar_t *STRING = L"I hope you'll find me in the heap!"; -static jboolean BOOLEAN_ARRAY[] = {JNI_TRUE, JNI_TRUE, JNI_FALSE, JNI_TRUE, JNI_FALSE}; -static jbyte BYTE_ARRAY[] = {BYTE, BYTE+1, BYTE+2, BYTE+3, BYTE+4}; -static jchar CHAR_ARRAY[] = {CHAR, CHAR+1, CHAR+2, CHAR+3, CHAR+4}; -static jshort SHORT_ARRAY[] = {SHORT, SHORT+1, SHORT+2, SHORT+3, SHORT+4}; -static jint INT_ARRAY[] = {INT, INT+1, INT+2, INT+3, INT+4}; -static jlong LONG_ARRAY[] = {LONG, LONG+1, LONG+2, LONG+3, LONG+4}; -static jfloat FLOAT_ARRAY[] = {FLOAT, FLOAT+1, FLOAT+2, FLOAT+3, FLOAT+4}; -static jdouble DOUBLE_ARRAY[] = {DOUBLE, DOUBLE+1, DOUBLE+2, DOUBLE+3, DOUBLE+4}; - -static long timeout = 0; - -///information about field -typedef struct { - char *name; - char *signature; - int found; - int collected; - int primitive; -} field_info_t; - -///information about object -typedef struct { - char *name; - int fields_count; - field_info_t *fields; - int collected; -} object_info_t; - -static object_info_t objects_info[TEST_OBJECTS_COUNT]; - -#define className "nsk/jvmti/IterateThroughHeap/callbacks/Callbacks" -#define fieldName "testObjects" -#define fieldSig "[Ljava/lang/Object;" - -// Check if the signature is signature of primitive type. -jboolean is_primitive_type(const char *signature) { - if(!strcmp(signature,"C") - || !strcmp(signature, "B") - || !strcmp(signature, "S") - || !strcmp(signature, "I") - || !strcmp(signature, "J") - || !strcmp(signature, "F") - || !strcmp(signature, "D") - || !strcmp(signature, "Z")) - return JNI_TRUE; - return JNI_FALSE; -} - -// For given signature find expected tag type -int get_tag_type(const char *signature) { - if(is_primitive_type(signature)) { - return TAG_TYPE_PRIMITIVE; - } else if(signature[0]=='[' && is_primitive_type(signature+1)) { - return TAG_TYPE_ARRAY; - } else if(!strcmp(signature, "Ljava/lang/String;")) { - return TAG_TYPE_STRING; - } else { - return TAG_TYPE_OBJECT; - } -} - -/** - * Check value corectness accordning to it's type. - * Returns 0 if value matched with expected. - */ -jboolean verify_value(jvalue value, jvmtiPrimitiveType type) { - switch(type) { - case JVMTI_PRIMITIVE_TYPE_BOOLEAN: - return value.z==BOOLEAN; - case JVMTI_PRIMITIVE_TYPE_BYTE: - return value.b==BYTE; - case JVMTI_PRIMITIVE_TYPE_CHAR: - return value.c==CHAR; - case JVMTI_PRIMITIVE_TYPE_SHORT: - return value.s==SHORT; - case JVMTI_PRIMITIVE_TYPE_INT: - return value.i==INT; - case JVMTI_PRIMITIVE_TYPE_LONG: - return value.j==LONG; - case JVMTI_PRIMITIVE_TYPE_FLOAT: - return value.f==FLOAT; - case JVMTI_PRIMITIVE_TYPE_DOUBLE: - return value.d==DOUBLE; - default: - NSK_COMPLAIN1("Unknown type: %X.",type); - return JNI_FALSE; - } -} - -// Check that array values are correct depending on type of elements -jboolean verify_array(const void *array, jvmtiPrimitiveType type, jint length) { - void *expected_array; - switch(type) { - case JVMTI_PRIMITIVE_TYPE_BOOLEAN: - expected_array = (void*)BOOLEAN_ARRAY; - break; - case JVMTI_PRIMITIVE_TYPE_CHAR: - expected_array = (void*)CHAR_ARRAY; - break; - case JVMTI_PRIMITIVE_TYPE_BYTE: - expected_array = (void*)BYTE_ARRAY; - break; - case JVMTI_PRIMITIVE_TYPE_SHORT: - expected_array = (void*)SHORT_ARRAY; - break; - case JVMTI_PRIMITIVE_TYPE_INT: - expected_array = (void*)INT_ARRAY; - break; - case JVMTI_PRIMITIVE_TYPE_LONG: - expected_array = (void*)LONG_ARRAY; - break; - case JVMTI_PRIMITIVE_TYPE_FLOAT: - expected_array = (void*)FLOAT_ARRAY; - break; - case JVMTI_PRIMITIVE_TYPE_DOUBLE: - expected_array = (void*)DOUBLE_ARRAY; - break; - default: - NSK_COMPLAIN0("Unexpected type of array's elements.\n"); - return JNI_FALSE; - } - return memcmp(expected_array,array,length) == 0; -} - -jint JNICALL field_callback(jvmtiHeapReferenceKind kind, - const jvmtiHeapReferenceInfo* info, - jlong object_class_tag, - jlong* object_tag_ptr, - jvalue value, - jvmtiPrimitiveType value_type, - void* user_data) { - jlong tag; - tag = *object_tag_ptr; - - // skip all non-tagged fields as well as fields of tagged objects - if(tag == 0 || - DECODE_TYPE(tag) == TAG_TYPE_OBJECT || - DECODE_TYPE(tag) == TAG_TYPE_STRING) { - return 0; - } else if(DECODE_TYPE(tag) != TAG_TYPE_PRIMITIVE) { - NSK_COMPLAIN3("jvmtiPrimitiveFieldCallback was invoked for an object with " - "non-primitive field tag (0x%lX) corresponging to %s::%s.\n", - DECODE_TYPE(tag), - objects_info[DECODE_OBJECT(tag)].name, - objects_info[DECODE_OBJECT(tag)].fields[DECODE_FIELD(tag)].name); - nsk_jvmti_setFailStatus(); - return 0; - } - - objects_info[DECODE_OBJECT(tag)].fields[info->field.index].found++; - - if(!verify_value(value, value_type)) { - NSK_COMPLAIN2("Field %s::%s has unexpected value.\n", - objects_info[DECODE_OBJECT(tag)].name, - objects_info[DECODE_OBJECT(tag)].fields[info->field.index].name); - nsk_jvmti_setFailStatus(); - } - return 0; -} - -jint JNICALL string_callback(jlong class_tag, - jlong size, - jlong* tag_ptr, - const jchar* value, - jint value_length, - void* user_data) { - int matched = 1; - int i; - - //skip all untegged strings - if(*tag_ptr==0) { - return 0; - } else if(DECODE_TYPE(*tag_ptr) != TAG_TYPE_STRING) { - NSK_COMPLAIN2("jvmtiStringPrimitiveValueCallback was invoked for an object " - "with non-string tag corresponding to %s::%s.\n", - objects_info[DECODE_OBJECT(*tag_ptr)].name, - objects_info[DECODE_OBJECT(*tag_ptr)].fields[DECODE_FIELD(*tag_ptr)].name); - return 0; - } - - objects_info[DECODE_OBJECT(*tag_ptr)].fields[DECODE_FIELD(*tag_ptr)].found++; - - //check that reported length is the same as expected - if(value_length != (jint) wcslen(STRING)) { - NSK_COMPLAIN4("Length of reported string %s::%s is %d while %d is expected.\n", - objects_info[DECODE_OBJECT(*tag_ptr)].name, - objects_info[DECODE_OBJECT(*tag_ptr)].fields[DECODE_FIELD(*tag_ptr)].name, - value_length, - wcslen(STRING)); - nsk_jvmti_setFailStatus(); - return 0; - } - - //compare reported value with expected one - for(i = 0; i +#include +#include + +#include "jvmti.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define STATIC_FIELD 0x0008 + +///amount of objects to be tagged +#define TEST_OBJECTS_COUNT 4 + +///expected amount of times object will bre ported by callbacks +#define PRIMITIVE_OCCURANCE_COUNT 1 +#define STRING_OCCURANCE_COUNT 2 +#define PRIMITIVE_ARRAY_OCCURANCE_COUNT 2 +#define NONPRIMITIVE_OCCURANCE_COUNT 1 + + +/** + tag format + + 63 35 32 16 0 + |1 |type|obj idx|field idx| + +*/ + +#define TAG_TYPE_PRIMITIVE 0 +#define TAG_TYPE_STRING 1 +#define TAG_TYPE_ARRAY 2 +#define TAG_TYPE_OBJECT 3 + +#define ENCODE_TAG(type,obj,fld) (0x8000000000000000ULL|(((jlong)type)<<32)|(((jlong)obj)<<16)|fld) + +#define DECODE_TYPE(tag) ((tag>>32)&0x0FFFF) +#define DECODE_OBJECT(tag) ((tag>>16)&0x0FFFF) +#define DECODE_FIELD(tag) (tag&0x0FFFF) + +///expected values +#define BOOLEAN JNI_FALSE +#define BYTE 0xB +#define CHAR 'z' +#define SHORT 0xB00 +#define INT ((int)0xDEADBEEF) +#define LONG 0xDEADBEEFDEADLL +#define FLOAT 3.1416f +#define DOUBLE 3.14159265 + +#define ARRAY_LENGTH 5 + +static const wchar_t *STRING = L"I hope you'll find me in the heap!"; +static jboolean BOOLEAN_ARRAY[] = {JNI_TRUE, JNI_TRUE, JNI_FALSE, JNI_TRUE, JNI_FALSE}; +static jbyte BYTE_ARRAY[] = {BYTE, BYTE+1, BYTE+2, BYTE+3, BYTE+4}; +static jchar CHAR_ARRAY[] = {CHAR, CHAR+1, CHAR+2, CHAR+3, CHAR+4}; +static jshort SHORT_ARRAY[] = {SHORT, SHORT+1, SHORT+2, SHORT+3, SHORT+4}; +static jint INT_ARRAY[] = {INT, INT+1, INT+2, INT+3, INT+4}; +static jlong LONG_ARRAY[] = {LONG, LONG+1, LONG+2, LONG+3, LONG+4}; +static jfloat FLOAT_ARRAY[] = {FLOAT, FLOAT+1, FLOAT+2, FLOAT+3, FLOAT+4}; +static jdouble DOUBLE_ARRAY[] = {DOUBLE, DOUBLE+1, DOUBLE+2, DOUBLE+3, DOUBLE+4}; + +static long timeout = 0; + +///information about field +typedef struct { + char *name; + char *signature; + int found; + int collected; + int primitive; +} field_info_t; + +///information about object +typedef struct { + char *name; + jint fields_count; + field_info_t *fields; + int collected; +} object_info_t; + +static object_info_t objects_info[TEST_OBJECTS_COUNT]; + +#define className "nsk/jvmti/IterateThroughHeap/callbacks/Callbacks" +#define fieldName "testObjects" +#define fieldSig "[Ljava/lang/Object;" + +// Check if the signature is signature of primitive type. +jboolean is_primitive_type(const char *signature) { + if(!strcmp(signature,"C") + || !strcmp(signature, "B") + || !strcmp(signature, "S") + || !strcmp(signature, "I") + || !strcmp(signature, "J") + || !strcmp(signature, "F") + || !strcmp(signature, "D") + || !strcmp(signature, "Z")) + return JNI_TRUE; + return JNI_FALSE; +} + +// For given signature find expected tag type +int get_tag_type(const char *signature) { + if(is_primitive_type(signature)) { + return TAG_TYPE_PRIMITIVE; + } else if(signature[0]=='[' && is_primitive_type(signature+1)) { + return TAG_TYPE_ARRAY; + } else if(!strcmp(signature, "Ljava/lang/String;")) { + return TAG_TYPE_STRING; + } else { + return TAG_TYPE_OBJECT; + } +} + +/** + * Check value corectness accordning to it's type. + * Returns 0 if value matched with expected. + */ +jboolean verify_value(jvalue value, jvmtiPrimitiveType type) { + switch(type) { + case JVMTI_PRIMITIVE_TYPE_BOOLEAN: + return value.z==BOOLEAN; + case JVMTI_PRIMITIVE_TYPE_BYTE: + return value.b==BYTE; + case JVMTI_PRIMITIVE_TYPE_CHAR: + return value.c==CHAR; + case JVMTI_PRIMITIVE_TYPE_SHORT: + return value.s==SHORT; + case JVMTI_PRIMITIVE_TYPE_INT: + return value.i==INT; + case JVMTI_PRIMITIVE_TYPE_LONG: + return value.j==LONG; + case JVMTI_PRIMITIVE_TYPE_FLOAT: + return value.f==FLOAT; + case JVMTI_PRIMITIVE_TYPE_DOUBLE: + return value.d==DOUBLE; + default: + NSK_COMPLAIN1("Unknown type: %X.",type); + return JNI_FALSE; + } +} + +// Check that array values are correct depending on type of elements +jboolean verify_array(const void *array, jvmtiPrimitiveType type, jint length) { + void *expected_array; + switch(type) { + case JVMTI_PRIMITIVE_TYPE_BOOLEAN: + expected_array = (void*)BOOLEAN_ARRAY; + break; + case JVMTI_PRIMITIVE_TYPE_CHAR: + expected_array = (void*)CHAR_ARRAY; + break; + case JVMTI_PRIMITIVE_TYPE_BYTE: + expected_array = (void*)BYTE_ARRAY; + break; + case JVMTI_PRIMITIVE_TYPE_SHORT: + expected_array = (void*)SHORT_ARRAY; + break; + case JVMTI_PRIMITIVE_TYPE_INT: + expected_array = (void*)INT_ARRAY; + break; + case JVMTI_PRIMITIVE_TYPE_LONG: + expected_array = (void*)LONG_ARRAY; + break; + case JVMTI_PRIMITIVE_TYPE_FLOAT: + expected_array = (void*)FLOAT_ARRAY; + break; + case JVMTI_PRIMITIVE_TYPE_DOUBLE: + expected_array = (void*)DOUBLE_ARRAY; + break; + default: + NSK_COMPLAIN0("Unexpected type of array's elements.\n"); + return JNI_FALSE; + } + return memcmp(expected_array,array,length) == 0; +} + +jint JNICALL field_callback(jvmtiHeapReferenceKind kind, + const jvmtiHeapReferenceInfo* info, + jlong object_class_tag, + jlong* object_tag_ptr, + jvalue value, + jvmtiPrimitiveType value_type, + void* user_data) { + jlong tag; + tag = *object_tag_ptr; + + // skip all non-tagged fields as well as fields of tagged objects + if(tag == 0 || + DECODE_TYPE(tag) == TAG_TYPE_OBJECT || + DECODE_TYPE(tag) == TAG_TYPE_STRING) { + return 0; + } else if(DECODE_TYPE(tag) != TAG_TYPE_PRIMITIVE) { + NSK_COMPLAIN3("jvmtiPrimitiveFieldCallback was invoked for an object with " + "non-primitive field tag (0x%lX) corresponging to %s::%s.\n", + DECODE_TYPE(tag), + objects_info[DECODE_OBJECT(tag)].name, + objects_info[DECODE_OBJECT(tag)].fields[DECODE_FIELD(tag)].name); + nsk_jvmti_setFailStatus(); + return 0; + } + + objects_info[DECODE_OBJECT(tag)].fields[info->field.index].found++; + + if(!verify_value(value, value_type)) { + NSK_COMPLAIN2("Field %s::%s has unexpected value.\n", + objects_info[DECODE_OBJECT(tag)].name, + objects_info[DECODE_OBJECT(tag)].fields[info->field.index].name); + nsk_jvmti_setFailStatus(); + } + return 0; +} + +jint JNICALL string_callback(jlong class_tag, + jlong size, + jlong* tag_ptr, + const jchar* value, + jint value_length, + void* user_data) { + int matched = 1; + int i; + + //skip all untegged strings + if(*tag_ptr==0) { + return 0; + } else if(DECODE_TYPE(*tag_ptr) != TAG_TYPE_STRING) { + NSK_COMPLAIN2("jvmtiStringPrimitiveValueCallback was invoked for an object " + "with non-string tag corresponding to %s::%s.\n", + objects_info[DECODE_OBJECT(*tag_ptr)].name, + objects_info[DECODE_OBJECT(*tag_ptr)].fields[DECODE_FIELD(*tag_ptr)].name); + return 0; + } + + objects_info[DECODE_OBJECT(*tag_ptr)].fields[DECODE_FIELD(*tag_ptr)].found++; + + //check that reported length is the same as expected + if(value_length != (jint) wcslen(STRING)) { + NSK_COMPLAIN4("Length of reported string %s::%s is %d while %d is expected.\n", + objects_info[DECODE_OBJECT(*tag_ptr)].name, + objects_info[DECODE_OBJECT(*tag_ptr)].fields[DECODE_FIELD(*tag_ptr)].name, + value_length, + wcslen(STRING)); + nsk_jvmti_setFailStatus(); + return 0; + } + + //compare reported value with expected one + for(i = 0; i -#include -#include - -#include "jvmti.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define STATIC_FIELD 0x0008 - -/* - For this test tags have following format: - |63 48| 32| 16| 0| - | |tag type|obj idx|fld idx| -*/ - -#define FIELD_TAG 1 -#define OBJECT_TAG 2 -#define CLASS_TAG 4 - -#define ENCODE_TAG(type, obj, fld) (((jlong)type)<<32 | ((jlong)obj)<<16 | (jlong)fld) -#define DECODE_TYPE(tag) tag>>32 -#define DECODE_OBJECT(tag) ((tag>>16)&0xFFFF) -#define DECODE_FIELD(tag) (tag&0xFFFF) - -#define TEST_OBJECTS_COUNT 2 -#define TAGGED_OBJECTS 1 - -static long timeout = 0; -static int filter_type = -1; - -// by default at least one object will be reported regardless to filter type -static int expected_object_count = 1; -static int reported_objects = 0; - -//expected values -#define INT_ARRAY_LENGTH 2 - -static jint TAGGED_STATIC_INT_VALUE = 0xC0DE01; -static jint TAGGED_INT_VALUE = 0xC0DE02; -static jint UNTAGGED_STATIC_INT_VALUE = 0xC0DE03; -static jint UNTAGGED_INT_VALUE = 0xC0DE04; -static jint TAGGED_INT_ARRAY_VALUE[] = {0xC0DE01, - 0xC0DE01+1}; -static jint UNTAGGED_INT_ARRAY_VALUE[] = {0xC0DE03, - 0xC0DE03+1}; -static wchar_t *TAGGED_STRING_VALUE = L"I'm a tagged string"; -static wchar_t *UNTAGGED_STRING_VALUE = L"I'm an untagged string"; - -//kind of field -#define TYPE_FIELD 1 -#define TYPE_ARRAY 2 -#define TYPE_STRING 4 - -//field info -typedef struct { - char *name; - char *signature; - int found; - int collected; - int primitive; - int expected; - int type; - void *value; - int size; -} field_info_t; - -//object info -typedef struct { - char *name; - int fields_count; - field_info_t *fields; - int collected; -} object_info_t; - -static object_info_t objects_info[TEST_OBJECTS_COUNT]; - -#define className "nsk/jvmti/IterateThroughHeap/filter_tagged/HeapFilter" -#define fieldName "testObjects" -#define fieldSig "[Ljava/lang/Object;" -#define STRING_SIGNATURE "Ljava/lang/String;" -#define INT_ARRAY_SIGNATURE "[I" - -// Check if the signature is signature of primitive type. -jboolean is_primitive_type(const char *signature) { - if(!strcmp(signature,"C") - || !strcmp(signature, "B") - || !strcmp(signature, "S") - || !strcmp(signature, "I") - || !strcmp(signature, "J") - || !strcmp(signature, "F") - || !strcmp(signature, "D") - || !strcmp(signature, "Z")) - return JNI_TRUE; - return JNI_FALSE; -} - -//check tag values accoring to heap filter choosed for test -jboolean verify_tag(jlong class_tag, jlong object_tag) { - switch(filter_type) { - case JVMTI_HEAP_FILTER_TAGGED: - return object_tag == 0; - case JVMTI_HEAP_FILTER_UNTAGGED: - return object_tag != 0; - case JVMTI_HEAP_FILTER_CLASS_TAGGED: - return class_tag == 0; - case JVMTI_HEAP_FILTER_CLASS_UNTAGGED: - return class_tag != 0; - default: - return JNI_FALSE; - } -} - -//check whether or not field expected to be reported -jboolean occurance_expected(int tagged, int is_static, int is_primitive) { - switch(filter_type) { - case JVMTI_HEAP_FILTER_TAGGED: - return !tagged; - case JVMTI_HEAP_FILTER_UNTAGGED: - return tagged; - case JVMTI_HEAP_FILTER_CLASS_TAGGED: - return (is_static && is_primitive) || !is_primitive || !tagged; - case JVMTI_HEAP_FILTER_CLASS_UNTAGGED: - return !is_static && is_primitive && tagged; - default: - return JNI_ERR; - } -} - -jint JNICALL field_callback(jvmtiHeapReferenceKind kind, - const jvmtiHeapReferenceInfo* info, - jlong object_class_tag, - jlong* object_tag_ptr, - jvalue value, - jvmtiPrimitiveType value_type, - void* user_data) { - int object; - int field; - if (!NSK_VERIFY(verify_tag(object_class_tag, *object_tag_ptr))) { - nsk_jvmti_setFailStatus(); - } - - //iterate over all fields found during tagging and compare reported value - //with their values. - if(value_type != JVMTI_PRIMITIVE_TYPE_INT) - return 0; - for(object = 0; object < TEST_OBJECTS_COUNT; object++) { - for(field = 0; field < objects_info[object].fields_count; field++) { - if(objects_info[object].fields[field].type == TYPE_FIELD && - *(jint*)(objects_info[object].fields[field].value) == value.i) { - objects_info[object].fields[field].found++; - } - } - } - return 0; -} - -jint JNICALL string_callback(jlong class_tag, - jlong size, - jlong* tag_ptr, - const jchar* value, - jint value_length, - void* user_data) { - int object; - int field; - if (!NSK_VERIFY(verify_tag(class_tag, *tag_ptr))) { - nsk_jvmti_setFailStatus(); - } - for(object = 0; object < TEST_OBJECTS_COUNT; object++) { - for(field = 0; field < objects_info[object].fields_count; field++) { - if(objects_info[object].fields[field].type == TYPE_STRING && - value_length == objects_info[object].fields[field].size) { - int matched = 1; - int i; - wchar_t *str = (wchar_t*)objects_info[object].fields[field].value; - for(i = 0; i < value_length && matched; i++) { - matched = (str[i] == value[i]); - } - if(matched) - objects_info[object].fields[field].found++; - } - } - } - return 0; -} - - -jint JNICALL array_callback(jlong class_tag, - jlong size, - jlong* tag_ptr, - jint element_count, - jvmtiPrimitiveType element_type, - const void* elements, - void* user_data) { - int object; - int field; - if (!NSK_VERIFY(verify_tag(class_tag, *tag_ptr))) { - nsk_jvmti_setFailStatus(); - } - for(object = 0; object < TEST_OBJECTS_COUNT; object++) { - for(field = 0; field < objects_info[object].fields_count; field++) { - if(objects_info[object].fields[field].type == TYPE_ARRAY && - element_count == objects_info[object].fields[field].size) { - int matched = 1; - int i; - for(i = 0; i < element_count && matched; i++) { - matched = ((jint*)objects_info[object].fields[field].value)[i]== - ((jint*)elements)[i]; - } - if(matched) - objects_info[object].fields[field].found++; - } - } - } - return 0; -} - -jint JNICALL heap_callback(jlong class_tag, - jlong size, - jlong* tag_ptr, - jint length, - void* user_data) { - if (!NSK_VERIFY(verify_tag(class_tag, *tag_ptr))) { - NSK_COMPLAIN0("Tag values invalid for selected heap filter were passed " - "to jvmtiHeapIterationCallback.\n"); - NSK_COMPLAIN2("\tClass tag: 0x%lX;\n\tObject tag: 0x%lX.\n", class_tag, *tag_ptr); - nsk_jvmti_setFailStatus(); - } - reported_objects++; - return 0; -} - -JNIEXPORT void JNICALL -object_free_callback(jvmtiEnv* jvmti, jlong tag) { - if(DECODE_TYPE(tag) == OBJECT_TAG) { - objects_info[DECODE_OBJECT(tag)].collected = 1; - } else if(DECODE_TYPE(tag) == FIELD_TAG) { - objects_info[DECODE_OBJECT(tag)].fields[DECODE_FIELD(tag)].collected = 1; - } -} - -//set expected fields value according to it's type -void set_expected_value(field_info_t *field, int tagged, int is_static) { - if(field->primitive) { - field->size = (int) sizeof(jint); - if(is_static) { - field->value = (void*)(tagged ? &TAGGED_STATIC_INT_VALUE: - &UNTAGGED_STATIC_INT_VALUE); - } else { - field->value = (void*)(tagged ? &TAGGED_INT_VALUE: - &UNTAGGED_INT_VALUE); - } - field->type = TYPE_FIELD; - } else if (0==strcmp(field->signature,STRING_SIGNATURE)) { - field->value = (void*)(tagged ? TAGGED_STRING_VALUE: - UNTAGGED_STRING_VALUE); - field->size = (int) wcslen((wchar_t*)field->value); - field->type = TYPE_STRING; - } else if (0==strcmp(field->signature,INT_ARRAY_SIGNATURE)) { - field->size = INT_ARRAY_LENGTH; - field->value = (void*)(tagged ? TAGGED_INT_ARRAY_VALUE: - UNTAGGED_INT_ARRAY_VALUE); - field->type = TYPE_ARRAY; - } -} - -/** - * Read array of test objects. - * Tag each of these objects, their classes, non-primitive fields and non-primitive fields classes. - */ -int tag_objects(jvmtiEnv *jvmti, JNIEnv *jni) { - jclass debugee; - jfieldID testObjectsField; - jobjectArray testObjects; - int object; - - if(!NSK_VERIFY(NULL != - (debugee = NSK_CPP_STUB2(FindClass, jni, className)))) - return JNI_ERR; - - if(!NSK_VERIFY(NULL != - (testObjectsField = NSK_CPP_STUB4(GetStaticFieldID, - jni, debugee, - fieldName, - fieldSig)))) - return JNI_ERR; - - if(!NSK_VERIFY(NULL != - (testObjects = (jobjectArray)(NSK_CPP_STUB3(GetStaticObjectField, - jni, debugee, - testObjectsField))))) - return JNI_ERR; - - // For each of test objects tag every field - for(object = 0; object +#include +#include + +#include "jvmti.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define STATIC_FIELD 0x0008 + +/* + For this test tags have following format: + |63 48| 32| 16| 0| + | |tag type|obj idx|fld idx| +*/ + +#define FIELD_TAG 1 +#define OBJECT_TAG 2 +#define CLASS_TAG 4 + +#define ENCODE_TAG(type, obj, fld) (((jlong)type)<<32 | ((jlong)obj)<<16 | (jlong)fld) +#define DECODE_TYPE(tag) tag>>32 +#define DECODE_OBJECT(tag) ((tag>>16)&0xFFFF) +#define DECODE_FIELD(tag) (tag&0xFFFF) + +#define TEST_OBJECTS_COUNT 2 +#define TAGGED_OBJECTS 1 + +static long timeout = 0; +static int filter_type = -1; + +// by default at least one object will be reported regardless to filter type +static int expected_object_count = 1; +static int reported_objects = 0; + +//expected values +#define INT_ARRAY_LENGTH 2 + +static jint TAGGED_STATIC_INT_VALUE = 0xC0DE01; +static jint TAGGED_INT_VALUE = 0xC0DE02; +static jint UNTAGGED_STATIC_INT_VALUE = 0xC0DE03; +static jint UNTAGGED_INT_VALUE = 0xC0DE04; +static jint TAGGED_INT_ARRAY_VALUE[] = {0xC0DE01, + 0xC0DE01+1}; +static jint UNTAGGED_INT_ARRAY_VALUE[] = {0xC0DE03, + 0xC0DE03+1}; +static const wchar_t *TAGGED_STRING_VALUE = L"I'm a tagged string"; +static const wchar_t *UNTAGGED_STRING_VALUE = L"I'm an untagged string"; + +//kind of field +#define TYPE_FIELD 1 +#define TYPE_ARRAY 2 +#define TYPE_STRING 4 + +//field info +typedef struct { + char *name; + char *signature; + int found; + int collected; + int primitive; + int expected; + int type; + void *value; + int size; +} field_info_t; + +//object info +typedef struct { + char *name; + jint fields_count; + field_info_t *fields; + int collected; +} object_info_t; + +static object_info_t objects_info[TEST_OBJECTS_COUNT]; + +#define className "nsk/jvmti/IterateThroughHeap/filter_tagged/HeapFilter" +#define fieldName "testObjects" +#define fieldSig "[Ljava/lang/Object;" +#define STRING_SIGNATURE "Ljava/lang/String;" +#define INT_ARRAY_SIGNATURE "[I" + +// Check if the signature is signature of primitive type. +jboolean is_primitive_type(const char *signature) { + if(!strcmp(signature,"C") + || !strcmp(signature, "B") + || !strcmp(signature, "S") + || !strcmp(signature, "I") + || !strcmp(signature, "J") + || !strcmp(signature, "F") + || !strcmp(signature, "D") + || !strcmp(signature, "Z")) + return JNI_TRUE; + return JNI_FALSE; +} + +//check tag values accoring to heap filter choosed for test +jboolean verify_tag(jlong class_tag, jlong object_tag) { + switch(filter_type) { + case JVMTI_HEAP_FILTER_TAGGED: + return object_tag == 0; + case JVMTI_HEAP_FILTER_UNTAGGED: + return object_tag != 0; + case JVMTI_HEAP_FILTER_CLASS_TAGGED: + return class_tag == 0; + case JVMTI_HEAP_FILTER_CLASS_UNTAGGED: + return class_tag != 0; + default: + return JNI_FALSE; + } +} + +//check whether or not field expected to be reported +jboolean occurance_expected(int tagged, int is_static, int is_primitive) { + switch(filter_type) { + case JVMTI_HEAP_FILTER_TAGGED: + return !tagged; + case JVMTI_HEAP_FILTER_UNTAGGED: + return tagged; + case JVMTI_HEAP_FILTER_CLASS_TAGGED: + return (is_static && is_primitive) || !is_primitive || !tagged; + case JVMTI_HEAP_FILTER_CLASS_UNTAGGED: + return !is_static && is_primitive && tagged; + default: + return JNI_ERR; + } +} + +jint JNICALL field_callback(jvmtiHeapReferenceKind kind, + const jvmtiHeapReferenceInfo* info, + jlong object_class_tag, + jlong* object_tag_ptr, + jvalue value, + jvmtiPrimitiveType value_type, + void* user_data) { + int object; + int field; + if (!NSK_VERIFY(verify_tag(object_class_tag, *object_tag_ptr))) { + nsk_jvmti_setFailStatus(); + } + + //iterate over all fields found during tagging and compare reported value + //with their values. + if(value_type != JVMTI_PRIMITIVE_TYPE_INT) + return 0; + for(object = 0; object < TEST_OBJECTS_COUNT; object++) { + for(field = 0; field < objects_info[object].fields_count; field++) { + if(objects_info[object].fields[field].type == TYPE_FIELD && + *(jint*)(objects_info[object].fields[field].value) == value.i) { + objects_info[object].fields[field].found++; + } + } + } + return 0; +} + +jint JNICALL string_callback(jlong class_tag, + jlong size, + jlong* tag_ptr, + const jchar* value, + jint value_length, + void* user_data) { + int object; + int field; + if (!NSK_VERIFY(verify_tag(class_tag, *tag_ptr))) { + nsk_jvmti_setFailStatus(); + } + for(object = 0; object < TEST_OBJECTS_COUNT; object++) { + for(field = 0; field < objects_info[object].fields_count; field++) { + if(objects_info[object].fields[field].type == TYPE_STRING && + value_length == objects_info[object].fields[field].size) { + int matched = 1; + int i; + wchar_t *str = (wchar_t*)objects_info[object].fields[field].value; + for(i = 0; i < value_length && matched; i++) { + matched = (str[i] == value[i]); + } + if(matched) + objects_info[object].fields[field].found++; + } + } + } + return 0; +} + + +jint JNICALL array_callback(jlong class_tag, + jlong size, + jlong* tag_ptr, + jint element_count, + jvmtiPrimitiveType element_type, + const void* elements, + void* user_data) { + int object; + int field; + if (!NSK_VERIFY(verify_tag(class_tag, *tag_ptr))) { + nsk_jvmti_setFailStatus(); + } + for(object = 0; object < TEST_OBJECTS_COUNT; object++) { + for(field = 0; field < objects_info[object].fields_count; field++) { + if(objects_info[object].fields[field].type == TYPE_ARRAY && + element_count == objects_info[object].fields[field].size) { + int matched = 1; + int i; + for(i = 0; i < element_count && matched; i++) { + matched = ((jint*)objects_info[object].fields[field].value)[i]== + ((jint*)elements)[i]; + } + if(matched) + objects_info[object].fields[field].found++; + } + } + } + return 0; +} + +jint JNICALL heap_callback(jlong class_tag, + jlong size, + jlong* tag_ptr, + jint length, + void* user_data) { + if (!NSK_VERIFY(verify_tag(class_tag, *tag_ptr))) { + NSK_COMPLAIN0("Tag values invalid for selected heap filter were passed " + "to jvmtiHeapIterationCallback.\n"); + NSK_COMPLAIN2("\tClass tag: 0x%lX;\n\tObject tag: 0x%lX.\n", class_tag, *tag_ptr); + nsk_jvmti_setFailStatus(); + } + reported_objects++; + return 0; +} + +JNIEXPORT void JNICALL +object_free_callback(jvmtiEnv* jvmti, jlong tag) { + if(DECODE_TYPE(tag) == OBJECT_TAG) { + objects_info[DECODE_OBJECT(tag)].collected = 1; + } else if(DECODE_TYPE(tag) == FIELD_TAG) { + objects_info[DECODE_OBJECT(tag)].fields[DECODE_FIELD(tag)].collected = 1; + } +} + +//set expected fields value according to it's type +void set_expected_value(field_info_t *field, int tagged, int is_static) { + if(field->primitive) { + field->size = (int) sizeof(jint); + if(is_static) { + field->value = (void*)(tagged ? &TAGGED_STATIC_INT_VALUE: + &UNTAGGED_STATIC_INT_VALUE); + } else { + field->value = (void*)(tagged ? &TAGGED_INT_VALUE: + &UNTAGGED_INT_VALUE); + } + field->type = TYPE_FIELD; + } else if (0==strcmp(field->signature,STRING_SIGNATURE)) { + field->value = (void*)(tagged ? TAGGED_STRING_VALUE: + UNTAGGED_STRING_VALUE); + field->size = (int) wcslen((wchar_t*)field->value); + field->type = TYPE_STRING; + } else if (0==strcmp(field->signature,INT_ARRAY_SIGNATURE)) { + field->size = INT_ARRAY_LENGTH; + field->value = (void*)(tagged ? TAGGED_INT_ARRAY_VALUE: + UNTAGGED_INT_ARRAY_VALUE); + field->type = TYPE_ARRAY; + } +} + +/** + * Read array of test objects. + * Tag each of these objects, their classes, non-primitive fields and non-primitive fields classes. + */ +int tag_objects(jvmtiEnv *jvmti, JNIEnv *jni) { + jclass debugee; + jfieldID testObjectsField; + jobjectArray testObjects; + int object; + + if(!NSK_VERIFY(NULL != + (debugee = NSK_CPP_STUB2(FindClass, jni, className)))) + return JNI_ERR; + + if(!NSK_VERIFY(NULL != + (testObjectsField = NSK_CPP_STUB4(GetStaticFieldID, + jni, debugee, + fieldName, + fieldSig)))) + return JNI_ERR; + + if(!NSK_VERIFY(NULL != + (testObjects = (jobjectArray)(NSK_CPP_STUB3(GetStaticObjectField, + jni, debugee, + testObjectsField))))) + return JNI_ERR; + + // For each of test objects tag every field + for(object = 0; object -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *name; - char *sig; - jlocation loc; -} entry_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static size_t eventsExpected = 0; -static size_t eventsCount = 0; -static entry_info entries[] = { - {"check", "()I", -1}, - {"dummy", "()V", 0}, - {"chain", "()V", -1} -}; - -void JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method) { - jvmtiError err; - char *cls_sig, *generic; - entry_info entry; - jclass cls; - jmethodID mid; - char buffer[32]; - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &cls_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (cls_sig != NULL && - strcmp(cls_sig, "Lnsk/jvmti/MethodEntry/mentry001;") == 0) { - if (printdump == JNI_TRUE) { - printf(">>> retrieving method entry info ...\n"); - } - err = (*jvmti_env)->GetMethodName(jvmti_env, method, - &entry.name, &entry.sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thr, 0, &mid, &entry.loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", cls_sig); - printf(">>> method: \"%s%s\"\n", entry.name, entry.sig); - printf(">>> location: %s\n", jlong_to_string(entry.loc, buffer)); - printf(">>> ... done\n"); - } - if (eventsCount < sizeof(entries)/sizeof(entry_info)) { - if (entry.name == NULL || - strcmp(entry.name, entries[eventsCount].name) != 0) { - printf("(entry#%" PRIuPTR ") wrong method name: \"%s\"", - eventsCount, entry.name); - printf(", expected: \"%s\"\n", entries[eventsCount].name); - result = STATUS_FAILED; - } - if (entry.sig == NULL || - strcmp(entry.sig, entries[eventsCount].sig) != 0) { - printf("(entry#%" PRIuPTR ") wrong method sig: \"%s\"", - eventsCount, entry.sig); - printf(", expected: \"%s\"\n", entries[eventsCount].sig); - result = STATUS_FAILED; - } - if (entry.loc != entries[eventsCount].loc) { - printf("(entry#%" PRIuPTR ") wrong location: %s", - eventsCount, jlong_to_string(entry.loc, buffer)); - printf(", expected: %s\n", - jlong_to_string(entries[eventsCount].loc, buffer)); - result = STATUS_FAILED; - } - } else { - printf("Unexpected method entry catched:"); - printf(" class: \"%s\"\n", cls_sig); - printf(" method: \"%s%s\"\n", entry.name, entry.sig); - printf(" location: %s\n", jlong_to_string(entry.loc, buffer)); - result = STATUS_FAILED; - } - eventsCount++; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_mentry001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_mentry001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_mentry001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_method_entry_events) { - callbacks.MethodEntry = &MethodEntry; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: MethodEntry event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_MethodEntry_mentry001_enable(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - return; - } - - if (!caps.can_generate_method_entry_events) { - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_ENTRY, NULL); - if (err == JVMTI_ERROR_NONE) { - eventsExpected = sizeof(entries)/sizeof(entry_info); - } else { - printf("Failed to enable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_MethodEntry_mentry001_check(JNIEnv *env, jclass cls) { - jmethodID mid; - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "dummy", "()V"); - if (mid == NULL) { - printf("Cannot find metod \"dummy()\"!\n"); - return STATUS_FAILED; - } - - JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, cls), mid); - if (eventsCount != eventsExpected) { - printf("Wrong number of MethodEntry events: %" PRIuPTR ", expected: %" PRIuPTR "\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_MethodEntry_mentry001_chain(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_generate_method_entry_events) { - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_ENTRY, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry001/mentry001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry001/mentry001.cpp new file mode 100644 index 00000000000..3dd3a66a7f2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry001/mentry001.cpp @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + char *name; + char *sig; + jlocation loc; +} writable_entry_info; + +typedef struct { + const char *name; + const char *sig; + const jlocation loc; +} entry_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static size_t eventsExpected = 0; +static size_t eventsCount = 0; +static entry_info entries[] = { + {"check", "()I", -1}, + {"dummy", "()V", 0}, + {"chain", "()V", -1} +}; + +void JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method) { + jvmtiError err; + char *cls_sig, *generic; + writable_entry_info entry; + jclass cls; + jmethodID mid; + char buffer[32]; + + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, &cls_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (cls_sig != NULL && + strcmp(cls_sig, "Lnsk/jvmti/MethodEntry/mentry001;") == 0) { + if (printdump == JNI_TRUE) { + printf(">>> retrieving method entry info ...\n"); + } + err = jvmti_env->GetMethodName(method, + &entry.name, &entry.sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetFrameLocation(thr, 0, &mid, &entry.loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", cls_sig); + printf(">>> method: \"%s%s\"\n", entry.name, entry.sig); + printf(">>> location: %s\n", jlong_to_string(entry.loc, buffer)); + printf(">>> ... done\n"); + } + if (eventsCount < sizeof(entries)/sizeof(entry_info)) { + if (entry.name == NULL || + strcmp(entry.name, entries[eventsCount].name) != 0) { + printf("(entry#%" PRIuPTR ") wrong method name: \"%s\"", + eventsCount, entry.name); + printf(", expected: \"%s\"\n", entries[eventsCount].name); + result = STATUS_FAILED; + } + if (entry.sig == NULL || + strcmp(entry.sig, entries[eventsCount].sig) != 0) { + printf("(entry#%" PRIuPTR ") wrong method sig: \"%s\"", + eventsCount, entry.sig); + printf(", expected: \"%s\"\n", entries[eventsCount].sig); + result = STATUS_FAILED; + } + if (entry.loc != entries[eventsCount].loc) { + printf("(entry#%" PRIuPTR ") wrong location: %s", + eventsCount, jlong_to_string(entry.loc, buffer)); + printf(", expected: %s\n", + jlong_to_string(entries[eventsCount].loc, buffer)); + result = STATUS_FAILED; + } + } else { + printf("Unexpected method entry catched:"); + printf(" class: \"%s\"\n", cls_sig); + printf(" method: \"%s%s\"\n", entry.name, entry.sig); + printf(" location: %s\n", jlong_to_string(entry.loc, buffer)); + result = STATUS_FAILED; + } + eventsCount++; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_mentry001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_mentry001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_mentry001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_method_entry_events) { + callbacks.MethodEntry = &MethodEntry; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: MethodEntry event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_MethodEntry_mentry001_enable(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + return; + } + + if (!caps.can_generate_method_entry_events) { + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_ENTRY, NULL); + if (err == JVMTI_ERROR_NONE) { + eventsExpected = sizeof(entries)/sizeof(entry_info); + } else { + printf("Failed to enable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_MethodEntry_mentry001_check(JNIEnv *env, jclass cls) { + jmethodID mid; + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "dummy", "()V"); + if (mid == NULL) { + printf("Cannot find metod \"dummy()\"!\n"); + return STATUS_FAILED; + } + + JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, cls), mid); + if (eventsCount != eventsExpected) { + printf("Wrong number of MethodEntry events: %" PRIuPTR ", expected: %" PRIuPTR "\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_MethodEntry_mentry001_chain(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_generate_method_entry_events) { + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_ENTRY, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/libmentry002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/libmentry002.c deleted file mode 100644 index a7f0134c878..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/libmentry002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "mentry002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/libmentry002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/libmentry002.cpp new file mode 100644 index 00000000000..fe76093ea44 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/libmentry002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "mentry002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/mentry002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/mentry002.c deleted file mode 100644 index 8ba58b4f042..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/mentry002.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int MethodEntriesExpected = 0; -static int MethodExitsExpected = 0; -static int MethodEntriesCount = 0; -static int MethodExitsCount = 0; -static jmethodID mid = NULL; - -void JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method) { - if (mid == method) { - MethodEntriesCount++; - } -} - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jboolean was_poped_by_exc, jvalue return_value) { - if (mid == method) { - MethodExitsCount++; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_mentry002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_mentry002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_mentry002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_method_entry_events && - caps.can_generate_method_exit_events) { - callbacks.MethodEntry = &MethodEntry; - callbacks.MethodExit = &MethodExit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: MethodEntry or MethodExit event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_MethodEntry_mentry002_getReady(JNIEnv *env, jclass cls, jint i) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return; - } - - if (!caps.can_generate_method_entry_events || - !caps.can_generate_method_exit_events) { - return; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "emptyMethod", "()V"); - if (mid == NULL) { - printf("Cannot find Method ID for emptyMethod\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_ENTRY, NULL); - if (err == JVMTI_ERROR_NONE) { - MethodEntriesExpected = i; - } else { - printf("Failed to enable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, NULL); - if (err == JVMTI_ERROR_NONE) { - MethodExitsExpected = i; - } else { - printf("Failed to enable JVMTI_EVENT_METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_MethodEntry_mentry002_check(JNIEnv *env, jclass cls) { - if (printdump == JNI_TRUE) { - printf(">>> MethodEntry events: %d, MethodExit events: %d\n", - MethodEntriesCount, MethodExitsCount); - } - if (MethodEntriesCount != MethodEntriesExpected) { - printf("Wrong number of method entry events: %d, expected: %d\n", - MethodEntriesCount, MethodEntriesExpected); - result = STATUS_FAILED; - } - if (MethodExitsCount != MethodExitsExpected) { - printf("Wrong number of method exit events: %d, expected: %d\n", - MethodExitsCount, MethodExitsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/mentry002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/mentry002.cpp new file mode 100644 index 00000000000..fbb48eeb007 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry002/mentry002.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int MethodEntriesExpected = 0; +static int MethodExitsExpected = 0; +static int MethodEntriesCount = 0; +static int MethodExitsCount = 0; +static jmethodID mid = NULL; + +void JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method) { + if (mid == method) { + MethodEntriesCount++; + } +} + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jboolean was_poped_by_exc, jvalue return_value) { + if (mid == method) { + MethodExitsCount++; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_mentry002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_mentry002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_mentry002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_method_entry_events && + caps.can_generate_method_exit_events) { + callbacks.MethodEntry = &MethodEntry; + callbacks.MethodExit = &MethodExit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: MethodEntry or MethodExit event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_MethodEntry_mentry002_getReady(JNIEnv *env, jclass cls, jint i) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return; + } + + if (!caps.can_generate_method_entry_events || + !caps.can_generate_method_exit_events) { + return; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "emptyMethod", "()V"); + if (mid == NULL) { + printf("Cannot find Method ID for emptyMethod\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_ENTRY, NULL); + if (err == JVMTI_ERROR_NONE) { + MethodEntriesExpected = i; + } else { + printf("Failed to enable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, NULL); + if (err == JVMTI_ERROR_NONE) { + MethodExitsExpected = i; + } else { + printf("Failed to enable JVMTI_EVENT_METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_MethodEntry_mentry002_check(JNIEnv *env, jclass cls) { + if (printdump == JNI_TRUE) { + printf(">>> MethodEntry events: %d, MethodExit events: %d\n", + MethodEntriesCount, MethodExitsCount); + } + if (MethodEntriesCount != MethodEntriesExpected) { + printf("Wrong number of method entry events: %d, expected: %d\n", + MethodEntriesCount, MethodEntriesExpected); + result = STATUS_FAILED; + } + if (MethodExitsCount != MethodExitsExpected) { + printf("Wrong number of method exit events: %d, expected: %d\n", + MethodExitsCount, MethodExitsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/libmexit001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/libmexit001.c deleted file mode 100644 index 3ffc91f106e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/libmexit001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "mexit001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/libmexit001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/libmexit001.cpp new file mode 100644 index 00000000000..d8b0cf4b93b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/libmexit001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "mexit001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/mexit001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/mexit001.c deleted file mode 100644 index ea3576d7ca0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/mexit001.c +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls_sig; - char *name; - char *sig; - jlocation loc; -} exit_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static size_t eventsExpected = 0; -static size_t eventsCount = 0; -static exit_info exits[] = { - {"Lnsk/jvmti/MethodExit/mexit001a;", "chain", "()V", -1}, - {"Lnsk/jvmti/MethodExit/mexit001a;", "dummy", "()V", 3} -}; - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jboolean was_poped_by_exc, jvalue return_value) { - jvmtiError err; - char *cls_sig, *name, *sig, *generic; - jclass cls; - jmethodID mid; - jlocation loc; - char buffer[32]; - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &cls_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (cls_sig != NULL && - strcmp(cls_sig, "Lnsk/jvmti/MethodExit/mexit001a;") == 0) { - if (printdump == JNI_TRUE) { - printf(">>> retrieving method exit info ...\n"); - } - err = (*jvmti_env)->GetMethodName(jvmti_env, method, - &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thr, 0, &mid, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", cls_sig); - printf(">>> method: \"%s%s\"\n", name, sig); - printf(">>> location: %s\n", jlong_to_string(loc, buffer)); - printf(">>> ... done\n"); - } - if (eventsCount < sizeof(exits)/sizeof(exit_info)) { - if (cls_sig == NULL || - strcmp(cls_sig, exits[eventsCount].cls_sig) != 0) { - printf("(exit#%" PRIuPTR ") wrong class: \"%s\"", - eventsCount, cls_sig); - printf(", expected: \"%s\"\n", exits[eventsCount].cls_sig); - result = STATUS_FAILED; - } - if (name == NULL || - strcmp(name, exits[eventsCount].name) != 0) { - printf("(exit#%" PRIuPTR ") wrong method name: \"%s\"", - eventsCount, name); - printf(", expected: \"%s\"\n", exits[eventsCount].name); - result = STATUS_FAILED; - } - if (sig == NULL || - strcmp(sig, exits[eventsCount].sig) != 0) { - printf("(exit#%" PRIuPTR ") wrong method sig: \"%s\"", - eventsCount, sig); - printf(", expected: \"%s\"\n", exits[eventsCount].sig); - result = STATUS_FAILED; - } - if (loc != exits[eventsCount].loc) { - printf("(exit#%" PRIuPTR ") wrong location: %s", - eventsCount, jlong_to_string(loc, buffer)); - printf(", expected: %s\n", - jlong_to_string(exits[eventsCount].loc, buffer)); - result = STATUS_FAILED; - } - } else { - printf("Unexpected method exit catched:"); - printf(" class: \"%s\"\n", cls_sig); - printf(" method: \"%s%s\"\n", name, sig); - printf(" location: %s\n", jlong_to_string(loc, buffer)); - result = STATUS_FAILED; - } - eventsCount++; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_mexit001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_mexit001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_mexit001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: MethodExit event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_MethodExit_mexit001_init0(JNIEnv *env, jclass cls) { - jvmtiError err; - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, NULL); - if (err == JVMTI_ERROR_NONE) { - eventsExpected = sizeof(exits)/sizeof(exit_info); - } else { - printf("Failed to enable JVMTI_EVENT_METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - // TODO: should we return result instead? - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_MethodExit_mexit001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jclass clz; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_generate_method_exit_events) { - return result; - } - - clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/MethodExit/mexit001a")); - if (clz == NULL) { - printf("Cannot find nsk.jvmti.MethodExit.mexit001a class!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clz), - "dummy", "()V"); - if (mid == NULL) { - printf("Cannot find metod \"dummy()\"!\n"); - return STATUS_FAILED; - } - - JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, clz), mid); - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_EXIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (eventsCount != eventsExpected) { - printf("Wrong number of MethodExit events: %" PRIuPTR ", expected: %" PRIuPTR "\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_MethodExit_mexit001a_chain(JNIEnv *env, jclass cls) { - printf("Executing chain()\n"); -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/mexit001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/mexit001.cpp new file mode 100644 index 00000000000..2ebcf48cda2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit001/mexit001.cpp @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls_sig; + const char *name; + const char *sig; + jlocation loc; +} exit_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static size_t eventsExpected = 0; +static size_t eventsCount = 0; +static exit_info exits[] = { + {"Lnsk/jvmti/MethodExit/mexit001a;", "chain", "()V", -1}, + {"Lnsk/jvmti/MethodExit/mexit001a;", "dummy", "()V", 3} +}; + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jboolean was_poped_by_exc, jvalue return_value) { + jvmtiError err; + char *cls_sig, *name, *sig, *generic; + jclass cls; + jmethodID mid; + jlocation loc; + char buffer[32]; + + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, &cls_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (cls_sig != NULL && + strcmp(cls_sig, "Lnsk/jvmti/MethodExit/mexit001a;") == 0) { + if (printdump == JNI_TRUE) { + printf(">>> retrieving method exit info ...\n"); + } + err = jvmti_env->GetMethodName(method, + &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetFrameLocation(thr, 0, &mid, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", cls_sig); + printf(">>> method: \"%s%s\"\n", name, sig); + printf(">>> location: %s\n", jlong_to_string(loc, buffer)); + printf(">>> ... done\n"); + } + if (eventsCount < sizeof(exits)/sizeof(exit_info)) { + if (cls_sig == NULL || + strcmp(cls_sig, exits[eventsCount].cls_sig) != 0) { + printf("(exit#%" PRIuPTR ") wrong class: \"%s\"", + eventsCount, cls_sig); + printf(", expected: \"%s\"\n", exits[eventsCount].cls_sig); + result = STATUS_FAILED; + } + if (name == NULL || + strcmp(name, exits[eventsCount].name) != 0) { + printf("(exit#%" PRIuPTR ") wrong method name: \"%s\"", + eventsCount, name); + printf(", expected: \"%s\"\n", exits[eventsCount].name); + result = STATUS_FAILED; + } + if (sig == NULL || + strcmp(sig, exits[eventsCount].sig) != 0) { + printf("(exit#%" PRIuPTR ") wrong method sig: \"%s\"", + eventsCount, sig); + printf(", expected: \"%s\"\n", exits[eventsCount].sig); + result = STATUS_FAILED; + } + if (loc != exits[eventsCount].loc) { + printf("(exit#%" PRIuPTR ") wrong location: %s", + eventsCount, jlong_to_string(loc, buffer)); + printf(", expected: %s\n", + jlong_to_string(exits[eventsCount].loc, buffer)); + result = STATUS_FAILED; + } + } else { + printf("Unexpected method exit catched:"); + printf(" class: \"%s\"\n", cls_sig); + printf(" method: \"%s%s\"\n", name, sig); + printf(" location: %s\n", jlong_to_string(loc, buffer)); + result = STATUS_FAILED; + } + eventsCount++; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_mexit001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_mexit001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_mexit001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: MethodExit event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_MethodExit_mexit001_init0(JNIEnv *env, jclass cls) { + jvmtiError err; + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, NULL); + if (err == JVMTI_ERROR_NONE) { + eventsExpected = sizeof(exits)/sizeof(exit_info); + } else { + printf("Failed to enable JVMTI_EVENT_METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + // TODO: should we return result instead? + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_MethodExit_mexit001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jclass clz; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_generate_method_exit_events) { + return result; + } + + clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/MethodExit/mexit001a")); + if (clz == NULL) { + printf("Cannot find nsk.jvmti.MethodExit.mexit001a class!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clz), + "dummy", "()V"); + if (mid == NULL) { + printf("Cannot find metod \"dummy()\"!\n"); + return STATUS_FAILED; + } + + JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, clz), mid); + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_EXIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (eventsCount != eventsExpected) { + printf("Wrong number of MethodExit events: %" PRIuPTR ", expected: %" PRIuPTR "\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_MethodExit_mexit001a_chain(JNIEnv *env, jclass cls) { + printf("Executing chain()\n"); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/libmexit002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/libmexit002.c deleted file mode 100644 index de838dab163..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/libmexit002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "mexit002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/libmexit002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/libmexit002.cpp new file mode 100644 index 00000000000..6aa41f0e9b2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/libmexit002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "mexit002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/mexit002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/mexit002.c deleted file mode 100644 index 769d23deb6e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/mexit002.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls_sig; - char *name; - char *sig; - jlocation loc; -} exit_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static size_t eventsExpected = 0; -static size_t eventsCount = 0; -static exit_info exits[] = { - {"Lnsk/jvmti/MethodExit/mexit002a;", "chain", "()V", -1}, - {"Lnsk/jvmti/MethodExit/mexit002a;", "dummy", "()V", 3} -}; - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jboolean was_poped_by_exc, jvalue return_value) { - jvmtiError err; - char *cls_sig, *name, *sig, *generic; - jclass cls; - jmethodID mid; - jlocation loc; - char buffer[32]; - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &cls_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (cls_sig != NULL && - strcmp(cls_sig, "Lnsk/jvmti/MethodExit/mexit002a;") == 0) { - if (printdump == JNI_TRUE) { - printf(">>> retrieving method exit info ...\n"); - } - err = (*jvmti_env)->GetMethodName(jvmti_env, method, - &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thr, 0, &mid, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> class: \"%s\"\n", cls_sig); - printf(">>> method: \"%s%s\"\n", name, sig); - printf(">>> location: %s\n", jlong_to_string(loc, buffer)); - printf(">>> ... done\n"); - } - if (eventsCount < sizeof(exits)/sizeof(exit_info)) { - if (cls_sig == NULL || - strcmp(cls_sig, exits[eventsCount].cls_sig) != 0) { - printf("(exit#%" PRIuPTR ") wrong class: \"%s\"", - eventsCount, cls_sig); - printf(", expected: \"%s\"\n", exits[eventsCount].cls_sig); - result = STATUS_FAILED; - } - if (name == NULL || - strcmp(name, exits[eventsCount].name) != 0) { - printf("(exit#%" PRIuPTR ") wrong method name: \"%s\"", - eventsCount, name); - printf(", expected: \"%s\"\n", exits[eventsCount].name); - result = STATUS_FAILED; - } - if (sig == NULL || - strcmp(sig, exits[eventsCount].sig) != 0) { - printf("(exit#%" PRIuPTR ") wrong method sig: \"%s\"", - eventsCount, sig); - printf(", expected: \"%s\"\n", exits[eventsCount].sig); - result = STATUS_FAILED; - } - if (loc != exits[eventsCount].loc) { - printf("(exit#%" PRIuPTR ") wrong location: %s", - eventsCount, jlong_to_string(loc, buffer)); - printf(", expected: %s\n", - jlong_to_string(exits[eventsCount].loc, buffer)); - result = STATUS_FAILED; - } - } else { - printf("Unexpected method exit catched:"); - printf(" class: \"%s\"\n", cls_sig); - printf(" method: \"%s%s\"\n", name, sig); - printf(" location: %s\n", jlong_to_string(loc, buffer)); - result = STATUS_FAILED; - } - eventsCount++; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_mexit002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_mexit002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_mexit002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: MethodExit event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_MethodExit_mexit002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jclass clz; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_generate_method_exit_events) { - return result; - } - - clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/MethodExit/mexit002a")); - if (clz == NULL) { - printf("Failed to find class \"mexit002a\"!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clz), - "dummy", "()V"); - if (mid == NULL) { - printf("Failed to get method \"dummy\"!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, NULL); - if (err == JVMTI_ERROR_NONE) { - eventsExpected = sizeof(exits)/sizeof(exit_info); - } else { - printf("Failed to enable JVMTI_EVENT_METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, clz), mid); - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_EXIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (eventsCount != eventsExpected) { - printf("Wrong number of method exit events: %" PRIuPTR ", expected: %" PRIuPTR "\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_MethodExit_mexit002a_chain(JNIEnv *env, jclass cls) { - if (printdump == JNI_TRUE) { - printf(">>> about to exit method chain ...\n"); - } -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/mexit002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/mexit002.cpp new file mode 100644 index 00000000000..9cc694c4aa7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodExit/mexit002/mexit002.cpp @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls_sig; + const char *name; + const char *sig; + jlocation loc; +} exit_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static size_t eventsExpected = 0; +static size_t eventsCount = 0; +static exit_info exits[] = { + {"Lnsk/jvmti/MethodExit/mexit002a;", "chain", "()V", -1}, + {"Lnsk/jvmti/MethodExit/mexit002a;", "dummy", "()V", 3} +}; + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jboolean was_poped_by_exc, jvalue return_value) { + jvmtiError err; + char *cls_sig, *name, *sig, *generic; + jclass cls; + jmethodID mid; + jlocation loc; + char buffer[32]; + + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, &cls_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (cls_sig != NULL && + strcmp(cls_sig, "Lnsk/jvmti/MethodExit/mexit002a;") == 0) { + if (printdump == JNI_TRUE) { + printf(">>> retrieving method exit info ...\n"); + } + err = jvmti_env->GetMethodName(method, + &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetFrameLocation(thr, 0, &mid, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> class: \"%s\"\n", cls_sig); + printf(">>> method: \"%s%s\"\n", name, sig); + printf(">>> location: %s\n", jlong_to_string(loc, buffer)); + printf(">>> ... done\n"); + } + if (eventsCount < sizeof(exits)/sizeof(exit_info)) { + if (cls_sig == NULL || + strcmp(cls_sig, exits[eventsCount].cls_sig) != 0) { + printf("(exit#%" PRIuPTR ") wrong class: \"%s\"", + eventsCount, cls_sig); + printf(", expected: \"%s\"\n", exits[eventsCount].cls_sig); + result = STATUS_FAILED; + } + if (name == NULL || + strcmp(name, exits[eventsCount].name) != 0) { + printf("(exit#%" PRIuPTR ") wrong method name: \"%s\"", + eventsCount, name); + printf(", expected: \"%s\"\n", exits[eventsCount].name); + result = STATUS_FAILED; + } + if (sig == NULL || + strcmp(sig, exits[eventsCount].sig) != 0) { + printf("(exit#%" PRIuPTR ") wrong method sig: \"%s\"", + eventsCount, sig); + printf(", expected: \"%s\"\n", exits[eventsCount].sig); + result = STATUS_FAILED; + } + if (loc != exits[eventsCount].loc) { + printf("(exit#%" PRIuPTR ") wrong location: %s", + eventsCount, jlong_to_string(loc, buffer)); + printf(", expected: %s\n", + jlong_to_string(exits[eventsCount].loc, buffer)); + result = STATUS_FAILED; + } + } else { + printf("Unexpected method exit catched:"); + printf(" class: \"%s\"\n", cls_sig); + printf(" method: \"%s%s\"\n", name, sig); + printf(" location: %s\n", jlong_to_string(loc, buffer)); + result = STATUS_FAILED; + } + eventsCount++; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_mexit002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_mexit002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_mexit002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: MethodExit event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_MethodExit_mexit002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jclass clz; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_generate_method_exit_events) { + return result; + } + + clz = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/MethodExit/mexit002a")); + if (clz == NULL) { + printf("Failed to find class \"mexit002a\"!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clz), + "dummy", "()V"); + if (mid == NULL) { + printf("Failed to get method \"dummy\"!\n"); + return STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, NULL); + if (err == JVMTI_ERROR_NONE) { + eventsExpected = sizeof(exits)/sizeof(exit_info); + } else { + printf("Failed to enable JVMTI_EVENT_METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, clz), mid); + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_EXIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (eventsCount != eventsExpected) { + printf("Wrong number of method exit events: %" PRIuPTR ", expected: %" PRIuPTR "\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_MethodExit_mexit002a_chain(JNIEnv *env, jclass cls) { + if (printdump == JNI_TRUE) { + printf(">>> about to exit method chain ...\n"); + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/libmcontenter001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/libmcontenter001.c deleted file mode 100644 index 3db18f14daa..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/libmcontenter001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "mcontenter001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/libmcontenter001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/libmcontenter001.cpp new file mode 100644 index 00000000000..b5602d4f3e9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/libmcontenter001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "mcontenter001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/mcontenter001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/mcontenter001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/mcontenter001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/mcontenter001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/libmcontentered001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/libmcontentered001.c deleted file mode 100644 index 9fcc97ba11c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/libmcontentered001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "mcontentered001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/libmcontentered001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/libmcontentered001.cpp new file mode 100644 index 00000000000..a566d674628 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/libmcontentered001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "mcontentered001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/mcontentered001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/mcontentered001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/mcontentered001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/mcontentered001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/libmonitorwait001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/libmonitorwait001.c deleted file mode 100644 index 0d52e245e19..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/libmonitorwait001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "monitorwait001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/libmonitorwait001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/libmonitorwait001.cpp new file mode 100644 index 00000000000..99327ad8e65 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/libmonitorwait001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "monitorwait001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/monitorwait001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/monitorwait001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/monitorwait001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/monitorwait001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/libmonitorwaited001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/libmonitorwaited001.c deleted file mode 100644 index 53842d3cb4d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/libmonitorwaited001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "monitorwaited001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/libmonitorwaited001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/libmonitorwaited001.cpp new file mode 100644 index 00000000000..555eddfac4e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/libmonitorwaited001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "monitorwaited001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/monitorwaited001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/monitorwaited001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/monitorwaited001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/monitorwaited001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/libnativemethbind001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/libnativemethbind001.c deleted file mode 100644 index 89947c25a72..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/libnativemethbind001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "nativemethbind001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/libnativemethbind001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/libnativemethbind001.cpp new file mode 100644 index 00000000000..47f913eeeb4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/libnativemethbind001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "nativemethbind001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/nativemethbind001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/nativemethbind001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/nativemethbind001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/nativemethbind001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/libnativemethbind002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/libnativemethbind002.c deleted file mode 100644 index fe21ffe893c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/libnativemethbind002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "nativemethbind002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/libnativemethbind002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/libnativemethbind002.cpp new file mode 100644 index 00000000000..8ae997f233e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/libnativemethbind002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "nativemethbind002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/nativemethbind002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/nativemethbind002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/nativemethbind002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/nativemethbind002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/libnativemethbind003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/libnativemethbind003.c deleted file mode 100644 index e7f9b9fcc3f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/libnativemethbind003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "nativemethbind003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/libnativemethbind003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/libnativemethbind003.cpp new file mode 100644 index 00000000000..dfdb6fa6bac --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/libnativemethbind003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "nativemethbind003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/nativemethbind003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/nativemethbind003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/nativemethbind003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/nativemethbind003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/libnativemethbind004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/libnativemethbind004.c deleted file mode 100644 index 2691372d30f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/libnativemethbind004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "nativemethbind004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/libnativemethbind004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/libnativemethbind004.cpp new file mode 100644 index 00000000000..12370c2fc6b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/libnativemethbind004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "nativemethbind004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/nativemethbind004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/nativemethbind004.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/nativemethbind004.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/nativemethbind004.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/libnframepop001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/libnframepop001.c deleted file mode 100644 index 50f6bdac252..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/libnframepop001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "nframepop001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/libnframepop001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/libnframepop001.cpp new file mode 100644 index 00000000000..b444e35ffba --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/libnframepop001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "nframepop001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/nframepop001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/nframepop001.c deleted file mode 100644 index 38c86a5609f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/nframepop001.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jmethodID mid1, mid2; - -static jthread currThread = NULL, popThread = NULL; -static jclass currClass = NULL, popClass = NULL; -static jmethodID currMethod = NULL, popMethod = NULL; -static jboolean currFlag = JNI_FALSE, popFlag = JNI_FALSE; -static jint currLoc = 0, popLoc = 0; - -void JNICALL -FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean wasPopedByException) { - jvmtiError err; - - popThread = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, - thread)); - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &popClass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - popClass = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, - popClass)); - - popMethod = method; - popFlag = wasPopedByException; - - err = (*jvmti_env)->GetLocalInt(jvmti_env, thread, 0, 1, &popLoc); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_access_local_variables) { - /* It is OK */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#pop) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL -ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - jvmtiError err; - - if (method == mid1 || method == mid2) { - currThread = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, - thread)); - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, - method, &currClass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - currClass = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, - currClass)); - - currMethod = method; - - err = (*jvmti_env)->GetLocalInt(jvmti_env, thread, 0, 1, &currLoc); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_access_local_variables) { - /* It is OK */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#catch) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (method == mid2) { - currFlag = JNI_TRUE; - } - - err = (*jvmti_env)->NotifyFramePop(jvmti_env, thread, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(NotifyFramePop#catch) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_nframepop001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_nframepop001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_nframepop001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_frame_pop_events && - caps.can_generate_exception_events) { - callbacks.ExceptionCatch = &ExceptionCatch; - callbacks.FramePop = &FramePop; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FramePop or ExceptionCatch event is not implemented\n"); - } - - if (!caps.can_access_local_variables) { - printf("Warning: GetLocalInt is not implemented\n"); - } - - if (!caps.can_suspend) { - printf("Warning: suspend/resume is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_NotifyFramePop_nframepop001_getMethIds(JNIEnv *env, jclass cl) { - jvmtiError err; - - if (caps.can_generate_frame_pop_events) { - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FRAME_POP, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - } - - mid1 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), - "meth01", "(I)V"); - if (mid1 == NULL) { - printf("Cannot find method \"meth01\"\n"); - result = STATUS_FAILED; - return; - } - - mid2 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), - "meth02", "(I)V"); - if (mid2 == NULL) { - printf("Cannot find method \"meth02\"\n"); - result = STATUS_FAILED; - return; - } - - if (caps.can_generate_exception_events) { - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_EXCEPTION_CATCH, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable EXCEPTION_CATCH event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_NotifyFramePop_nframepop001_setFramePopNotif(JNIEnv *env, - jclass cl, jthread thr) { - jvmtiError err; - - if (!caps.can_generate_frame_pop_events || !caps.can_suspend) { - return; - } - - err = (*jvmti)->SuspendThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(SuspendThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - currThread = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, thr)); - - currClass = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, - "nsk/jvmti/NotifyFramePop/nframepop001a")); - if (currClass == NULL) { - printf("Cannot find nsk.jvmti.NotifyFramePop.nframepop001a class!\n"); - result = STATUS_FAILED; - return; - } - currClass = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, currClass)); - - currMethod = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, currClass), - "run", "()V"); - if (currMethod == NULL) { - printf("Cannot find method \"run\"\n"); - result = STATUS_FAILED; - } - - err = (*jvmti)->GetLocalInt(jvmti, thr, 0, 1, &currLoc); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_access_local_variables) { - /* It is OK */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->NotifyFramePop(jvmti, thr, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(NotifyFramePop) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->ResumeThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(ResumeThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_NotifyFramePop_nframepop001_checkFrame(JNIEnv *env, - jclass cls, jint point) { - - if (!caps.can_generate_frame_pop_events) { - return; - } - - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, currThread), - popThread) != JNI_TRUE) { - printf("Point %d: thread is not the same as expected\n", point); - result = STATUS_FAILED; - } - - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, currClass), - popClass) != JNI_TRUE) { - printf("Point %d: class is not the same as expected\n", point); - result = STATUS_FAILED; - } - - if (currMethod != popMethod) { - printf("Point %d: method ID expected: 0x%p, actual: 0x%p\n", - point, currMethod, popMethod); - result = STATUS_FAILED; - } - - if (currFlag != popFlag) { - printf("Point %d: was_poped_by_exception expected: %d, actual: %d\n", - point, currFlag, popFlag); - result = STATUS_FAILED; - } - - if (currLoc != popLoc) { - printf("Point %d: local expected: %d, actual: %d\n", - point, currLoc, popLoc); - result = STATUS_FAILED; - } - - currThread = NULL; popThread = NULL; - currClass = NULL; popClass = NULL; - currMethod = NULL; popMethod = NULL; - currFlag = JNI_FALSE; popFlag = JNI_FALSE; - currLoc = 0; popLoc = 0; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_NotifyFramePop_nframepop001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/nframepop001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/nframepop001.cpp new file mode 100644 index 00000000000..2876e6acec5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/nframepop001.cpp @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jmethodID mid1, mid2; + +static jthread currThread = NULL, popThread = NULL; +static jclass currClass = NULL, popClass = NULL; +static jmethodID currMethod = NULL, popMethod = NULL; +static jboolean currFlag = JNI_FALSE, popFlag = JNI_FALSE; +static jint currLoc = 0, popLoc = 0; + +void JNICALL +FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean wasPopedByException) { + jvmtiError err; + + popThread = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, + thread)); + + err = jvmti_env->GetMethodDeclaringClass(method, &popClass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + popClass = (jclass) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, + popClass)); + + popMethod = method; + popFlag = wasPopedByException; + + err = jvmti_env->GetLocalInt(thread, 0, 1, &popLoc); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_access_local_variables) { + /* It is OK */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#pop) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL +ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + jvmtiError err; + + if (method == mid1 || method == mid2) { + currThread = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, + thread)); + + err = jvmti_env->GetMethodDeclaringClass( + method, &currClass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + currClass = (jclass) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, + currClass)); + + currMethod = method; + + err = jvmti_env->GetLocalInt(thread, 0, 1, &currLoc); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_access_local_variables) { + /* It is OK */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#catch) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (method == mid2) { + currFlag = JNI_TRUE; + } + + err = jvmti_env->NotifyFramePop(thread, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(NotifyFramePop#catch) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_nframepop001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_nframepop001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_nframepop001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_frame_pop_events && + caps.can_generate_exception_events) { + callbacks.ExceptionCatch = &ExceptionCatch; + callbacks.FramePop = &FramePop; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FramePop or ExceptionCatch event is not implemented\n"); + } + + if (!caps.can_access_local_variables) { + printf("Warning: GetLocalInt is not implemented\n"); + } + + if (!caps.can_suspend) { + printf("Warning: suspend/resume is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_NotifyFramePop_nframepop001_getMethIds(JNIEnv *env, jclass cl) { + jvmtiError err; + + if (caps.can_generate_frame_pop_events) { + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FRAME_POP, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + } + + mid1 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), + "meth01", "(I)V"); + if (mid1 == NULL) { + printf("Cannot find method \"meth01\"\n"); + result = STATUS_FAILED; + return; + } + + mid2 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cl), + "meth02", "(I)V"); + if (mid2 == NULL) { + printf("Cannot find method \"meth02\"\n"); + result = STATUS_FAILED; + return; + } + + if (caps.can_generate_exception_events) { + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_EXCEPTION_CATCH, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable EXCEPTION_CATCH event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_NotifyFramePop_nframepop001_setFramePopNotif(JNIEnv *env, + jclass cl, jthread thr) { + jvmtiError err; + + if (!caps.can_generate_frame_pop_events || !caps.can_suspend) { + return; + } + + err = jvmti->SuspendThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(SuspendThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + currThread = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, thr)); + + currClass = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/NotifyFramePop/nframepop001a")); + if (currClass == NULL) { + printf("Cannot find nsk.jvmti.NotifyFramePop.nframepop001a class!\n"); + result = STATUS_FAILED; + return; + } + currClass = (jclass) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, currClass)); + + currMethod = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, currClass), + "run", "()V"); + if (currMethod == NULL) { + printf("Cannot find method \"run\"\n"); + result = STATUS_FAILED; + } + + err = jvmti->GetLocalInt(thr, 0, 1, &currLoc); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_access_local_variables) { + /* It is OK */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->NotifyFramePop(thr, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(NotifyFramePop) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->ResumeThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(ResumeThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_NotifyFramePop_nframepop001_checkFrame(JNIEnv *env, + jclass cls, jint point) { + + if (!caps.can_generate_frame_pop_events) { + return; + } + + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, currThread), + popThread) != JNI_TRUE) { + printf("Point %d: thread is not the same as expected\n", point); + result = STATUS_FAILED; + } + + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, currClass), + popClass) != JNI_TRUE) { + printf("Point %d: class is not the same as expected\n", point); + result = STATUS_FAILED; + } + + if (currMethod != popMethod) { + printf("Point %d: method ID expected: 0x%p, actual: 0x%p\n", + point, currMethod, popMethod); + result = STATUS_FAILED; + } + + if (currFlag != popFlag) { + printf("Point %d: was_poped_by_exception expected: %d, actual: %d\n", + point, currFlag, popFlag); + result = STATUS_FAILED; + } + + if (currLoc != popLoc) { + printf("Point %d: local expected: %d, actual: %d\n", + point, currLoc, popLoc); + result = STATUS_FAILED; + } + + currThread = NULL; popThread = NULL; + currClass = NULL; popClass = NULL; + currMethod = NULL; popMethod = NULL; + currFlag = JNI_FALSE; popFlag = JNI_FALSE; + currLoc = 0; popLoc = 0; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_NotifyFramePop_nframepop001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/libnframepop002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/libnframepop002.c deleted file mode 100644 index 9810dfaeaaa..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/libnframepop002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "nframepop002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/libnframepop002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/libnframepop002.cpp new file mode 100644 index 00000000000..d4a1494b946 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/libnframepop002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "nframepop002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/nframepop002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/nframepop002.c deleted file mode 100644 index 514fa830796..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/nframepop002.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_nframepop002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_nframepop002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_nframepop002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_generate_frame_pop_events) { - printf("Warning: FramePop event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_NotifyFramePop_nframepop002_check(JNIEnv *env, - jclass cls, jthread thread) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->NotifyFramePop(jvmti, thread, 0); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_generate_frame_pop_events) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_OPAQUE_FRAME) { - printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/nframepop002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/nframepop002.cpp new file mode 100644 index 00000000000..ce0c1cd0520 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/nframepop002.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_nframepop002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_nframepop002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_nframepop002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_generate_frame_pop_events) { + printf("Warning: FramePop event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_NotifyFramePop_nframepop002_check(JNIEnv *env, + jclass cls, jthread thread) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->NotifyFramePop(thread, 0); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_generate_frame_pop_events) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_OPAQUE_FRAME) { + printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/libnframepop003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/libnframepop003.c deleted file mode 100644 index f98d4e0e305..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/libnframepop003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "nframepop003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/libnframepop003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/libnframepop003.cpp new file mode 100644 index 00000000000..7089cca150d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/libnframepop003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "nframepop003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/nframepop003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/nframepop003.c deleted file mode 100644 index ed81f201b1d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/nframepop003.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_nframepop003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_nframepop003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_nframepop003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_generate_frame_pop_events) { - printf("Warning: FramePop event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_NotifyFramePop_nframepop003_check(JNIEnv *env, - jclass cls, jthread thread) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->NotifyFramePop(jvmti, cls, 0); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_generate_frame_pop_events) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->NotifyFramePop(jvmti, thread, -1); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_generate_frame_pop_events) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { - printf("Error expected: JVMTI_ERROR_ILLEGAL_ARGUMENT,\n"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/nframepop003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/nframepop003.cpp new file mode 100644 index 00000000000..06457e0587e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/nframepop003.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_nframepop003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_nframepop003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_nframepop003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_generate_frame_pop_events) { + printf("Warning: FramePop event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_NotifyFramePop_nframepop003_check(JNIEnv *env, + jclass cls, jthread thread) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->NotifyFramePop(cls, 0); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_generate_frame_pop_events) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->NotifyFramePop(thread, -1); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_generate_frame_pop_events) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { + printf("Error expected: JVMTI_ERROR_ILLEGAL_ARGUMENT,\n"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/libobjfree001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/libobjfree001.c deleted file mode 100644 index b0ce84512c0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/libobjfree001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "objfree001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/libobjfree001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/libobjfree001.cpp new file mode 100644 index 00000000000..333c547e266 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/libobjfree001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "objfree001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/objfree001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/objfree001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/objfree001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree001/objfree001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/libobjfree002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/libobjfree002.c deleted file mode 100644 index 10840606f1e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/libobjfree002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "objfree002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/libobjfree002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/libobjfree002.cpp new file mode 100644 index 00000000000..c99e6fc861c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/libobjfree002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "objfree002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/objfree002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/objfree002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/objfree002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ObjectFree/objfree002/objfree002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/libpopframe001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/libpopframe001.c deleted file mode 100644 index f8b0014236b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/libpopframe001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "popframe001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/libpopframe001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/libpopframe001.cpp new file mode 100644 index 00000000000..608a3b48683 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/libpopframe001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "popframe001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/popframe001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/popframe001.c deleted file mode 100644 index b0b9233bc24..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/popframe001.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static int watch_ev = 0; /* ignore JVMTI events by default */ -static int gen_ev = 0; /* number of generated events */ -static int tot_result = PASSED; /* total result of the test */ - -static jrawMonitorID watch_ev_monitor; - -static void set_watch_ev(int value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - watch_ev = value; - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean wasPopedByException) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev) { - printf("#### FramePop event occurred ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, - jmethodID method, jboolean was_poped_by_exc, jvalue return_value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev) { - printf("#### MethodExit event occurred ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe001_suspThread(JNIEnv *env, - jclass cls, jint vrb, jobject susThr) { - jvmtiError err; - - if (!caps.can_pop_frame || !caps.can_suspend) { - return PASSED; - } - - if (vrb == 1) - printf(">>>>>>>> Invoke SuspendThread()\n"); - if ((err = ((*jvmti)->SuspendThread(jvmti, susThr))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call SuspendThread(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - return JNI_ERR; - } - if (vrb == 1) - printf("<<<<<<<< SuspendThread() is successfully done\n"); - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe001_resThread(JNIEnv *env, - jclass cls, jint vrb, jobject susThr) { - jvmtiError err; - - if (!caps.can_pop_frame || !caps.can_suspend) { - return PASSED; - } - - if (vrb == 1) - printf(">>>>>>>> Invoke ResumeThread()\n"); - if ((err = ((*jvmti)->ResumeThread(jvmti, susThr))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call ResumeThread(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - return JNI_ERR; - } - if (vrb == 1) - printf("<<<<<<<< ResumeThread() is successfully done\n"); - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe001_doPopFrame(JNIEnv *env, - jclass cls, jint vrb, jobject frameThr) { - jvmtiError err; - - if (!caps.can_pop_frame || !caps.can_suspend) { - return PASSED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, frameThr); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - tot_result = STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FRAME_POP, frameThr); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - tot_result = STATUS_FAILED; - } - - if (vrb == 1) - printf(">>>>>>>> Invoke PopFrame()\n"); - set_watch_ev(1); /* watch JVMTI events */ - - if ((err = ((*jvmti)->PopFrame(jvmti, frameThr))) != JVMTI_ERROR_NONE) { - printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", - err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - tot_result = STATUS_FAILED; - } - else if (vrb == 1) - printf("Check #1 PASSED: PopFrame() is successfully done\n"); - - set_watch_ev(0); /* ignore again JVMTI events */ - if (gen_ev) { - printf("TEST FAILED: %d JVMTI events were generated by the function PopFrame()\n", - gen_ev); - tot_result = STATUS_FAILED; - } else if (vrb == 1) - printf("Check #2 PASSED: No JVMTI events were generated by the function PopFrame()\n"); - - return(tot_result); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_popframe001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_popframe001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_popframe001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_pop_frame) { - printf("Warning: PopFrame is not implemented\n"); - return JNI_OK; - } - - if (!caps.can_suspend) { - printf("Warning: suspend/resume is not implemented\n"); - return JNI_OK; - } - - if (caps.can_generate_frame_pop_events && - caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - callbacks.FramePop = &FramePop; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FramePop or MethodExit event is not implemented\n"); - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "watch_ev_monitor", &watch_ev_monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/popframe001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/popframe001.cpp new file mode 100644 index 00000000000..0cac500e4ab --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe001/popframe001.cpp @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static int watch_ev = 0; /* ignore JVMTI events by default */ +static int gen_ev = 0; /* number of generated events */ +static int tot_result = PASSED; /* total result of the test */ + +static jrawMonitorID watch_ev_monitor; + +static void set_watch_ev(int value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + watch_ev = value; + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean wasPopedByException) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev) { + printf("#### FramePop event occurred ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, + jmethodID method, jboolean was_poped_by_exc, jvalue return_value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev) { + printf("#### MethodExit event occurred ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe001_suspThread(JNIEnv *env, + jclass cls, jint vrb, jobject susThr) { + jvmtiError err; + + if (!caps.can_pop_frame || !caps.can_suspend) { + return PASSED; + } + + if (vrb == 1) + printf(">>>>>>>> Invoke SuspendThread()\n"); + if ((err = (jvmti->SuspendThread(susThr))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call SuspendThread(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + return JNI_ERR; + } + if (vrb == 1) + printf("<<<<<<<< SuspendThread() is successfully done\n"); + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe001_resThread(JNIEnv *env, + jclass cls, jint vrb, jobject susThr) { + jvmtiError err; + + if (!caps.can_pop_frame || !caps.can_suspend) { + return PASSED; + } + + if (vrb == 1) + printf(">>>>>>>> Invoke ResumeThread()\n"); + if ((err = (jvmti->ResumeThread(susThr))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call ResumeThread(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + return JNI_ERR; + } + if (vrb == 1) + printf("<<<<<<<< ResumeThread() is successfully done\n"); + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe001_doPopFrame(JNIEnv *env, + jclass cls, jint vrb, jobject frameThr) { + jvmtiError err; + + if (!caps.can_pop_frame || !caps.can_suspend) { + return PASSED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, frameThr); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + tot_result = STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FRAME_POP, frameThr); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + tot_result = STATUS_FAILED; + } + + if (vrb == 1) + printf(">>>>>>>> Invoke PopFrame()\n"); + set_watch_ev(1); /* watch JVMTI events */ + + if ((err = (jvmti->PopFrame(frameThr))) != JVMTI_ERROR_NONE) { + printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", + err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + tot_result = STATUS_FAILED; + } + else if (vrb == 1) + printf("Check #1 PASSED: PopFrame() is successfully done\n"); + + set_watch_ev(0); /* ignore again JVMTI events */ + if (gen_ev) { + printf("TEST FAILED: %d JVMTI events were generated by the function PopFrame()\n", + gen_ev); + tot_result = STATUS_FAILED; + } else if (vrb == 1) + printf("Check #2 PASSED: No JVMTI events were generated by the function PopFrame()\n"); + + return(tot_result); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_popframe001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_popframe001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_popframe001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_pop_frame) { + printf("Warning: PopFrame is not implemented\n"); + return JNI_OK; + } + + if (!caps.can_suspend) { + printf("Warning: suspend/resume is not implemented\n"); + return JNI_OK; + } + + if (caps.can_generate_frame_pop_events && + caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + callbacks.FramePop = &FramePop; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FramePop or MethodExit event is not implemented\n"); + } + + err = jvmti->CreateRawMonitor("watch_ev_monitor", &watch_ev_monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/libpopframe002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/libpopframe002.c deleted file mode 100644 index 20f93aa8584..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/libpopframe002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "popframe002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/libpopframe002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/libpopframe002.cpp new file mode 100644 index 00000000000..239b4d3025e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/libpopframe002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "popframe002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/popframe002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/popframe002.c deleted file mode 100644 index 0b134623861..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/popframe002.c +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static int watch_ev = 0; /* ignore JVMTI events by default */ -static int gen_ev = 0; /* number of generated events */ -static int tot_result = PASSED; /* total result of the test */ - -static jrawMonitorID watch_ev_monitor; - -static void set_watch_ev(int value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - watch_ev = value; - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean wasPopedByException) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev) { - printf("#### FramePop event occurred ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, - jmethodID method, jboolean was_poped_by_exc, jvalue return_value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev) { - printf("#### MethodExit event occurred ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe002_doPopFrame(JNIEnv *env, - jclass cls, jint t_case, jobject frameThr) { - jvmtiError err; - - if (!caps.can_pop_frame) { - return PASSED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, frameThr); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - tot_result = STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FRAME_POP, frameThr); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - tot_result = STATUS_FAILED; - } - - switch(t_case) { -/* NULL pointer to the thread in debug mode */ - case 1: - printf("\nInvoke PopFrame() with NULL pointer to a thread...\n"); - fflush(stdout); - // fallthrough -/* NULL pointer to the thread */ - case 0: - set_watch_ev(1); /* watch JVMTI events */ - err = ((*jvmti)->PopFrame(jvmti, NULL)); /* explode the bomb */ - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", - err, TranslateError(err)); - printf("\tBut it should return the error JVMTI_ERROR_INVALID_THREAD.\n"); - tot_result = STATUS_FAILED; - } - break; -/* invalid thread in debug mode */ - case 3: - printf("\nInvoke PopFrame() for an invalid thread...\n"); - fflush(stdout); - // fallthrough -/* invalid thread */ - case 2: - set_watch_ev(1); /* watch JVMTI events */ - err = ((*jvmti)->PopFrame(jvmti, cls)); /* explode the bomb */ - set_watch_ev(0); /* ignore again JVMTI events */ - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", - err, TranslateError(err)); - printf("\tBut it should return the error JVMTI_ERROR_INVALID_THREAD.\n"); - tot_result = STATUS_FAILED; - } - break; -/* non suspended thread in debug mode */ - case 5: - printf("\nInvoke PopFrame() for a non suspended thread...\n"); - fflush(stdout); - // fallthrough -/* non suspended thread */ - case 4: - set_watch_ev(1); /* watch JVMTI events */ - err = ((*jvmti)->PopFrame(jvmti, frameThr)); /* explode the bomb */ - set_watch_ev(0); /* ignore again JVMTI events */ - if (err != JVMTI_ERROR_THREAD_NOT_SUSPENDED) { - printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", - err, TranslateError(err)); - printf("\tBut it should return the error JVMTI_ERROR_THREAD_NOT_SUSPENDED.\n"); - tot_result = STATUS_FAILED; - } - break; - } - - if (gen_ev) { - printf("TEST FAILED: %d JVMTI events were generated by the function PopFrame()\n", - gen_ev); - tot_result = STATUS_FAILED; - } else if (t_case == 1 || t_case == 3 || t_case == 5) - printf("Check #%d PASSED: No JVMTI events were generated by the function PopFrame()\n", - t_case+1); - - set_watch_ev(0); /* ignore again JVMTI events */ - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_EXIT, frameThr); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - tot_result = STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_FRAME_POP, frameThr); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - tot_result = STATUS_FAILED; - } - - return(tot_result); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_popframe002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_popframe002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_popframe002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_pop_frame) { - printf("Warning: PopFrame is not implemented\n"); - return JNI_OK; - } - - if (caps.can_generate_frame_pop_events && - caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - callbacks.FramePop = &FramePop; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FramePop or MethodExit event is not implemented\n"); - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "watch_ev_monitor", &watch_ev_monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/popframe002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/popframe002.cpp new file mode 100644 index 00000000000..658a3eeab21 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002/popframe002.cpp @@ -0,0 +1,273 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static int watch_ev = 0; /* ignore JVMTI events by default */ +static int gen_ev = 0; /* number of generated events */ +static int tot_result = PASSED; /* total result of the test */ + +static jrawMonitorID watch_ev_monitor; + +static void set_watch_ev(int value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + watch_ev = value; + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean wasPopedByException) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev) { + printf("#### FramePop event occurred ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, + jmethodID method, jboolean was_poped_by_exc, jvalue return_value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev) { + printf("#### MethodExit event occurred ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe002_doPopFrame(JNIEnv *env, + jclass cls, jint t_case, jobject frameThr) { + jvmtiError err; + + if (!caps.can_pop_frame) { + return PASSED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, frameThr); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + tot_result = STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FRAME_POP, frameThr); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + tot_result = STATUS_FAILED; + } + + switch(t_case) { +/* NULL pointer to the thread in debug mode */ + case 1: + printf("\nInvoke PopFrame() with NULL pointer to a thread...\n"); + fflush(stdout); + // fallthrough +/* NULL pointer to the thread */ + case 0: + set_watch_ev(1); /* watch JVMTI events */ + err = (jvmti->PopFrame(NULL)); /* explode the bomb */ + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", + err, TranslateError(err)); + printf("\tBut it should return the error JVMTI_ERROR_INVALID_THREAD.\n"); + tot_result = STATUS_FAILED; + } + break; +/* invalid thread in debug mode */ + case 3: + printf("\nInvoke PopFrame() for an invalid thread...\n"); + fflush(stdout); + // fallthrough +/* invalid thread */ + case 2: + set_watch_ev(1); /* watch JVMTI events */ + err = (jvmti->PopFrame(cls)); /* explode the bomb */ + set_watch_ev(0); /* ignore again JVMTI events */ + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", + err, TranslateError(err)); + printf("\tBut it should return the error JVMTI_ERROR_INVALID_THREAD.\n"); + tot_result = STATUS_FAILED; + } + break; +/* non suspended thread in debug mode */ + case 5: + printf("\nInvoke PopFrame() for a non suspended thread...\n"); + fflush(stdout); + // fallthrough +/* non suspended thread */ + case 4: + set_watch_ev(1); /* watch JVMTI events */ + err = (jvmti->PopFrame(frameThr)); /* explode the bomb */ + set_watch_ev(0); /* ignore again JVMTI events */ + if (err != JVMTI_ERROR_THREAD_NOT_SUSPENDED) { + printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", + err, TranslateError(err)); + printf("\tBut it should return the error JVMTI_ERROR_THREAD_NOT_SUSPENDED.\n"); + tot_result = STATUS_FAILED; + } + break; + } + + if (gen_ev) { + printf("TEST FAILED: %d JVMTI events were generated by the function PopFrame()\n", + gen_ev); + tot_result = STATUS_FAILED; + } else if (t_case == 1 || t_case == 3 || t_case == 5) + printf("Check #%d PASSED: No JVMTI events were generated by the function PopFrame()\n", + t_case+1); + + set_watch_ev(0); /* ignore again JVMTI events */ + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_EXIT, frameThr); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + tot_result = STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_FRAME_POP, frameThr); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + tot_result = STATUS_FAILED; + } + + return(tot_result); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_popframe002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_popframe002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_popframe002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_pop_frame) { + printf("Warning: PopFrame is not implemented\n"); + return JNI_OK; + } + + if (caps.can_generate_frame_pop_events && + caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + callbacks.FramePop = &FramePop; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FramePop or MethodExit event is not implemented\n"); + } + + err = jvmti->CreateRawMonitor("watch_ev_monitor", &watch_ev_monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/libpopframe003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/libpopframe003.c deleted file mode 100644 index 9403b186c26..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/libpopframe003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "popframe003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/libpopframe003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/libpopframe003.cpp new file mode 100644 index 00000000000..961218cacc6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/libpopframe003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "popframe003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/popframe003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/popframe003.c deleted file mode 100644 index 954132c7853..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/popframe003.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static int watch_ev = 0; /* ignore JVMTI events by default */ -static int gen_ev = 0; /* number of generated events */ -static int tot_result = PASSED; /* total result of the test */ - -static jrawMonitorID watch_ev_monitor; - -static void set_watch_ev(int value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - watch_ev = value; - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean wasPopedByException) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev) { - printf("#### FramePop event occurred ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, - jmethodID method, jboolean was_poped_by_exc, jvalue return_value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev) { - printf("#### MethodExit event occurred ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe003_suspThread(JNIEnv *env, - jclass cls, jint vrb, jobject susThr) { - jvmtiError err; - - if (!caps.can_pop_frame || !caps.can_suspend) { - return PASSED; - } - - if (vrb == 1) - printf(">>>>>>>> Invoke SuspendThread()\n"); - if ((err = ((*jvmti)->SuspendThread(jvmti, susThr))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call SuspendThread(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - return JNI_ERR; - } - if (vrb == 1) - printf("<<<<<<<< SuspendThread() is successfully done\n"); - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe003_resThread(JNIEnv *env, jclass cls, jint vrb, - jobject susThr) { - jvmtiError err; - - if (!caps.can_pop_frame || !caps.can_suspend) { - return PASSED; - } - - if (vrb == 1) - printf(">>>>>>>> Invoke ResumeThread()\n"); - if ((err = ((*jvmti)->ResumeThread(jvmti, susThr))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call ResumeThread(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - return JNI_ERR; - } - if (vrb == 1) - printf("<<<<<<<< ResumeThread() is successfully done\n"); - return PASSED; -} - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe003_doPopFrame(JNIEnv *env, jclass cls, jint vrb, - jobject frameThr) { - jvmtiError err; - - if (!caps.can_pop_frame || !caps.can_suspend) { - return PASSED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, frameThr); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - tot_result = STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FRAME_POP, frameThr); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - tot_result = STATUS_FAILED; - } - - if (vrb == 1) - printf(">>>>>>>> Invoke PopFrame()\n"); - set_watch_ev(1); /* watch JVMTI events */ - - if ((err = ((*jvmti)->PopFrame(jvmti, frameThr))) != JVMTI_ERROR_NONE) { - printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", - err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - tot_result = STATUS_FAILED; - } - else if (vrb == 1) - printf("Check #1 PASSED: PopFrame() is successfully done\n"); - - set_watch_ev(0); /* ignore again JVMTI events */ - if (gen_ev) { - printf("TEST FAILED: %d JVMTI events were generated by the function PopFrame()\n", - gen_ev); - tot_result = STATUS_FAILED; - } else if (vrb == 1) - printf("Check #2 PASSED: No JVMTI events were generated by the function PopFrame()\n"); - - return(tot_result); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_popframe003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_popframe003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_popframe003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_pop_frame) { - printf("Warning: PopFrame is not implemented\n"); - return JNI_OK; - } - - if (!caps.can_suspend) { - printf("Warning: suspend/resume is not implemented\n"); - return JNI_OK; - } - - if (caps.can_generate_frame_pop_events && - caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - callbacks.FramePop = &FramePop; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FramePop or MethodExit event is not implemented\n"); - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "watch_ev_monitor", &watch_ev_monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/popframe003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/popframe003.cpp new file mode 100644 index 00000000000..3864239f4f3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe003/popframe003.cpp @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static int watch_ev = 0; /* ignore JVMTI events by default */ +static int gen_ev = 0; /* number of generated events */ +static int tot_result = PASSED; /* total result of the test */ + +static jrawMonitorID watch_ev_monitor; + +static void set_watch_ev(int value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + watch_ev = value; + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean wasPopedByException) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev) { + printf("#### FramePop event occurred ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, + jmethodID method, jboolean was_poped_by_exc, jvalue return_value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev) { + printf("#### MethodExit event occurred ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe003_suspThread(JNIEnv *env, + jclass cls, jint vrb, jobject susThr) { + jvmtiError err; + + if (!caps.can_pop_frame || !caps.can_suspend) { + return PASSED; + } + + if (vrb == 1) + printf(">>>>>>>> Invoke SuspendThread()\n"); + if ((err = (jvmti->SuspendThread(susThr))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call SuspendThread(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + return JNI_ERR; + } + if (vrb == 1) + printf("<<<<<<<< SuspendThread() is successfully done\n"); + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe003_resThread(JNIEnv *env, jclass cls, jint vrb, + jobject susThr) { + jvmtiError err; + + if (!caps.can_pop_frame || !caps.can_suspend) { + return PASSED; + } + + if (vrb == 1) + printf(">>>>>>>> Invoke ResumeThread()\n"); + if ((err = (jvmti->ResumeThread(susThr))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call ResumeThread(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + return JNI_ERR; + } + if (vrb == 1) + printf("<<<<<<<< ResumeThread() is successfully done\n"); + return PASSED; +} + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe003_doPopFrame(JNIEnv *env, jclass cls, jint vrb, + jobject frameThr) { + jvmtiError err; + + if (!caps.can_pop_frame || !caps.can_suspend) { + return PASSED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, frameThr); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + tot_result = STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FRAME_POP, frameThr); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + tot_result = STATUS_FAILED; + } + + if (vrb == 1) + printf(">>>>>>>> Invoke PopFrame()\n"); + set_watch_ev(1); /* watch JVMTI events */ + + if ((err = (jvmti->PopFrame(frameThr))) != JVMTI_ERROR_NONE) { + printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", + err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + tot_result = STATUS_FAILED; + } + else if (vrb == 1) + printf("Check #1 PASSED: PopFrame() is successfully done\n"); + + set_watch_ev(0); /* ignore again JVMTI events */ + if (gen_ev) { + printf("TEST FAILED: %d JVMTI events were generated by the function PopFrame()\n", + gen_ev); + tot_result = STATUS_FAILED; + } else if (vrb == 1) + printf("Check #2 PASSED: No JVMTI events were generated by the function PopFrame()\n"); + + return(tot_result); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_popframe003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_popframe003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_popframe003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_pop_frame) { + printf("Warning: PopFrame is not implemented\n"); + return JNI_OK; + } + + if (!caps.can_suspend) { + printf("Warning: suspend/resume is not implemented\n"); + return JNI_OK; + } + + if (caps.can_generate_frame_pop_events && + caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + callbacks.FramePop = &FramePop; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FramePop or MethodExit event is not implemented\n"); + } + + err = jvmti->CreateRawMonitor("watch_ev_monitor", &watch_ev_monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/libpopframe004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/libpopframe004.c deleted file mode 100644 index c3989289cc1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/libpopframe004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "popframe004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/libpopframe004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/libpopframe004.cpp new file mode 100644 index 00000000000..05301ab59b3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/libpopframe004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "popframe004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/popframe004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/popframe004.c deleted file mode 100644 index 1a3b095120c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/popframe004.c +++ /dev/null @@ -1,321 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static int watch_ev = 0; /* ignore JVMTI events by default */ -static int gen_ev = 0; /* number of generated events */ -static int popDone = 0; /* 1- if PopFrame() is already done */ -static int tot_result = PASSED; /* total result of the test */ - -static jrawMonitorID watch_ev_monitor; - -static void set_watch_ev(int value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - watch_ev = value; - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean wasPopedByException) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev) { - printf("#### FramePop event occurred ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, - jmethodID method, jboolean was_poped_by_exc, jvalue return_value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev) { - printf("#### MethodExit event occurred ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -int suspThread(jint vrb, jobject susThr) { - jvmtiError err; - - if (!caps.can_pop_frame || !caps.can_suspend) { - return PASSED; - } - - if (vrb == 1) { - printf(">>>>>>>> Invoke SuspendThread()\n"); - fflush(stdout); - } - if ((err = ((*jvmti)->SuspendThread(jvmti, susThr))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call SuspendThread(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - return JNI_ERR; - } - if (vrb == 1) { - printf("<<<<<<<< SuspendThread() is successfully done\n"); - fflush(stdout); - } - return PASSED; -} - -int resThread(jint vrb, jobject susThr) { - jvmtiError err; - - if (!caps.can_pop_frame || !caps.can_suspend) { - return PASSED; - } - - if (vrb == 1) { - printf(">>>>>>>> Invoke ResumeThread()\n"); - fflush(stdout); - } - if ((err = ((*jvmti)->ResumeThread(jvmti, susThr))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call ResumeThread(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - return JNI_ERR; - } - if (vrb == 1) { - printf("<<<<<<<< ResumeThread() is successfully done\n"); - fflush(stdout); - } - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe004_doPopFrame(JNIEnv *env, jclass cls, jint t_case, - jobject frameThr) { - jvmtiError err; - - if (popDone) return PASSED; - - if (!caps.can_pop_frame || !caps.can_suspend) { - return PASSED; - } - - if (t_case <= 1) /* we are in a different thread */ - if (suspThread(t_case, frameThr) != PASSED) - return STATUS_FAILED; - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, frameThr); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - tot_result = STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FRAME_POP, frameThr); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - tot_result = STATUS_FAILED; - } - - if (t_case & 1) { - printf(">>>>>>>> Invoke PopFrame()\n"); - fflush(stdout); - } - set_watch_ev(1); /* watch JVMTI events */ - - if ((err = ((*jvmti)->PopFrame(jvmti, frameThr))) == JVMTI_ERROR_NONE) { - printf("Check #%d FAILED: PopFrame() was unexpectedly done\n", t_case); - tot_result = STATUS_FAILED; - } else if (err != JVMTI_ERROR_NO_MORE_FRAMES && - err != JVMTI_ERROR_OPAQUE_FRAME) { - printf("Check #%d FAILED: PopFrame() returned unexpected error %d: %s\n", - t_case, err, TranslateError(err)); - printf("\tFor more info about this error please refer to the JVMTI spec.\n"); - tot_result = STATUS_FAILED; - } else if (t_case & 1) { - printf("Check #%d PASSED: PopFrame() failed as expected with %d: %s\n", - t_case, err, TranslateError(err)); - fflush(stdout); - } - - set_watch_ev(0); /* ignore again JVMTI events */ - if (gen_ev) { - printf("TEST FAILED: %d JVMTI events were generated by the function PopFrame()\n", - gen_ev); - tot_result = STATUS_FAILED; - } else if (t_case & 1) { - printf("Check #%d PASSED: No JVMTI events were generated by the function PopFrame()\n", - t_case+1); - fflush(stdout); - } - - if (t_case <= 1) /* we are in a different thread */ - return resThread(t_case, frameThr); - else popDone = 1; /* stop looping */ - return PASSED; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_popframe004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_popframe004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_popframe004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_pop_frame) { - printf("Warning: PopFrame is not implemented\n"); - return JNI_OK; - } - - if (!caps.can_suspend) { - printf("Warning: suspend/resume is not implemented\n"); - return JNI_OK; - } - - if (caps.can_generate_frame_pop_events && - caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - callbacks.FramePop = &FramePop; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FramePop or MethodExit event is not implemented\n"); - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "watch_ev_monitor", &watch_ev_monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe004_getResult(JNIEnv *env, jclass cls) { - return (tot_result); -} - -void nativeMeth2(JNIEnv *env, jobject obj, jint vrb, - jobject frameThr) { - jclass cls = - JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, frameThr)); - jmethodID mid = NULL; - - if ((mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "activeMethod", "()V")) == NULL) { - printf("TEST FAILURE: nativeMeth2(): Unable to get method ID\n"); - tot_result = STATUS_FAILED; - return; - } - if (vrb ==1) { - printf("nativeMeth2(): calling the Java activeMethod()\n"); - fflush(stdout); - } - JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG(env, frameThr), mid); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_PopFrame_popframe004_nativeMeth(JNIEnv *env, jobject obj, jint vrb, - jobject frameThr) { - if (vrb ==1) { - printf("nativeMeth(): calling the native nativeMeth2()\n"); - fflush(stdout); - } - nativeMeth2(env, obj, vrb, frameThr); -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/popframe004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/popframe004.cpp new file mode 100644 index 00000000000..8d041685c8c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe004/popframe004.cpp @@ -0,0 +1,321 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static int watch_ev = 0; /* ignore JVMTI events by default */ +static int gen_ev = 0; /* number of generated events */ +static int popDone = 0; /* 1- if PopFrame() is already done */ +static int tot_result = PASSED; /* total result of the test */ + +static jrawMonitorID watch_ev_monitor; + +static void set_watch_ev(int value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + watch_ev = value; + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean wasPopedByException) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev) { + printf("#### FramePop event occurred ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, + jmethodID method, jboolean was_poped_by_exc, jvalue return_value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev) { + printf("#### MethodExit event occurred ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +int suspThread(jint vrb, jobject susThr) { + jvmtiError err; + + if (!caps.can_pop_frame || !caps.can_suspend) { + return PASSED; + } + + if (vrb == 1) { + printf(">>>>>>>> Invoke SuspendThread()\n"); + fflush(stdout); + } + if ((err = (jvmti->SuspendThread(susThr))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call SuspendThread(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + return JNI_ERR; + } + if (vrb == 1) { + printf("<<<<<<<< SuspendThread() is successfully done\n"); + fflush(stdout); + } + return PASSED; +} + +int resThread(jint vrb, jobject susThr) { + jvmtiError err; + + if (!caps.can_pop_frame || !caps.can_suspend) { + return PASSED; + } + + if (vrb == 1) { + printf(">>>>>>>> Invoke ResumeThread()\n"); + fflush(stdout); + } + if ((err = (jvmti->ResumeThread(susThr))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call ResumeThread(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + return JNI_ERR; + } + if (vrb == 1) { + printf("<<<<<<<< ResumeThread() is successfully done\n"); + fflush(stdout); + } + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe004_doPopFrame(JNIEnv *env, jclass cls, jint t_case, + jobject frameThr) { + jvmtiError err; + + if (popDone) return PASSED; + + if (!caps.can_pop_frame || !caps.can_suspend) { + return PASSED; + } + + if (t_case <= 1) /* we are in a different thread */ + if (suspThread(t_case, frameThr) != PASSED) + return STATUS_FAILED; + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, frameThr); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + tot_result = STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FRAME_POP, frameThr); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + tot_result = STATUS_FAILED; + } + + if (t_case & 1) { + printf(">>>>>>>> Invoke PopFrame()\n"); + fflush(stdout); + } + set_watch_ev(1); /* watch JVMTI events */ + + if ((err = (jvmti->PopFrame(frameThr))) == JVMTI_ERROR_NONE) { + printf("Check #%d FAILED: PopFrame() was unexpectedly done\n", t_case); + tot_result = STATUS_FAILED; + } else if (err != JVMTI_ERROR_NO_MORE_FRAMES && + err != JVMTI_ERROR_OPAQUE_FRAME) { + printf("Check #%d FAILED: PopFrame() returned unexpected error %d: %s\n", + t_case, err, TranslateError(err)); + printf("\tFor more info about this error please refer to the JVMTI spec.\n"); + tot_result = STATUS_FAILED; + } else if (t_case & 1) { + printf("Check #%d PASSED: PopFrame() failed as expected with %d: %s\n", + t_case, err, TranslateError(err)); + fflush(stdout); + } + + set_watch_ev(0); /* ignore again JVMTI events */ + if (gen_ev) { + printf("TEST FAILED: %d JVMTI events were generated by the function PopFrame()\n", + gen_ev); + tot_result = STATUS_FAILED; + } else if (t_case & 1) { + printf("Check #%d PASSED: No JVMTI events were generated by the function PopFrame()\n", + t_case+1); + fflush(stdout); + } + + if (t_case <= 1) /* we are in a different thread */ + return resThread(t_case, frameThr); + else popDone = 1; /* stop looping */ + return PASSED; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_popframe004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_popframe004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_popframe004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_pop_frame) { + printf("Warning: PopFrame is not implemented\n"); + return JNI_OK; + } + + if (!caps.can_suspend) { + printf("Warning: suspend/resume is not implemented\n"); + return JNI_OK; + } + + if (caps.can_generate_frame_pop_events && + caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + callbacks.FramePop = &FramePop; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FramePop or MethodExit event is not implemented\n"); + } + + err = jvmti->CreateRawMonitor("watch_ev_monitor", &watch_ev_monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe004_getResult(JNIEnv *env, jclass cls) { + return (tot_result); +} + +void nativeMeth2(JNIEnv *env, jobject obj, jint vrb, + jobject frameThr) { + jclass cls = + JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, frameThr)); + jmethodID mid = NULL; + + if ((mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "activeMethod", "()V")) == NULL) { + printf("TEST FAILURE: nativeMeth2(): Unable to get method ID\n"); + tot_result = STATUS_FAILED; + return; + } + if (vrb ==1) { + printf("nativeMeth2(): calling the Java activeMethod()\n"); + fflush(stdout); + } + JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG(env, frameThr), mid); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_PopFrame_popframe004_nativeMeth(JNIEnv *env, jobject obj, jint vrb, + jobject frameThr) { + if (vrb ==1) { + printf("nativeMeth(): calling the native nativeMeth2()\n"); + fflush(stdout); + } + nativeMeth2(env, obj, vrb, frameThr); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/libpopframe005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/libpopframe005.c deleted file mode 100644 index 6fc7ea26c09..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/libpopframe005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "popframe005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/libpopframe005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/libpopframe005.cpp new file mode 100644 index 00000000000..e1703577953 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/libpopframe005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "popframe005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/popframe005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/popframe005.c deleted file mode 100644 index 1834e59f2f1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/popframe005.c +++ /dev/null @@ -1,388 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include -#include "JVMTITools.h" - -// Deallocate memory region allocated by VM -#define DEALLOCATE(p) \ - if (p != NULL) \ - if (!NSK_JVMTI_VERIFY( \ - NSK_CPP_STUB2( \ - Deallocate \ - , jvmti \ - , p \ - ))) \ - { \ - NSK_COMPLAIN0("Failed to deallocate: ##p##\n"); \ - } - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static int watch_jvmti_events = 0; /* ignore JVMTI events by default */ -static volatile int number_of_generated_events = 0; /* number of generated events */ -static jboolean result = JNI_TRUE; /* total result of the test */ - -static jrawMonitorID watch_ev_monitor; - -static void set_watch_jvmti_events(int value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - watch_jvmti_events = value; - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -FramePop( - jvmtiEnv *jvmti_env - , JNIEnv *env - , jthread thread - , jmethodID method - , jboolean wasPopedByException - ) -{ - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_jvmti_events) { - NSK_COMPLAIN1("#### FramePop event occurred (%d) ####\n", method); - number_of_generated_events++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -MethodExit( - jvmtiEnv *jvmti_env - , JNIEnv *env - , jthread thread - , jmethodID method - , jboolean was_poped_by_exc - , jvalue return_value - ) -{ - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_jvmti_events) { - jvmtiThreadInfo thr_info; - char *class_signature; - char *entry_name; - char *entry_sig; - jclass klass; - - int failure = 1; - - do { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - GetThreadInfo - , jvmti - , thread - , &thr_info - ))) - { - break; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - GetMethodDeclaringClass - , jvmti - , method - , &klass - ))) - { - break; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4( - GetClassSignature - , jvmti - , klass - , &class_signature - , NULL - ))) - { - break; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5( - GetMethodName - , jvmti - , method - , &entry_name - , &entry_sig - , NULL - ))) - { - break; - } - - failure = 0; - NSK_COMPLAIN5("#### MethodExit event occurred: (tid: %d), thread: %s, %s %s %s\n" - , thread - , thr_info.name == NULL ? "" : thr_info.name - , class_signature - , entry_name - , entry_sig - ); - } while(0); - - if (failure) { - NSK_COMPLAIN1("#### MethodExit event occurred (tid: %d) ####\n" - , thread - ); - } - - DEALLOCATE((unsigned char *)class_signature); - DEALLOCATE((unsigned char *)entry_name); - DEALLOCATE((unsigned char *)entry_sig); - - number_of_generated_events++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -jboolean suspendThread(jobject suspendedThread) { - if (!caps.can_pop_frame || !caps.can_suspend) { - return JNI_TRUE; - } - - NSK_DISPLAY0(">>>>>>>> Invoke SuspendThread()\n"); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - SuspendThread - , jvmti - , suspendedThread - ))) - { - return JNI_FALSE; - } - - NSK_DISPLAY0("<<<<<<<< SuspendThread() is successfully done\n"); - - return JNI_TRUE; -} - -jboolean resThread(jobject suspendedThread) { - if (!caps.can_pop_frame || !caps.can_suspend) { - return JNI_TRUE; - } - - NSK_DISPLAY0(">>>>>>>> Invoke ResumeThread()\n"); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - ResumeThread - , jvmti - , suspendedThread - ))) - { - return JNI_FALSE; - } - - NSK_DISPLAY0("<<<<<<<< ResumeThread() is successfully done\n"); - - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_PopFrame_popframe005_doPopFrame( - JNIEnv *env - , jclass klass - , jobject frameThr - ) -{ - if (!caps.can_pop_frame || !caps.can_suspend) { - return JNI_TRUE; - } - - if (suspendThread(frameThr) != JNI_TRUE) { - return JNI_FALSE; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4( - SetEventNotificationMode - , jvmti - , JVMTI_ENABLE - , JVMTI_EVENT_METHOD_EXIT - , frameThr - ))) - { - result = JNI_FALSE; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4( - SetEventNotificationMode - , jvmti - , JVMTI_ENABLE - , JVMTI_EVENT_FRAME_POP - , frameThr - ))) - { - result = JNI_FALSE; - } - - NSK_DISPLAY0(">>>>>>>> Invoke PopFrame()\n"); - - set_watch_jvmti_events(1); /* watch JVMTI events */ - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - PopFrame - , jvmti - , frameThr - ))) - { - result = JNI_FALSE; - } else { - NSK_DISPLAY0("Check #1 PASSED: PopFrame() is successfully done\n"); - } - - set_watch_jvmti_events(0); /* ignore again JVMTI events */ - - if (number_of_generated_events) { - NSK_COMPLAIN1("%d JVMTI events have been generated by the function PopFrame()\n" - , number_of_generated_events - ); - result = JNI_FALSE; - } else { - NSK_DISPLAY0("Check #2 PASSED: No JVMTI events have been generated by the function PopFrame()\n"); - } - - if (resThread(frameThr) != JNI_TRUE) - return JNI_FALSE; - - return result; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_popframe005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_popframe005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_popframe005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) -{ - jvmtiError err; - - if (!NSK_VERIFY( - nsk_jvmti_parseOptions(options) - )) - { - return JNI_ERR; - } - - if (!NSK_VERIFY( - (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL - )) - { - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - GetPotentialCapabilities - , jvmti - , &caps - ))) - { - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - AddCapabilities - , jvmti - , &caps - ))) - { - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - GetCapabilities - , jvmti - , &caps - ))) - { - return JNI_ERR; - } - - if (!caps.can_pop_frame) { - NSK_COMPLAIN0("Warning: PopFrame is not implemented\n"); - return JNI_OK; - } - - if (!caps.can_suspend) { - NSK_COMPLAIN0("Warning: suspend/resume is not implemented\n"); - return JNI_OK; - } - - if (caps.can_generate_frame_pop_events - && caps.can_generate_method_exit_events) - { - callbacks.MethodExit = &MethodExit; - callbacks.FramePop = &FramePop; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - SetEventCallbacks - , jvmti - , &callbacks - , sizeof(callbacks) - ))) - { - return JNI_ERR; - } - } else { - NSK_COMPLAIN0("Warning: FramePop or MethodExit event is not implemented\n"); - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "watch_ev_monitor", &watch_ev_monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/popframe005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/popframe005.cpp new file mode 100644 index 00000000000..4d38d4e1e96 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe005/popframe005.cpp @@ -0,0 +1,396 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Deallocate memory region allocated by VM +#define DEALLOCATE(p) \ + if (p != NULL) \ + if (!NSK_JVMTI_VERIFY( \ + NSK_CPP_STUB2( \ + Deallocate \ + , jvmti \ + , p \ + ))) \ + { \ + NSK_COMPLAIN0("Failed to deallocate: ##p##\n"); \ + } + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static int watch_jvmti_events = 0; /* ignore JVMTI events by default */ +static volatile int number_of_generated_events = 0; /* number of generated events */ +static jboolean result = JNI_TRUE; /* total result of the test */ + +static jrawMonitorID watch_ev_monitor; + +static void set_watch_jvmti_events(int value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + watch_jvmti_events = value; + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +FramePop( + jvmtiEnv *jvmti_env + , JNIEnv *env + , jthread thread + , jmethodID method + , jboolean wasPopedByException + ) +{ + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_jvmti_events) { + NSK_COMPLAIN1("#### FramePop event occurred (%d) ####\n", method); + number_of_generated_events++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +MethodExit( + jvmtiEnv *jvmti_env + , JNIEnv *env + , jthread thread + , jmethodID method + , jboolean was_poped_by_exc + , jvalue return_value + ) +{ + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_jvmti_events) { + jvmtiThreadInfo thr_info; + char *class_signature; + char *entry_name; + char *entry_sig; + jclass klass; + + int failure = 1; + + do { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + GetThreadInfo + , jvmti + , thread + , &thr_info + ))) + { + break; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + GetMethodDeclaringClass + , jvmti + , method + , &klass + ))) + { + break; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4( + GetClassSignature + , jvmti + , klass + , &class_signature + , NULL + ))) + { + break; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5( + GetMethodName + , jvmti + , method + , &entry_name + , &entry_sig + , NULL + ))) + { + break; + } + + failure = 0; + NSK_COMPLAIN5("#### MethodExit event occurred: (tid: %d), thread: %s, %s %s %s\n" + , thread + , thr_info.name == NULL ? "" : thr_info.name + , class_signature + , entry_name + , entry_sig + ); + } while(0); + + if (failure) { + NSK_COMPLAIN1("#### MethodExit event occurred (tid: %d) ####\n" + , thread + ); + } + + DEALLOCATE((unsigned char *)class_signature); + DEALLOCATE((unsigned char *)entry_name); + DEALLOCATE((unsigned char *)entry_sig); + + number_of_generated_events++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +jboolean suspendThread(jobject suspendedThread) { + if (!caps.can_pop_frame || !caps.can_suspend) { + return JNI_TRUE; + } + + NSK_DISPLAY0(">>>>>>>> Invoke SuspendThread()\n"); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + SuspendThread + , jvmti + , suspendedThread + ))) + { + return JNI_FALSE; + } + + NSK_DISPLAY0("<<<<<<<< SuspendThread() is successfully done\n"); + + return JNI_TRUE; +} + +jboolean resThread(jobject suspendedThread) { + if (!caps.can_pop_frame || !caps.can_suspend) { + return JNI_TRUE; + } + + NSK_DISPLAY0(">>>>>>>> Invoke ResumeThread()\n"); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + ResumeThread + , jvmti + , suspendedThread + ))) + { + return JNI_FALSE; + } + + NSK_DISPLAY0("<<<<<<<< ResumeThread() is successfully done\n"); + + return JNI_TRUE; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_PopFrame_popframe005_doPopFrame( + JNIEnv *env + , jclass klass + , jobject frameThr + ) +{ + if (!caps.can_pop_frame || !caps.can_suspend) { + return JNI_TRUE; + } + + if (suspendThread(frameThr) != JNI_TRUE) { + return JNI_FALSE; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4( + SetEventNotificationMode + , jvmti + , JVMTI_ENABLE + , JVMTI_EVENT_METHOD_EXIT + , frameThr + ))) + { + result = JNI_FALSE; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4( + SetEventNotificationMode + , jvmti + , JVMTI_ENABLE + , JVMTI_EVENT_FRAME_POP + , frameThr + ))) + { + result = JNI_FALSE; + } + + NSK_DISPLAY0(">>>>>>>> Invoke PopFrame()\n"); + + set_watch_jvmti_events(1); /* watch JVMTI events */ + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + PopFrame + , jvmti + , frameThr + ))) + { + result = JNI_FALSE; + } else { + NSK_DISPLAY0("Check #1 PASSED: PopFrame() is successfully done\n"); + } + + set_watch_jvmti_events(0); /* ignore again JVMTI events */ + + if (number_of_generated_events) { + NSK_COMPLAIN1("%d JVMTI events have been generated by the function PopFrame()\n" + , number_of_generated_events + ); + result = JNI_FALSE; + } else { + NSK_DISPLAY0("Check #2 PASSED: No JVMTI events have been generated by the function PopFrame()\n"); + } + + if (resThread(frameThr) != JNI_TRUE) + return JNI_FALSE; + + return result; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_popframe005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_popframe005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_popframe005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) +{ + jvmtiError err; + + if (!NSK_VERIFY( + nsk_jvmti_parseOptions(options) + )) + { + return JNI_ERR; + } + + if (!NSK_VERIFY( + (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL + )) + { + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + GetPotentialCapabilities + , jvmti + , &caps + ))) + { + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + AddCapabilities + , jvmti + , &caps + ))) + { + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + GetCapabilities + , jvmti + , &caps + ))) + { + return JNI_ERR; + } + + if (!caps.can_pop_frame) { + NSK_COMPLAIN0("Warning: PopFrame is not implemented\n"); + return JNI_OK; + } + + if (!caps.can_suspend) { + NSK_COMPLAIN0("Warning: suspend/resume is not implemented\n"); + return JNI_OK; + } + + if (caps.can_generate_frame_pop_events + && caps.can_generate_method_exit_events) + { + callbacks.MethodExit = &MethodExit; + callbacks.FramePop = &FramePop; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + SetEventCallbacks + , jvmti + , &callbacks + , sizeof(callbacks) + ))) + { + return JNI_ERR; + } + } else { + NSK_COMPLAIN0("Warning: FramePop or MethodExit event is not implemented\n"); + } + + err = jvmti->CreateRawMonitor("watch_ev_monitor", &watch_ev_monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/libpopframe006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/libpopframe006.c deleted file mode 100644 index c08edece2d2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/libpopframe006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "popframe006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/libpopframe006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/libpopframe006.cpp new file mode 100644 index 00000000000..c4992286041 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/libpopframe006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "popframe006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/popframe006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/popframe006.c deleted file mode 100644 index 4b2068e801e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/popframe006.c +++ /dev/null @@ -1,533 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls; - char *name; - char *sig; - jlocation loc; -} check_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jboolean wasFramePop = JNI_FALSE; -static jmethodID mid_run, mid_A, mid_B, mid_C; -static int bpCount = 0, bpExpected = 0; -static int stepCount = 0, stepExpected = 0; -static int popCount = 0, popExpected = 0; -static check_info checks[] = { - {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "run", "()V", 0}, - {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "A", "()V", 0}, - {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "B", "()V", 0}, - {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "A", "()V", 0}, - {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "B", "()V", 0}, - {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "C", "()V", 0}, - {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "C", "()V", 0}, - {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "B", "()V", 3}, - {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "A", "()V", 3} -}; - -void check(jvmtiEnv *jvmti_env, jmethodID mid, jlocation loc, int i) { - jvmtiError err; - jclass cls; - char *note, *sigClass, *name, *sig, *generic; - - switch (i) { - case 0: - bpCount++; - note = "bp"; - break; - case 1: case 2: case 3: case 4: case 5: - stepCount++; - note = "step"; - break; - case 6: case 7: case 8: - popCount++; - note = "pop"; - break; - default: - return; - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, mid, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(%s, GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - note, i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(%s, GetClassSignature#%d) unexpected error: %s (%d)\n", - note, i, TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(%s, GetMethodName#%d) unexpected error: %s (%d)\n", - note, i, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (sigClass == NULL || strcmp(sigClass, checks[i].cls) != 0) { - printf("(%s, %d) wrong class sig: \"%s\",\n", note, i, sigClass); - printf(" expected: \"%s\"\n", checks[i].cls); - result = STATUS_FAILED; - } - if (name == NULL || strcmp(name, checks[i].name) != 0) { - printf("(%s, %d) wrong method name: \"%s\",", note, i, name); - printf(" expected: \"%s\"\n", checks[i].name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, checks[i].sig) != 0) { - printf("(%s, %d) wrong method sig: \"%s\",", note, i, sig); - printf(" expected: \"%s\"\n", checks[i].sig); - result = STATUS_FAILED; - } - if (loc != checks[i].loc) { - printf("(%s, %d) wrong location: 0x%x%08x,", - note, i, (jint)(loc >> 32), (jint)loc); - printf(" expected: 0x%x\n", (jint)checks[i].loc); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> (%s, %d) \"%s.%s%s\"", note, i, sigClass, name, sig); - printf(", location: 0x%x%08x\n", (jint)(loc >> 32), (jint)loc); - } -} - - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (method != mid_run) { - printf("bp: don't know where we get called from"); - result = STATUS_FAILED; - return; - } - if (printdump == JNI_TRUE) { - printf(">>> breakpoint in run\n"); - } - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, mid_run, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - check(jvmti_env, method, location, 0); - - if (!caps.can_generate_single_step_events) { - return; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable single step: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - stepExpected = 3; - } - if (printdump == JNI_TRUE) { - printf(">>> about to step into A\n"); - } -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (method == mid_A) { - if (wasFramePop == JNI_FALSE) { - if (printdump == JNI_TRUE) { - printf(">>> step into A\n"); - } - check(jvmti_env, method, location, 1); - err = (*jvmti_env)->NotifyFramePop(jvmti_env, thread, 0); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_generate_frame_pop_events) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(NotifyFramePop#A) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - popExpected = popExpected + 1; - } - if (printdump == JNI_TRUE) { - printf(">>> about to step into B\n"); - } - } else { - if (printdump == JNI_TRUE) { - printf(">>> step into A after pop frame\n"); - } - check(jvmti_env, method, location, 3); - if (printdump == JNI_TRUE) { - printf(">>> about to step into B after pop\n"); - } - } - } else if (method == mid_B) { - if (wasFramePop == JNI_FALSE) { - if (printdump == JNI_TRUE) { - printf(">>> step into B\n"); - } - check(jvmti_env, method, location, 2); - if (!caps.can_pop_frame) { - return; - } - if (printdump == JNI_TRUE) { - printf(">>> about to pop frame\n"); - } - err = (*jvmti_env)->PopFrame(jvmti_env, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(PopFrame) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } else { - stepExpected = stepExpected + 2; - } - wasFramePop = JNI_TRUE; - if (printdump == JNI_TRUE) { - printf(">>> about to step into A after pop frame\n"); - } - } else { - if (printdump == JNI_TRUE) { - printf(">>> step into B after pop frame\n"); - } - check(jvmti_env, method, location, 4); - err = (*jvmti)->NotifyFramePop(jvmti, thread, 0); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_generate_frame_pop_events) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(NotifyFramePop#B) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - popExpected = popExpected + 1; - } - if (printdump == JNI_TRUE) { - printf(">>> about to step into C\n"); - } - } - } else if (method == mid_C) { - if (printdump == JNI_TRUE) { - printf(">>> step into C\n"); - } - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable single step: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - check(jvmti_env, method, location, 5); - err = (*jvmti)->NotifyFramePop(jvmti, thread, 0); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_generate_frame_pop_events) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(NotifyFramePop#C) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - popExpected = popExpected + 1; - } - if (printdump == JNI_TRUE) { - printf(">>> about to step out of C\n"); - } - } else { - printf("step: don't know where we get called from"); - result = STATUS_FAILED; - return; - } -} - -void JNICALL -FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jboolean wasPopedByException) { - jvmtiError err; - jmethodID mid; - jlocation loc; - - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thread, 0, &mid, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (method == mid_C) { - if (printdump == JNI_TRUE) { - printf(">>> step out of C\n"); - } - check(jvmti_env, mid, loc, 6); - if (printdump == JNI_TRUE) { - if (wasFramePop == JNI_FALSE) { - printf(">>> about to step out of A\n"); - } else { - printf(">>> about to step out of B\n"); - } - } - } else if (method == mid_B) { - if (printdump == JNI_TRUE) { - printf(">>> step out of B\n"); - } - check(jvmti_env, mid, loc, 7); - if (printdump == JNI_TRUE) { - printf(">>> about to step out of A\n"); - } - } else if (method == mid_A) { - if (printdump == JNI_TRUE) { - printf(">>> step out of A\n"); - } - check(jvmti_env, mid, loc, 8); - } else { - printf("pop: don't know where we get called from"); - result = STATUS_FAILED; - return; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_popframe006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_popframe006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_popframe006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_pop_frame) { - printf("Warning: PopFrame is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_single_step_events && - caps.can_generate_frame_pop_events) { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - callbacks.FramePop = &FramePop; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint, SingleStep or FramePop event are not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_PopFrame_popframe006_getReady(JNIEnv *env, - jclass cls, jthread thr) { - jvmtiError err; - jclass clazz; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_pop_frame) { - return; - } - - if (!caps.can_generate_breakpoint_events) { - return; - } - - clazz = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, thr)); - if (clazz == NULL) { - printf("Cannot get the class of thread object\n"); - result = STATUS_FAILED; - return; - } - - mid_run = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "run", "()V"); - if (mid_run == NULL) { - printf("Cannot find Method ID for method \"run\"\n"); - result = STATUS_FAILED; - return; - } - - mid_A = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clazz), - "A", "()V"); - if (mid_A == NULL) { - printf("Cannot find Method ID for method \"A\"\n"); - result = STATUS_FAILED; - return; - } - - mid_B = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clazz), - "B", "()V"); - if (mid_B == NULL) { - printf("Cannot find Method ID for method \"B\"\n"); - result = STATUS_FAILED; - return; - } - - mid_C = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clazz), - "C", "()V"); - if (mid_C == NULL) { - printf("Cannot find Method ID for method \"C\"\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, mid_run, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - bpExpected = 1; - } - - if (!caps.can_generate_frame_pop_events) { - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FRAME_POP, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe006_getRes(JNIEnv *env, jclass cls) { - if (printdump == JNI_TRUE) { - printf(">>> Total: %d breakpoint, %d steps, %d frame pops\n", - bpCount, stepCount, popCount); - } - if (bpCount != bpExpected) { - printf("Wrong number of breakpoint events: %d, expected: %d\n", - bpCount, bpExpected); - result = STATUS_FAILED; - } - if (stepCount != stepExpected) { - printf("Wrong number of step events: %d, expected: %d\n", - stepCount, stepExpected); - result = STATUS_FAILED; - } - if (popCount != popExpected) { - printf("Wrong number of frame pop events: %d, expected: %d\n", - popCount, popExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/popframe006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/popframe006.cpp new file mode 100644 index 00000000000..b6bc40ea5cc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe006/popframe006.cpp @@ -0,0 +1,534 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls; + const char *name; + const char *sig; + jlocation loc; +} check_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jboolean wasFramePop = JNI_FALSE; +static jmethodID mid_run, mid_A, mid_B, mid_C; +static int bpCount = 0, bpExpected = 0; +static int stepCount = 0, stepExpected = 0; +static int popCount = 0, popExpected = 0; +static check_info checks[] = { + {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "run", "()V", 0}, + {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "A", "()V", 0}, + {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "B", "()V", 0}, + {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "A", "()V", 0}, + {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "B", "()V", 0}, + {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "C", "()V", 0}, + {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "C", "()V", 0}, + {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "B", "()V", 3}, + {"Lnsk/jvmti/PopFrame/popframe006$TestThread;", "A", "()V", 3} +}; + +void check(jvmtiEnv *jvmti_env, jmethodID mid, jlocation loc, int i) { + jvmtiError err; + jclass cls; + const char *note; + char *sigClass, *name, *sig, *generic; + + switch (i) { + case 0: + bpCount++; + note = "bp"; + break; + case 1: case 2: case 3: case 4: case 5: + stepCount++; + note = "step"; + break; + case 6: case 7: case 8: + popCount++; + note = "pop"; + break; + default: + return; + } + + err = jvmti_env->GetMethodDeclaringClass(mid, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(%s, GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + note, i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti_env->GetClassSignature(cls, &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(%s, GetClassSignature#%d) unexpected error: %s (%d)\n", + note, i, TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(%s, GetMethodName#%d) unexpected error: %s (%d)\n", + note, i, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (sigClass == NULL || strcmp(sigClass, checks[i].cls) != 0) { + printf("(%s, %d) wrong class sig: \"%s\",\n", note, i, sigClass); + printf(" expected: \"%s\"\n", checks[i].cls); + result = STATUS_FAILED; + } + if (name == NULL || strcmp(name, checks[i].name) != 0) { + printf("(%s, %d) wrong method name: \"%s\",", note, i, name); + printf(" expected: \"%s\"\n", checks[i].name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, checks[i].sig) != 0) { + printf("(%s, %d) wrong method sig: \"%s\",", note, i, sig); + printf(" expected: \"%s\"\n", checks[i].sig); + result = STATUS_FAILED; + } + if (loc != checks[i].loc) { + printf("(%s, %d) wrong location: 0x%x%08x,", + note, i, (jint)(loc >> 32), (jint)loc); + printf(" expected: 0x%x\n", (jint)checks[i].loc); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> (%s, %d) \"%s.%s%s\"", note, i, sigClass, name, sig); + printf(", location: 0x%x%08x\n", (jint)(loc >> 32), (jint)loc); + } +} + + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (method != mid_run) { + printf("bp: don't know where we get called from"); + result = STATUS_FAILED; + return; + } + if (printdump == JNI_TRUE) { + printf(">>> breakpoint in run\n"); + } + err = jvmti_env->ClearBreakpoint(mid_run, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + check(jvmti_env, method, location, 0); + + if (!caps.can_generate_single_step_events) { + return; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable single step: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + stepExpected = 3; + } + if (printdump == JNI_TRUE) { + printf(">>> about to step into A\n"); + } +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (method == mid_A) { + if (wasFramePop == JNI_FALSE) { + if (printdump == JNI_TRUE) { + printf(">>> step into A\n"); + } + check(jvmti_env, method, location, 1); + err = jvmti_env->NotifyFramePop(thread, 0); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_generate_frame_pop_events) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(NotifyFramePop#A) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + popExpected = popExpected + 1; + } + if (printdump == JNI_TRUE) { + printf(">>> about to step into B\n"); + } + } else { + if (printdump == JNI_TRUE) { + printf(">>> step into A after pop frame\n"); + } + check(jvmti_env, method, location, 3); + if (printdump == JNI_TRUE) { + printf(">>> about to step into B after pop\n"); + } + } + } else if (method == mid_B) { + if (wasFramePop == JNI_FALSE) { + if (printdump == JNI_TRUE) { + printf(">>> step into B\n"); + } + check(jvmti_env, method, location, 2); + if (!caps.can_pop_frame) { + return; + } + if (printdump == JNI_TRUE) { + printf(">>> about to pop frame\n"); + } + err = jvmti_env->PopFrame(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(PopFrame) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } else { + stepExpected = stepExpected + 2; + } + wasFramePop = JNI_TRUE; + if (printdump == JNI_TRUE) { + printf(">>> about to step into A after pop frame\n"); + } + } else { + if (printdump == JNI_TRUE) { + printf(">>> step into B after pop frame\n"); + } + check(jvmti_env, method, location, 4); + err = jvmti->NotifyFramePop(thread, 0); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_generate_frame_pop_events) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(NotifyFramePop#B) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + popExpected = popExpected + 1; + } + if (printdump == JNI_TRUE) { + printf(">>> about to step into C\n"); + } + } + } else if (method == mid_C) { + if (printdump == JNI_TRUE) { + printf(">>> step into C\n"); + } + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable single step: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + check(jvmti_env, method, location, 5); + err = jvmti->NotifyFramePop(thread, 0); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_generate_frame_pop_events) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(NotifyFramePop#C) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + popExpected = popExpected + 1; + } + if (printdump == JNI_TRUE) { + printf(">>> about to step out of C\n"); + } + } else { + printf("step: don't know where we get called from"); + result = STATUS_FAILED; + return; + } +} + +void JNICALL +FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jboolean wasPopedByException) { + jvmtiError err; + jmethodID mid; + jlocation loc; + + err = jvmti_env->GetFrameLocation(thread, 0, &mid, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (method == mid_C) { + if (printdump == JNI_TRUE) { + printf(">>> step out of C\n"); + } + check(jvmti_env, mid, loc, 6); + if (printdump == JNI_TRUE) { + if (wasFramePop == JNI_FALSE) { + printf(">>> about to step out of A\n"); + } else { + printf(">>> about to step out of B\n"); + } + } + } else if (method == mid_B) { + if (printdump == JNI_TRUE) { + printf(">>> step out of B\n"); + } + check(jvmti_env, mid, loc, 7); + if (printdump == JNI_TRUE) { + printf(">>> about to step out of A\n"); + } + } else if (method == mid_A) { + if (printdump == JNI_TRUE) { + printf(">>> step out of A\n"); + } + check(jvmti_env, mid, loc, 8); + } else { + printf("pop: don't know where we get called from"); + result = STATUS_FAILED; + return; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_popframe006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_popframe006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_popframe006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_pop_frame) { + printf("Warning: PopFrame is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_single_step_events && + caps.can_generate_frame_pop_events) { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + callbacks.FramePop = &FramePop; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint, SingleStep or FramePop event are not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_PopFrame_popframe006_getReady(JNIEnv *env, + jclass cls, jthread thr) { + jvmtiError err; + jclass clazz; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_pop_frame) { + return; + } + + if (!caps.can_generate_breakpoint_events) { + return; + } + + clazz = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, thr)); + if (clazz == NULL) { + printf("Cannot get the class of thread object\n"); + result = STATUS_FAILED; + return; + } + + mid_run = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "run", "()V"); + if (mid_run == NULL) { + printf("Cannot find Method ID for method \"run\"\n"); + result = STATUS_FAILED; + return; + } + + mid_A = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clazz), + "A", "()V"); + if (mid_A == NULL) { + printf("Cannot find Method ID for method \"A\"\n"); + result = STATUS_FAILED; + return; + } + + mid_B = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clazz), + "B", "()V"); + if (mid_B == NULL) { + printf("Cannot find Method ID for method \"B\"\n"); + result = STATUS_FAILED; + return; + } + + mid_C = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clazz), + "C", "()V"); + if (mid_C == NULL) { + printf("Cannot find Method ID for method \"C\"\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetBreakpoint(mid_run, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + bpExpected = 1; + } + + if (!caps.can_generate_frame_pop_events) { + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FRAME_POP, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe006_getRes(JNIEnv *env, jclass cls) { + if (printdump == JNI_TRUE) { + printf(">>> Total: %d breakpoint, %d steps, %d frame pops\n", + bpCount, stepCount, popCount); + } + if (bpCount != bpExpected) { + printf("Wrong number of breakpoint events: %d, expected: %d\n", + bpCount, bpExpected); + result = STATUS_FAILED; + } + if (stepCount != stepExpected) { + printf("Wrong number of step events: %d, expected: %d\n", + stepCount, stepExpected); + result = STATUS_FAILED; + } + if (popCount != popExpected) { + printf("Wrong number of frame pop events: %d, expected: %d\n", + popCount, popExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/libpopframe007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/libpopframe007.c deleted file mode 100644 index 7269c50c702..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/libpopframe007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "popframe007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/libpopframe007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/libpopframe007.cpp new file mode 100644 index 00000000000..e9be2eb79cf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/libpopframe007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "popframe007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/popframe007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/popframe007.c deleted file mode 100644 index 31ae1b0d8e9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/popframe007.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID mid; - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (method != mid) { - printf("bp: don't know where we get called from"); - result = STATUS_FAILED; - return; - } - if (printdump == JNI_TRUE) { - printf(">>> breakpoint in C\n"); - } - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> about to pop to a native frame\n"); - } - err = (*jvmti_env)->PopFrame(jvmti_env, thread); - if (err != JVMTI_ERROR_OPAQUE_FRAME) { - printf("(PopFrame) error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_popframe007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_popframe007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_popframe007(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_pop_frame) { - printf("Warning: PopFrame is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_PopFrame_popframe007_getReady(JNIEnv *env, - jclass cls, jthread thr) { - jvmtiError err; - jclass clazz; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_pop_frame || !caps.can_generate_breakpoint_events) { - return; - } - - clazz = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, thr)); - if (clazz == NULL) { - printf("Cannot get class of the thread object\n"); - result = STATUS_FAILED; - return; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clazz), - "C", "()V"); - if (mid == NULL) { - printf("Cannot find Method ID for method \"C\"\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe007_getRes(JNIEnv *env, jclass cls) { - return result; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_PopFrame_popframe007_B(JNIEnv *env, jclass cls) { - if (mid != NULL) { - JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, cls), mid); - } -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/popframe007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/popframe007.cpp new file mode 100644 index 00000000000..43ecf430c62 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe007/popframe007.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID mid; + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (method != mid) { + printf("bp: don't know where we get called from"); + result = STATUS_FAILED; + return; + } + if (printdump == JNI_TRUE) { + printf(">>> breakpoint in C\n"); + } + err = jvmti_env->ClearBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> about to pop to a native frame\n"); + } + err = jvmti_env->PopFrame(thread); + if (err != JVMTI_ERROR_OPAQUE_FRAME) { + printf("(PopFrame) error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_popframe007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_popframe007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_popframe007(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_pop_frame) { + printf("Warning: PopFrame is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_PopFrame_popframe007_getReady(JNIEnv *env, + jclass cls, jthread thr) { + jvmtiError err; + jclass clazz; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_pop_frame || !caps.can_generate_breakpoint_events) { + return; + } + + clazz = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, thr)); + if (clazz == NULL) { + printf("Cannot get class of the thread object\n"); + result = STATUS_FAILED; + return; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, clazz), + "C", "()V"); + if (mid == NULL) { + printf("Cannot find Method ID for method \"C\"\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe007_getRes(JNIEnv *env, jclass cls) { + return result; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_PopFrame_popframe007_B(JNIEnv *env, jclass cls) { + if (mid != NULL) { + JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, cls), mid); + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/libpopframe008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/libpopframe008.c deleted file mode 100644 index 6d5a2aa75bf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/libpopframe008.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "popframe008.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/libpopframe008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/libpopframe008.cpp new file mode 100644 index 00000000000..5c8a89b5ca8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/libpopframe008.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "popframe008.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/popframe008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/popframe008.c deleted file mode 100644 index 6fc295696f2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/popframe008.c +++ /dev/null @@ -1,333 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *cls; - char *name; - char *sig; - jlocation loc; -} frame_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID midD = NULL; -static jmethodID midRun = NULL; -static int framesExpected = 0; -static int framesCount = 0; -static frame_info frames[] = { - {"Lnsk/jvmti/PopFrame/popframe008$TestThread;", "C", "()V", 1}, - {"Lnsk/jvmti/PopFrame/popframe008$TestThread;", "B", "()V", 1}, - {"Lnsk/jvmti/PopFrame/popframe008$TestThread;", "A", "()V", 1}, - {"Lnsk/jvmti/PopFrame/popframe008$TestThread;", "run", "()V", 1} -}; - -void check(jvmtiEnv *jvmti_env, jmethodID mid, jlocation loc, int i) { - jvmtiError err; - jclass cls; - char *sigClass, *name, *sig, *generic; - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, mid, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) { - printf("(%d) wrong class sig: \"%s\",\n", i, sigClass); - printf(" expected: \"%s\"\n", frames[i].cls); - result = STATUS_FAILED; - } - if (name == NULL || strcmp(name, frames[i].name) != 0) { - printf("(%d) wrong method name: \"%s\",", i, name); - printf(" expected: \"%s\"\n", frames[i].name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { - printf("(%d) wrong method sig: \"%s\",", i, sig); - printf(" expected: \"%s\"\n", frames[i].sig); - result = STATUS_FAILED; - } - if (loc != frames[i].loc) { - printf("(%d) wrong location: 0x%x%08x,", - i, (jint)(loc >> 32), (jint)loc); - printf(" expected: 0x%x\n", (jint)frames[i].loc); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> \"%s.%s%s\"", sigClass, name, sig); - printf(", location: 0x%x%08x\n", (jint)(loc >> 32), (jint)loc); - } -} - - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (method != midD) { - printf("bp: don't know where we get called from"); - result = STATUS_FAILED; - return; - } - if (printdump == JNI_TRUE) { - printf(">>> breakpoint in D\n"); - } - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, midD, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (caps.can_pop_frame) { - framesExpected = 4; - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable single step: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->PopFrame(jvmti_env, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(PopFrame) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - check(jvmti_env, method, location, framesCount); - framesCount++; - - if (method == midRun) { - if (printdump == JNI_TRUE) { - printf(">>> poped %d frames till method \"run()\"\n", - framesCount); - } - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable single step: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else { - err = (*jvmti_env)->PopFrame(jvmti_env, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(PopFrame) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_popframe008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_popframe008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_popframe008(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_pop_frame) { - printf("Warning: PopFrame is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_single_step_events) { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or SingleStep event are not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_PopFrame_popframe008_getReady(JNIEnv *env, - jclass cls, jthread thr) { - jvmtiError err; - jclass clazz; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_pop_frame || - !caps.can_generate_breakpoint_events || - !caps.can_generate_single_step_events) { - return; - } - - clazz = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, thr)); - if (clazz == NULL) { - printf("Cannot get class of the thread object\n"); - result = STATUS_FAILED; - return; - } - - midD = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), "D", "()V"); - if (midD == NULL) { - printf("Cannot get Method ID for method \"D\"\n"); - result = STATUS_FAILED; - return; - } - - midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "run", "()V"); - if (midRun == NULL) { - printf("Cannot get Method ID for method \"run\"\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, midD, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe008_getRes(JNIEnv *env, jclass cls) { - if (framesCount != framesExpected) { - printf("Wrong number of poped frames: %d, expected: %d\n", - framesCount, framesExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/popframe008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/popframe008.cpp new file mode 100644 index 00000000000..bc6d7a3759c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe008/popframe008.cpp @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *cls; + const char *name; + const char *sig; + jlocation loc; +} frame_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID midD = NULL; +static jmethodID midRun = NULL; +static int framesExpected = 0; +static int framesCount = 0; +static frame_info frames[] = { + {"Lnsk/jvmti/PopFrame/popframe008$TestThread;", "C", "()V", 1}, + {"Lnsk/jvmti/PopFrame/popframe008$TestThread;", "B", "()V", 1}, + {"Lnsk/jvmti/PopFrame/popframe008$TestThread;", "A", "()V", 1}, + {"Lnsk/jvmti/PopFrame/popframe008$TestThread;", "run", "()V", 1} +}; + +void check(jvmtiEnv *jvmti_env, jmethodID mid, jlocation loc, int i) { + jvmtiError err; + jclass cls; + char *sigClass, *name, *sig, *generic; + + err = jvmti_env->GetMethodDeclaringClass(mid, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti_env->GetClassSignature(cls, &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) { + printf("(%d) wrong class sig: \"%s\",\n", i, sigClass); + printf(" expected: \"%s\"\n", frames[i].cls); + result = STATUS_FAILED; + } + if (name == NULL || strcmp(name, frames[i].name) != 0) { + printf("(%d) wrong method name: \"%s\",", i, name); + printf(" expected: \"%s\"\n", frames[i].name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { + printf("(%d) wrong method sig: \"%s\",", i, sig); + printf(" expected: \"%s\"\n", frames[i].sig); + result = STATUS_FAILED; + } + if (loc != frames[i].loc) { + printf("(%d) wrong location: 0x%x%08x,", + i, (jint)(loc >> 32), (jint)loc); + printf(" expected: 0x%x\n", (jint)frames[i].loc); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> \"%s.%s%s\"", sigClass, name, sig); + printf(", location: 0x%x%08x\n", (jint)(loc >> 32), (jint)loc); + } +} + + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (method != midD) { + printf("bp: don't know where we get called from"); + result = STATUS_FAILED; + return; + } + if (printdump == JNI_TRUE) { + printf(">>> breakpoint in D\n"); + } + err = jvmti_env->ClearBreakpoint(midD, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (caps.can_pop_frame) { + framesExpected = 4; + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable single step: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->PopFrame(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(PopFrame) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + check(jvmti_env, method, location, framesCount); + framesCount++; + + if (method == midRun) { + if (printdump == JNI_TRUE) { + printf(">>> poped %d frames till method \"run()\"\n", + framesCount); + } + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable single step: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else { + err = jvmti_env->PopFrame(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(PopFrame) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_popframe008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_popframe008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_popframe008(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_pop_frame) { + printf("Warning: PopFrame is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_single_step_events) { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or SingleStep event are not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_PopFrame_popframe008_getReady(JNIEnv *env, + jclass cls, jthread thr) { + jvmtiError err; + jclass clazz; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_pop_frame || + !caps.can_generate_breakpoint_events || + !caps.can_generate_single_step_events) { + return; + } + + clazz = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, thr)); + if (clazz == NULL) { + printf("Cannot get class of the thread object\n"); + result = STATUS_FAILED; + return; + } + + midD = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), "D", "()V"); + if (midD == NULL) { + printf("Cannot get Method ID for method \"D\"\n"); + result = STATUS_FAILED; + return; + } + + midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "run", "()V"); + if (midRun == NULL) { + printf("Cannot get Method ID for method \"run\"\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetBreakpoint(midD, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe008_getRes(JNIEnv *env, jclass cls) { + if (framesCount != framesExpected) { + printf("Wrong number of poped frames: %d, expected: %d\n", + framesCount, framesExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/libpopframe009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/libpopframe009.c deleted file mode 100644 index dd0d251de7a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/libpopframe009.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "popframe009.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/libpopframe009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/libpopframe009.cpp new file mode 100644 index 00000000000..3f31ddee141 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/libpopframe009.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "popframe009.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/popframe009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/popframe009.c deleted file mode 100644 index 5c722913e50..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/popframe009.c +++ /dev/null @@ -1,613 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define WAIT_FOREVER ((jlong)(3600*1000)) - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jrawMonitorID breakpointLock = NULL; -static jrawMonitorID popFrameLock = NULL; -static jrawMonitorID suspendLock = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jboolean popDone = JNI_FALSE; -static jmethodID midCheckPoint = NULL; -static jmethodID midRun = NULL; -static int bpCount = 0; -static int framesCount = 0; - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (midCheckPoint != method) { - printf("bp: don't know where we get called from"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti_env)->RawMonitorEnter(jvmti_env, breakpointLock); - if (err != JVMTI_ERROR_NONE) { - printf("step: Cannot enter breakpointLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - bpCount++; - - if (printdump == JNI_TRUE) { - printf(">>> breakpoint %d\n", bpCount); - } - - err = (*jvmti_env)->RawMonitorWait(jvmti_env, breakpointLock, WAIT_FOREVER); - if (err != JVMTI_ERROR_NONE) { - printf("step: Cannot wait breakpointLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (bpCount == 2) { - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - - err = (*jvmti_env)->RawMonitorExit(jvmti_env, breakpointLock); - if (err != JVMTI_ERROR_NONE) { - printf("step: Cannot exit breakpointLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - framesCount++; - - if (method == midRun) { - popDone = JNI_TRUE; - if (printdump == JNI_TRUE) { - printf(">>> poped %d frames till \"run()\"\n", framesCount); - } - } - - err = (*jvmti_env)->RawMonitorEnter(jvmti_env, suspendLock); - if (err != JVMTI_ERROR_NONE) { - printf("step: Cannot enter suspendLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->RawMonitorEnter(jvmti_env, popFrameLock); - if (err != JVMTI_ERROR_NONE) { - printf("step: Cannot enter popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->RawMonitorNotify(jvmti_env, popFrameLock); - if (err != JVMTI_ERROR_NONE) { - printf("step: Cannot notify popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->RawMonitorExit(jvmti_env, popFrameLock); - if (err != JVMTI_ERROR_NONE) { - printf("step: Cannot exit popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->RawMonitorWait(jvmti_env, suspendLock, WAIT_FOREVER); - if (err != JVMTI_ERROR_NONE) { - printf("step: Cannot wait suspendLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->RawMonitorExit(jvmti_env, suspendLock); - if (err != JVMTI_ERROR_NONE) { - printf("step: Cannot exit suspendLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_popframe009(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_popframe009(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_popframe009(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_pop_frame) { - printf("Warning: PopFrame is not implemented\n"); - } - - if (!caps.can_suspend) { - printf("Warning: suspend/resume is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_single_step_events) { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or SingleStep event are not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_PopFrame_popframe009_getReady(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_pop_frame || !caps.can_suspend || - !caps.can_generate_breakpoint_events || - !caps.can_generate_single_step_events) { - return; - } - - midCheckPoint = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (midCheckPoint == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "Breakpoint Lock", &breakpointLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot create breakpointLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void popFrames(jthread thr) { - jvmtiError err; - - while (popDone != JNI_TRUE && result != STATUS_FAILED) { - err = (*jvmti)->PopFrame(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(PopFrame) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - break; - } - - err = (*jvmti)->ResumeThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(ResumeThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - break; - } - - err = (*jvmti)->RawMonitorWait(jvmti, popFrameLock, WAIT_FOREVER); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot wait popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorEnter(jvmti, suspendLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enter suspendLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->SuspendThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(SuspendThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorNotify(jvmti, suspendLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot notify suspendLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorExit(jvmti, suspendLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot exit suspendLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe009_check(JNIEnv *env, jclass cls, jthread thr) { - jvmtiError err; - jmethodID midFibonacci; - jclass clazz; - jmethodID method = NULL; - jlocation loc; - char *name, *sig, *generic; - jlong delayTime = 1; - int popCount = 0; - int i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_pop_frame || !caps.can_suspend || - !caps.can_generate_breakpoint_events || - !caps.can_generate_single_step_events) { - return result; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "Pop Frame Lock", &popFrameLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot create popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> waiting breakpoint 1\n"); - } - - while (bpCount < 1) { - err = (*jvmti)->RawMonitorEnter(jvmti, popFrameLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enter popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorWait(jvmti, popFrameLock, (jlong)delayTime); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot wait popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorExit(jvmti, popFrameLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot exit popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - - err = (*jvmti)->RawMonitorEnter(jvmti, breakpointLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enter breakpointLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorNotify(jvmti, breakpointLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot notify breakpointLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->SuspendThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(SuspendThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorExit(jvmti, breakpointLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot exit breakpointLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - midFibonacci = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "fibonacci", "(I)I"); - if (midFibonacci == NULL) { - printf("Cannot get method ID for method \"fibonacci\"\n"); - result = STATUS_FAILED; - } - - clazz = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, thr)); - if (clazz == NULL) { - printf("Cannot get class of thread object\n"); - return STATUS_FAILED; - } - - midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "run", "()V"); - if (midRun == NULL) { - printf("Cannot get method ID for \"run\"\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorEnter(jvmti, popFrameLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enter popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> catching method \"fibonacci\"\n"); - } - - for (i = 1; i < 10 && bpCount == 1; i++) { - err = (*jvmti)->GetFrameLocation(jvmti, thr, 0, &method, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - break; - } - - if (printdump == JNI_TRUE) { - (*jvmti)->GetMethodName(jvmti, method, &name, &sig, &generic); - printf(">>> %d: \"%s%s\"\n", i, name, sig); - } - - if (method == midFibonacci) break; - - err = (*jvmti)->ResumeThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(ResumeThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorWait(jvmti, popFrameLock, (jlong)delayTime); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot wait popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->SuspendThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(SuspendThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - - err = (*jvmti)->RawMonitorExit(jvmti, popFrameLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot exit popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (method == midFibonacci) { - framesCount = 0; - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thr); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable single step: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "Suspend Lock", &suspendLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot create suspendLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> popping frames\n"); - } - - err = (*jvmti)->RawMonitorEnter(jvmti, popFrameLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enter popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - popFrames(thr); - - err = (*jvmti)->RawMonitorExit(jvmti, popFrameLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot exit popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thr); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable single step: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else { - printf("Warning: method \"fibonacci\" was missed\n"); - } - - err = (*jvmti)->ResumeThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(ResumeThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> waiting breakpoint 2\n"); - } - - while (bpCount < 2) { - err = (*jvmti)->RawMonitorEnter(jvmti, popFrameLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enter popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorWait(jvmti, popFrameLock, (jlong)delayTime); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot wait popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorExit(jvmti, popFrameLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot exit popFrameLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - - err = (*jvmti)->RawMonitorEnter(jvmti, breakpointLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enter breakpointLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorNotify(jvmti, breakpointLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot notify breakpointLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorExit(jvmti, breakpointLock); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot exit breakpointLock: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/popframe009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/popframe009.cpp new file mode 100644 index 00000000000..3d59a7cf5c5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe009/popframe009.cpp @@ -0,0 +1,613 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define WAIT_FOREVER ((jlong)(3600*1000)) + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jrawMonitorID breakpointLock = NULL; +static jrawMonitorID popFrameLock = NULL; +static jrawMonitorID suspendLock = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jboolean popDone = JNI_FALSE; +static jmethodID midCheckPoint = NULL; +static jmethodID midRun = NULL; +static int bpCount = 0; +static int framesCount = 0; + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (midCheckPoint != method) { + printf("bp: don't know where we get called from"); + result = STATUS_FAILED; + return; + } + + err = jvmti_env->RawMonitorEnter(breakpointLock); + if (err != JVMTI_ERROR_NONE) { + printf("step: Cannot enter breakpointLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + bpCount++; + + if (printdump == JNI_TRUE) { + printf(">>> breakpoint %d\n", bpCount); + } + + err = jvmti_env->RawMonitorWait(breakpointLock, WAIT_FOREVER); + if (err != JVMTI_ERROR_NONE) { + printf("step: Cannot wait breakpointLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (bpCount == 2) { + err = jvmti_env->ClearBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + + err = jvmti_env->RawMonitorExit(breakpointLock); + if (err != JVMTI_ERROR_NONE) { + printf("step: Cannot exit breakpointLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + framesCount++; + + if (method == midRun) { + popDone = JNI_TRUE; + if (printdump == JNI_TRUE) { + printf(">>> poped %d frames till \"run()\"\n", framesCount); + } + } + + err = jvmti_env->RawMonitorEnter(suspendLock); + if (err != JVMTI_ERROR_NONE) { + printf("step: Cannot enter suspendLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->RawMonitorEnter(popFrameLock); + if (err != JVMTI_ERROR_NONE) { + printf("step: Cannot enter popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->RawMonitorNotify(popFrameLock); + if (err != JVMTI_ERROR_NONE) { + printf("step: Cannot notify popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->RawMonitorExit(popFrameLock); + if (err != JVMTI_ERROR_NONE) { + printf("step: Cannot exit popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->RawMonitorWait(suspendLock, WAIT_FOREVER); + if (err != JVMTI_ERROR_NONE) { + printf("step: Cannot wait suspendLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->RawMonitorExit(suspendLock); + if (err != JVMTI_ERROR_NONE) { + printf("step: Cannot exit suspendLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_popframe009(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_popframe009(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_popframe009(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_pop_frame) { + printf("Warning: PopFrame is not implemented\n"); + } + + if (!caps.can_suspend) { + printf("Warning: suspend/resume is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_single_step_events) { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or SingleStep event are not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_PopFrame_popframe009_getReady(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_pop_frame || !caps.can_suspend || + !caps.can_generate_breakpoint_events || + !caps.can_generate_single_step_events) { + return; + } + + midCheckPoint = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (midCheckPoint == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->CreateRawMonitor("Breakpoint Lock", &breakpointLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot create breakpointLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void popFrames(jthread thr) { + jvmtiError err; + + while (popDone != JNI_TRUE && result != STATUS_FAILED) { + err = jvmti->PopFrame(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(PopFrame) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + break; + } + + err = jvmti->ResumeThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(ResumeThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + break; + } + + err = jvmti->RawMonitorWait(popFrameLock, WAIT_FOREVER); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot wait popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorEnter(suspendLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enter suspendLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->SuspendThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(SuspendThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorNotify(suspendLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot notify suspendLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorExit(suspendLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot exit suspendLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe009_check(JNIEnv *env, jclass cls, jthread thr) { + jvmtiError err; + jmethodID midFibonacci; + jclass clazz; + jmethodID method = NULL; + jlocation loc; + char *name, *sig, *generic; + jlong delayTime = 1; + int popCount = 0; + int i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_pop_frame || !caps.can_suspend || + !caps.can_generate_breakpoint_events || + !caps.can_generate_single_step_events) { + return result; + } + + err = jvmti->CreateRawMonitor("Pop Frame Lock", &popFrameLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot create popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> waiting breakpoint 1\n"); + } + + while (bpCount < 1) { + err = jvmti->RawMonitorEnter(popFrameLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enter popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorWait(popFrameLock, (jlong)delayTime); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot wait popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorExit(popFrameLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot exit popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + + err = jvmti->RawMonitorEnter(breakpointLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enter breakpointLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorNotify(breakpointLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot notify breakpointLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->SuspendThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(SuspendThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + err = jvmti->RawMonitorExit(breakpointLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot exit breakpointLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + midFibonacci = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "fibonacci", "(I)I"); + if (midFibonacci == NULL) { + printf("Cannot get method ID for method \"fibonacci\"\n"); + result = STATUS_FAILED; + } + + clazz = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, thr)); + if (clazz == NULL) { + printf("Cannot get class of thread object\n"); + return STATUS_FAILED; + } + + midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "run", "()V"); + if (midRun == NULL) { + printf("Cannot get method ID for \"run\"\n"); + return STATUS_FAILED; + } + + err = jvmti->RawMonitorEnter(popFrameLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enter popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> catching method \"fibonacci\"\n"); + } + + for (i = 1; i < 10 && bpCount == 1; i++) { + err = jvmti->GetFrameLocation(thr, 0, &method, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + break; + } + + if (printdump == JNI_TRUE) { + jvmti->GetMethodName(method, &name, &sig, &generic); + printf(">>> %d: \"%s%s\"\n", i, name, sig); + } + + if (method == midFibonacci) break; + + err = jvmti->ResumeThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(ResumeThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorWait(popFrameLock, (jlong)delayTime); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot wait popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->SuspendThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(SuspendThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + + err = jvmti->RawMonitorExit(popFrameLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot exit popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (method == midFibonacci) { + framesCount = 0; + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thr); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable single step: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->CreateRawMonitor("Suspend Lock", &suspendLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot create suspendLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> popping frames\n"); + } + + err = jvmti->RawMonitorEnter(popFrameLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enter popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + popFrames(thr); + + err = jvmti->RawMonitorExit(popFrameLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot exit popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thr); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable single step: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else { + printf("Warning: method \"fibonacci\" was missed\n"); + } + + err = jvmti->ResumeThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(ResumeThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> waiting breakpoint 2\n"); + } + + while (bpCount < 2) { + err = jvmti->RawMonitorEnter(popFrameLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enter popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorWait(popFrameLock, (jlong)delayTime); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot wait popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorExit(popFrameLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot exit popFrameLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + + err = jvmti->RawMonitorEnter(breakpointLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enter breakpointLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorNotify(breakpointLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot notify breakpointLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorExit(breakpointLock); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot exit breakpointLock: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/libpopframe010.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/libpopframe010.c deleted file mode 100644 index 204d0aa7f10..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/libpopframe010.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "popframe010.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/libpopframe010.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/libpopframe010.cpp new file mode 100644 index 00000000000..48d5f809b56 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/libpopframe010.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "popframe010.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/popframe010.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/popframe010.c deleted file mode 100644 index a0dc2bacad7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/popframe010.c +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID midCheckPoint = NULL; -static jmethodID midRun = NULL; -static jint framesExpected = 0; -static jint framesCount = 0; -static const char *cls_exp = "Lnsk/jvmti/PopFrame/popframe010$TestThread;"; -static const char *name_exp = "countDown"; -static const char *sig_exp = "(I)V"; -static const char *argName = "nestingCount"; - -void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, jlocation loc, jint i) { - jvmtiError err; - jclass cls; - jlocation loc_exp = (i == 0) ? 15 : 8; - char *sigClass, *name, *sig, *generic; - jvmtiLocalVariableEntry *table = NULL; - jint entryCount = 0; - jint argValue; - jint j; - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, mid, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - if (strcmp(table[j].name, argName) == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, 0, - table[j].slot, &argValue); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - } - - if (printdump == JNI_TRUE) { - printf(">>> step %d: \"%s.%s%s\"\n", i, sigClass, name, sig); - printf(">>> location: 0x%x%08x", (jint)(loc >> 32), (jint)loc); - printf(", arg value: %d\n", argValue); - } - - if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { - printf("(step %d) wrong class sig: \"%s\",\n", i, sigClass); - printf(" expected: \"%s\"\n", cls_exp); - result = STATUS_FAILED; - } - if (name == NULL || strcmp(name, name_exp) != 0) { - printf("(step %d) wrong method name: \"%s\",", i, name); - printf(" expected: \"%s\"\n", name_exp); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, sig_exp) != 0) { - printf("(step %d) wrong method sig: \"%s\",", i, sig); - printf(" expected: \"%s\"\n", sig_exp); - result = STATUS_FAILED; - } - if (loc != loc_exp) { - printf("(step %d) wrong location: 0x%x%08x,", - i, (jint)(loc >> 32), (jint)loc); - printf(" expected: 0x%x\n", (jint)loc_exp); - result = STATUS_FAILED; - } - if (argValue != i) { - printf("(step %d) wrong argument value: %d,", i, argValue); - printf(" expected: %d\n", i); - result = STATUS_FAILED; - } - - if (sigClass != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sigClass); - } - if (name != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)name); - } - if (sig != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sig); - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].name)); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].signature)); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table); - } -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (midCheckPoint != method) { - printf("bp: don't know where we get called from"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> breakpoint in checkPoint\n"); - } - - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable single step: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->PopFrame(jvmti_env, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(PopFrame) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (method == midRun) { - if (printdump == JNI_TRUE) { - printf(">>> poped %d frames till method \"run()\"\n", - framesCount); - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable single step: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else { - check(jvmti_env, thread, method, location, framesCount); - framesCount++; - - err = (*jvmti_env)->PopFrame(jvmti_env, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(PopFrame) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_popframe010(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_popframe010(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_popframe010(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_pop_frame) { - printf("Warning: PopFrame is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_single_step_events) { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or SingleStep event are not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_PopFrame_popframe010_getReady(JNIEnv *env, jclass c, jclass cls, jint depth) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_pop_frame || - !caps.can_generate_breakpoint_events || - !caps.can_generate_single_step_events) { - return; - } - - midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "run", "()V"); - if (midRun == NULL) { - printf("Cannot find Method ID for method run\n"); - result = STATUS_FAILED; - return; - } - - midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (midCheckPoint == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - framesExpected = depth; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe010_check(JNIEnv *env, jclass cls) { - if (framesCount != framesExpected) { - printf("Wrong number of poped frames: %d, expected: %d\n", - framesCount, framesExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/popframe010.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/popframe010.cpp new file mode 100644 index 00000000000..f55d5642742 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe010/popframe010.cpp @@ -0,0 +1,364 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID midCheckPoint = NULL; +static jmethodID midRun = NULL; +static jint framesExpected = 0; +static jint framesCount = 0; +static const char *cls_exp = "Lnsk/jvmti/PopFrame/popframe010$TestThread;"; +static const char *name_exp = "countDown"; +static const char *sig_exp = "(I)V"; +static const char *argName = "nestingCount"; + +void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, jlocation loc, jint i) { + jvmtiError err; + jclass cls; + jlocation loc_exp = (i == 0) ? 15 : 8; + char *sigClass, *name, *sig, *generic; + jvmtiLocalVariableEntry *table = NULL; + jint entryCount = 0; + jint argValue; + jint j; + + err = jvmti_env->GetMethodDeclaringClass(mid, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti_env->GetClassSignature(cls, &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + if (strcmp(table[j].name, argName) == 0) { + err = jvmti_env->GetLocalInt(thr, 0, + table[j].slot, &argValue); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + } + + if (printdump == JNI_TRUE) { + printf(">>> step %d: \"%s.%s%s\"\n", i, sigClass, name, sig); + printf(">>> location: 0x%x%08x", (jint)(loc >> 32), (jint)loc); + printf(", arg value: %d\n", argValue); + } + + if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { + printf("(step %d) wrong class sig: \"%s\",\n", i, sigClass); + printf(" expected: \"%s\"\n", cls_exp); + result = STATUS_FAILED; + } + if (name == NULL || strcmp(name, name_exp) != 0) { + printf("(step %d) wrong method name: \"%s\",", i, name); + printf(" expected: \"%s\"\n", name_exp); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, sig_exp) != 0) { + printf("(step %d) wrong method sig: \"%s\",", i, sig); + printf(" expected: \"%s\"\n", sig_exp); + result = STATUS_FAILED; + } + if (loc != loc_exp) { + printf("(step %d) wrong location: 0x%x%08x,", + i, (jint)(loc >> 32), (jint)loc); + printf(" expected: 0x%x\n", (jint)loc_exp); + result = STATUS_FAILED; + } + if (argValue != i) { + printf("(step %d) wrong argument value: %d,", i, argValue); + printf(" expected: %d\n", i); + result = STATUS_FAILED; + } + + if (sigClass != NULL) { + jvmti_env->Deallocate((unsigned char*)sigClass); + } + if (name != NULL) { + jvmti_env->Deallocate((unsigned char*)name); + } + if (sig != NULL) { + jvmti_env->Deallocate((unsigned char*)sig); + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + jvmti_env->Deallocate((unsigned char*)(table[j].name)); + jvmti_env->Deallocate((unsigned char*)(table[j].signature)); + } + jvmti_env->Deallocate((unsigned char*)table); + } +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (midCheckPoint != method) { + printf("bp: don't know where we get called from"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> breakpoint in checkPoint\n"); + } + + err = jvmti_env->ClearBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable single step: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->PopFrame(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(PopFrame) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (method == midRun) { + if (printdump == JNI_TRUE) { + printf(">>> poped %d frames till method \"run()\"\n", + framesCount); + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable single step: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else { + check(jvmti_env, thread, method, location, framesCount); + framesCount++; + + err = jvmti_env->PopFrame(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(PopFrame) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_popframe010(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_popframe010(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_popframe010(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_pop_frame) { + printf("Warning: PopFrame is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_single_step_events) { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or SingleStep event are not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_PopFrame_popframe010_getReady(JNIEnv *env, jclass c, jclass cls, jint depth) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_pop_frame || + !caps.can_generate_breakpoint_events || + !caps.can_generate_single_step_events) { + return; + } + + midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "run", "()V"); + if (midRun == NULL) { + printf("Cannot find Method ID for method run\n"); + result = STATUS_FAILED; + return; + } + + midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (midCheckPoint == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + framesExpected = depth; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe010_check(JNIEnv *env, jclass cls) { + if (framesCount != framesExpected) { + printf("Wrong number of poped frames: %d, expected: %d\n", + framesCount, framesExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/libpopframe011.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/libpopframe011.c deleted file mode 100644 index ef2982e11fc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/libpopframe011.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "popframe011.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/libpopframe011.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/libpopframe011.cpp new file mode 100644 index 00000000000..c8cd1be2d15 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/libpopframe011.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "popframe011.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/popframe011.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/popframe011.c deleted file mode 100644 index 773be4ebc5b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/popframe011.c +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static int watch_ev = 0; /* ignore JVMTI events by default */ -static int gen_ev = 0; /* number of generated events */ -static jvmtiError popframe_err = JVMTI_ERROR_NONE; - -static jrawMonitorID watch_ev_monitor; - -static void set_watch_ev(int value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - watch_ev = value; - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean wasPopedByException) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev) { - printf("#### FramePop event occurred ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, - jmethodID method, jboolean was_poped_by_exc, jvalue return_value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev) { - printf("#### MethodExit event occurred ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_PopFrame_popframe011_doPopFrame(JNIEnv *env, - jclass cls, jint t_case, jobject frameThr) { - if (!caps.can_pop_frame) { - return PASSED; - } - - if (t_case != 6 && t_case != 7) { - /* - * Only enable this event for test cases where the event - * should not happen. - */ - popframe_err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, frameThr); - if (popframe_err != JVMTI_ERROR_NONE) { - printf("Failed to enable METHOD_EXIT event: %s (%d)\n", - TranslateError(popframe_err), popframe_err); - return STATUS_FAILED; - } - } - - popframe_err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FRAME_POP, frameThr); - if ((t_case == 6 || t_case == 7) && - popframe_err == JVMTI_ERROR_THREAD_NOT_ALIVE) { - // Our target thread has exited which is okay. - return PASSED; - } - if (popframe_err != JVMTI_ERROR_NONE) { - printf("Failed to enable FRAME_POP event: %s (%d)\n", - TranslateError(popframe_err), popframe_err); - return STATUS_FAILED; - } - - switch(t_case) { -/* NULL pointer to the thread in debug mode */ - case 1: - printf("\nInvoke PopFrame() with NULL pointer to a thread...\n"); - fflush(stdout); - // fallthrough -/* NULL pointer to the thread */ - case 0: - set_watch_ev(1); /* watch JVMTI events */ - popframe_err = ((*jvmti)->PopFrame(jvmti, NULL)); /* explode the bomb */ - if (popframe_err != JVMTI_ERROR_INVALID_THREAD) { - printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", - popframe_err, TranslateError(popframe_err)); - printf("\tBut it should return the error JVMTI_ERROR_INVALID_THREAD.\n"); - return STATUS_FAILED; - } - break; -/* invalid thread in debug mode */ - case 3: - printf("\nInvoke PopFrame() for an invalid thread...\n"); - fflush(stdout); - // fallthrough -/* invalid thread */ - case 2: - set_watch_ev(1); /* watch JVMTI events */ - popframe_err = ((*jvmti)->PopFrame(jvmti, cls)); /* explode the bomb */ - set_watch_ev(0); /* ignore again JVMTI events */ - if (popframe_err != JVMTI_ERROR_INVALID_THREAD) { - printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", - popframe_err, TranslateError(popframe_err)); - printf("\tBut it should return the error JVMTI_ERROR_INVALID_THREAD.\n"); - return STATUS_FAILED; - } - break; -/* non suspended thread in debug mode */ - case 5: - printf("\nInvoke PopFrame() for a non suspended thread...\n"); - fflush(stdout); - // fallthrough -/* non suspended thread */ - case 4: - set_watch_ev(1); /* watch JVMTI events */ - popframe_err = ((*jvmti)->PopFrame(jvmti, frameThr)); /* explode the bomb */ - set_watch_ev(0); /* ignore again JVMTI events */ - if (popframe_err != JVMTI_ERROR_THREAD_NOT_SUSPENDED) { - printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", - popframe_err, TranslateError(popframe_err)); - printf("\tBut it should return the error JVMTI_ERROR_THREAD_NOT_SUSPENDED.\n"); - return STATUS_FAILED; - } - break; -/* non suspended and exiting thread in debug mode */ - case 7: - printf("\nInvoke PopFrame() for a non suspended and exiting thread...\n"); - fflush(stdout); - // fallthrough -/* non suspended and exiting thread */ - case 6: - set_watch_ev(1); /* watch JVMTI events */ - popframe_err = ((*jvmti)->PopFrame(jvmti, frameThr)); /* explode the bomb */ - set_watch_ev(0); /* ignore again JVMTI events */ - if (popframe_err != JVMTI_ERROR_THREAD_NOT_SUSPENDED && - popframe_err != JVMTI_ERROR_THREAD_NOT_ALIVE) { - printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", - popframe_err, TranslateError(popframe_err)); - printf("\tBut it should return the error JVMTI_ERROR_THREAD_NOT_SUSPENDED or JVMTI_ERROR_THREAD_NOT_ALIVE.\n"); - return STATUS_FAILED; - } - break; - } - - if (gen_ev) { - printf("TEST FAILED: %d JVMTI events were generated by the function PopFrame()\n", - gen_ev); - return STATUS_FAILED; - } else if (t_case == 1 || t_case == 3 || t_case == 5 || t_case == 7) - printf("Check #%d PASSED: No JVMTI events were generated by the function PopFrame()\n", - t_case+1); - - set_watch_ev(0); /* ignore again JVMTI events */ - - if (t_case != 6 && t_case != 7) { - /* - * Only disable this event for test cases where the event - * should not happen. - */ - popframe_err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_EXIT, frameThr); - if (popframe_err != JVMTI_ERROR_NONE) { - printf("Failed to disable METHOD_EXIT event: %s (%d)\n", - TranslateError(popframe_err), popframe_err); - return STATUS_FAILED; - } - } - - popframe_err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_FRAME_POP, frameThr); - if ((t_case == 6 || t_case == 7) && - popframe_err == JVMTI_ERROR_THREAD_NOT_ALIVE) { - // Our target thread has exited which is okay. - return PASSED; - } - if (popframe_err != JVMTI_ERROR_NONE) { - printf("Failed to disable FRAME_POP event: %s (%d)\n", - TranslateError(popframe_err), popframe_err); - return STATUS_FAILED; - } - - return PASSED; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_PopFrame_popframe011_isThreadNotAliveError(JNIEnv *env, jclass cls) { - if (popframe_err == JVMTI_ERROR_THREAD_NOT_ALIVE) { - return JNI_TRUE; - } - return JNI_FALSE; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_popframe011(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_popframe011(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_popframe011(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_pop_frame) { - printf("Warning: PopFrame is not implemented\n"); - return JNI_OK; - } - - if (caps.can_generate_frame_pop_events && - caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - callbacks.FramePop = &FramePop; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FramePop or MethodExit event is not implemented\n"); - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "watch_ev_monitor", &watch_ev_monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/popframe011.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/popframe011.cpp new file mode 100644 index 00000000000..29ebb497695 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe011/popframe011.cpp @@ -0,0 +1,319 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static int watch_ev = 0; /* ignore JVMTI events by default */ +static int gen_ev = 0; /* number of generated events */ +static jvmtiError popframe_err = JVMTI_ERROR_NONE; + +static jrawMonitorID watch_ev_monitor; + +static void set_watch_ev(int value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + watch_ev = value; + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean wasPopedByException) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev) { + printf("#### FramePop event occurred ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, + jmethodID method, jboolean was_poped_by_exc, jvalue return_value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev) { + printf("#### MethodExit event occurred ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_PopFrame_popframe011_doPopFrame(JNIEnv *env, + jclass cls, jint t_case, jobject frameThr) { + if (!caps.can_pop_frame) { + return PASSED; + } + + if (t_case != 6 && t_case != 7) { + /* + * Only enable this event for test cases where the event + * should not happen. + */ + popframe_err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, frameThr); + if (popframe_err != JVMTI_ERROR_NONE) { + printf("Failed to enable METHOD_EXIT event: %s (%d)\n", + TranslateError(popframe_err), popframe_err); + return STATUS_FAILED; + } + } + + popframe_err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FRAME_POP, frameThr); + if ((t_case == 6 || t_case == 7) && + popframe_err == JVMTI_ERROR_THREAD_NOT_ALIVE) { + // Our target thread has exited which is okay. + return PASSED; + } + if (popframe_err != JVMTI_ERROR_NONE) { + printf("Failed to enable FRAME_POP event: %s (%d)\n", + TranslateError(popframe_err), popframe_err); + return STATUS_FAILED; + } + + switch(t_case) { +/* NULL pointer to the thread in debug mode */ + case 1: + printf("\nInvoke PopFrame() with NULL pointer to a thread...\n"); + fflush(stdout); + // fallthrough +/* NULL pointer to the thread */ + case 0: + set_watch_ev(1); /* watch JVMTI events */ + popframe_err = (jvmti->PopFrame(NULL)); /* explode the bomb */ + if (popframe_err != JVMTI_ERROR_INVALID_THREAD) { + printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", + popframe_err, TranslateError(popframe_err)); + printf("\tBut it should return the error JVMTI_ERROR_INVALID_THREAD.\n"); + return STATUS_FAILED; + } + break; +/* invalid thread in debug mode */ + case 3: + printf("\nInvoke PopFrame() for an invalid thread...\n"); + fflush(stdout); + // fallthrough +/* invalid thread */ + case 2: + set_watch_ev(1); /* watch JVMTI events */ + popframe_err = (jvmti->PopFrame(cls)); /* explode the bomb */ + set_watch_ev(0); /* ignore again JVMTI events */ + if (popframe_err != JVMTI_ERROR_INVALID_THREAD) { + printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", + popframe_err, TranslateError(popframe_err)); + printf("\tBut it should return the error JVMTI_ERROR_INVALID_THREAD.\n"); + return STATUS_FAILED; + } + break; +/* non suspended thread in debug mode */ + case 5: + printf("\nInvoke PopFrame() for a non suspended thread...\n"); + fflush(stdout); + // fallthrough +/* non suspended thread */ + case 4: + set_watch_ev(1); /* watch JVMTI events */ + popframe_err = (jvmti->PopFrame(frameThr)); /* explode the bomb */ + set_watch_ev(0); /* ignore again JVMTI events */ + if (popframe_err != JVMTI_ERROR_THREAD_NOT_SUSPENDED) { + printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", + popframe_err, TranslateError(popframe_err)); + printf("\tBut it should return the error JVMTI_ERROR_THREAD_NOT_SUSPENDED.\n"); + return STATUS_FAILED; + } + break; +/* non suspended and exiting thread in debug mode */ + case 7: + printf("\nInvoke PopFrame() for a non suspended and exiting thread...\n"); + fflush(stdout); + // fallthrough +/* non suspended and exiting thread */ + case 6: + set_watch_ev(1); /* watch JVMTI events */ + popframe_err = (jvmti->PopFrame(frameThr)); /* explode the bomb */ + set_watch_ev(0); /* ignore again JVMTI events */ + if (popframe_err != JVMTI_ERROR_THREAD_NOT_SUSPENDED && + popframe_err != JVMTI_ERROR_THREAD_NOT_ALIVE) { + printf("TEST FAILED: the function PopFrame() returned the error %d: %s\n", + popframe_err, TranslateError(popframe_err)); + printf("\tBut it should return the error JVMTI_ERROR_THREAD_NOT_SUSPENDED or JVMTI_ERROR_THREAD_NOT_ALIVE.\n"); + return STATUS_FAILED; + } + break; + } + + if (gen_ev) { + printf("TEST FAILED: %d JVMTI events were generated by the function PopFrame()\n", + gen_ev); + return STATUS_FAILED; + } else if (t_case == 1 || t_case == 3 || t_case == 5 || t_case == 7) + printf("Check #%d PASSED: No JVMTI events were generated by the function PopFrame()\n", + t_case+1); + + set_watch_ev(0); /* ignore again JVMTI events */ + + if (t_case != 6 && t_case != 7) { + /* + * Only disable this event for test cases where the event + * should not happen. + */ + popframe_err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_EXIT, frameThr); + if (popframe_err != JVMTI_ERROR_NONE) { + printf("Failed to disable METHOD_EXIT event: %s (%d)\n", + TranslateError(popframe_err), popframe_err); + return STATUS_FAILED; + } + } + + popframe_err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_FRAME_POP, frameThr); + if ((t_case == 6 || t_case == 7) && + popframe_err == JVMTI_ERROR_THREAD_NOT_ALIVE) { + // Our target thread has exited which is okay. + return PASSED; + } + if (popframe_err != JVMTI_ERROR_NONE) { + printf("Failed to disable FRAME_POP event: %s (%d)\n", + TranslateError(popframe_err), popframe_err); + return STATUS_FAILED; + } + + return PASSED; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_PopFrame_popframe011_isThreadNotAliveError(JNIEnv *env, jclass cls) { + if (popframe_err == JVMTI_ERROR_THREAD_NOT_ALIVE) { + return JNI_TRUE; + } + return JNI_FALSE; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_popframe011(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_popframe011(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_popframe011(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_pop_frame) { + printf("Warning: PopFrame is not implemented\n"); + return JNI_OK; + } + + if (caps.can_generate_frame_pop_events && + caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + callbacks.FramePop = &FramePop; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FramePop or MethodExit event is not implemented\n"); + } + + err = jvmti->CreateRawMonitor("watch_ev_monitor", &watch_ev_monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/librawmonenter001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/librawmonenter001.c deleted file mode 100644 index 6b205d00dd4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/librawmonenter001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmonenter001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/librawmonenter001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/librawmonenter001.cpp new file mode 100644 index 00000000000..a8291783652 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/librawmonenter001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmonenter001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/rawmonenter001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/rawmonenter001.c deleted file mode 100644 index 9379da56873..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/rawmonenter001.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define RAW_MONITORS_NUMBER 1024 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - jvmtiError err; - char name[32]; - int i; - - if (printdump == JNI_TRUE) { - printf(">>> VMInit event\n"); - printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - sprintf(name, "RawMonitor-%d", i); - err = (*jvmti)->CreateRawMonitor(jvmti, name, &monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorEnter(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->DestroyRawMonitor(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmonenter001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmonenter001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmonenter001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_RawMonitorEnter_rawmonenter001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - char name[32]; - int i; - - if (printdump == JNI_TRUE) { - printf(">>> native call\n"); - printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - sprintf(name, "RawMonitor-%d", i); - err = (*jvmti)->CreateRawMonitor(jvmti, name, &monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorEnter(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->DestroyRawMonitor(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/rawmonenter001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/rawmonenter001.cpp new file mode 100644 index 00000000000..2d7fe93478f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter001/rawmonenter001.cpp @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define RAW_MONITORS_NUMBER 1024 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + jvmtiError err; + char name[32]; + int i; + + if (printdump == JNI_TRUE) { + printf(">>> VMInit event\n"); + printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + sprintf(name, "RawMonitor-%d", i); + err = jvmti->CreateRawMonitor(name, &monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorEnter(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->DestroyRawMonitor(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmonenter001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmonenter001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmonenter001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_RawMonitorEnter_rawmonenter001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + char name[32]; + int i; + + if (printdump == JNI_TRUE) { + printf(">>> native call\n"); + printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + sprintf(name, "RawMonitor-%d", i); + err = jvmti->CreateRawMonitor(name, &monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorEnter(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->DestroyRawMonitor(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/librawmonenter002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/librawmonenter002.c deleted file mode 100644 index cdebf771165..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/librawmonenter002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmonenter002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/librawmonenter002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/librawmonenter002.cpp new file mode 100644 index 00000000000..18c6b437b5f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/librawmonenter002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmonenter002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/rawmonenter002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/rawmonenter002.c deleted file mode 100644 index d3bbb279035..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/rawmonenter002.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmonenter002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmonenter002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmonenter002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorEnter_rawmonenter002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorEnter(jvmti, NULL); - if (err != JVMTI_ERROR_INVALID_MONITOR) { - printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/rawmonenter002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/rawmonenter002.cpp new file mode 100644 index 00000000000..dabf5ca8ae1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter002/rawmonenter002.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmonenter002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmonenter002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmonenter002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorEnter_rawmonenter002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid monitor check ...\n"); + } + + err = jvmti->RawMonitorEnter(NULL); + if (err != JVMTI_ERROR_INVALID_MONITOR) { + printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/librawmonenter003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/librawmonenter003.c deleted file mode 100644 index fe71fe87537..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/librawmonenter003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmonenter003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/librawmonenter003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/librawmonenter003.cpp new file mode 100644 index 00000000000..eb8c4efeb15 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/librawmonenter003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmonenter003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/rawmonenter003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/rawmonenter003.c deleted file mode 100644 index bf891d2ca09..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/rawmonenter003.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static char bad_buf[] = "this is a bad raw monitor"; -static jrawMonitorID bad_monitor = (jrawMonitorID)bad_buf; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmonenter003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmonenter003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmonenter003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorEnter_rawmonenter003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorEnter(jvmti, bad_monitor); - if (err != JVMTI_ERROR_INVALID_MONITOR) { - printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/rawmonenter003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/rawmonenter003.cpp new file mode 100644 index 00000000000..d5acf5af3bb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter003/rawmonenter003.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static char bad_buf[] = "this is a bad raw monitor"; +static jrawMonitorID bad_monitor = (jrawMonitorID)bad_buf; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmonenter003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmonenter003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmonenter003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorEnter_rawmonenter003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid monitor check ...\n"); + } + + err = jvmti->RawMonitorEnter(bad_monitor); + if (err != JVMTI_ERROR_INVALID_MONITOR) { + printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/librawmonenter004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/librawmonenter004.c deleted file mode 100644 index 7582c24074b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/librawmonenter004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmonenter004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/librawmonenter004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/librawmonenter004.cpp new file mode 100644 index 00000000000..d56d0fdc444 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/librawmonenter004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmonenter004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/rawmonenter004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/rawmonenter004.c deleted file mode 100644 index 1176d45394b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/rawmonenter004.c +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define WAIT_STEP 100 -#define INCREMENT_LIMIT 1000 -#define DELAY 100 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jrawMonitorID monitor; -static jrawMonitorID wait_lock; -static jint monitorCount = 0; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmonenter004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmonenter004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmonenter004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -static void JNICALL -increment_thread(jvmtiEnv* jvmti, JNIEnv* jni, void *unused) { - jvmtiError err; - jint temp; - int i, j; - - for (i = 0; i < INCREMENT_LIMIT; i++) { - err = (*jvmti)->RawMonitorEnter(jvmti, monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#test) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - temp = monitorCount; - for (j = 0; j < DELAY; j++) ; - monitorCount = temp + 1; - - err = (*jvmti)->RawMonitorExit(jvmti, monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#test) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorEnter_rawmonenter004_check(JNIEnv *env, jclass cls, jarray threads, jint wtime) { - jvmtiError err; - jsize i, threads_limit; - jthread thr; - jint wait_time = wtime * 60000; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "test monitor", &monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#test) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "wait lock", &wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#wait) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - threads_limit = JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, threads)); - - if (printdump == JNI_TRUE) { - printf(">>> starting %d threads ...\n", threads_limit); - } - - for (i = 0; i < threads_limit; i++) { - thr = JNI_ENV_PTR(env)->GetObjectArrayElement(JNI_ENV_ARG(env, - threads), i); - err = (*jvmti)->RunAgentThread(jvmti, thr, increment_thread, NULL, - JVMTI_THREAD_NORM_PRIORITY); - if (err != JVMTI_ERROR_NONE) { - printf("(RunDebugThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - } - - for (i = 0; i < wait_time/WAIT_STEP && - monitorCount != INCREMENT_LIMIT * threads_limit; i++) { - err = (*jvmti)->RawMonitorEnter(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#wait) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - break; - } - err = (*jvmti)->RawMonitorWait(jvmti, wait_lock, (jlong)WAIT_STEP); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - break; - } - err = (*jvmti)->RawMonitorExit(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#wait) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - break; - } - } - - if (monitorCount != INCREMENT_LIMIT * threads_limit) { - printf("Timeout value is reached, monitorCount expected: %d", - INCREMENT_LIMIT * threads_limit); - printf(", actual: %d\n", monitorCount); - result = STATUS_FAILED; - } else if (printdump == JNI_TRUE) { - printf(">>> final monitorCount: %d\n", monitorCount); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/rawmonenter004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/rawmonenter004.cpp new file mode 100644 index 00000000000..2725f638030 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/rawmonenter004.cpp @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define WAIT_STEP 100 +#define INCREMENT_LIMIT 1000 +#define DELAY 100 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jrawMonitorID monitor; +static jrawMonitorID wait_lock; +static jint monitorCount = 0; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmonenter004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmonenter004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmonenter004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +static void JNICALL +increment_thread(jvmtiEnv* jvmti, JNIEnv* jni, void *unused) { + jvmtiError err; + jint temp; + int i, j; + + for (i = 0; i < INCREMENT_LIMIT; i++) { + err = jvmti->RawMonitorEnter(monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#test) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + temp = monitorCount; + for (j = 0; j < DELAY; j++) ; + monitorCount = temp + 1; + + err = jvmti->RawMonitorExit(monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#test) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorEnter_rawmonenter004_check(JNIEnv *env, jclass cls, jobjectArray threads, jint wtime) { + jvmtiError err; + jsize i, threads_limit; + jthread thr; + jint wait_time = wtime * 60000; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->CreateRawMonitor("test monitor", &monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#test) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + err = jvmti->CreateRawMonitor("wait lock", &wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#wait) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + threads_limit = JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, threads)); + + if (printdump == JNI_TRUE) { + printf(">>> starting %d threads ...\n", threads_limit); + } + + for (i = 0; i < threads_limit; i++) { + thr = JNI_ENV_PTR(env)->GetObjectArrayElement(JNI_ENV_ARG(env, + threads), i); + err = jvmti->RunAgentThread(thr, increment_thread, NULL, + JVMTI_THREAD_NORM_PRIORITY); + if (err != JVMTI_ERROR_NONE) { + printf("(RunDebugThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + } + + for (i = 0; i < wait_time/WAIT_STEP && + monitorCount != INCREMENT_LIMIT * threads_limit; i++) { + err = jvmti->RawMonitorEnter(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#wait) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + break; + } + err = jvmti->RawMonitorWait(wait_lock, (jlong)WAIT_STEP); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + break; + } + err = jvmti->RawMonitorExit(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#wait) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + break; + } + } + + if (monitorCount != INCREMENT_LIMIT * threads_limit) { + printf("Timeout value is reached, monitorCount expected: %d", + INCREMENT_LIMIT * threads_limit); + printf(", actual: %d\n", monitorCount); + result = STATUS_FAILED; + } else if (printdump == JNI_TRUE) { + printf(">>> final monitorCount: %d\n", monitorCount); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/librawmonexit001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/librawmonexit001.c deleted file mode 100644 index 01bf41ce8c1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/librawmonexit001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmonexit001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/librawmonexit001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/librawmonexit001.cpp new file mode 100644 index 00000000000..847a85826e4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/librawmonexit001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmonexit001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/rawmonexit001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/rawmonexit001.c deleted file mode 100644 index 5470b3436b9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/rawmonexit001.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define RAW_MONITORS_NUMBER 1024 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - jvmtiError err; - char name[32]; - int i; - - if (printdump == JNI_TRUE) { - printf(">>> VMInit event\n"); - printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - sprintf(name, "RawMonitor-%d", i); - err = (*jvmti)->CreateRawMonitor(jvmti, name, &monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorEnter(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorExit(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->DestroyRawMonitor(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmonexit001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmonexit001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmonexit001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_RawMonitorExit_rawmonexit001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - char name[32]; - int i; - - if (printdump == JNI_TRUE) { - printf(">>> native method call\n"); - printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - sprintf(name, "RawMonitor-%d", i); - err = (*jvmti)->CreateRawMonitor(jvmti, name, &monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorEnter(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorExit(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->DestroyRawMonitor(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/rawmonexit001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/rawmonexit001.cpp new file mode 100644 index 00000000000..65d1436b422 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit001/rawmonexit001.cpp @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define RAW_MONITORS_NUMBER 1024 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + jvmtiError err; + char name[32]; + int i; + + if (printdump == JNI_TRUE) { + printf(">>> VMInit event\n"); + printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + sprintf(name, "RawMonitor-%d", i); + err = jvmti->CreateRawMonitor(name, &monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorEnter(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorExit(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->DestroyRawMonitor(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmonexit001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmonexit001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmonexit001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_RawMonitorExit_rawmonexit001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + char name[32]; + int i; + + if (printdump == JNI_TRUE) { + printf(">>> native method call\n"); + printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + sprintf(name, "RawMonitor-%d", i); + err = jvmti->CreateRawMonitor(name, &monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorEnter(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorExit(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->DestroyRawMonitor(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/librawmonexit002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/librawmonexit002.c deleted file mode 100644 index d41c1da367f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/librawmonexit002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmonexit002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/librawmonexit002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/librawmonexit002.cpp new file mode 100644 index 00000000000..31db539e9b0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/librawmonexit002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmonexit002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/rawmonexit002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/rawmonexit002.c deleted file mode 100644 index 014a7f4d6d8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/rawmonexit002.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmonexit002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmonexit002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmonexit002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorExit_rawmonexit002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorExit(jvmti, NULL); - if (err != JVMTI_ERROR_INVALID_MONITOR) { - printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/rawmonexit002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/rawmonexit002.cpp new file mode 100644 index 00000000000..a1d59645c97 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit002/rawmonexit002.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmonexit002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmonexit002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmonexit002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorExit_rawmonexit002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid monitor check ...\n"); + } + + err = jvmti->RawMonitorExit(NULL); + if (err != JVMTI_ERROR_INVALID_MONITOR) { + printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/librawmonexit003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/librawmonexit003.c deleted file mode 100644 index 5105b4b7a80..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/librawmonexit003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmonexit003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/librawmonexit003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/librawmonexit003.cpp new file mode 100644 index 00000000000..ea3f3a83e31 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/librawmonexit003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmonexit003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/rawmonexit003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/rawmonexit003.c deleted file mode 100644 index 6210e6eb11f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/rawmonexit003.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static char bad_buf[] = "this is a bad raw monitor"; -static jrawMonitorID bad_monitor = (jrawMonitorID)bad_buf; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmonexit003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmonexit003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmonexit003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorExit_rawmonexit003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorExit(jvmti, bad_monitor); - if (err != JVMTI_ERROR_INVALID_MONITOR) { - printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/rawmonexit003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/rawmonexit003.cpp new file mode 100644 index 00000000000..9443ff2b75a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit003/rawmonexit003.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static char bad_buf[] = "this is a bad raw monitor"; +static jrawMonitorID bad_monitor = (jrawMonitorID)bad_buf; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmonexit003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmonexit003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmonexit003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorExit_rawmonexit003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid monitor check ...\n"); + } + + err = jvmti->RawMonitorExit(bad_monitor); + if (err != JVMTI_ERROR_INVALID_MONITOR) { + printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/librawmonexit005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/librawmonexit005.c deleted file mode 100644 index b4c5e205134..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/librawmonexit005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmonexit005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/librawmonexit005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/librawmonexit005.cpp new file mode 100644 index 00000000000..22eb380377c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/librawmonexit005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmonexit005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/rawmonexit005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/rawmonexit005.c deleted file mode 100644 index a1244847dae..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/rawmonexit005.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmonexit005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmonexit005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmonexit005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorExit_rawmonexit005_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jrawMonitorID monitor; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "test monitor", &monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> unowned monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorExit(jvmti, monitor); - - if (err != JVMTI_ERROR_NOT_MONITOR_OWNER) { - printf("Error expected: JVMTI_ERROR_NOT_MONITOR_OWNER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/rawmonexit005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/rawmonexit005.cpp new file mode 100644 index 00000000000..b8dc4626718 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorExit/rawmonexit005/rawmonexit005.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmonexit005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmonexit005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmonexit005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorExit_rawmonexit005_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jrawMonitorID monitor; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->CreateRawMonitor("test monitor", &monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> unowned monitor check ...\n"); + } + + err = jvmti->RawMonitorExit(monitor); + + if (err != JVMTI_ERROR_NOT_MONITOR_OWNER) { + printf("Error expected: JVMTI_ERROR_NOT_MONITOR_OWNER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/librawmnntfy001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/librawmnntfy001.c deleted file mode 100644 index ca5047c4453..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/librawmnntfy001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnntfy001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/librawmnntfy001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/librawmnntfy001.cpp new file mode 100644 index 00000000000..28f43ee7adf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/librawmnntfy001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnntfy001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/rawmnntfy001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/rawmnntfy001.c deleted file mode 100644 index bcbc9e672bf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/rawmnntfy001.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define RAW_MONITORS_NUMBER 1024 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - jvmtiError err; - char name[32]; - int i; - - if (printdump == JNI_TRUE) { - printf(">>> VMInit event\n"); - printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - sprintf(name, "RawMonitor-%d", i); - err = (*jvmti)->CreateRawMonitor(jvmti, name, &monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorEnter(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> notifying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorNotify(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorNorify#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorExit(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->DestroyRawMonitor(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfy001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfy001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnntfy001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_RawMonitorNotify_rawmnntfy001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - char name[32]; - int i; - - if (printdump == JNI_TRUE) { - printf(">>> native method call\n"); - printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - sprintf(name, "RawMonitor-%d", i); - err = (*jvmti)->CreateRawMonitor(jvmti, name, &monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorEnter(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> notifying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorNotify(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorNorify#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorExit(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->DestroyRawMonitor(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/rawmnntfy001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/rawmnntfy001.cpp new file mode 100644 index 00000000000..5f951668034 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy001/rawmnntfy001.cpp @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define RAW_MONITORS_NUMBER 1024 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + jvmtiError err; + char name[32]; + int i; + + if (printdump == JNI_TRUE) { + printf(">>> VMInit event\n"); + printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + sprintf(name, "RawMonitor-%d", i); + err = jvmti->CreateRawMonitor(name, &monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorEnter(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> notifying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorNotify(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorNorify#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorExit(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->DestroyRawMonitor(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfy001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfy001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnntfy001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_RawMonitorNotify_rawmnntfy001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + char name[32]; + int i; + + if (printdump == JNI_TRUE) { + printf(">>> native method call\n"); + printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + sprintf(name, "RawMonitor-%d", i); + err = jvmti->CreateRawMonitor(name, &monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorEnter(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> notifying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorNotify(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorNorify#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorExit(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->DestroyRawMonitor(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/librawmnntfy002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/librawmnntfy002.c deleted file mode 100644 index bcbaa0e49e2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/librawmnntfy002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnntfy002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/librawmnntfy002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/librawmnntfy002.cpp new file mode 100644 index 00000000000..e04b877bce3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/librawmnntfy002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnntfy002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/rawmnntfy002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/rawmnntfy002.c deleted file mode 100644 index 472d89dca21..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/rawmnntfy002.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfy002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfy002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnntfy002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorNotify_rawmnntfy002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorNotify(jvmti, NULL); - if (err != JVMTI_ERROR_INVALID_MONITOR) { - printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/rawmnntfy002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/rawmnntfy002.cpp new file mode 100644 index 00000000000..d57eed1669f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy002/rawmnntfy002.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfy002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfy002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnntfy002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorNotify_rawmnntfy002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid monitor check ...\n"); + } + + err = jvmti->RawMonitorNotify(NULL); + if (err != JVMTI_ERROR_INVALID_MONITOR) { + printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/librawmnntfy003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/librawmnntfy003.c deleted file mode 100644 index 6124d41f308..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/librawmnntfy003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnntfy003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/librawmnntfy003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/librawmnntfy003.cpp new file mode 100644 index 00000000000..7d094aca43c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/librawmnntfy003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnntfy003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/rawmnntfy003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/rawmnntfy003.c deleted file mode 100644 index 29d87f300e3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/rawmnntfy003.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static char bad_buf[] = "this is a bad raw monitor"; -static jrawMonitorID bad_monitor = (jrawMonitorID)bad_buf; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfy003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfy003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnntfy003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorNotify_rawmnntfy003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorNotify(jvmti, bad_monitor); - if (err != JVMTI_ERROR_INVALID_MONITOR) { - printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/rawmnntfy003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/rawmnntfy003.cpp new file mode 100644 index 00000000000..458f2dd26eb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy003/rawmnntfy003.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static char bad_buf[] = "this is a bad raw monitor"; +static jrawMonitorID bad_monitor = (jrawMonitorID)bad_buf; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfy003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfy003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnntfy003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorNotify_rawmnntfy003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid monitor check ...\n"); + } + + err = jvmti->RawMonitorNotify(bad_monitor); + if (err != JVMTI_ERROR_INVALID_MONITOR) { + printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/librawmnntfy004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/librawmnntfy004.c deleted file mode 100644 index ad081ef430f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/librawmnntfy004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnntfy004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/librawmnntfy004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/librawmnntfy004.cpp new file mode 100644 index 00000000000..8d78868eb04 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/librawmnntfy004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnntfy004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/rawmnntfy004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/rawmnntfy004.c deleted file mode 100644 index 93d406a4a20..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/rawmnntfy004.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfy004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfy004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnntfy004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorNotify_rawmnntfy004_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jrawMonitorID monitor; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "test monitor", &monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> unowned monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorNotify(jvmti, monitor); - if (err != JVMTI_ERROR_NOT_MONITOR_OWNER) { - printf("Error expected: JVMTI_ERROR_NOT_MONITOR_OWNER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/rawmnntfy004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/rawmnntfy004.cpp new file mode 100644 index 00000000000..b5380595319 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotify/rawmnntfy004/rawmnntfy004.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfy004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfy004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnntfy004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorNotify_rawmnntfy004_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jrawMonitorID monitor; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->CreateRawMonitor("test monitor", &monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> unowned monitor check ...\n"); + } + + err = jvmti->RawMonitorNotify(monitor); + if (err != JVMTI_ERROR_NOT_MONITOR_OWNER) { + printf("Error expected: JVMTI_ERROR_NOT_MONITOR_OWNER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/librawmnntfyall001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/librawmnntfyall001.c deleted file mode 100644 index a63179d8b75..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/librawmnntfyall001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnntfyall001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/librawmnntfyall001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/librawmnntfyall001.cpp new file mode 100644 index 00000000000..20c8f97deea --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/librawmnntfyall001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnntfyall001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/rawmnntfyall001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/rawmnntfyall001.c deleted file mode 100644 index 65561de9a1d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/rawmnntfyall001.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define RAW_MONITORS_NUMBER 1024 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - jvmtiError err; - char name[32]; - int i; - - if (printdump == JNI_TRUE) { - printf(">>> VMInit event\n"); - printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - sprintf(name, "RawMonitor-%d", i); - err = (*jvmti)->CreateRawMonitor(jvmti, name, &monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorEnter(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> notifying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorNotifyAll(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorNotifyAll#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorExit(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->DestroyRawMonitor(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfyall001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfyall001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnntfyall001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_RawMonitorNotifyAll_rawmnntfyall001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - char name[32]; - int i; - - if (printdump == JNI_TRUE) { - printf(">>> native method call\n"); - printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - sprintf(name, "RawMonitor-%d", i); - err = (*jvmti)->CreateRawMonitor(jvmti, name, &monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorEnter(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> notifying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorNotifyAll(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorNotifyAll#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorExit(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->DestroyRawMonitor(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/rawmnntfyall001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/rawmnntfyall001.cpp new file mode 100644 index 00000000000..6ab00f754fb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall001/rawmnntfyall001.cpp @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define RAW_MONITORS_NUMBER 1024 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + jvmtiError err; + char name[32]; + int i; + + if (printdump == JNI_TRUE) { + printf(">>> VMInit event\n"); + printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + sprintf(name, "RawMonitor-%d", i); + err = jvmti->CreateRawMonitor(name, &monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorEnter(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> notifying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorNotifyAll(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorNotifyAll#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorExit(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->DestroyRawMonitor(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfyall001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfyall001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnntfyall001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_RawMonitorNotifyAll_rawmnntfyall001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + char name[32]; + int i; + + if (printdump == JNI_TRUE) { + printf(">>> native method call\n"); + printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + sprintf(name, "RawMonitor-%d", i); + err = jvmti->CreateRawMonitor(name, &monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorEnter(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> notifying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorNotifyAll(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorNotifyAll#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorExit(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->DestroyRawMonitor(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/librawmnntfyall002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/librawmnntfyall002.c deleted file mode 100644 index 72e9bf963f7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/librawmnntfyall002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnntfyall002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/librawmnntfyall002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/librawmnntfyall002.cpp new file mode 100644 index 00000000000..637e85c772a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/librawmnntfyall002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnntfyall002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/rawmnntfyall002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/rawmnntfyall002.c deleted file mode 100644 index 595d5fb7d30..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/rawmnntfyall002.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfyall002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfyall002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnntfyall002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorNotifyAll_rawmnntfyall002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorNotifyAll(jvmti, NULL); - if (err != JVMTI_ERROR_INVALID_MONITOR) { - printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/rawmnntfyall002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/rawmnntfyall002.cpp new file mode 100644 index 00000000000..ae780a1d079 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall002/rawmnntfyall002.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfyall002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfyall002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnntfyall002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorNotifyAll_rawmnntfyall002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid monitor check ...\n"); + } + + err = jvmti->RawMonitorNotifyAll(NULL); + if (err != JVMTI_ERROR_INVALID_MONITOR) { + printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/librawmnntfyall003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/librawmnntfyall003.c deleted file mode 100644 index ab77abe068e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/librawmnntfyall003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnntfyall003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/librawmnntfyall003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/librawmnntfyall003.cpp new file mode 100644 index 00000000000..43ee4d8511e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/librawmnntfyall003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnntfyall003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/rawmnntfyall003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/rawmnntfyall003.c deleted file mode 100644 index b73f6a5bb77..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/rawmnntfyall003.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static char bad_buf[] = "this is a bad raw monitor"; -static jrawMonitorID bad_monitor = (jrawMonitorID)bad_buf; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfyall003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfyall003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnntfyall003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorNotifyAll_rawmnntfyall003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorNotifyAll(jvmti, bad_monitor); - if (err != JVMTI_ERROR_INVALID_MONITOR) { - printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/rawmnntfyall003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/rawmnntfyall003.cpp new file mode 100644 index 00000000000..04b64d5e005 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall003/rawmnntfyall003.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static char bad_buf[] = "this is a bad raw monitor"; +static jrawMonitorID bad_monitor = (jrawMonitorID)bad_buf; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfyall003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfyall003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnntfyall003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorNotifyAll_rawmnntfyall003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid monitor check ...\n"); + } + + err = jvmti->RawMonitorNotifyAll(bad_monitor); + if (err != JVMTI_ERROR_INVALID_MONITOR) { + printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/librawmnntfyall004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/librawmnntfyall004.c deleted file mode 100644 index b2d4563cdcb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/librawmnntfyall004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnntfyall004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/librawmnntfyall004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/librawmnntfyall004.cpp new file mode 100644 index 00000000000..d606c17354f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/librawmnntfyall004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnntfyall004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/rawmnntfyall004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/rawmnntfyall004.c deleted file mode 100644 index f0a38ebea6b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/rawmnntfyall004.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfyall004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfyall004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnntfyall004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorNotifyAll_rawmnntfyall004_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jrawMonitorID monitor; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "test monitor", &monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> unowned monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorNotifyAll(jvmti, monitor); - if (err != JVMTI_ERROR_NOT_MONITOR_OWNER) { - printf("Error expected: JVMTI_ERROR_NOT_MONITOR_OWNER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/rawmnntfyall004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/rawmnntfyall004.cpp new file mode 100644 index 00000000000..453067e5109 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorNotifyAll/rawmnntfyall004/rawmnntfyall004.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnntfyall004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnntfyall004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnntfyall004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorNotifyAll_rawmnntfyall004_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jrawMonitorID monitor; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->CreateRawMonitor("test monitor", &monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> unowned monitor check ...\n"); + } + + err = jvmti->RawMonitorNotifyAll(monitor); + if (err != JVMTI_ERROR_NOT_MONITOR_OWNER) { + printf("Error expected: JVMTI_ERROR_NOT_MONITOR_OWNER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/librawmnwait001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/librawmnwait001.c deleted file mode 100644 index c7bb45c79a4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/librawmnwait001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnwait001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/librawmnwait001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/librawmnwait001.cpp new file mode 100644 index 00000000000..9bf0f111370 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/librawmnwait001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnwait001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/rawmnwait001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/rawmnwait001.c deleted file mode 100644 index 86ef8bde36c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/rawmnwait001.c +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define RAW_MONITORS_NUMBER 1024 -#define MONITOR_WAIT_TIMEOUT ((jlong)10) - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - jvmtiError err; - char name[32]; - int i; - - if (printdump == JNI_TRUE) { - printf(">>> VMInit event\n"); - printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - sprintf(name, "RawMonitor-%d", i); - err = (*jvmti)->CreateRawMonitor(jvmti, name, &monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorEnter(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> waiting %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorWait(jvmti, monitors[i], MONITOR_WAIT_TIMEOUT); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorExit(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->DestroyRawMonitor(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnwait001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnwait001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnwait001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL Java_nsk_jvmti_RawMonitorWait_rawmnwait001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - char name[32]; - int i; - - if (printdump == JNI_TRUE) { - printf(">>> native method call\n"); - printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - sprintf(name, "RawMonitor-%d", i); - err = (*jvmti)->CreateRawMonitor(jvmti, name, &monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorEnter(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> waiting %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorWait(jvmti, monitors[i], MONITOR_WAIT_TIMEOUT); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->RawMonitorExit(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - if (printdump == JNI_TRUE) { - printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); - } - - for (i = 0; i < RAW_MONITORS_NUMBER; i++) { - err = (*jvmti)->DestroyRawMonitor(jvmti, monitors[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/rawmnwait001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/rawmnwait001.cpp new file mode 100644 index 00000000000..25c4c77012f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait001/rawmnwait001.cpp @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define RAW_MONITORS_NUMBER 1024 +#define MONITOR_WAIT_TIMEOUT ((jlong)10) + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jrawMonitorID monitors[RAW_MONITORS_NUMBER]; + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + jvmtiError err; + char name[32]; + int i; + + if (printdump == JNI_TRUE) { + printf(">>> VMInit event\n"); + printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + sprintf(name, "RawMonitor-%d", i); + err = jvmti->CreateRawMonitor(name, &monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorEnter(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> waiting %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorWait(monitors[i], MONITOR_WAIT_TIMEOUT); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorExit(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->DestroyRawMonitor(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnwait001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnwait001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnwait001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL Java_nsk_jvmti_RawMonitorWait_rawmnwait001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + char name[32]; + int i; + + if (printdump == JNI_TRUE) { + printf(">>> native method call\n"); + printf(">>> creating %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + sprintf(name, "RawMonitor-%d", i); + err = jvmti->CreateRawMonitor(name, &monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> entering %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorEnter(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(EnterRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> waiting %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorWait(monitors[i], MONITOR_WAIT_TIMEOUT); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> exiting %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->RawMonitorExit(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + if (printdump == JNI_TRUE) { + printf(">>> destroying %d raw monitors\n", RAW_MONITORS_NUMBER); + } + + for (i = 0; i < RAW_MONITORS_NUMBER; i++) { + err = jvmti->DestroyRawMonitor(monitors[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/librawmnwait002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/librawmnwait002.c deleted file mode 100644 index 709a37a3379..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/librawmnwait002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnwait002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/librawmnwait002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/librawmnwait002.cpp new file mode 100644 index 00000000000..65337bded3b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/librawmnwait002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnwait002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/rawmnwait002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/rawmnwait002.c deleted file mode 100644 index a2dcdb599c4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/rawmnwait002.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define MONITOR_WAIT_TIMEOUT ((jlong)100) - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnwait002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnwait002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnwait002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorWait_rawmnwait002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorWait(jvmti, NULL, MONITOR_WAIT_TIMEOUT); - if (err != JVMTI_ERROR_INVALID_MONITOR) { - printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/rawmnwait002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/rawmnwait002.cpp new file mode 100644 index 00000000000..5d01395b2b8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait002/rawmnwait002.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define MONITOR_WAIT_TIMEOUT ((jlong)100) + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnwait002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnwait002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnwait002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorWait_rawmnwait002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid monitor check ...\n"); + } + + err = jvmti->RawMonitorWait(NULL, MONITOR_WAIT_TIMEOUT); + if (err != JVMTI_ERROR_INVALID_MONITOR) { + printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/librawmnwait003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/librawmnwait003.c deleted file mode 100644 index 753baa579ec..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/librawmnwait003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnwait003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/librawmnwait003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/librawmnwait003.cpp new file mode 100644 index 00000000000..15a5fd324e2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/librawmnwait003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnwait003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/rawmnwait003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/rawmnwait003.c deleted file mode 100644 index cf14e304712..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/rawmnwait003.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define MONITOR_WAIT_TIMEOUT ((jlong)100) - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static char bad_buf[] = "this is a bad raw monitor"; -static jrawMonitorID bad_monitor = (jrawMonitorID)bad_buf; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnwait003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnwait003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnwait003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorWait_rawmnwait003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorWait(jvmti, bad_monitor, MONITOR_WAIT_TIMEOUT); - if (err != JVMTI_ERROR_INVALID_MONITOR) { - printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/rawmnwait003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/rawmnwait003.cpp new file mode 100644 index 00000000000..b83e1e55b75 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait003/rawmnwait003.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define MONITOR_WAIT_TIMEOUT ((jlong)100) + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static char bad_buf[] = "this is a bad raw monitor"; +static jrawMonitorID bad_monitor = (jrawMonitorID)bad_buf; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnwait003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnwait003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnwait003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorWait_rawmnwait003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid monitor check ...\n"); + } + + err = jvmti->RawMonitorWait(bad_monitor, MONITOR_WAIT_TIMEOUT); + if (err != JVMTI_ERROR_INVALID_MONITOR) { + printf("Error expected: JVMTI_ERROR_INVALID_MONITOR,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/librawmnwait004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/librawmnwait004.c deleted file mode 100644 index 587a5e4068e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/librawmnwait004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnwait004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/librawmnwait004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/librawmnwait004.cpp new file mode 100644 index 00000000000..eeda2c1f4ba --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/librawmnwait004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnwait004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/rawmnwait004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/rawmnwait004.c deleted file mode 100644 index 393258697e9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/rawmnwait004.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define MONITOR_WAIT_TIMEOUT ((jlong)100) - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnwait004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnwait004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnwait004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorWait_rawmnwait004_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jrawMonitorID monitor; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "test monitor", &monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> unowned monitor check ...\n"); - } - - err = (*jvmti)->RawMonitorWait(jvmti, monitor, MONITOR_WAIT_TIMEOUT); - if (err != JVMTI_ERROR_NOT_MONITOR_OWNER) { - printf("Error expected: JVMTI_ERROR_NOT_MONITOR_OWNER,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/rawmnwait004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/rawmnwait004.cpp new file mode 100644 index 00000000000..d1af1464770 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait004/rawmnwait004.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define MONITOR_WAIT_TIMEOUT ((jlong)100) + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnwait004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnwait004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnwait004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorWait_rawmnwait004_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jrawMonitorID monitor; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->CreateRawMonitor("test monitor", &monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> unowned monitor check ...\n"); + } + + err = jvmti->RawMonitorWait(monitor, MONITOR_WAIT_TIMEOUT); + if (err != JVMTI_ERROR_NOT_MONITOR_OWNER) { + printf("Error expected: JVMTI_ERROR_NOT_MONITOR_OWNER,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/librawmnwait005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/librawmnwait005.c deleted file mode 100644 index d5b3617ce4b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/librawmnwait005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmnwait005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/librawmnwait005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/librawmnwait005.cpp new file mode 100644 index 00000000000..32510e8858b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/librawmnwait005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmnwait005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/rawmnwait005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/rawmnwait005.c deleted file mode 100644 index b7af7018cae..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/rawmnwait005.c +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define MILLIS_PER_MINUTE (60 * 1000) - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jrawMonitorID monitor; -static jrawMonitorID wait_lock; -static jlong wait_time; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmnwait005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmnwait005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmnwait005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_signal_thread) { - printf("Warning: InterruptThread is not implemented\n"); - } - - return JNI_OK; -} - -static void JNICALL -test_thread(jvmtiEnv* jvmti, JNIEnv* jni, void *unused) { - jvmtiError err; - const char* const thread_name = "test thread"; - - err = (*jvmti)->RawMonitorEnter(jvmti, monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#test) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> [%s] acquired lock for 'monitor' ...\n", thread_name); - } - - err = (*jvmti)->RawMonitorEnter(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#wait) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> [%s] acquired lock for 'wait_lock' ...\n", thread_name); - printf(">>> [%s] notifying main thread (wait_lock.notify) ...\n", thread_name); - } - - err = (*jvmti)->RawMonitorNotify(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait#wait) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - err = (*jvmti)->RawMonitorExit(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#wait) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> [%s] waiting for interrupt ...\n", thread_name); - } - - err = (*jvmti)->RawMonitorWait(jvmti, monitor, wait_time); - if (err != JVMTI_ERROR_INTERRUPT) { - printf("Error expected: JVMTI_ERROR_INTERRUPT,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorExit(jvmti, monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#test) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> [%s] all done\n", thread_name); - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RawMonitorWait_rawmnwait005_check(JNIEnv *env, - jclass cls, jthread thr, jint wtime) { - jvmtiError err; - const char* const thread_name = "main thread"; - - if (!caps.can_signal_thread) { - return result; - } - - wait_time = wtime * MILLIS_PER_MINUTE; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "test monitor", &monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#test) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - // 'wait_lock' is used to notify current thread when child thread ('test_thread') - // is ready. This in particular means 'test_thread' is waiting for notification - // of the raw monitor 'monitor' and current thread can now interrupt 'test_thread'. - // - err = (*jvmti)->CreateRawMonitor(jvmti, "wait lock", &wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor#wait) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - // get exclusive ownership of 'wait_lock' monitor before - // starting 'test_thread' to avoid following race condition: - // 'test_thread' | current thread - // ------------------------------------- - // | RunAgentThread(..., test_thread, ...) - // wait_lock.enter | - // wait_lock.notify | - // | wait_lock.enter - // | wait_lock.wait(0) - // ... | - // | ... will wait forever ... - // - // See also 6399368 test bug. - // - err = (*jvmti)->RawMonitorEnter(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#wait) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> [%s] acquired lock for 'wait_lock' ... \n", thread_name); - } - - if (printdump == JNI_TRUE) { - printf(">>> [%s] starting test thread ...\n", thread_name); - } - err = (*jvmti)->RunAgentThread(jvmti, thr, test_thread, NULL, - JVMTI_THREAD_NORM_PRIORITY); - if (err != JVMTI_ERROR_NONE) { - printf("(RunDebugThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> [%s] waiting for test thread to run (do wait_lock.wait)...\n", thread_name); - } - err = (*jvmti)->RawMonitorWait(jvmti, wait_lock, (jlong)0); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait#wait) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> [%s] got notification from test thread ...\n", thread_name); - } - - err = (*jvmti)->RawMonitorExit(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#wait) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorEnter(jvmti, monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#test) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> [%s] acquired lock for 'monitor' ... \n", thread_name); - } - - if (printdump == JNI_TRUE) { - printf(">>> [%s] interrupting test thread ...\n", thread_name); - } - - err = (*jvmti)->InterruptThread(jvmti, thr); - if (err != JVMTI_ERROR_NONE) { - printf("(InterruptThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorExit(jvmti, monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#test) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> [%s] all done\n", thread_name); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/rawmnwait005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/rawmnwait005.cpp new file mode 100644 index 00000000000..ab4d7a1f773 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorWait/rawmnwait005/rawmnwait005.cpp @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define MILLIS_PER_MINUTE (60 * 1000) + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jrawMonitorID monitor; +static jrawMonitorID wait_lock; +static jlong wait_time; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmnwait005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmnwait005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmnwait005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_signal_thread) { + printf("Warning: InterruptThread is not implemented\n"); + } + + return JNI_OK; +} + +static void JNICALL +test_thread(jvmtiEnv* jvmti, JNIEnv* jni, void *unused) { + jvmtiError err; + const char* const thread_name = "test thread"; + + err = jvmti->RawMonitorEnter(monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#test) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> [%s] acquired lock for 'monitor' ...\n", thread_name); + } + + err = jvmti->RawMonitorEnter(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#wait) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> [%s] acquired lock for 'wait_lock' ...\n", thread_name); + printf(">>> [%s] notifying main thread (wait_lock.notify) ...\n", thread_name); + } + + err = jvmti->RawMonitorNotify(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait#wait) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + err = jvmti->RawMonitorExit(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#wait) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> [%s] waiting for interrupt ...\n", thread_name); + } + + err = jvmti->RawMonitorWait(monitor, wait_time); + if (err != JVMTI_ERROR_INTERRUPT) { + printf("Error expected: JVMTI_ERROR_INTERRUPT,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorExit(monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#test) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> [%s] all done\n", thread_name); + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RawMonitorWait_rawmnwait005_check(JNIEnv *env, + jclass cls, jthread thr, jint wtime) { + jvmtiError err; + const char* const thread_name = "main thread"; + + if (!caps.can_signal_thread) { + return result; + } + + wait_time = wtime * MILLIS_PER_MINUTE; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->CreateRawMonitor("test monitor", &monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#test) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + // 'wait_lock' is used to notify current thread when child thread ('test_thread') + // is ready. This in particular means 'test_thread' is waiting for notification + // of the raw monitor 'monitor' and current thread can now interrupt 'test_thread'. + // + err = jvmti->CreateRawMonitor("wait lock", &wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor#wait) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + // get exclusive ownership of 'wait_lock' monitor before + // starting 'test_thread' to avoid following race condition: + // 'test_thread' | current thread + // ------------------------------------- + // | RunAgentThread(..., test_thread, ...) + // wait_lock.enter | + // wait_lock.notify | + // | wait_lock.enter + // | wait_lock.wait(0) + // ... | + // | ... will wait forever ... + // + // See also 6399368 test bug. + // + err = jvmti->RawMonitorEnter(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#wait) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> [%s] acquired lock for 'wait_lock' ... \n", thread_name); + } + + if (printdump == JNI_TRUE) { + printf(">>> [%s] starting test thread ...\n", thread_name); + } + err = jvmti->RunAgentThread(thr, test_thread, NULL, + JVMTI_THREAD_NORM_PRIORITY); + if (err != JVMTI_ERROR_NONE) { + printf("(RunDebugThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> [%s] waiting for test thread to run (do wait_lock.wait)...\n", thread_name); + } + err = jvmti->RawMonitorWait(wait_lock, (jlong)0); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait#wait) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> [%s] got notification from test thread ...\n", thread_name); + } + + err = jvmti->RawMonitorExit(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#wait) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + err = jvmti->RawMonitorEnter(monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#test) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> [%s] acquired lock for 'monitor' ... \n", thread_name); + } + + if (printdump == JNI_TRUE) { + printf(">>> [%s] interrupting test thread ...\n", thread_name); + } + + err = jvmti->InterruptThread(thr); + if (err != JVMTI_ERROR_NONE) { + printf("(InterruptThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorExit(monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#test) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> [%s] all done\n", thread_name); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/libstressRedefine.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/libstressRedefine.c deleted file mode 100644 index f08dd0b84c0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/libstressRedefine.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "stressRedefine.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/libstressRedefine.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/libstressRedefine.cpp new file mode 100644 index 00000000000..04d6a1cb4b2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/libstressRedefine.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "stressRedefine.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/stressRedefine.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/stressRedefine.c deleted file mode 100644 index 3a709d5beb1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/stressRedefine.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; - -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), - JVMTI_VERSION_1_1)) != JNI_OK) { - printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_StressRedefine_makeRedefinition(JNIEnv *env, - jclass cls, jint fl, jclass redefCls, jbyteArray classBytes) { - jvmtiClassDefinition classDef; - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_redefine_classes) { - return PASSED; - } - -/* filling the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), - NULL); - - if (fl == 2) { - printf(">>>>>>>> Invoke RedefineClasses():\n"); - printf("\tnew class byte count=%d\n", classDef.class_byte_count); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err != JVMTI_ERROR_NONE) { - printf("%s: Failed to call RedefineClasses():\n", __FILE__); - printf("\tthe function returned error %d: %s\n", - err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - return STATUS_FAILED; - } - if (fl == 2) - printf("<<<<<<<< RedefineClasses() is successfully done\n"); - - return PASSED; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/stressRedefine.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/stressRedefine.cpp new file mode 100644 index 00000000000..785812902c0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine/stressRedefine.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; + +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), + JVMTI_VERSION_1_1)) != JNI_OK) { + printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_StressRedefine_makeRedefinition(JNIEnv *env, + jclass cls, jint fl, jclass redefCls, jbyteArray classBytes) { + jvmtiClassDefinition classDef; + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_redefine_classes) { + return PASSED; + } + +/* filling the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), + NULL); + + if (fl == 2) { + printf(">>>>>>>> Invoke RedefineClasses():\n"); + printf("\tnew class byte count=%d\n", classDef.class_byte_count); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err != JVMTI_ERROR_NONE) { + printf("%s: Failed to call RedefineClasses():\n", __FILE__); + printf("\tthe function returned error %d: %s\n", + err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + return STATUS_FAILED; + } + if (fl == 2) + printf("<<<<<<<< RedefineClasses() is successfully done\n"); + + return PASSED; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/libredefclass001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/libredefclass001.c deleted file mode 100644 index d7fe25ea527..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/libredefclass001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/libredefclass001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/libredefclass001.cpp new file mode 100644 index 00000000000..e7ccc7c6d9a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/libredefclass001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/redefclass001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/redefclass001.c deleted file mode 100644 index 13bccfb080d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/redefclass001.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), - JVMTI_VERSION_1_1)) != JNI_OK) { - printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass001_makeRedefinition(JNIEnv *env, - jclass cls, jint fl, jclass redefCls, jbyteArray classBytes) { - jvmtiClassDefinition classDef; - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_redefine_classes) { - return PASSED; - } - -/* filling the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), - NULL); - - if (fl == 2) { - printf(">>>>>>>> Invoke RedefineClasses():\n"); - printf("\tnew class byte count=%d\n", classDef.class_byte_count); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err != JVMTI_ERROR_NONE) { - printf("%s: Failed to call RedefineClasses():\n", __FILE__); - printf("\tthe function returned error %d: %s\n", - err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - return STATUS_FAILED; - } - if (fl == 2) - printf("<<<<<<<< RedefineClasses() is successfully done\n"); - - return PASSED; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/redefclass001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/redefclass001.cpp new file mode 100644 index 00000000000..07330667a31 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/redefclass001.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), + JVMTI_VERSION_1_1)) != JNI_OK) { + printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass001_makeRedefinition(JNIEnv *env, + jclass cls, jint fl, jclass redefCls, jbyteArray classBytes) { + jvmtiClassDefinition classDef; + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_redefine_classes) { + return PASSED; + } + +/* filling the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), + NULL); + + if (fl == 2) { + printf(">>>>>>>> Invoke RedefineClasses():\n"); + printf("\tnew class byte count=%d\n", classDef.class_byte_count); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err != JVMTI_ERROR_NONE) { + printf("%s: Failed to call RedefineClasses():\n", __FILE__); + printf("\tthe function returned error %d: %s\n", + err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + return STATUS_FAILED; + } + if (fl == 2) + printf("<<<<<<<< RedefineClasses() is successfully done\n"); + + return PASSED; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/libredefclass002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/libredefclass002.c deleted file mode 100644 index c171d0b2ab3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/libredefclass002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/libredefclass002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/libredefclass002.cpp new file mode 100644 index 00000000000..4437e63b899 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/libredefclass002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/redefclass002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/redefclass002.c deleted file mode 100644 index 2b83da28272..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/redefclass002.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), - JVMTI_VERSION_1_1)) != JNI_OK) { - printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - if (!caps.can_suspend) { - printf("Warning: suspend/resume is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass002_suspThread(JNIEnv *env, jclass cls, jint vrb, - jobject susThr) { - jvmtiError err; - - if (vrb == 1) - printf(">>>>>>>> Invoke SuspendThread()\n"); - if ((err = ((*jvmti)->SuspendThread(jvmti, susThr))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call SuspendThread():\n\tthe function returned error %d: %s\n", - __FILE__, err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - return JNI_ERR; - } - if (vrb == 1) - printf("<<<<<<<< SuspendThread() is successfully done\n"); - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass002_resThread(JNIEnv *env, jclass cls, jint vrb, - jobject susThr) { - jvmtiError err; - - if (vrb == 1) - printf(">>>>>>>> Invoke ResumeThread()\n"); - if ((err = ((*jvmti)->ResumeThread(jvmti, susThr))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call ResumThread():\n\tthe function returned error %d: %s\n", - __FILE__, err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - return JNI_ERR; - } - if (vrb == 1) - printf("<<<<<<<< ResumeThread() is successfully done\n"); - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass002_makeRedefinition(JNIEnv *env, jclass cls, jint vrb, - jclass redefCls, jbyteArray classBytes) { - jvmtiClassDefinition classDef; - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_redefine_classes || !caps.can_suspend) { - return PASSED; - } - -/* filling the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); - - if (vrb == 1) - printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", - classDef.class_byte_count); - if ((err = ((*jvmti)->RedefineClasses(jvmti, 1, &classDef))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call RedefineClasses():\n\tthe function returned error %d: %s\n", - __FILE__, err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - return STATUS_FAILED; - } - if (vrb == 1) - printf("<<<<<<<< RedefineClasses() is successfully done\n"); - - return PASSED; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/redefclass002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/redefclass002.cpp new file mode 100644 index 00000000000..fd7b01569cf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass002/redefclass002.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), + JVMTI_VERSION_1_1)) != JNI_OK) { + printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + if (!caps.can_suspend) { + printf("Warning: suspend/resume is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass002_suspThread(JNIEnv *env, jclass cls, jint vrb, + jobject susThr) { + jvmtiError err; + + if (vrb == 1) + printf(">>>>>>>> Invoke SuspendThread()\n"); + if ((err = (jvmti->SuspendThread(susThr))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call SuspendThread():\n\tthe function returned error %d: %s\n", + __FILE__, err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + return JNI_ERR; + } + if (vrb == 1) + printf("<<<<<<<< SuspendThread() is successfully done\n"); + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass002_resThread(JNIEnv *env, jclass cls, jint vrb, + jobject susThr) { + jvmtiError err; + + if (vrb == 1) + printf(">>>>>>>> Invoke ResumeThread()\n"); + if ((err = (jvmti->ResumeThread(susThr))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call ResumThread():\n\tthe function returned error %d: %s\n", + __FILE__, err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + return JNI_ERR; + } + if (vrb == 1) + printf("<<<<<<<< ResumeThread() is successfully done\n"); + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass002_makeRedefinition(JNIEnv *env, jclass cls, jint vrb, + jclass redefCls, jbyteArray classBytes) { + jvmtiClassDefinition classDef; + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_redefine_classes || !caps.can_suspend) { + return PASSED; + } + +/* filling the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); + + if (vrb == 1) + printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", + classDef.class_byte_count); + if ((err = (jvmti->RedefineClasses(1, &classDef))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call RedefineClasses():\n\tthe function returned error %d: %s\n", + __FILE__, err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + return STATUS_FAILED; + } + if (vrb == 1) + printf("<<<<<<<< RedefineClasses() is successfully done\n"); + + return PASSED; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/libredefclass003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/libredefclass003.c deleted file mode 100644 index 8b1ed3b7040..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/libredefclass003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/libredefclass003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/libredefclass003.cpp new file mode 100644 index 00000000000..aa4d7348c1e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/libredefclass003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/redefclass003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/redefclass003.c deleted file mode 100644 index d17039f4514..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/redefclass003.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 -#define NO_RESULTS 3 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), - JVMTI_VERSION_1_1)) != JNI_OK) { - printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass003_makeRedefinition(JNIEnv *env, jclass cls, jint vrb, - jclass redefCls, jbyteArray classBytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - int no_results = 0; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_redefine_classes) { - return PASSED; - } - -/* filling the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); - - if (vrb == 1) - printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", - classDef.class_byte_count); - if ((err = ((*jvmti)->RedefineClasses(jvmti, 1, &classDef))) != JVMTI_ERROR_NONE) { - if (err == JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED) { - printf("Warning: unrestrictedly redefinition of classes is not implemented,\n\ -\tso the test has no results.\n"); - no_results = 1; - } - else { - printf("%s: Failed to call RedefineClasses():\n\tthe function returned error %d: %s\n", - __FILE__, err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - } - if (no_results == 1) return NO_RESULTS; - else return JNI_ERR; - } - if (vrb == 1) - printf("<<<<<<<< RedefineClasses() is successfully done\n"); - - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass003_checkNewFields(JNIEnv *env, - jclass obj, jint vrb, jclass redefCls) { - jfieldID fid; - jint intFld; - jlong longFld; - - if ((fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, redefCls), - "intComplNewFld", "I")) == NULL) { - printf("%s: Failed to get the field ID for the static field \"intComplNewFld\"\n", - __FILE__); - return STATUS_FAILED; - } - intFld = JNI_ENV_PTR(env)->GetStaticIntField(JNI_ENV_ARG(env, redefCls), - fid); - - if ((fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, redefCls), - "longComplNewFld", "J")) == NULL) { - printf("%s: Failed to get the field ID for the static field \"longComplNewFld\"\n", - __FILE__); - return STATUS_FAILED; - } - longFld = JNI_ENV_PTR(env)->GetStaticLongField(JNI_ENV_ARG(env, redefCls), - fid); - - if (intFld != 33 || longFld != 44) { - printf("Completely new static variable has not assigned its default value:\n"); - printf("\tintComplNewFld = %d, expected 33\n", intFld); - printf("\tlongComplNewFld = %"LL"d, expected 44\n", longFld); - return STATUS_FAILED; - } else { - if (vrb == 1) - printf("Completely new static variables:\n\ -\tintComplNewFld = %d\n\tlongComplNewFld = %"LL"d\n", intFld, longFld); - return PASSED; - } -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/redefclass003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/redefclass003.cpp new file mode 100644 index 00000000000..4ba28088dce --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass003/redefclass003.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 +#define NO_RESULTS 3 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), + JVMTI_VERSION_1_1)) != JNI_OK) { + printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass003_makeRedefinition(JNIEnv *env, jclass cls, jint vrb, + jclass redefCls, jbyteArray classBytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + int no_results = 0; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_redefine_classes) { + return PASSED; + } + +/* filling the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); + + if (vrb == 1) + printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", + classDef.class_byte_count); + if ((err = (jvmti->RedefineClasses(1, &classDef))) != JVMTI_ERROR_NONE) { + if (err == JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED) { + printf("Warning: unrestrictedly redefinition of classes is not implemented,\n\ +\tso the test has no results.\n"); + no_results = 1; + } + else { + printf("%s: Failed to call RedefineClasses():\n\tthe function returned error %d: %s\n", + __FILE__, err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + } + if (no_results == 1) return NO_RESULTS; + else return JNI_ERR; + } + if (vrb == 1) + printf("<<<<<<<< RedefineClasses() is successfully done\n"); + + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass003_checkNewFields(JNIEnv *env, + jclass obj, jint vrb, jclass redefCls) { + jfieldID fid; + jint intFld; + jlong longFld; + + if ((fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, redefCls), + "intComplNewFld", "I")) == NULL) { + printf("%s: Failed to get the field ID for the static field \"intComplNewFld\"\n", + __FILE__); + return STATUS_FAILED; + } + intFld = JNI_ENV_PTR(env)->GetStaticIntField(JNI_ENV_ARG(env, redefCls), + fid); + + if ((fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, redefCls), + "longComplNewFld", "J")) == NULL) { + printf("%s: Failed to get the field ID for the static field \"longComplNewFld\"\n", + __FILE__); + return STATUS_FAILED; + } + longFld = JNI_ENV_PTR(env)->GetStaticLongField(JNI_ENV_ARG(env, redefCls), + fid); + + if (intFld != 33 || longFld != 44) { + printf("Completely new static variable has not assigned its default value:\n"); + printf("\tintComplNewFld = %d, expected 33\n", intFld); + printf("\tlongComplNewFld = %" LL "d, expected 44\n", longFld); + return STATUS_FAILED; + } else { + if (vrb == 1) + printf("Completely new static variables:\n\ +\tintComplNewFld = %d\n\tlongComplNewFld = %" LL "d\n", intFld, longFld); + return PASSED; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/libredefclass004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/libredefclass004.c deleted file mode 100644 index 8abac692f17..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/libredefclass004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/libredefclass004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/libredefclass004.cpp new file mode 100644 index 00000000000..cb8717ac7cf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/libredefclass004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/redefclass004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/redefclass004.c deleted file mode 100644 index 80f5b12ee2f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/redefclass004.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 -#define NO_RESULTS 3 - -/* expected values of new instance fields */ -static jint INTFLD = 333; -static jlong LONGFLD = 444; -#define STRFLD "completely new String field" - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), - JVMTI_VERSION_1_1)) != JNI_OK) { - printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass004_makeRedefinition(JNIEnv *env, - jclass cls, jint vrb, jclass redefCls, jbyteArray classBytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - int no_results = 0; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_redefine_classes) { - return PASSED; - } - -/* fill the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); - - if (vrb == 1) - printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", - classDef.class_byte_count); - if ((err = ((*jvmti)->RedefineClasses(jvmti, 1, &classDef))) != JVMTI_ERROR_NONE) { - if (err == JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED) { - printf("Warning: unrestrictedly redefinition of classes is not implemented,\n\ -\tso the test has no results.\n"); - no_results = 1; - } - else { - printf("%s: Failed to call RedefineClasses():\n\tthe function returned error %d: %s\n", - __FILE__, err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - } - if (no_results == 1) return NO_RESULTS; - else return JNI_ERR; - } - if (vrb == 1) - printf("<<<<<<<< RedefineClasses() is successfully done\n"); - - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass004_checkNewFields(JNIEnv *env, - jobject obj, jint vrb, jobject redefObj) { - jclass redefCls = - JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, redefObj)); - jfieldID fid; - jint intFld; - jlong longFld; - jstring stringObj; - const char *strFld = NULL; - -/* get value of new instance field "intComplNewFld" */ - if ((fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, redefCls), - "intComplNewFld", "I")) == NULL) { - printf("%s: Failed to get the field ID for the field \"intComplNewFld\"\n", - __FILE__); - return STATUS_FAILED; - } - intFld = JNI_ENV_PTR(env)->GetIntField(JNI_ENV_ARG(env, redefObj), fid); - -/* get value of new instance field "longComplNewFld" */ - if ((fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, redefCls), - "longComplNewFld", "J")) == NULL) { - printf("%s: Failed to get the field ID for the field \"longComplNewFld\"\n", - __FILE__); - return STATUS_FAILED; - } - longFld = JNI_ENV_PTR(env)->GetLongField(JNI_ENV_ARG(env, redefObj), fid); - -/* get value of new instance field "stringComplNewFld" */ - if ((fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, redefCls), - "stringComplNewFld", "Ljava/lang/String;")) == NULL) { - printf("%s: Failed to get the field ID for the field \"stringComplNewFld\"\n", - __FILE__); - return STATUS_FAILED; - } - stringObj = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG(env, - redefObj), fid); - strFld = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, - stringObj), 0); - - if (intFld != INTFLD || longFld != LONGFLD || - strcmp(strFld, STRFLD) != 0) { - printf("Completely new fields have not assigned their default values:\n"); - printf("\tintComplNewFld = %d,\texpected %d\n", - intFld, INTFLD); - printf("\tlongComplNewFld = %"LL"d", longFld); - printf(",\texpected %"LL"d\n", LONGFLD); - printf("\tstringComplNewFld = \"%s\",\texpected \"%s\"\n", - strFld, STRFLD); - JNI_ENV_PTR(env)->ReleaseStringUTFChars(JNI_ENV_ARG(env, - stringObj), strFld); - return STATUS_FAILED; - } else { - if (vrb == 1) - printf("Completely new fields:\n\ -\tstringComplNewFld = \"%s\"\n\tintComplNewFld = %d\n\ -\tlongComplNewFld = %"LL"d\n", - strFld, intFld, longFld); - JNI_ENV_PTR(env)->ReleaseStringUTFChars(JNI_ENV_ARG(env, - stringObj), strFld); - return PASSED; - } -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/redefclass004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/redefclass004.cpp new file mode 100644 index 00000000000..c828ae81f41 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass004/redefclass004.cpp @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 +#define NO_RESULTS 3 + +/* expected values of new instance fields */ +static jint INTFLD = 333; +static jlong LONGFLD = 444; +#define STRFLD "completely new String field" + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), + JVMTI_VERSION_1_1)) != JNI_OK) { + printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass004_makeRedefinition(JNIEnv *env, + jclass cls, jint vrb, jclass redefCls, jbyteArray classBytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + int no_results = 0; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_redefine_classes) { + return PASSED; + } + +/* fill the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); + + if (vrb == 1) + printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", + classDef.class_byte_count); + if ((err = (jvmti->RedefineClasses(1, &classDef))) != JVMTI_ERROR_NONE) { + if (err == JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED) { + printf("Warning: unrestrictedly redefinition of classes is not implemented,\n\ +\tso the test has no results.\n"); + no_results = 1; + } + else { + printf("%s: Failed to call RedefineClasses():\n\tthe function returned error %d: %s\n", + __FILE__, err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + } + if (no_results == 1) return NO_RESULTS; + else return JNI_ERR; + } + if (vrb == 1) + printf("<<<<<<<< RedefineClasses() is successfully done\n"); + + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass004_checkNewFields(JNIEnv *env, + jobject obj, jint vrb, jobject redefObj) { + jclass redefCls = + JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, redefObj)); + jfieldID fid; + jint intFld; + jlong longFld; + jstring stringObj; + const char *strFld = NULL; + +/* get value of new instance field "intComplNewFld" */ + if ((fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, redefCls), + "intComplNewFld", "I")) == NULL) { + printf("%s: Failed to get the field ID for the field \"intComplNewFld\"\n", + __FILE__); + return STATUS_FAILED; + } + intFld = JNI_ENV_PTR(env)->GetIntField(JNI_ENV_ARG(env, redefObj), fid); + +/* get value of new instance field "longComplNewFld" */ + if ((fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, redefCls), + "longComplNewFld", "J")) == NULL) { + printf("%s: Failed to get the field ID for the field \"longComplNewFld\"\n", + __FILE__); + return STATUS_FAILED; + } + longFld = JNI_ENV_PTR(env)->GetLongField(JNI_ENV_ARG(env, redefObj), fid); + +/* get value of new instance field "stringComplNewFld" */ + if ((fid = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, redefCls), + "stringComplNewFld", "Ljava/lang/String;")) == NULL) { + printf("%s: Failed to get the field ID for the field \"stringComplNewFld\"\n", + __FILE__); + return STATUS_FAILED; + } + stringObj = (jstring) JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG(env, + redefObj), fid); + strFld = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, + stringObj), 0); + + if (intFld != INTFLD || longFld != LONGFLD || + strcmp(strFld, STRFLD) != 0) { + printf("Completely new fields have not assigned their default values:\n"); + printf("\tintComplNewFld = %d,\texpected %d\n", + intFld, INTFLD); + printf("\tlongComplNewFld = %" LL "d", longFld); + printf(",\texpected %" LL "d\n", LONGFLD); + printf("\tstringComplNewFld = \"%s\",\texpected \"%s\"\n", + strFld, STRFLD); + JNI_ENV_PTR(env)->ReleaseStringUTFChars(JNI_ENV_ARG(env, + stringObj), strFld); + return STATUS_FAILED; + } else { + if (vrb == 1) + printf("Completely new fields:\n\ +\tstringComplNewFld = \"%s\"\n\tintComplNewFld = %d\n\ +\tlongComplNewFld = %" LL "d\n", + strFld, intFld, longFld); + JNI_ENV_PTR(env)->ReleaseStringUTFChars(JNI_ENV_ARG(env, + stringObj), strFld); + return PASSED; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/libredefclass005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/libredefclass005.c deleted file mode 100644 index 0171f1f2967..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/libredefclass005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/libredefclass005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/libredefclass005.cpp new file mode 100644 index 00000000000..7715a799aba --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/libredefclass005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/redefclass005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/redefclass005.c deleted file mode 100644 index 3a30680e1db..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/redefclass005.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static int watch_ev = 0; /* ignore JVMTI events by default */ -static int CFLH_gen_ev = 0; /* number of generated ClassFileLoadHook events */ -static int gen_ev = 0; /* number of generated events */ -static int result = PASSED; /* total result of the test */ - -static jrawMonitorID watch_ev_monitor; - -static void set_watch_ev(int value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - watch_ev = value; - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *env, jclass class_being_redefined, - jobject loader, const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev && class_being_redefined != NULL) { - printf("#### JVMTI_EVENT_CLASS_FILE_LOAD_HOOK occurred ####\n"); - CFLH_gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jclass cls) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev) { - printf("#### JVMTI_EVENT_CLASS_LOAD occurred ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jclass cls) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev) { - printf("#### JVMTI_EVENT_CLASS_PREPARE occurred ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), - JVMTI_VERSION_1_1)) != JNI_OK) { - printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - callbacks.ClassLoad = &ClassLoad; - callbacks.ClassPrepare = &ClassPrepare; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "watch_ev_monitor", &watch_ev_monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass005_makeRedefinition(JNIEnv *env, - jclass cls, jint vrb, jclass redefCls, jbyteArray classBytes) { - jvmtiError err; - jthread thread; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_redefine_classes) { - return PASSED; - } - - if ((err = ((*jvmti)->GetCurrentThread(jvmti, &thread))) != JVMTI_ERROR_NONE) { - printf("Failed to get current thread: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - return STATUS_FAILED; - } - - if ((err = ((*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) != JVMTI_ERROR_NONE) { - printf("Failed to enable event JVMTI_EVENT_CLASS_FILE_LOAD_HOOK: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if ((err = ((*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_CLASS_LOAD, thread))) != JVMTI_ERROR_NONE) { - printf("Failed to enable event JVMTI_EVENT_CLASS_LOAD: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if ((err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_CLASS_PREPARE, thread)) != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - -/* filling the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); - - set_watch_ev(1); /* watch JVMTI events */ - - if (vrb == 1) - printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", - classDef.class_byte_count); - if ((err = ((*jvmti)->RedefineClasses(jvmti, 1, &classDef))) != JVMTI_ERROR_NONE) { - printf("TEST FAILED: the function RedefineClasses() returned error %d: %s\n", - err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - result = STATUS_FAILED; - } - else if (vrb == 1) - printf("Check #1 PASSED: RedefineClasses() is successfully done\n"); - - set_watch_ev(0); /* again ignore JVMTI events */ - - if (CFLH_gen_ev == 0) { - printf("TEST FAILED: ClassFileLoadHook event was not generated by the function RedefineClasses()\n"); - result = STATUS_FAILED; - } else if (vrb == 1) - printf("Check #2 PASSED: %d ClassFileLoadHook events were generated by the function RedefineClasses()\n", - CFLH_gen_ev); - if (gen_ev) { - printf("TEST FAILED: %d unexpected JVMTI events were generated by the function RedefineClasses()\n", - gen_ev); - result = STATUS_FAILED; - } else if (vrb == 1) - printf("Check #2 PASSED: No unexpected JVMTI events were generated by the function RedefineClasses()\n"); - - return(result); -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/redefclass005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/redefclass005.cpp new file mode 100644 index 00000000000..10bb269e7cf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass005/redefclass005.cpp @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static int watch_ev = 0; /* ignore JVMTI events by default */ +static int CFLH_gen_ev = 0; /* number of generated ClassFileLoadHook events */ +static int gen_ev = 0; /* number of generated events */ +static int result = PASSED; /* total result of the test */ + +static jrawMonitorID watch_ev_monitor; + +static void set_watch_ev(int value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + watch_ev = value; + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *env, jclass class_being_redefined, + jobject loader, const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev && class_being_redefined != NULL) { + printf("#### JVMTI_EVENT_CLASS_FILE_LOAD_HOOK occurred ####\n"); + CFLH_gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jclass cls) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev) { + printf("#### JVMTI_EVENT_CLASS_LOAD occurred ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jclass cls) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev) { + printf("#### JVMTI_EVENT_CLASS_PREPARE occurred ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), + JVMTI_VERSION_1_1)) != JNI_OK) { + printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + callbacks.ClassLoad = &ClassLoad; + callbacks.ClassPrepare = &ClassPrepare; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->CreateRawMonitor("watch_ev_monitor", &watch_ev_monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass005_makeRedefinition(JNIEnv *env, + jclass cls, jint vrb, jclass redefCls, jbyteArray classBytes) { + jvmtiError err; + jthread thread; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_redefine_classes) { + return PASSED; + } + + if ((err = (jvmti->GetCurrentThread(&thread))) != JVMTI_ERROR_NONE) { + printf("Failed to get current thread: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + return STATUS_FAILED; + } + + if ((err = (jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) != JVMTI_ERROR_NONE) { + printf("Failed to enable event JVMTI_EVENT_CLASS_FILE_LOAD_HOOK: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if ((err = (jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_CLASS_LOAD, thread))) != JVMTI_ERROR_NONE) { + printf("Failed to enable event JVMTI_EVENT_CLASS_LOAD: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if ((err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_CLASS_PREPARE, thread)) != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + +/* filling the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); + + set_watch_ev(1); /* watch JVMTI events */ + + if (vrb == 1) + printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", + classDef.class_byte_count); + if ((err = (jvmti->RedefineClasses(1, &classDef))) != JVMTI_ERROR_NONE) { + printf("TEST FAILED: the function RedefineClasses() returned error %d: %s\n", + err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + result = STATUS_FAILED; + } + else if (vrb == 1) + printf("Check #1 PASSED: RedefineClasses() is successfully done\n"); + + set_watch_ev(0); /* again ignore JVMTI events */ + + if (CFLH_gen_ev == 0) { + printf("TEST FAILED: ClassFileLoadHook event was not generated by the function RedefineClasses()\n"); + result = STATUS_FAILED; + } else if (vrb == 1) + printf("Check #2 PASSED: %d ClassFileLoadHook events were generated by the function RedefineClasses()\n", + CFLH_gen_ev); + if (gen_ev) { + printf("TEST FAILED: %d unexpected JVMTI events were generated by the function RedefineClasses()\n", + gen_ev); + result = STATUS_FAILED; + } else if (vrb == 1) + printf("Check #2 PASSED: No unexpected JVMTI events were generated by the function RedefineClasses()\n"); + + return(result); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/libredefclass006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/libredefclass006.c deleted file mode 100644 index 35e47264b44..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/libredefclass006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/libredefclass006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/libredefclass006.cpp new file mode 100644 index 00000000000..7044b838d9d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/libredefclass006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/redefclass006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/redefclass006.c deleted file mode 100644 index d7356fdd575..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/redefclass006.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), - JVMTI_VERSION_1_1)) != JNI_OK) { - printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass006_makeRedefinition(JNIEnv *env, - jclass cls, jint t_case, jclass redefCls, jbyteArray classBytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - jvmtiClassDefinition* classDefPtr = NULL; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_redefine_classes) { - return PASSED; - } - - switch(t_case) { -/* NULL pointer to the jvmtiClassDefinition */ - case 0: - break; -/* NULL pointer to the jvmtiClassDefinition in debug mode */ - case 1: - printf("Invoke RedefineClasses() with NULL pointer to the structure jvmtiClassDefinition\n"); - fflush(stdout); - break; -/* NULL pointer to the jvmtiClassDefinition->class_bytes in debug mode */ - case 3: - printf("Invoke RedefineClasses() with NULL pointer to the field jvmtiClassDefinition->class_bytes\n"); - fflush(stdout); - // fallthrough -/* NULL pointer to the jvmtiClassDefinition->class_bytes */ - case 2: - /* partly fill the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = NULL; - classDefPtr = &classDef; - break; - } - -/* explode the bomb */ - if ((err = ((*jvmti)->RedefineClasses(jvmti, 1, classDefPtr))) != JVMTI_ERROR_NULL_POINTER) { - printf("TEST FAILED: the function RedefineClasses() returned error %d: %s\n", - err, TranslateError(err)); - printf("\tBut it should return the error JVMTI_ERROR_NULL_POINTER.\n"); - return STATUS_FAILED; - } - - return PASSED; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/redefclass006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/redefclass006.cpp new file mode 100644 index 00000000000..7f90bf85381 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass006/redefclass006.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), + JVMTI_VERSION_1_1)) != JNI_OK) { + printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass006_makeRedefinition(JNIEnv *env, + jclass cls, jint t_case, jclass redefCls, jbyteArray classBytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + jvmtiClassDefinition* classDefPtr = NULL; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_redefine_classes) { + return PASSED; + } + + switch(t_case) { +/* NULL pointer to the jvmtiClassDefinition */ + case 0: + break; +/* NULL pointer to the jvmtiClassDefinition in debug mode */ + case 1: + printf("Invoke RedefineClasses() with NULL pointer to the structure jvmtiClassDefinition\n"); + fflush(stdout); + break; +/* NULL pointer to the jvmtiClassDefinition->class_bytes in debug mode */ + case 3: + printf("Invoke RedefineClasses() with NULL pointer to the field jvmtiClassDefinition->class_bytes\n"); + fflush(stdout); + // fallthrough +/* NULL pointer to the jvmtiClassDefinition->class_bytes */ + case 2: + /* partly fill the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = NULL; + classDefPtr = &classDef; + break; + } + +/* explode the bomb */ + if ((err = (jvmti->RedefineClasses(1, classDefPtr))) != JVMTI_ERROR_NULL_POINTER) { + printf("TEST FAILED: the function RedefineClasses() returned error %d: %s\n", + err, TranslateError(err)); + printf("\tBut it should return the error JVMTI_ERROR_NULL_POINTER.\n"); + return STATUS_FAILED; + } + + return PASSED; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/libredefclass008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/libredefclass008.c deleted file mode 100644 index 58b6937cad5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/libredefclass008.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass008.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/libredefclass008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/libredefclass008.cpp new file mode 100644 index 00000000000..3b3d5b737fd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/libredefclass008.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass008.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/redefclass008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/redefclass008.c deleted file mode 100644 index b7076e01cba..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/redefclass008.c +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define BP_NUM 5 /* overall number of breakpoints */ - -#define STATUS_FAILED 2 -#define PASSED 0 - -typedef struct { - int inst; /* type of a method: 0- static; 1- instance */ - char *m_name; /* method name */ - char *m_sign; /* JVM signature of a method */ - int loc; /* breakpoint location in a method's body */ - jmethodID mid; /* JNI's method ID */ -} breakpoint; - -/* list of breakpoints */ -static breakpoint breakpoints[] = { - {1, (char*) "checkIt", (char*) "(Ljava/io/PrintStream;Z)I", 0, NULL}, - {1, (char*) "finMethod", (char*) "(JIJ)V", 5, NULL}, - {1, (char*) "finMethod", (char*) "(JIJ)V", 4, NULL}, - {1, (char*) "checkIt", (char*) "(Ljava/io/PrintStream;Z)I", 1, NULL}, - {0, (char*) "statMethod", (char*) "(III)I", 1, NULL} -}; - -static jclass redefCls; /* JNI's Java class object */ - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass008(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), - JVMTI_VERSION_1_1)) != JNI_OK) { - printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass008_setBreakpoints(JNIEnv *env, - jclass cls, jint vrb, jobject redefObj) { - jvmtiError err; - int i; - - if (!caps.can_redefine_classes || !caps.can_generate_breakpoint_events) { - return PASSED; - } - - redefCls = - JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, redefObj)); - - for (i=0; iGetMethodID(JNI_ENV_ARG(env, redefCls), - breakpoints[i].m_name, breakpoints[i].m_sign)) == NULL) { - printf("%s: Failed to get the method ID for the instance method\ - \"%s\" with signature \"%s\"\n", - __FILE__, breakpoints[i].m_name, breakpoints[i].m_sign); - return STATUS_FAILED; - } - } else { /* a static method */ - if ((breakpoints[i].mid = - JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, redefCls), - breakpoints[i].m_name, breakpoints[i].m_sign)) == NULL) { - printf("%s: Failed to get the method ID for the static method\ - \"%s\" with signature \"%s\"\n", - __FILE__, breakpoints[i].m_name, breakpoints[i].m_sign); - return STATUS_FAILED; - } - } - - if (vrb == 1) - printf(">>>>>>>> #%d Invoke SetBreakpoint():\n\tbreakpoint in the %s\ - method: name=\"%s\"; signature=\"%s\"; location=%d\n", - i, breakpoints[i].inst?"instance":"static", - breakpoints[i].m_name, breakpoints[i].m_sign, breakpoints[i].loc); - if ((err = ((*jvmti)->SetBreakpoint(jvmti, breakpoints[i].mid, - breakpoints[i].loc))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call SetBreakpoint(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - return STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - if (vrb == 1) - printf("<<<<<<<< #%d SetBreakpoint() is successfully done\n\n", i); - } - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass008_makeRedefinition(JNIEnv *env, - jclass cls, jint vrb, jclass redefCls, jbyteArray classBytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_redefine_classes || !caps.can_generate_breakpoint_events) { - return PASSED; - } - -/* fill the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); - - if (vrb == 1) - printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", - classDef.class_byte_count); - if ((err = ((*jvmti)->RedefineClasses(jvmti, 1, &classDef))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call RedefineClasses(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - return STATUS_FAILED; - } - if (vrb == 1) - printf("<<<<<<<< RedefineClasses() is successfully done\n\n"); - - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass008_getResult(JNIEnv *env, - jclass cls, jint vrb, jobject redefObj) { - jvmtiError err; - int i; - int totRes = PASSED; - - if (!caps.can_redefine_classes || !caps.can_generate_breakpoint_events) { - return PASSED; - } - - redefCls = - JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, redefObj)); - -/* all breakpoints should be cleared after the redefinition */ - for (i=0; iGetMethodID(JNI_ENV_ARG(env, redefCls), - breakpoints[i].m_name, breakpoints[i].m_sign)) == NULL) { - printf("%s: getResult: Failed to get the method ID for the instance method\ - \"%s\" with signature \"%s\"\n", - __FILE__, breakpoints[i].m_name, breakpoints[i].m_sign); - return STATUS_FAILED; - } - } else { /* a static method */ - if ((breakpoints[i].mid = - JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, redefCls), - breakpoints[i].m_name, breakpoints[i].m_sign)) == NULL) { - printf("%s: getResult: Failed to get the method ID for the static method\ - \"%s\" with signature \"%s\"\n", - __FILE__, breakpoints[i].m_name, breakpoints[i].m_sign); - return STATUS_FAILED; - } - } - - if ((err = ((*jvmti)->ClearBreakpoint(jvmti, breakpoints[i].mid, - breakpoints[i].loc))) != JVMTI_ERROR_NOT_FOUND) { - printf("TEST FAILED: Breakpoint #%d in the %s method:\n\ -\tname=\"%s\"; signature=\"%s\"; location=%d was not cleared:\n\ -\tClearBreakpoint() returned the error %d: %s\n\n", - i, breakpoints[i].inst?"instance":"static", - breakpoints[i].m_name, breakpoints[i].m_sign, - breakpoints[i].loc, err, TranslateError(err)); - totRes = STATUS_FAILED; - } else { - if (vrb == 1) - printf("Check #%d PASSED: Breakpoint in the %s method:\n\ -\tname=\"%s\"; signature=\"%s\"; location=%d was cleared:\n\ -\tClearBreakpoint() returned the error %d: %s\n\n", - i, breakpoints[i].inst?"instance":"static", - breakpoints[i].m_name, breakpoints[i].m_sign, - breakpoints[i].loc, err, TranslateError(err)); - if ((err = ((*jvmti)->SetBreakpoint(jvmti, breakpoints[i].mid, - breakpoints[i].loc))) == JVMTI_ERROR_DUPLICATE) { - printf("TEST FAILED: the function SetBreakpoint() returned the error %d: %s\n\ -\ti.e. the breakpoint #%d has not been really cleared.\n\n", - err, TranslateError(err), i); - totRes = STATUS_FAILED; - } - } - } - - return totRes; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/redefclass008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/redefclass008.cpp new file mode 100644 index 00000000000..93a82a0619c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass008/redefclass008.cpp @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define BP_NUM 5 /* overall number of breakpoints */ + +#define STATUS_FAILED 2 +#define PASSED 0 + +typedef struct { + int inst; /* type of a method: 0- static; 1- instance */ + char *m_name; /* method name */ + char *m_sign; /* JVM signature of a method */ + int loc; /* breakpoint location in a method's body */ + jmethodID mid; /* JNI's method ID */ +} breakpoint; + +/* list of breakpoints */ +static breakpoint breakpoints[] = { + {1, (char*) "checkIt", (char*) "(Ljava/io/PrintStream;Z)I", 0, NULL}, + {1, (char*) "finMethod", (char*) "(JIJ)V", 5, NULL}, + {1, (char*) "finMethod", (char*) "(JIJ)V", 4, NULL}, + {1, (char*) "checkIt", (char*) "(Ljava/io/PrintStream;Z)I", 1, NULL}, + {0, (char*) "statMethod", (char*) "(III)I", 1, NULL} +}; + +static jclass redefCls; /* JNI's Java class object */ + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass008(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), + JVMTI_VERSION_1_1)) != JNI_OK) { + printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass008_setBreakpoints(JNIEnv *env, + jclass cls, jint vrb, jobject redefObj) { + jvmtiError err; + int i; + + if (!caps.can_redefine_classes || !caps.can_generate_breakpoint_events) { + return PASSED; + } + + redefCls = + JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, redefObj)); + + for (i=0; iGetMethodID(JNI_ENV_ARG(env, redefCls), + breakpoints[i].m_name, breakpoints[i].m_sign)) == NULL) { + printf("%s: Failed to get the method ID for the instance method\ + \"%s\" with signature \"%s\"\n", + __FILE__, breakpoints[i].m_name, breakpoints[i].m_sign); + return STATUS_FAILED; + } + } else { /* a static method */ + if ((breakpoints[i].mid = + JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, redefCls), + breakpoints[i].m_name, breakpoints[i].m_sign)) == NULL) { + printf("%s: Failed to get the method ID for the static method\ + \"%s\" with signature \"%s\"\n", + __FILE__, breakpoints[i].m_name, breakpoints[i].m_sign); + return STATUS_FAILED; + } + } + + if (vrb == 1) + printf(">>>>>>>> #%d Invoke SetBreakpoint():\n\tbreakpoint in the %s\ + method: name=\"%s\"; signature=\"%s\"; location=%d\n", + i, breakpoints[i].inst?"instance":"static", + breakpoints[i].m_name, breakpoints[i].m_sign, breakpoints[i].loc); + if ((err = (jvmti->SetBreakpoint(breakpoints[i].mid, + breakpoints[i].loc))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call SetBreakpoint(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + return STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + if (vrb == 1) + printf("<<<<<<<< #%d SetBreakpoint() is successfully done\n\n", i); + } + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass008_makeRedefinition(JNIEnv *env, + jclass cls, jint vrb, jclass redefCls, jbyteArray classBytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_redefine_classes || !caps.can_generate_breakpoint_events) { + return PASSED; + } + +/* fill the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); + + if (vrb == 1) + printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", + classDef.class_byte_count); + if ((err = (jvmti->RedefineClasses(1, &classDef))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call RedefineClasses(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + return STATUS_FAILED; + } + if (vrb == 1) + printf("<<<<<<<< RedefineClasses() is successfully done\n\n"); + + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass008_getResult(JNIEnv *env, + jclass cls, jint vrb, jobject redefObj) { + jvmtiError err; + int i; + int totRes = PASSED; + + if (!caps.can_redefine_classes || !caps.can_generate_breakpoint_events) { + return PASSED; + } + + redefCls = + JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, redefObj)); + +/* all breakpoints should be cleared after the redefinition */ + for (i=0; iGetMethodID(JNI_ENV_ARG(env, redefCls), + breakpoints[i].m_name, breakpoints[i].m_sign)) == NULL) { + printf("%s: getResult: Failed to get the method ID for the instance method\ + \"%s\" with signature \"%s\"\n", + __FILE__, breakpoints[i].m_name, breakpoints[i].m_sign); + return STATUS_FAILED; + } + } else { /* a static method */ + if ((breakpoints[i].mid = + JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, redefCls), + breakpoints[i].m_name, breakpoints[i].m_sign)) == NULL) { + printf("%s: getResult: Failed to get the method ID for the static method\ + \"%s\" with signature \"%s\"\n", + __FILE__, breakpoints[i].m_name, breakpoints[i].m_sign); + return STATUS_FAILED; + } + } + + if ((err = (jvmti->ClearBreakpoint(breakpoints[i].mid, + breakpoints[i].loc))) != JVMTI_ERROR_NOT_FOUND) { + printf("TEST FAILED: Breakpoint #%d in the %s method:\n\ +\tname=\"%s\"; signature=\"%s\"; location=%d was not cleared:\n\ +\tClearBreakpoint() returned the error %d: %s\n\n", + i, breakpoints[i].inst?"instance":"static", + breakpoints[i].m_name, breakpoints[i].m_sign, + breakpoints[i].loc, err, TranslateError(err)); + totRes = STATUS_FAILED; + } else { + if (vrb == 1) + printf("Check #%d PASSED: Breakpoint in the %s method:\n\ +\tname=\"%s\"; signature=\"%s\"; location=%d was cleared:\n\ +\tClearBreakpoint() returned the error %d: %s\n\n", + i, breakpoints[i].inst?"instance":"static", + breakpoints[i].m_name, breakpoints[i].m_sign, + breakpoints[i].loc, err, TranslateError(err)); + if ((err = (jvmti->SetBreakpoint(breakpoints[i].mid, + breakpoints[i].loc))) == JVMTI_ERROR_DUPLICATE) { + printf("TEST FAILED: the function SetBreakpoint() returned the error %d: %s\n\ +\ti.e. the breakpoint #%d has not been really cleared.\n\n", + err, TranslateError(err), i); + totRes = STATUS_FAILED; + } + } + } + + return totRes; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/libredefclass009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/libredefclass009.c deleted file mode 100644 index 527465e7d3f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/libredefclass009.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass009.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/libredefclass009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/libredefclass009.cpp new file mode 100644 index 00000000000..543cb3f40de --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/libredefclass009.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass009.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/redefclass009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/redefclass009.c deleted file mode 100644 index d101775198a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/redefclass009.c +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define METH_NUM 4 /* overall number of methods */ - -#define STATUS_FAILED 2 -#define PASSED 0 - -typedef struct { /* local variable info */ - char *v_name; /* a variable name */ - char *v_sign; /* JVM type signature */ -} localVar; - -/* local variables of redefined methods */ -static localVar constr_lv[] = { /* constructor's local variables */ - {(char*) "this", (char*) "Lnsk/jvmti/RedefineClasses/redefclass009r;"}, - {(char*) "constr_i", (char*) "I"}, - {(char*) "constr_l", (char*) "J"}, - {(char*) "constr_d", (char*) "D"}, - {(char*) "constr_f", (char*) "F"}, - {(char*) "constr_c", (char*) "C"} -}; -static localVar checkIt_lv[] = { /* checkIt()'s local variables */ - {(char*) "this", (char*) "Lnsk/jvmti/RedefineClasses/redefclass009r;"}, - {(char*) "out", (char*) "Ljava/io/PrintStream;"}, - {(char*) "DEBUG_MODE", (char*) "Z"} -}; -static localVar finMeth_lv[] = { /* finMethod()'s local variables */ - {(char*) "this", (char*) "Lnsk/jvmti/RedefineClasses/redefclass009r;"}, - {(char*) "fin_c", (char*) "C"}, - {(char*) "fin_i", (char*) "J"}, - {(char*) "fin_j", (char*) "I"}, - {(char*) "fin_k", (char*) "J"}, - {(char*) "fin_l", (char*) "J"}, - {(char*) "fin_f", (char*) "F"} -}; -static localVar statMeth_lv[] = { /* statMethod()'s local variables */ - {(char*) "stat_x", (char*) "I"}, - {(char*) "stat_y", (char*) "I"}, - {(char*) "stat_z", (char*) "I"}, - {(char*) "stat_j", (char*) "D"}, - {(char*) "stat_i", (char*) "I"} -}; - -typedef struct { /* local variables of a method */ - int inst; /* type of a method: 0- static; 1- instance */ - char *m_name; /* a method name */ - char *m_sign; /* JVM signature of a method */ - int vcount; /* overall number of local variables */ - localVar *vars; - jmethodID mid; /* JNI's method ID */ -} methInfo; - -/* list of original methods with NULL pointers to localVar */ -static methInfo origMethInfo[] = { - {1, (char*) "", (char*) "()V", 1, NULL, NULL}, - {1, (char*) "checkIt", (char*) "(Ljava/io/PrintStream;Z)I", 4, NULL, NULL}, - {1, (char*) "finMethod", (char*) "(CJIJ)V", 5, NULL, NULL}, - {0, (char*) "statMethod", (char*) "(III)D", 3, NULL, NULL} -}; - -/* list of redefined methods */ -static methInfo redefMethInfo[] = { - {1, (char*) "", (char*) "()V", 6, constr_lv, NULL}, - {1, (char*) "checkIt", (char*) "(Ljava/io/PrintStream;Z)I", 3, checkIt_lv, NULL}, - {1, (char*) "finMethod", (char*) "(CJIJ)V", 7, finMeth_lv, NULL}, - {0, (char*) "statMethod", (char*) "(III)D", 5, statMeth_lv, NULL} -}; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass009(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass009(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass009(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), - JVMTI_VERSION_1_1)) != JNI_OK) { - printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - if (!caps.can_access_local_variables) { - printf("Warning: Access to local variables is not implemented\n"); - } - - return JNI_OK; -} - -int checkAttr(JNIEnv *env, jclass redefCls, methInfo methodsInfo[], - jint vrb, int full) { - jvmtiError err; - int i, j, k; - int totRes = PASSED; - jint count = -1; - jvmtiLocalVariableEntry *lv_table; - - if (!caps.can_access_local_variables) { - return PASSED; - } - - for (i=0; iGetMethodID(JNI_ENV_ARG(env, redefCls), - methodsInfo[i].m_name, methodsInfo[i].m_sign); - else /* a static method */ - methodsInfo[i].mid = - JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, redefCls), - methodsInfo[i].m_name, methodsInfo[i].m_sign); - if (methodsInfo[i].mid == NULL) { - printf("%s: Failed to get the method ID for the%s%s method\ - \"%s\", signature \"%s\"\n", - __FILE__, full?" ":" original ", methodsInfo[i].inst?"instance":"static", - methodsInfo[i].m_name, methodsInfo[i].m_sign); - return STATUS_FAILED; - } - -/* get the LocalVariableTable attribute */ - if ((err = ((*jvmti)->GetLocalVariableTable(jvmti, methodsInfo[i].mid, - &count, &lv_table))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call GetLocalVariableTable(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - printf("\tfor the%s%s method \"%s\", signature \"%s\"\n\n", - full?" ":" original ", methodsInfo[i].inst?"instance":"static", - methodsInfo[i].m_name, methodsInfo[i].m_sign); - return STATUS_FAILED; - } else { - if (count != methodsInfo[i].vcount) { - printf("TEST FAILED: %s%s method \"%s\", signature \"%s\":\ - found %d vars in the LocalVariableTable, expected %d\n", - full?" ":" original ", methodsInfo[i].inst?"instance":"static", - methodsInfo[i].m_name, methodsInfo[i].m_sign, - count, methodsInfo[i].vcount); - totRes = STATUS_FAILED; - continue; - } - else if (vrb) - printf("\nChecking vars in the LocalVariableTable of the %s method \"%s\",\ - signature \"%s\" ...\n\tfound %d local vars as expected\n", - methodsInfo[i].inst?"instance":"static", - methodsInfo[i].m_name, methodsInfo[i].m_sign, count); - - if (full) { - for (j=0; jGetObjectClass(JNI_ENV_ARG(env, redefObj)); -/* check only the number of local variables */ - return checkAttr(env, redefCls, origMethInfo, 0, 0); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass009_makeRedefinition(JNIEnv *env, - jclass cls, jint vrb, jclass redefCls, jbyteArray classBytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_redefine_classes) { - return PASSED; - } - -/* fill the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); - - if (vrb) - printf("\n>>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", - classDef.class_byte_count); - if ((err = ((*jvmti)->RedefineClasses(jvmti, 1, &classDef))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call RedefineClasses(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - return JNI_ERR; - } - if (vrb) - printf("<<<<<<<< RedefineClasses() is successfully done\n\n"); - - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass009_getResult(JNIEnv *env, - jclass cls, jint vrb, jobject redefObj) { - jclass redefCls = - JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, redefObj)); - - return checkAttr(env, redefCls, redefMethInfo, vrb, 1); -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/redefclass009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/redefclass009.cpp new file mode 100644 index 00000000000..6dbe08601f1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass009/redefclass009.cpp @@ -0,0 +1,307 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define METH_NUM 4 /* overall number of methods */ + +#define STATUS_FAILED 2 +#define PASSED 0 + +typedef struct { /* local variable info */ + char *v_name; /* a variable name */ + char *v_sign; /* JVM type signature */ +} localVar; + +/* local variables of redefined methods */ +static localVar constr_lv[] = { /* constructor's local variables */ + {(char*) "this", (char*) "Lnsk/jvmti/RedefineClasses/redefclass009r;"}, + {(char*) "constr_i", (char*) "I"}, + {(char*) "constr_l", (char*) "J"}, + {(char*) "constr_d", (char*) "D"}, + {(char*) "constr_f", (char*) "F"}, + {(char*) "constr_c", (char*) "C"} +}; +static localVar checkIt_lv[] = { /* checkIt()'s local variables */ + {(char*) "this", (char*) "Lnsk/jvmti/RedefineClasses/redefclass009r;"}, + {(char*) "out", (char*) "Ljava/io/PrintStream;"}, + {(char*) "DEBUG_MODE", (char*) "Z"} +}; +static localVar finMeth_lv[] = { /* finMethod()'s local variables */ + {(char*) "this", (char*) "Lnsk/jvmti/RedefineClasses/redefclass009r;"}, + {(char*) "fin_c", (char*) "C"}, + {(char*) "fin_i", (char*) "J"}, + {(char*) "fin_j", (char*) "I"}, + {(char*) "fin_k", (char*) "J"}, + {(char*) "fin_l", (char*) "J"}, + {(char*) "fin_f", (char*) "F"} +}; +static localVar statMeth_lv[] = { /* statMethod()'s local variables */ + {(char*) "stat_x", (char*) "I"}, + {(char*) "stat_y", (char*) "I"}, + {(char*) "stat_z", (char*) "I"}, + {(char*) "stat_j", (char*) "D"}, + {(char*) "stat_i", (char*) "I"} +}; + +typedef struct { /* local variables of a method */ + int inst; /* type of a method: 0- static; 1- instance */ + char *m_name; /* a method name */ + char *m_sign; /* JVM signature of a method */ + int vcount; /* overall number of local variables */ + localVar *vars; + jmethodID mid; /* JNI's method ID */ +} methInfo; + +/* list of original methods with NULL pointers to localVar */ +static methInfo origMethInfo[] = { + {1, (char*) "", (char*) "()V", 1, NULL, NULL}, + {1, (char*) "checkIt", (char*) "(Ljava/io/PrintStream;Z)I", 4, NULL, NULL}, + {1, (char*) "finMethod", (char*) "(CJIJ)V", 5, NULL, NULL}, + {0, (char*) "statMethod", (char*) "(III)D", 3, NULL, NULL} +}; + +/* list of redefined methods */ +static methInfo redefMethInfo[] = { + {1, (char*) "", (char*) "()V", 6, constr_lv, NULL}, + {1, (char*) "checkIt", (char*) "(Ljava/io/PrintStream;Z)I", 3, checkIt_lv, NULL}, + {1, (char*) "finMethod", (char*) "(CJIJ)V", 7, finMeth_lv, NULL}, + {0, (char*) "statMethod", (char*) "(III)D", 5, statMeth_lv, NULL} +}; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass009(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass009(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass009(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), + JVMTI_VERSION_1_1)) != JNI_OK) { + printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + if (!caps.can_access_local_variables) { + printf("Warning: Access to local variables is not implemented\n"); + } + + return JNI_OK; +} + +int checkAttr(JNIEnv *env, jclass redefCls, methInfo methodsInfo[], + jint vrb, int full) { + jvmtiError err; + int i, j, k; + int totRes = PASSED; + jint count = -1; + jvmtiLocalVariableEntry *lv_table; + + if (!caps.can_access_local_variables) { + return PASSED; + } + + for (i=0; iGetMethodID(JNI_ENV_ARG(env, redefCls), + methodsInfo[i].m_name, methodsInfo[i].m_sign); + else /* a static method */ + methodsInfo[i].mid = + JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, redefCls), + methodsInfo[i].m_name, methodsInfo[i].m_sign); + if (methodsInfo[i].mid == NULL) { + printf("%s: Failed to get the method ID for the%s%s method\ + \"%s\", signature \"%s\"\n", + __FILE__, full?" ":" original ", methodsInfo[i].inst?"instance":"static", + methodsInfo[i].m_name, methodsInfo[i].m_sign); + return STATUS_FAILED; + } + +/* get the LocalVariableTable attribute */ + if ((err = (jvmti->GetLocalVariableTable(methodsInfo[i].mid, + &count, &lv_table))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call GetLocalVariableTable(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + printf("\tfor the%s%s method \"%s\", signature \"%s\"\n\n", + full?" ":" original ", methodsInfo[i].inst?"instance":"static", + methodsInfo[i].m_name, methodsInfo[i].m_sign); + return STATUS_FAILED; + } else { + if (count != methodsInfo[i].vcount) { + printf("TEST FAILED: %s%s method \"%s\", signature \"%s\":\ + found %d vars in the LocalVariableTable, expected %d\n", + full?" ":" original ", methodsInfo[i].inst?"instance":"static", + methodsInfo[i].m_name, methodsInfo[i].m_sign, + count, methodsInfo[i].vcount); + totRes = STATUS_FAILED; + continue; + } + else if (vrb) + printf("\nChecking vars in the LocalVariableTable of the %s method \"%s\",\ + signature \"%s\" ...\n\tfound %d local vars as expected\n", + methodsInfo[i].inst?"instance":"static", + methodsInfo[i].m_name, methodsInfo[i].m_sign, count); + + if (full) { + for (j=0; jGetObjectClass(JNI_ENV_ARG(env, redefObj)); +/* check only the number of local variables */ + return checkAttr(env, redefCls, origMethInfo, 0, 0); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass009_makeRedefinition(JNIEnv *env, + jclass cls, jint vrb, jclass redefCls, jbyteArray classBytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_redefine_classes) { + return PASSED; + } + +/* fill the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); + + if (vrb) + printf("\n>>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", + classDef.class_byte_count); + if ((err = (jvmti->RedefineClasses(1, &classDef))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call RedefineClasses(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + return JNI_ERR; + } + if (vrb) + printf("<<<<<<<< RedefineClasses() is successfully done\n\n"); + + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass009_getResult(JNIEnv *env, + jclass cls, jint vrb, jobject redefObj) { + jclass redefCls = + JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, redefObj)); + + return checkAttr(env, redefCls, redefMethInfo, vrb, 1); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/libredefclass010.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/libredefclass010.c deleted file mode 100644 index 99643a8617e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/libredefclass010.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass010.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/libredefclass010.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/libredefclass010.cpp new file mode 100644 index 00000000000..6f460a988c9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/libredefclass010.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass010.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/redefclass010.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/redefclass010.c deleted file mode 100644 index e335e272fa4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/redefclass010.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define METH_NUM 4 /* overall number of methods */ - -#define STATUS_FAILED 2 -#define PASSED 0 - -/* line number matrix of original methods */ -static int orig_ln[METH_NUM][8] = { - {34, 0, 0, 0, 0, 0, 0, 0}, /* */ - {40,41,43, 0, 0, 0, 0, 0}, /* checkIt */ - {55, 0, 0, 0, 0, 0, 0, 0}, /* finMethod */ - {48,50,51,50,52, 0, 0, 0} /* statMethod */ -}; - -/* line number matrix of redefined methods */ -static int redf_ln[METH_NUM][8] = { - {38,39,40,41,42,43,44,46}, /* */ - {51,53,55, 0, 0, 0, 0, 0}, /* checkIt */ - {64,66,67,68,69,70,72, 0}, /* finMethod */ - {60, 0, 0, 0, 0, 0, 0, 0} /* statMethod */ -}; - -typedef struct { /* line numbers of a method */ - int inst; /* type of a method: 0- static; 1- instance */ - char *m_name; /* a method name */ - char *m_sign; /* JVM signature of a method */ - int lcount; /* line numbers quantity */ - jmethodID mid; /* JNI's method ID */ -} methInfo; - -/* list of original methods */ -static methInfo origMethInfo[] = { - {1, (char*) "", (char*) "()V", 1, NULL}, - {1, (char*) "checkIt", (char*) "(Ljava/io/PrintStream;Z)I", 3, NULL}, - {1, (char*) "finMethod", (char*) "(CJIJ)V", 1, NULL}, - {0, (char*) "statMethod", (char*) "(III)D", 5, NULL} -}; - -/* list of redefined methods */ -static methInfo redefMethInfo[] = { - {1, (char*) "", (char*) "()V", 8, NULL}, - {1, (char*) "checkIt", (char*) "(Ljava/io/PrintStream;Z)I", 3, NULL}, - {1, (char*) "finMethod", (char*) "(CJIJ)V", 7, NULL}, - {0, (char*) "statMethod", (char*) "(III)D", 1, NULL} -}; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass010(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass010(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass010(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), - JVMTI_VERSION_1_1)) != JNI_OK) { - printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - if (!caps.can_get_line_numbers) { - printf("Warning: no access to line number info\n"); - } - - return JNI_OK; -} - -int checkAttr(JNIEnv *env, jclass redefCls, methInfo methodsInfo[], jint vrb) { - jvmtiError err; - int i, j, chkval = 0; - int totRes = PASSED; - jint count = -1; - jvmtiLineNumberEntry *ln_table; - - if (!caps.can_get_line_numbers) { - return PASSED; - } - - for (i=0; iGetMethodID(JNI_ENV_ARG(env, redefCls), - methodsInfo[i].m_name, methodsInfo[i].m_sign); - else /* a static method */ - methodsInfo[i].mid = - JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, redefCls), - methodsInfo[i].m_name, methodsInfo[i].m_sign); - if (methodsInfo[i].mid == NULL) { - printf("%s: Failed to get the method ID for the%s%s method\ - \"%s\", signature \"%s\"\n", - __FILE__, (vrb==2)?" original ":" ", methodsInfo[i].inst?"instance":"static", - methodsInfo[i].m_name, methodsInfo[i].m_sign); - return STATUS_FAILED; - } - -/* get the LineNumberTable attribute */ - if ((err = ((*jvmti)->GetLineNumberTable(jvmti, methodsInfo[i].mid, - &count, &ln_table))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call GetLineNumberTable(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - printf("\tfor the%s%s method \"%s\", signature \"%s\"\n\n", - (vrb==2)?" original ":" ", methodsInfo[i].inst?"instance":"static", - methodsInfo[i].m_name, methodsInfo[i].m_sign); - return STATUS_FAILED; - } else { - if (count != methodsInfo[i].lcount) { - printf("TEST %s %s method \"%s\", signature \"%s\":\ - found %d lines in the LineNumberTable, expected %d\n", - (vrb==2)?"BUG: original ":"FAILED:", - methodsInfo[i].inst?"instance":"static", - methodsInfo[i].m_name, methodsInfo[i].m_sign, - count, methodsInfo[i].lcount); - totRes = STATUS_FAILED; - continue; - } - else if (vrb == 1) - printf("\nChecking line numbers in the LineNumberTable of the %s method\ - \"%s\", signature \"%s\" ...\n\toverall number of lines: %d as expected\n", - methodsInfo[i].inst?"instance":"static", - methodsInfo[i].m_name, methodsInfo[i].m_sign, count); - - for (j=0; jGetObjectClass(JNI_ENV_ARG(env, redefObj)); - - return checkAttr(env, redefCls, origMethInfo, 2); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass010_makeRedefinition(JNIEnv *env, - jclass cls, jint vrb, jclass redefCls, jbyteArray classBytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_redefine_classes) { - return PASSED; - } - -/* fill the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); - - if (vrb) - printf("\n>>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", - classDef.class_byte_count); - if ((err = ((*jvmti)->RedefineClasses(jvmti, 1, &classDef))) != JVMTI_ERROR_NONE) { - printf("%s: Failed to call RedefineClasses(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - return JNI_ERR; - } - if (vrb) - printf("<<<<<<<< RedefineClasses() is successfully done\n\n"); - - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass010_getResult(JNIEnv *env, - jclass cls, jint vrb, jobject redefObj) { - jclass redefCls = - JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, redefObj)); - - return checkAttr(env, redefCls, redefMethInfo, vrb); -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/redefclass010.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/redefclass010.cpp new file mode 100644 index 00000000000..80159ae6bd8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass010/redefclass010.cpp @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define METH_NUM 4 /* overall number of methods */ + +#define STATUS_FAILED 2 +#define PASSED 0 + +/* line number matrix of original methods */ +static int orig_ln[METH_NUM][8] = { + {34, 0, 0, 0, 0, 0, 0, 0}, /* */ + {40,41,43, 0, 0, 0, 0, 0}, /* checkIt */ + {55, 0, 0, 0, 0, 0, 0, 0}, /* finMethod */ + {48,50,51,50,52, 0, 0, 0} /* statMethod */ +}; + +/* line number matrix of redefined methods */ +static int redf_ln[METH_NUM][8] = { + {38,39,40,41,42,43,44,46}, /* */ + {51,53,55, 0, 0, 0, 0, 0}, /* checkIt */ + {64,66,67,68,69,70,72, 0}, /* finMethod */ + {60, 0, 0, 0, 0, 0, 0, 0} /* statMethod */ +}; + +typedef struct { /* line numbers of a method */ + int inst; /* type of a method: 0- static; 1- instance */ + char *m_name; /* a method name */ + char *m_sign; /* JVM signature of a method */ + int lcount; /* line numbers quantity */ + jmethodID mid; /* JNI's method ID */ +} methInfo; + +/* list of original methods */ +static methInfo origMethInfo[] = { + {1, (char*) "", (char*) "()V", 1, NULL}, + {1, (char*) "checkIt", (char*) "(Ljava/io/PrintStream;Z)I", 3, NULL}, + {1, (char*) "finMethod", (char*) "(CJIJ)V", 1, NULL}, + {0, (char*) "statMethod", (char*) "(III)D", 5, NULL} +}; + +/* list of redefined methods */ +static methInfo redefMethInfo[] = { + {1, (char*) "", (char*) "()V", 8, NULL}, + {1, (char*) "checkIt", (char*) "(Ljava/io/PrintStream;Z)I", 3, NULL}, + {1, (char*) "finMethod", (char*) "(CJIJ)V", 7, NULL}, + {0, (char*) "statMethod", (char*) "(III)D", 1, NULL} +}; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass010(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass010(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass010(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), + JVMTI_VERSION_1_1)) != JNI_OK) { + printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + if (!caps.can_get_line_numbers) { + printf("Warning: no access to line number info\n"); + } + + return JNI_OK; +} + +int checkAttr(JNIEnv *env, jclass redefCls, methInfo methodsInfo[], jint vrb) { + jvmtiError err; + int i, j, chkval = 0; + int totRes = PASSED; + jint count = -1; + jvmtiLineNumberEntry *ln_table; + + if (!caps.can_get_line_numbers) { + return PASSED; + } + + for (i=0; iGetMethodID(JNI_ENV_ARG(env, redefCls), + methodsInfo[i].m_name, methodsInfo[i].m_sign); + else /* a static method */ + methodsInfo[i].mid = + JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, redefCls), + methodsInfo[i].m_name, methodsInfo[i].m_sign); + if (methodsInfo[i].mid == NULL) { + printf("%s: Failed to get the method ID for the%s%s method\ + \"%s\", signature \"%s\"\n", + __FILE__, (vrb==2)?" original ":" ", methodsInfo[i].inst?"instance":"static", + methodsInfo[i].m_name, methodsInfo[i].m_sign); + return STATUS_FAILED; + } + +/* get the LineNumberTable attribute */ + if ((err = (jvmti->GetLineNumberTable(methodsInfo[i].mid, + &count, &ln_table))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call GetLineNumberTable(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + printf("\tfor the%s%s method \"%s\", signature \"%s\"\n\n", + (vrb==2)?" original ":" ", methodsInfo[i].inst?"instance":"static", + methodsInfo[i].m_name, methodsInfo[i].m_sign); + return STATUS_FAILED; + } else { + if (count != methodsInfo[i].lcount) { + printf("TEST %s %s method \"%s\", signature \"%s\":\ + found %d lines in the LineNumberTable, expected %d\n", + (vrb==2)?"BUG: original ":"FAILED:", + methodsInfo[i].inst?"instance":"static", + methodsInfo[i].m_name, methodsInfo[i].m_sign, + count, methodsInfo[i].lcount); + totRes = STATUS_FAILED; + continue; + } + else if (vrb == 1) + printf("\nChecking line numbers in the LineNumberTable of the %s method\ + \"%s\", signature \"%s\" ...\n\toverall number of lines: %d as expected\n", + methodsInfo[i].inst?"instance":"static", + methodsInfo[i].m_name, methodsInfo[i].m_sign, count); + + for (j=0; jGetObjectClass(JNI_ENV_ARG(env, redefObj)); + + return checkAttr(env, redefCls, origMethInfo, 2); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass010_makeRedefinition(JNIEnv *env, + jclass cls, jint vrb, jclass redefCls, jbyteArray classBytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_redefine_classes) { + return PASSED; + } + +/* fill the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); + + if (vrb) + printf("\n>>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", + classDef.class_byte_count); + if ((err = (jvmti->RedefineClasses(1, &classDef))) != JVMTI_ERROR_NONE) { + printf("%s: Failed to call RedefineClasses(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + return JNI_ERR; + } + if (vrb) + printf("<<<<<<<< RedefineClasses() is successfully done\n\n"); + + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass010_getResult(JNIEnv *env, + jclass cls, jint vrb, jobject redefObj) { + jclass redefCls = + JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, redefObj)); + + return checkAttr(env, redefCls, redefMethInfo, vrb); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/libredefclass011.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/libredefclass011.c deleted file mode 100644 index 924b2ff196e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/libredefclass011.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass011.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/libredefclass011.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/libredefclass011.cpp new file mode 100644 index 00000000000..216bef5ec95 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/libredefclass011.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass011.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/redefclass011.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/redefclass011.c deleted file mode 100644 index cd36c2ce2b9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/redefclass011.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass011(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass011(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass011(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass011_check(JNIEnv *env, - jclass cls, jbyteArray bytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - classDef.klass = NULL; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> invalid class check ...\n"); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_redefine_classes) { - /* It is OK */ - } else if (err != JVMTI_ERROR_INVALID_CLASS) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/redefclass011.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/redefclass011.cpp new file mode 100644 index 00000000000..e78fdae574a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass011/redefclass011.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass011(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass011(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass011(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass011_check(JNIEnv *env, + jclass cls, jbyteArray bytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + classDef.klass = NULL; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> invalid class check ...\n"); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_redefine_classes) { + /* It is OK */ + } else if (err != JVMTI_ERROR_INVALID_CLASS) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/libredefclass012.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/libredefclass012.c deleted file mode 100644 index 944c890d74e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/libredefclass012.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass012.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/libredefclass012.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/libredefclass012.cpp new file mode 100644 index 00000000000..571bfd173d2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/libredefclass012.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass012.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/redefclass012.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/redefclass012.c deleted file mode 100644 index 8f4b31fef61..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/redefclass012.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass012(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass012(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass012(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass012_check(JNIEnv *env, - jclass cls, jbyteArray jbytes) { - jvmtiError err; - unsigned char *bytes; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - classDef.klass = cls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, jbytes)); - bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, jbytes), NULL); - - /* put 0,0 into version fields */ - bytes[4] = 0; - bytes[5] = 0; - bytes[6] = 0; - bytes[7] = 0; - - classDef.class_bytes = bytes; - - if (printdump == JNI_TRUE) { - printf(">>> unsupported version check ...\n"); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_redefine_classes) { - /* It is OK */ - } else if (err != JVMTI_ERROR_UNSUPPORTED_VERSION) { - printf("Error expected: JVMTI_ERROR_UNSUPPORTED_VERSION,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/redefclass012.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/redefclass012.cpp new file mode 100644 index 00000000000..d73b840c145 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass012/redefclass012.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass012(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass012(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass012(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass012_check(JNIEnv *env, + jclass cls, jbyteArray jbytes) { + jvmtiError err; + unsigned char *bytes; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + classDef.klass = cls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, jbytes)); + bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, jbytes), NULL); + + /* put 0,0 into version fields */ + bytes[4] = 0; + bytes[5] = 0; + bytes[6] = 0; + bytes[7] = 0; + + classDef.class_bytes = bytes; + + if (printdump == JNI_TRUE) { + printf(">>> unsupported version check ...\n"); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_redefine_classes) { + /* It is OK */ + } else if (err != JVMTI_ERROR_UNSUPPORTED_VERSION) { + printf("Error expected: JVMTI_ERROR_UNSUPPORTED_VERSION,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/libredefclass013.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/libredefclass013.c deleted file mode 100644 index 8b23df157e4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/libredefclass013.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass013.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/libredefclass013.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/libredefclass013.cpp new file mode 100644 index 00000000000..59b33832187 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/libredefclass013.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass013.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/redefclass013.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/redefclass013.c deleted file mode 100644 index 423bada01d2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/redefclass013.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass013(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass013(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass013(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass013_check(JNIEnv *env, - jclass cls, jbyteArray jbytes) { - jvmtiError err; - unsigned char *bytes; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - classDef.klass = cls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, jbytes)); - bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, jbytes), NULL); - - /* put 0 into magic field */ - bytes[0] = 0; - bytes[1] = 0; - bytes[2] = 0; - bytes[3] = 0; - - classDef.class_bytes = bytes; - - if (printdump == JNI_TRUE) { - printf(">>> invalid class format check ...\n"); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_redefine_classes) { - /* It is OK */ - } else if (err != JVMTI_ERROR_INVALID_CLASS_FORMAT) { - printf("Error expected: JVMTI_ERROR_INVALID_CLASS_FORMAT,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/redefclass013.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/redefclass013.cpp new file mode 100644 index 00000000000..96f1cbed050 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass013/redefclass013.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass013(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass013(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass013(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass013_check(JNIEnv *env, + jclass cls, jbyteArray jbytes) { + jvmtiError err; + unsigned char *bytes; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + classDef.klass = cls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, jbytes)); + bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, jbytes), NULL); + + /* put 0 into magic field */ + bytes[0] = 0; + bytes[1] = 0; + bytes[2] = 0; + bytes[3] = 0; + + classDef.class_bytes = bytes; + + if (printdump == JNI_TRUE) { + printf(">>> invalid class format check ...\n"); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_redefine_classes) { + /* It is OK */ + } else if (err != JVMTI_ERROR_INVALID_CLASS_FORMAT) { + printf("Error expected: JVMTI_ERROR_INVALID_CLASS_FORMAT,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/libredefclass014.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/libredefclass014.c deleted file mode 100644 index 6663620786d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/libredefclass014.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass014.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/libredefclass014.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/libredefclass014.cpp new file mode 100644 index 00000000000..e2f448f2390 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/libredefclass014.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass014.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/redefclass014.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/redefclass014.c deleted file mode 100644 index ecc91978b00..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/redefclass014.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass014(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass014(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass014(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass014_check(JNIEnv *env, jclass cls, jbyteArray bytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - /* to check if RedefineClasses is supported */ - if ((err = ((*jvmti)->GetCapabilities(jvmti, &caps))) != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - classDef.klass = cls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> circularity error check ...\n"); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_redefine_classes) { - /* It is OK */ - } else if (err == JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED) { - printf("Warning: RedefineClasses is restricted\n"); - } else if (err != JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION) { - printf("Error expected: JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/redefclass014.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/redefclass014.cpp new file mode 100644 index 00000000000..702d8b4ac3e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass014/redefclass014.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass014(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass014(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass014(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass014_check(JNIEnv *env, jclass cls, jbyteArray bytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + /* to check if RedefineClasses is supported */ + if ((err = (jvmti->GetCapabilities(&caps))) != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + classDef.klass = cls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> circularity error check ...\n"); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_redefine_classes) { + /* It is OK */ + } else if (err == JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED) { + printf("Warning: RedefineClasses is restricted\n"); + } else if (err != JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION) { + printf("Error expected: JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/libredefclass015.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/libredefclass015.c deleted file mode 100644 index 2a600faea34..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/libredefclass015.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass015.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/libredefclass015.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/libredefclass015.cpp new file mode 100644 index 00000000000..a69fff3afa4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/libredefclass015.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass015.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/redefclass015.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/redefclass015.c deleted file mode 100644 index b0c42a4393f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/redefclass015.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass015(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass015(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass015(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass015_check(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - classDef.klass = clazz; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> verify error check ...\n"); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_redefine_classes) { - /* It is OK */ - } else if (err != JVMTI_ERROR_FAILS_VERIFICATION) { - printf("Error expected: JVMTI_ERROR_FAILS_VERIFICATION,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/redefclass015.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/redefclass015.cpp new file mode 100644 index 00000000000..2944d453e9b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass015/redefclass015.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass015(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass015(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass015(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass015_check(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + classDef.klass = clazz; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> verify error check ...\n"); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_redefine_classes) { + /* It is OK */ + } else if (err != JVMTI_ERROR_FAILS_VERIFICATION) { + printf("Error expected: JVMTI_ERROR_FAILS_VERIFICATION,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/libredefclass016.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/libredefclass016.c deleted file mode 100644 index 4e1d441e364..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/libredefclass016.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass016.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/libredefclass016.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/libredefclass016.cpp new file mode 100644 index 00000000000..848e2355488 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/libredefclass016.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass016.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/redefclass016.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/redefclass016.c deleted file mode 100644 index bb454ccde43..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/redefclass016.c +++ /dev/null @@ -1,358 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID mid = NULL; -static jint bpeakpointsExpected = 0; -static jint bpeakpointsCount = 0; -static jlocation loc = 0; -static jbyteArray classBytes; -static jint magicNumber; - -void check(jvmtiEnv *jvmti_env, jthread thr, jclass cls, jmethodID mid, jint i) { - jvmtiError err; - char *sigClass, *name, *sig, *generic; - jvmtiLocalVariableEntry *table = NULL; - jint entryCount = 0; - jint varValue = -1; - jint j; - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, - &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - if (strcmp(table[j].name, "localVar") == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, 0, - table[j].slot, &varValue); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - } - - if (printdump == JNI_TRUE) { - printf(">>> bp %d: \"%s.%s%s\"", i, sigClass, name, sig); - printf(", localVar value: %d\n", varValue); - } - - if (varValue != i) { - printf("(bp %d) wrong localVar value: %d,", i, varValue); - printf(" expected: %d\n", i); - result = STATUS_FAILED; - } - - if (sigClass != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sigClass); - } - if (name != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)name); - } - if (sig != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sig); - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].name)); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].signature)); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table); - } -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - jclass klass; - unsigned char *bytes; - jvmtiClassDefinition classDef; - jboolean found = JNI_FALSE; - jint i; - - if (mid != method) { - printf("bp: don't know where we get called from"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - bpeakpointsCount, TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - check(jvmti_env, thread, klass, method, bpeakpointsCount); - bpeakpointsCount++; - - classDef.klass = klass; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes)); - bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env, - classBytes), NULL); - - for (i = 0; i < classDef.class_byte_count - 3; i++) { - if (((jint)bytes[i+3] | - ((jint)bytes[i+2] << 8) | - ((jint)bytes[i+1] << 16) | - ((jint)bytes[i] << 24)) == magicNumber) { - found = JNI_TRUE; - break; - } - } - - if (found == JNI_TRUE) { - bytes[i] = 0; - bytes[i+1] = 0; - bytes[i+2] = 0; - bytes[i+3] = (jbyte)bpeakpointsCount; - } else { - printf("Cannot find magic number\n"); - result = STATUS_FAILED; - return; - } - - classDef.class_bytes = bytes; - err = (*jvmti_env)->RedefineClasses(jvmti_env, 1, &classDef); - if (err != JVMTI_ERROR_NONE) { - printf("(RedefineClasses#%d) unexpected error: %s (%d)\n", - bpeakpointsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->SetBreakpoint(jvmti_env, mid, loc); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint#%d) unexpected error: %s (%d)\n", - bpeakpointsCount, TranslateError(err), err); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass016(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass016(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass016(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - if (!caps.can_get_line_numbers) { - printf("Warning: GetLineNumberTable is not implemented\n"); - } - - if (!caps.can_access_local_variables) { - printf("Warning: access to local variables is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass016_getReady(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes, jint magic, jint line) { - jvmtiError err; - jvmtiLineNumberEntry *lines = NULL; - jint i = 0, entryCount = 0; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_redefine_classes || - !caps.can_generate_breakpoint_events || - !caps.can_get_line_numbers || - !caps.can_access_local_variables) return; - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), "run", "()V"); - if (mid == NULL) { - printf("Cannot find Method ID for method run\n"); - result = STATUS_FAILED; - return; - } - - classBytes = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); - - err = (*jvmti)->GetLineNumberTable(jvmti, mid, &entryCount, &lines); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLineNumberTable) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - if (lines != NULL && entryCount > 0) { - for (i = 0; i < entryCount; i++) { - if (line == lines[i].line_number) { - loc = lines[i].start_location; - break; - } - } - } - if (i == entryCount) { - printf("Cannot find line number entry for %d\n", line); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, mid, loc); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - magicNumber = magic; - bpeakpointsExpected = 8; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass016_check(JNIEnv *env, jclass cls) { - if (bpeakpointsCount != bpeakpointsExpected) { - printf("Wrong number of breakpoints: %d, expected: %d\n", - bpeakpointsCount, bpeakpointsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/redefclass016.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/redefclass016.cpp new file mode 100644 index 00000000000..28a7f2c825c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/redefclass016.cpp @@ -0,0 +1,358 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID mid = NULL; +static jint bpeakpointsExpected = 0; +static jint bpeakpointsCount = 0; +static jlocation loc = 0; +static jbyteArray classBytes; +static jint magicNumber; + +void check(jvmtiEnv *jvmti_env, jthread thr, jclass cls, jmethodID mid, jint i) { + jvmtiError err; + char *sigClass, *name, *sig, *generic; + jvmtiLocalVariableEntry *table = NULL; + jint entryCount = 0; + jint varValue = -1; + jint j; + + err = jvmti_env->GetClassSignature(cls, &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetLocalVariableTable(mid, + &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + if (strcmp(table[j].name, "localVar") == 0) { + err = jvmti_env->GetLocalInt(thr, 0, + table[j].slot, &varValue); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + } + + if (printdump == JNI_TRUE) { + printf(">>> bp %d: \"%s.%s%s\"", i, sigClass, name, sig); + printf(", localVar value: %d\n", varValue); + } + + if (varValue != i) { + printf("(bp %d) wrong localVar value: %d,", i, varValue); + printf(" expected: %d\n", i); + result = STATUS_FAILED; + } + + if (sigClass != NULL) { + jvmti_env->Deallocate((unsigned char*)sigClass); + } + if (name != NULL) { + jvmti_env->Deallocate((unsigned char*)name); + } + if (sig != NULL) { + jvmti_env->Deallocate((unsigned char*)sig); + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + jvmti_env->Deallocate((unsigned char*)(table[j].name)); + jvmti_env->Deallocate((unsigned char*)(table[j].signature)); + } + jvmti_env->Deallocate((unsigned char*)table); + } +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + jclass klass; + unsigned char *bytes; + jvmtiClassDefinition classDef; + jboolean found = JNI_FALSE; + jint i; + + if (mid != method) { + printf("bp: don't know where we get called from"); + result = STATUS_FAILED; + return; + } + + err = jvmti_env->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + bpeakpointsCount, TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + check(jvmti_env, thread, klass, method, bpeakpointsCount); + bpeakpointsCount++; + + classDef.klass = klass; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes)); + bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env, + classBytes), NULL); + + for (i = 0; i < classDef.class_byte_count - 3; i++) { + if (((jint)bytes[i+3] | + ((jint)bytes[i+2] << 8) | + ((jint)bytes[i+1] << 16) | + ((jint)bytes[i] << 24)) == magicNumber) { + found = JNI_TRUE; + break; + } + } + + if (found == JNI_TRUE) { + bytes[i] = 0; + bytes[i+1] = 0; + bytes[i+2] = 0; + bytes[i+3] = (jbyte)bpeakpointsCount; + } else { + printf("Cannot find magic number\n"); + result = STATUS_FAILED; + return; + } + + classDef.class_bytes = bytes; + err = jvmti_env->RedefineClasses(1, &classDef); + if (err != JVMTI_ERROR_NONE) { + printf("(RedefineClasses#%d) unexpected error: %s (%d)\n", + bpeakpointsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->SetBreakpoint(mid, loc); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint#%d) unexpected error: %s (%d)\n", + bpeakpointsCount, TranslateError(err), err); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass016(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass016(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass016(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + if (!caps.can_get_line_numbers) { + printf("Warning: GetLineNumberTable is not implemented\n"); + } + + if (!caps.can_access_local_variables) { + printf("Warning: access to local variables is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass016_getReady(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes, jint magic, jint line) { + jvmtiError err; + jvmtiLineNumberEntry *lines = NULL; + jint i = 0, entryCount = 0; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_redefine_classes || + !caps.can_generate_breakpoint_events || + !caps.can_get_line_numbers || + !caps.can_access_local_variables) return; + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), "run", "()V"); + if (mid == NULL) { + printf("Cannot find Method ID for method run\n"); + result = STATUS_FAILED; + return; + } + + classBytes = (jbyteArray) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); + + err = jvmti->GetLineNumberTable(mid, &entryCount, &lines); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLineNumberTable) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + if (lines != NULL && entryCount > 0) { + for (i = 0; i < entryCount; i++) { + if (line == lines[i].line_number) { + loc = lines[i].start_location; + break; + } + } + } + if (i == entryCount) { + printf("Cannot find line number entry for %d\n", line); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetBreakpoint(mid, loc); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + magicNumber = magic; + bpeakpointsExpected = 8; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass016_check(JNIEnv *env, jclass cls) { + if (bpeakpointsCount != bpeakpointsExpected) { + printf("Wrong number of breakpoints: %d, expected: %d\n", + bpeakpointsCount, bpeakpointsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/libredefclass017.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/libredefclass017.c deleted file mode 100644 index 67541f4c501..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/libredefclass017.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass017.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/libredefclass017.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/libredefclass017.cpp new file mode 100644 index 00000000000..6392b11d5dd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/libredefclass017.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass017.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/redefclass017.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/redefclass017.c deleted file mode 100644 index 4fd574e9750..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/redefclass017.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID mid = NULL; -static jbyteArray classBytes; - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - jclass klass; - jvmtiClassDefinition classDef; - - if (mid != method) { - printf("bp: don't know where we get called from"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - classDef.klass = klass; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env, - classBytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> bp: about to call RedefineClasses\n"); - } - - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err != JVMTI_ERROR_NONE) { - printf("(RedefineClasses) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass017(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass017(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass017(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass017_getReady(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_redefine_classes || - !caps.can_generate_breakpoint_events) return; - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "checkPoint", "()V"); - if (mid == NULL) { - printf("Cannot find Method ID for method run\n"); - result = STATUS_FAILED; - return; - } - - classBytes = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); - - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass017_check(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/redefclass017.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/redefclass017.cpp new file mode 100644 index 00000000000..4f0986d4c34 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass017/redefclass017.cpp @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID mid = NULL; +static jbyteArray classBytes; + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + jclass klass; + jvmtiClassDefinition classDef; + + if (mid != method) { + printf("bp: don't know where we get called from"); + result = STATUS_FAILED; + return; + } + + err = jvmti_env->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + classDef.klass = klass; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env, + classBytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> bp: about to call RedefineClasses\n"); + } + + err = jvmti->RedefineClasses(1, &classDef); + if (err != JVMTI_ERROR_NONE) { + printf("(RedefineClasses) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass017(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass017(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass017(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass017_getReady(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_redefine_classes || + !caps.can_generate_breakpoint_events) return; + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "checkPoint", "()V"); + if (mid == NULL) { + printf("Cannot find Method ID for method run\n"); + result = STATUS_FAILED; + return; + } + + classBytes = (jbyteArray) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); + + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass017_check(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/libredefclass018.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/libredefclass018.c deleted file mode 100644 index 884241c64b1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/libredefclass018.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass018.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/libredefclass018.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/libredefclass018.cpp new file mode 100644 index 00000000000..fe6ce7d3ae7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/libredefclass018.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass018.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/redefclass018.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/redefclass018.c deleted file mode 100644 index bbce0ac4dc2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/redefclass018.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jbyteArray classBytes; - -void JNICALL -Exception(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID c_method, jlocation c_location) { - jvmtiError err; - jclass klass; - jvmtiClassDefinition classDef; - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_EXCEPTION, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_EXCEPTION: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - classDef.klass = klass; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env, - classBytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> about to call RedefineClasses\n"); - } - - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err != JVMTI_ERROR_NONE) { - printf("(RedefineClasses) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass018(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass018(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass018(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - if (caps.can_generate_exception_events) { - callbacks.Exception = &Exception; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass018_getReady(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes) { - jvmtiError err; - jthread thread; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_redefine_classes || - !caps.can_generate_exception_events) return; - - classBytes = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); - - if ((err = ((*jvmti)->GetCurrentThread(jvmti, &thread))) != JVMTI_ERROR_NONE) { - printf("Failed to get current thread: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_EXCEPTION, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_EXCEPTION_CATCH: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass018_check(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/redefclass018.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/redefclass018.cpp new file mode 100644 index 00000000000..bd03857a699 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass018/redefclass018.cpp @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jbyteArray classBytes; + +void JNICALL +Exception(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID c_method, jlocation c_location) { + jvmtiError err; + jclass klass; + jvmtiClassDefinition classDef; + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_EXCEPTION, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_EXCEPTION: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + classDef.klass = klass; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env, + classBytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> about to call RedefineClasses\n"); + } + + err = jvmti->RedefineClasses(1, &classDef); + if (err != JVMTI_ERROR_NONE) { + printf("(RedefineClasses) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass018(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass018(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass018(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + if (caps.can_generate_exception_events) { + callbacks.Exception = &Exception; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass018_getReady(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes) { + jvmtiError err; + jthread thread; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_redefine_classes || + !caps.can_generate_exception_events) return; + + classBytes = (jbyteArray) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); + + if ((err = (jvmti->GetCurrentThread(&thread))) != JVMTI_ERROR_NONE) { + printf("Failed to get current thread: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_EXCEPTION, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_EXCEPTION_CATCH: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass018_check(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/libredefclass019.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/libredefclass019.c deleted file mode 100644 index b91074c9227..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/libredefclass019.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass019.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/libredefclass019.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/libredefclass019.cpp new file mode 100644 index 00000000000..72e43db3e3e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/libredefclass019.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass019.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/redefclass019.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/redefclass019.c deleted file mode 100644 index cdf858b2960..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/redefclass019.c +++ /dev/null @@ -1,516 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - const char *name; - const char *sig; - jint value; -} var_info; - -typedef struct { - jboolean isObsolete; - const char *name; - const char *sig; - jint line; - jint count; - var_info *vars; -} frame_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jbyteArray classBytes; -static jmethodID midCheckPoint = NULL; -static jmethodID midRun = NULL; -static jint framesExpected = 0; -static jint framesCount = 0; - -static const char *cls_exp = "Lnsk/jvmti/RedefineClasses/redefclass019a;"; - -static var_info run[] = { - {"this", "Lnsk/jvmti/RedefineClasses/redefclass019a;", 0} -}; - -static var_info checkPoint[] = { - {"this", "Lnsk/jvmti/RedefineClasses/redefclass019a;", 0} -}; - -static var_info chain1[] = { - {"this", "Lnsk/jvmti/RedefineClasses/redefclass019a;", 0}, - {"localInt1", "I", 2}, - {"localInt2", "I", 3333} -}; - -static var_info chain2[] = { - {"this", "Lnsk/jvmti/RedefineClasses/redefclass019a;", 0} -}; - -static var_info chain3[] = { - {"this", "Lnsk/jvmti/RedefineClasses/redefclass019a;", 0} -}; - -static frame_info frames[] = { - {JNI_TRUE, "checkPoint", "()V", 115, 1, checkPoint}, - {JNI_FALSE, "chain3", "()V", 49, 1, chain3}, - {JNI_FALSE, "chain2", "()V", 44, 1, chain2}, - {JNI_FALSE, "chain1", "()V", 39, 3, chain1}, - {JNI_FALSE, "run", "()V", 32, 1, run}, -}; - - -void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, jint i) { - jvmtiError err; - jclass cls; - jlocation loc; - char *sigClass, *name = NULL, *sig = NULL, *generic; - jboolean is_obsolete; - jvmtiLineNumberEntry *lines = NULL; - jvmtiLocalVariableEntry *table = NULL; - jint line = -1; - jint entryCount = 0; - jint varValue = -1; - jint j, k; - - if (i >= (jint) (sizeof(frames)/sizeof(frame_info))) { - printf("(pop %d) too many frames\n", i); - result = STATUS_FAILED; - return; - } - - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thr, 0, &mid, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, mid, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { - printf("(pop %d) wrong class sig: \"%s\",", i, sigClass); - printf(" expected: \"%s\"\n", cls_exp); - if (sigClass != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sigClass); - } - result = STATUS_FAILED; - } else { - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->IsMethodObsolete(jvmti_env, mid, &is_obsolete); - if (err != JVMTI_ERROR_NONE) { - printf("(IsMethodObsolete#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> pop %d: \"%s.%s%s\"%s\n", i, sigClass, name, sig, - (is_obsolete == JNI_TRUE) ? " (obsolete)" : ""); - } - if (frames[i].isObsolete != is_obsolete) { - printf("(pop %d) %s obsolete method\n", i, - (is_obsolete == JNI_TRUE) ? "unexpected" : "should be"); - result = STATUS_FAILED; - } - if (name == NULL || strcmp(name, frames[i].name) != 0) { - printf("(pop %d) wrong method name: \"%s\",", i, name); - printf(" expected: \"%s\"\n", frames[i].name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { - printf("(pop %d) wrong method sig: \"%s\",", i, sig); - printf(" expected: \"%s\"\n", frames[i].sig); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetLineNumberTable(jvmti_env, mid, - &entryCount, &lines); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (lines != NULL && entryCount > 0) { - for (k = 0; k < entryCount; k++) { - if (loc < lines[k].start_location) { - break; - } - } - line = lines[k-1].line_number; - } - if (line != frames[i].line) { - printf("(pop %d) wrong line number: %d, expected: %d\n", - i, line, frames[i].line); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, - &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (frames[i].count != entryCount) { - printf("(pop %d) wrong number of locals: %d, expected: %d\n", - i, entryCount, frames[i].count); - result = STATUS_FAILED; - } - - if (table != NULL) { - for (k = 0; k < frames[i].count; k++) { - for (j = 0; j < entryCount; j++) { - if (strcmp(table[j].name, frames[i].vars[k].name) == 0 && - strcmp(table[j].signature, frames[i].vars[k].sig) == 0) { - if (table[j].signature[0] == 'I') { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, 0, - table[j].slot, &varValue); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> var: \"%s %s\"", - table[j].name, table[j].signature); - printf(", value: %d\n", varValue); - } - if (varValue != frames[i].vars[k].value) { - printf("(pop %d) wrong local var value: %d,", - i, varValue); - printf(" expected: %d\n", frames[i].vars[k].value); - result = STATUS_FAILED; - } - } else if (printdump == JNI_TRUE) { - printf(">>> var: \"%s %s\"\n", - table[j].name, table[j].signature); - } - break; - } - } - if (j == entryCount) { - printf("(pop %d) var \"%s %s\" not found\n", - i, frames[i].vars[k].name, frames[i].vars[k].sig); - result = STATUS_FAILED; - } - } - } - } - - if (sigClass != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sigClass); - } - if (name != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)name); - } - if (sig != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sig); - } - if (lines != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)lines); - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].name)); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].signature)); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table); - } -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - jclass klass; - jvmtiClassDefinition classDef; - - if (midCheckPoint != method) { - printf("bp: don't know where we get called from\n"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> breakpoint in checkPoint\n"); - } - - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - classDef.klass = klass; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env, - classBytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> about to call RedefineClasses\n"); - } - - err = (*jvmti_env)->RedefineClasses(jvmti_env, 1, &classDef); - if (err != JVMTI_ERROR_NONE) { - printf("(RedefineClasses) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->NotifyFramePop(jvmti_env, thread, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(NotifyFramePop) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean wasPopedByException) { - jvmtiError err; - - check(jvmti_env, thread, method, framesCount); - framesCount++; - if (method != midRun) { - err = (*jvmti_env)->NotifyFramePop(jvmti_env, thread, 1); - if (err != JVMTI_ERROR_NONE) { - printf("(NotifyFramePop#%d) unexpected error: %s (%d)\n", - framesCount, TranslateError(err), err); - result = STATUS_FAILED; - } - } else { - if (printdump == JNI_TRUE) { - printf(">>> poped %d frames till method \"run()\"\n", - framesCount); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass019(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass019(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass019(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - if (!caps.can_get_line_numbers) { - printf("Warning: GetLineNumberTable is not implemented\n"); - } - - if (!caps.can_access_local_variables) { - printf("Warning: access to local variables is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_frame_pop_events) { - callbacks.Breakpoint = &Breakpoint; - callbacks.FramePop = &FramePop; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass019_getReady(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes, jint depth) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_redefine_classes || - !caps.can_generate_breakpoint_events || - !caps.can_generate_frame_pop_events || - !caps.can_get_line_numbers || - !caps.can_access_local_variables) return; - - classBytes = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); - - midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "run", "()V"); - if (midRun == NULL) { - printf("Cannot find Method ID for method run\n"); - result = STATUS_FAILED; - return; - } - - midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "checkPoint", "()V"); - if (midCheckPoint == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FRAME_POP, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - framesExpected = depth; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass019_check(JNIEnv *env, jclass cls) { - if (framesCount != framesExpected) { - printf("Wrong number of frames: %d, expected: %d\n", - framesCount, framesExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/redefclass019.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/redefclass019.cpp new file mode 100644 index 00000000000..d6fa7a671c6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass019/redefclass019.cpp @@ -0,0 +1,516 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + const char *sig; + jint value; +} var_info; + +typedef struct { + jboolean isObsolete; + const char *name; + const char *sig; + jint line; + jint count; + var_info *vars; +} frame_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jbyteArray classBytes; +static jmethodID midCheckPoint = NULL; +static jmethodID midRun = NULL; +static jint framesExpected = 0; +static jint framesCount = 0; + +static const char *cls_exp = "Lnsk/jvmti/RedefineClasses/redefclass019a;"; + +static var_info run[] = { + {"this", "Lnsk/jvmti/RedefineClasses/redefclass019a;", 0} +}; + +static var_info checkPoint[] = { + {"this", "Lnsk/jvmti/RedefineClasses/redefclass019a;", 0} +}; + +static var_info chain1[] = { + {"this", "Lnsk/jvmti/RedefineClasses/redefclass019a;", 0}, + {"localInt1", "I", 2}, + {"localInt2", "I", 3333} +}; + +static var_info chain2[] = { + {"this", "Lnsk/jvmti/RedefineClasses/redefclass019a;", 0} +}; + +static var_info chain3[] = { + {"this", "Lnsk/jvmti/RedefineClasses/redefclass019a;", 0} +}; + +static frame_info frames[] = { + {JNI_TRUE, "checkPoint", "()V", 115, 1, checkPoint}, + {JNI_FALSE, "chain3", "()V", 49, 1, chain3}, + {JNI_FALSE, "chain2", "()V", 44, 1, chain2}, + {JNI_FALSE, "chain1", "()V", 39, 3, chain1}, + {JNI_FALSE, "run", "()V", 32, 1, run}, +}; + + +void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, jint i) { + jvmtiError err; + jclass cls; + jlocation loc; + char *sigClass, *name = NULL, *sig = NULL, *generic; + jboolean is_obsolete; + jvmtiLineNumberEntry *lines = NULL; + jvmtiLocalVariableEntry *table = NULL; + jint line = -1; + jint entryCount = 0; + jint varValue = -1; + jint j, k; + + if (i >= (jint) (sizeof(frames)/sizeof(frame_info))) { + printf("(pop %d) too many frames\n", i); + result = STATUS_FAILED; + return; + } + + err = jvmti_env->GetFrameLocation(thr, 0, &mid, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetMethodDeclaringClass(mid, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetClassSignature(cls, &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { + printf("(pop %d) wrong class sig: \"%s\",", i, sigClass); + printf(" expected: \"%s\"\n", cls_exp); + if (sigClass != NULL) { + jvmti_env->Deallocate((unsigned char*)sigClass); + } + result = STATUS_FAILED; + } else { + err = jvmti_env->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->IsMethodObsolete(mid, &is_obsolete); + if (err != JVMTI_ERROR_NONE) { + printf("(IsMethodObsolete#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> pop %d: \"%s.%s%s\"%s\n", i, sigClass, name, sig, + (is_obsolete == JNI_TRUE) ? " (obsolete)" : ""); + } + if (frames[i].isObsolete != is_obsolete) { + printf("(pop %d) %s obsolete method\n", i, + (is_obsolete == JNI_TRUE) ? "unexpected" : "should be"); + result = STATUS_FAILED; + } + if (name == NULL || strcmp(name, frames[i].name) != 0) { + printf("(pop %d) wrong method name: \"%s\",", i, name); + printf(" expected: \"%s\"\n", frames[i].name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { + printf("(pop %d) wrong method sig: \"%s\",", i, sig); + printf(" expected: \"%s\"\n", frames[i].sig); + result = STATUS_FAILED; + } + + err = jvmti_env->GetLineNumberTable(mid, + &entryCount, &lines); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (lines != NULL && entryCount > 0) { + for (k = 0; k < entryCount; k++) { + if (loc < lines[k].start_location) { + break; + } + } + line = lines[k-1].line_number; + } + if (line != frames[i].line) { + printf("(pop %d) wrong line number: %d, expected: %d\n", + i, line, frames[i].line); + result = STATUS_FAILED; + } + + err = jvmti_env->GetLocalVariableTable(mid, + &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (frames[i].count != entryCount) { + printf("(pop %d) wrong number of locals: %d, expected: %d\n", + i, entryCount, frames[i].count); + result = STATUS_FAILED; + } + + if (table != NULL) { + for (k = 0; k < frames[i].count; k++) { + for (j = 0; j < entryCount; j++) { + if (strcmp(table[j].name, frames[i].vars[k].name) == 0 && + strcmp(table[j].signature, frames[i].vars[k].sig) == 0) { + if (table[j].signature[0] == 'I') { + err = jvmti_env->GetLocalInt(thr, 0, + table[j].slot, &varValue); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> var: \"%s %s\"", + table[j].name, table[j].signature); + printf(", value: %d\n", varValue); + } + if (varValue != frames[i].vars[k].value) { + printf("(pop %d) wrong local var value: %d,", + i, varValue); + printf(" expected: %d\n", frames[i].vars[k].value); + result = STATUS_FAILED; + } + } else if (printdump == JNI_TRUE) { + printf(">>> var: \"%s %s\"\n", + table[j].name, table[j].signature); + } + break; + } + } + if (j == entryCount) { + printf("(pop %d) var \"%s %s\" not found\n", + i, frames[i].vars[k].name, frames[i].vars[k].sig); + result = STATUS_FAILED; + } + } + } + } + + if (sigClass != NULL) { + jvmti_env->Deallocate((unsigned char*)sigClass); + } + if (name != NULL) { + jvmti_env->Deallocate((unsigned char*)name); + } + if (sig != NULL) { + jvmti_env->Deallocate((unsigned char*)sig); + } + if (lines != NULL) { + jvmti_env->Deallocate((unsigned char*)lines); + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + jvmti_env->Deallocate((unsigned char*)(table[j].name)); + jvmti_env->Deallocate((unsigned char*)(table[j].signature)); + } + jvmti_env->Deallocate((unsigned char*)table); + } +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + jclass klass; + jvmtiClassDefinition classDef; + + if (midCheckPoint != method) { + printf("bp: don't know where we get called from\n"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> breakpoint in checkPoint\n"); + } + + err = jvmti_env->ClearBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + classDef.klass = klass; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env, + classBytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> about to call RedefineClasses\n"); + } + + err = jvmti_env->RedefineClasses(1, &classDef); + if (err != JVMTI_ERROR_NONE) { + printf("(RedefineClasses) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->NotifyFramePop(thread, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(NotifyFramePop) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean wasPopedByException) { + jvmtiError err; + + check(jvmti_env, thread, method, framesCount); + framesCount++; + if (method != midRun) { + err = jvmti_env->NotifyFramePop(thread, 1); + if (err != JVMTI_ERROR_NONE) { + printf("(NotifyFramePop#%d) unexpected error: %s (%d)\n", + framesCount, TranslateError(err), err); + result = STATUS_FAILED; + } + } else { + if (printdump == JNI_TRUE) { + printf(">>> poped %d frames till method \"run()\"\n", + framesCount); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass019(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass019(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass019(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + if (!caps.can_get_line_numbers) { + printf("Warning: GetLineNumberTable is not implemented\n"); + } + + if (!caps.can_access_local_variables) { + printf("Warning: access to local variables is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_frame_pop_events) { + callbacks.Breakpoint = &Breakpoint; + callbacks.FramePop = &FramePop; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass019_getReady(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes, jint depth) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_redefine_classes || + !caps.can_generate_breakpoint_events || + !caps.can_generate_frame_pop_events || + !caps.can_get_line_numbers || + !caps.can_access_local_variables) return; + + classBytes = (jbyteArray) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); + + midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "run", "()V"); + if (midRun == NULL) { + printf("Cannot find Method ID for method run\n"); + result = STATUS_FAILED; + return; + } + + midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "checkPoint", "()V"); + if (midCheckPoint == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FRAME_POP, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + framesExpected = depth; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass019_check(JNIEnv *env, jclass cls) { + if (framesCount != framesExpected) { + printf("Wrong number of frames: %d, expected: %d\n", + framesCount, framesExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/libredefclass020.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/libredefclass020.c deleted file mode 100644 index d95f991e5ad..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/libredefclass020.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass020.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/libredefclass020.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/libredefclass020.cpp new file mode 100644 index 00000000000..34737ff5d35 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/libredefclass020.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass020.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/redefclass020.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/redefclass020.c deleted file mode 100644 index ab09eec4612..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/redefclass020.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass020(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass020(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass020(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass020_check(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - classDef.klass = clazz; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> add method capability check ...\n"); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_redefine_classes) { - /* It is OK */ - } else - if (err != JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED) { - printf("Error expected: "); - printf("JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/redefclass020.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/redefclass020.cpp new file mode 100644 index 00000000000..439b8695125 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass020/redefclass020.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass020(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass020(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass020(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass020_check(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + classDef.klass = clazz; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> add method capability check ...\n"); + } + err = jvmti->RedefineClasses(1, &classDef); + + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_redefine_classes) { + /* It is OK */ + } else + if (err != JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED) { + printf("Error expected: "); + printf("JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/libredefclass021.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/libredefclass021.c deleted file mode 100644 index 85f138cb52b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/libredefclass021.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass021.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/libredefclass021.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/libredefclass021.cpp new file mode 100644 index 00000000000..0b5fb0b1808 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/libredefclass021.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass021.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/redefclass021.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/redefclass021.c deleted file mode 100644 index 64b65b4c04d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/redefclass021.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass021(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass021(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass021(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass021_check(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - classDef.klass = clazz; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> delete method capability check ...\n"); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_redefine_classes) { - /* It is OK */ - } else - if (err != JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED) { - printf("Error expected: "); - printf("JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/redefclass021.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/redefclass021.cpp new file mode 100644 index 00000000000..340700aa612 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass021/redefclass021.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass021(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass021(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass021(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass021_check(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + classDef.klass = clazz; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> delete method capability check ...\n"); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_redefine_classes) { + /* It is OK */ + } else + if (err != JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED) { + printf("Error expected: "); + printf("JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/libredefclass022.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/libredefclass022.c deleted file mode 100644 index 62fc89a54b3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/libredefclass022.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass022.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/libredefclass022.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/libredefclass022.cpp new file mode 100644 index 00000000000..518a71fb13f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/libredefclass022.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass022.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/redefclass022.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/redefclass022.c deleted file mode 100644 index 718c9cfe0bd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/redefclass022.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass022(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass022(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass022(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass022_check(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - classDef.klass = clazz; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> change fields capability check ...\n"); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_redefine_classes) { - /* It is OK */ - } else - if (err != JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED) { - printf("Warning: RedefineClasses is restricted\n"); - printf("Error expected: "); - printf("JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/redefclass022.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/redefclass022.cpp new file mode 100644 index 00000000000..bff034cd37c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass022/redefclass022.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass022(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass022(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass022(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass022_check(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + classDef.klass = clazz; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> change fields capability check ...\n"); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_redefine_classes) { + /* It is OK */ + } else + if (err != JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED) { + printf("Warning: RedefineClasses is restricted\n"); + printf("Error expected: "); + printf("JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/libredefclass023.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/libredefclass023.c deleted file mode 100644 index 26007992a0b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/libredefclass023.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass023.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/libredefclass023.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/libredefclass023.cpp new file mode 100644 index 00000000000..08043fc1a80 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/libredefclass023.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass023.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/redefclass023.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/redefclass023.c deleted file mode 100644 index ac9d6a15916..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/redefclass023.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass023(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass023(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass023(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass023_check(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - classDef.klass = clazz; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> change implemented interface capability check ...\n"); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_redefine_classes) { - /* It is OK */ - } else - if (err != JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED) { - printf("Warning: RedefineClasses is restricted\n"); - printf("Error expected: "); - printf("JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/redefclass023.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/redefclass023.cpp new file mode 100644 index 00000000000..c56469e9273 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass023/redefclass023.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass023(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass023(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass023(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass023_check(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + classDef.klass = clazz; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> change implemented interface capability check ...\n"); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_redefine_classes) { + /* It is OK */ + } else + if (err != JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED) { + printf("Warning: RedefineClasses is restricted\n"); + printf("Error expected: "); + printf("JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/libredefclass024.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/libredefclass024.c deleted file mode 100644 index 9854d517139..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/libredefclass024.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass024.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/libredefclass024.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/libredefclass024.cpp new file mode 100644 index 00000000000..5b12e325fb2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/libredefclass024.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass024.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/redefclass024.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/redefclass024.c deleted file mode 100644 index d79c5a97866..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/redefclass024.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass024(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass024(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass024(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass024_check(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - classDef.klass = clazz; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> change class modifiers capability check ...\n"); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_redefine_classes) { - /* It is OK */ - } else - if (err != JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED) { - printf("Warning: RedefineClasses is restricted\n"); - printf("Error expected: "); - printf("JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/redefclass024.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/redefclass024.cpp new file mode 100644 index 00000000000..c432f07e6c6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass024/redefclass024.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass024(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass024(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass024(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass024_check(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + classDef.klass = clazz; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> change class modifiers capability check ...\n"); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_redefine_classes) { + /* It is OK */ + } else + if (err != JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED) { + printf("Warning: RedefineClasses is restricted\n"); + printf("Error expected: "); + printf("JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/libredefclass025.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/libredefclass025.c deleted file mode 100644 index 15f2210ebd9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/libredefclass025.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass025.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/libredefclass025.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/libredefclass025.cpp new file mode 100644 index 00000000000..8c6a7a15ecf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/libredefclass025.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass025.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/redefclass025.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/redefclass025.c deleted file mode 100644 index 02bac410243..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/redefclass025.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass025(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass025(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass025(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass025_check(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - classDef.klass = clazz; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> change method modifiers capability check ...\n"); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_redefine_classes) { - /* It is OK */ - } else - if (err != JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED) { - printf("Warning: RedefineClasses is restricted\n"); - printf("Error expected: "); - printf("JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/redefclass025.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/redefclass025.cpp new file mode 100644 index 00000000000..4d1311a765a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass025/redefclass025.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass025(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass025(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass025(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass025_check(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + classDef.klass = clazz; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> change method modifiers capability check ...\n"); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_redefine_classes) { + /* It is OK */ + } else + if (err != JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED) { + printf("Warning: RedefineClasses is restricted\n"); + printf("Error expected: "); + printf("JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/libredefclass026.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/libredefclass026.c deleted file mode 100644 index 25d170a2f85..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/libredefclass026.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass026.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/libredefclass026.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/libredefclass026.cpp new file mode 100644 index 00000000000..0d5b35bfb4d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/libredefclass026.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass026.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/redefclass026.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/redefclass026.c deleted file mode 100644 index cff67708e9d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/redefclass026.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass026(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass026(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass026(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass026_check(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - classDef.klass = clazz; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> changed class name check ...\n"); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_redefine_classes) { - /* It is OK */ - } else if (err != JVMTI_ERROR_NAMES_DONT_MATCH) { - printf("Error expected: JVMTI_ERROR_NAMES_DONT_MATCH,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/redefclass026.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/redefclass026.cpp new file mode 100644 index 00000000000..0daa1901e17 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass026/redefclass026.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass026(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass026(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass026(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass026_check(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + classDef.klass = clazz; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, bytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, bytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> changed class name check ...\n"); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_redefine_classes) { + /* It is OK */ + } else if (err != JVMTI_ERROR_NAMES_DONT_MATCH) { + printf("Error expected: JVMTI_ERROR_NAMES_DONT_MATCH,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/libredefclass027.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/libredefclass027.c deleted file mode 100644 index 4f31aac30bb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/libredefclass027.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass027.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/libredefclass027.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/libredefclass027.cpp new file mode 100644 index 00000000000..85d5019b2c4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/libredefclass027.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass027.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/redefclass027.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/redefclass027.c deleted file mode 100644 index cfa9e91ed2a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/redefclass027.c +++ /dev/null @@ -1,853 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" -#include "jni_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - const char *name; - const char *sig; - jint value; -} var_info; - -typedef struct { - jboolean isObsolete; - const char *name; - const char *sig; - jint line; - jint count; - var_info *vars; - const char *desc; -} frame_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jbyteArray classBytes; -static jmethodID midRun = NULL; -static jmethodID mid1 = NULL; -static jmethodID mid2 = NULL; -static jfieldID fid1 = NULL; -static jfieldID fid2 = NULL; -static jint stepEventsExpected = 0; -static jint bpEventsExpected = 0; -static jint popEventsExpected = 0; -static jint accessEventsExpected = 0; -static jint modificationEventsExpected = 0; -static jint exceptionEventsExpected = 0; -static jint catchEventsExpected = 0; -static jint stepEventsCount = 0; -static jint bpEventsCount = 0; -static jint popEventsCount = 0; -static jint accessEventsCount = 0; -static jint modificationEventsCount = 0; -static jint exceptionEventsCount = 0; -static jint catchEventsCount = 0; -static jint redefinesCount = 0; - -static const char *cls_exp = "Lnsk/jvmti/RedefineClasses/redefclass027a;"; - -static var_info run[] = { - {"this", "Lnsk/jvmti/RedefineClasses/redefclass027a;", 0}, - {"localInt1", "I", 1} -}; - -static var_info method1[] = { - {"this", "Lnsk/jvmti/RedefineClasses/redefclass027a;", 0}, - {"argInt1", "I", 10}, - {"localInt2", "I", 2}, - {"ex", "Ljava/lang/Exception;", 0} -}; - -static var_info pop[] = { - {"this", "Lnsk/jvmti/RedefineClasses/redefclass027a;", 0}, - {"argInt1", "I", 10}, - {"localInt2", "I", 2}, - {"ex", "Ljava/lang/Exception;", 0} -}; - -static var_info method2[] = { - {"this", "Lnsk/jvmti/RedefineClasses/redefclass027a;", 0}, - {"argInt2", "I", 20}, - {"localInt4", "I", 4} -}; - -static frame_info frames[] = { - {JNI_FALSE, "run", "()V", 97, 2, run, "bp"}, - {JNI_FALSE, "run", "()V", 97, 2, run, "step"}, - {JNI_FALSE, "run", "()V", 99, 2, run, "mod"}, - {JNI_FALSE, "method2", "(I)V", 116, 3, method2, "acc"}, - {JNI_FALSE, "method2", "(I)V", 117, 3, method2, "exc"}, - {JNI_FALSE, "method1", "(I)V", 108, 4, method1, "catch"}, - {JNI_FALSE, "method1", "(I)V", 112, 4, pop, "pop"}, -}; - - -void check(jvmtiEnv *jvmti_env, jthread thr, jclass cls, jmethodID mid, - jlocation loc, jint i) { - jvmtiError err; - char *sigClass, *name = NULL, *sig = NULL, *generic; - const char *desc; - jboolean is_obsolete; - jvmtiLineNumberEntry *lines = NULL; - jvmtiLocalVariableEntry *table = NULL; - jint line = -1; - jint entryCount = 0; - jint varValue = -1; - jint j, k; - char buffer[32]; - - if (i >= (jint) (sizeof(frames)/sizeof(frame_info))) { - printf("%d -- too many frames\n", i); - result = STATUS_FAILED; - return; - } - - desc = frames[i].desc; - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%s) unexpected error: %s (%d)\n", - desc, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { - printf("(%s) wrong class sig: \"%s\",", desc, sigClass); - printf(" expected: \"%s\"\n", cls_exp); - if (sigClass != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)sigClass); - } - result = STATUS_FAILED; - } else { - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%s) unexpected error: %s (%d)\n", - desc, TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->IsMethodObsolete(jvmti_env, mid, &is_obsolete); - if (err != JVMTI_ERROR_NONE) { - printf("(IsMethodObsolete#%s) unexpected error: %s (%d)\n", - desc, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> %s: \"%s.%s%s\"%s", desc, sigClass, name, sig, - (is_obsolete == JNI_TRUE) ? " (obsolete)" : ""); - printf(", location=%s\n", jlong_to_string(loc, buffer)); - } - if (frames[i].isObsolete != is_obsolete) { - printf("(%s) %s obsolete method\n", desc, - (is_obsolete == JNI_TRUE) ? "unexpected" : "should be"); - result = STATUS_FAILED; - } - if (name == NULL || strcmp(name, frames[i].name) != 0) { - printf("(%s) wrong method name: \"%s\",", desc, name); - printf(" expected: \"%s\"\n", frames[i].name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { - printf("(%s) wrong method sig: \"%s\",", desc, sig); - printf(" expected: \"%s\"\n", frames[i].sig); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetLineNumberTable(jvmti_env, mid, - &entryCount, &lines); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLineNumberTable#%s) unexpected error: %s (%d)\n", - desc, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (lines != NULL && entryCount > 0) { - for (k = 0; k < entryCount; k++) { - if (loc < lines[k].start_location) { - break; - } - } - line = lines[k-1].line_number; - } - if (line != frames[i].line) { - printf("(%s) wrong line number: %d, expected: %d\n", - desc, line, frames[i].line); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, - &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable#%s) unexpected error: %s (%d)\n", - desc, TranslateError(err), err); - result = STATUS_FAILED; - } - - if (frames[i].count != entryCount) { - printf("(%s) wrong number of locals: %d, expected: %d\n", - desc, entryCount, frames[i].count); - result = STATUS_FAILED; - } - - if (table != NULL) { - for (k = 0; k < frames[i].count; k++) { - for (j = 0; j < entryCount; j++) { - if (strcmp(table[j].name, frames[i].vars[k].name) == 0 && - strcmp(table[j].signature, frames[i].vars[k].sig) == 0) { - if (printdump == JNI_TRUE) { - printf(">>> var \"%s:%s\": ", - table[j].name, table[j].signature); - printf("start_location=%s, length=%d", - jlong_to_string(table[j].start_location, buffer), - table[j].length); - } - if (table[j].signature[0] == 'I' && - loc >= table[j].start_location && - loc <= (table[j].start_location + table[j].length)) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, - 0, table[j].slot, &varValue); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#%s) unexpected error: %s (%d)\n", - desc, TranslateError(err), err); - result = STATUS_FAILED; - } - else { - if (printdump == JNI_TRUE) { - printf(", tvalue=%d\n", varValue); - } - if (varValue != frames[i].vars[k].value) { - printf("(%s) wrong local var \"%s:%s\" value: %d,", - desc, table[j].name, table[j].signature, - varValue); - printf(" expected: %d\n", frames[i].vars[k].value); - result = STATUS_FAILED; - } - } - } else if (printdump == JNI_TRUE) { - printf("\n"); - } - break; - } - } - if (j == entryCount) { - printf("(%s) var \"%s %s\" not found\n", - desc, frames[i].vars[k].name, frames[i].vars[k].sig); - result = STATUS_FAILED; - } - } - } - } - - if (sigClass != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)sigClass); - } - if (name != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)name); - } - if (sig != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)sig); - } - if (lines != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)lines); - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)(table[j].name)); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)(table[j].signature)); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)table); - } -} - -void redefine(jvmtiEnv *jvmti_env, JNIEnv *env, jclass cls) { - jvmtiClassDefinition classDef; - jvmtiError err; - - classDef.klass = cls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); - - if (printdump == JNI_TRUE) { - printf(">>> about to call RedefineClasses %d\n", redefinesCount); - } - - err = (*jvmti_env)->RedefineClasses(jvmti_env, 1, &classDef); - if (err != JVMTI_ERROR_NONE) { - printf("(RedefineClasses#%d) unexpected error: %s (%d)\n", - redefinesCount, TranslateError(err), err); - result = STATUS_FAILED; - } - redefinesCount++; -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - jclass klass; - - if (midRun != method) { - printf("bp: don't know where we get called from\n"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> breakpoint in \"run\"\n"); - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - check(jvmti_env, thread, klass, method, location, 0); - bpEventsCount++; - - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, midRun, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - redefine(jvmti_env, (JNIEnv *)env, klass); - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err == JVMTI_ERROR_NONE) { - stepEventsExpected++; - } else { - printf("Cannot enable single step: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jlocation location) { - jvmtiError err; - jclass klass; - - if (midRun != method) { - printf("step: don't know where we get called from\n"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> single step in \"run\"\n"); - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - check(jvmti_env, thread, klass, method, location, 1); - stepEventsCount++; - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable single step: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - redefine(jvmti_env, (JNIEnv *)env, klass); - - if (caps.can_generate_exception_events) { - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_EXCEPTION, thread); - if (err == JVMTI_ERROR_NONE) { - exceptionEventsExpected++; - } else { - printf("Cannot enable exception: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location, - jclass field_klass, jobject obj, jfieldID field, char sig, jvalue new_value) { - jvmtiError err; - jclass klass; - - if (printdump == JNI_TRUE) { - printf(">>> field modification\n"); - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - check(jvmti_env, thread, klass, method, location, 2); - modificationEventsCount++; - - redefine(jvmti_env, (JNIEnv *)env, klass); -} - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location, - jclass field_klass, jobject obj, jfieldID field) { - jvmtiError err; - jclass klass; - - if (printdump == JNI_TRUE) { - printf(">>> field access\n"); - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - check(jvmti_env, thread, klass, method, location, 3); - accessEventsCount++; - - redefine(jvmti_env, (JNIEnv *)env, klass); -} - -void JNICALL Exception(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - jvmtiError err; - jclass klass; - - if (printdump == JNI_TRUE) { - printf(">>> exception\n"); - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - check(jvmti_env, thread, klass, method, location, 4); - exceptionEventsCount++; - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_EXCEPTION, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable exception: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - redefine(jvmti_env, (JNIEnv *)env, klass); - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_EXCEPTION_CATCH, thread); - if (err == JVMTI_ERROR_NONE) { - catchEventsExpected++; - } else { - printf("Cannot enable exception catch: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location, jobject exception) { - jvmtiError err; - jclass klass; - - if (printdump == JNI_TRUE) { - printf(">>> catch\n"); - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - check(jvmti_env, thread, klass, method, location, 5); - catchEventsCount++; - - redefine(jvmti_env, (JNIEnv *)env, klass); - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_EXCEPTION_CATCH, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable exception catch: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (caps.can_generate_frame_pop_events) { - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_FRAME_POP, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - err = (*jvmti_env)->NotifyFramePop(jvmti_env, thread, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(NotifyFramePop) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - popEventsExpected++; - } - } - } -} - -void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean wasPopedByException) { - jvmtiError err; - jclass klass; - jmethodID mid; - jlocation loc; - - if (printdump == JNI_TRUE) { - printf(">>> frame pop\n"); - } - - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thread, 0, &mid, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation#pop) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &klass); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - check(jvmti_env, thread, klass, method, loc, 6); - popEventsCount++; - - redefine(jvmti_env, (JNIEnv *)env, klass); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass027(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass027(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass027(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - if (!caps.can_get_line_numbers) { - printf("Warning: GetLineNumberTable is not implemented\n"); - } - - if (!caps.can_access_local_variables) { - printf("Warning: access to local variables is not implemented\n"); - } - - if (caps.can_redefine_classes) { - if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - } else { - printf("Warning: Breakpoint event is not implemented\n"); - } - if (caps.can_generate_single_step_events) { - callbacks.SingleStep = &SingleStep; - } else { - printf("Warning: SingleStep event is not implemented\n"); - } - if (caps.can_generate_exception_events) { - callbacks.Exception = &Exception; - callbacks.ExceptionCatch = &ExceptionCatch; - } else { - printf("Warning: exception events are not implemented\n"); - } - if (caps.can_generate_frame_pop_events) { - callbacks.FramePop = &FramePop; - } else { - printf("Warning: FramePop event is not implemented\n"); - } - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - } else { - printf("Warning: FieldAccess event is not implemented\n"); - } - if (caps.can_generate_field_modification_events) { - callbacks.FieldModification = &FieldModification; - } else { - printf("Warning: FieldModification event is not implemented\n"); - } - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass027_getReady(JNIEnv *env, jclass cls, - jclass clazz, jbyteArray bytes) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_redefine_classes || - !caps.can_get_line_numbers || - !caps.can_access_local_variables) return; - - classBytes = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); - - midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "run", "()V"); - if (midRun == NULL) { - printf("Cannot find Method ID for method run\n"); - result = STATUS_FAILED; - } - - mid1 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "method1", "(I)V"); - if (mid1 == NULL) { - printf("Cannot find Method ID for method1\n"); - result = STATUS_FAILED; - } - - mid2 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), - "method2", "(I)V"); - if (mid2 == NULL) { - printf("Cannot find Method ID for method2\n"); - result = STATUS_FAILED; - } - - if (caps.can_generate_breakpoint_events && midRun != NULL) { - err = (*jvmti)->SetBreakpoint(jvmti, midRun, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - bpEventsExpected++; - } - } - } - - fid1 = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, clazz), - "staticInt", "I"); - if (fid1 == NULL) { - printf("Cannot find Field ID for staticInt\n"); - result = STATUS_FAILED; - } - - if (caps.can_generate_field_modification_events && fid1 != NULL) { - err = (*jvmti)->SetFieldModificationWatch(jvmti, clazz, fid1); - if (err != JVMTI_ERROR_NONE) { - printf("(SetFieldModificationWatch) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_MODIFICATION, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable FIELD_MODIFICATION event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - modificationEventsExpected++; - } - } - } - - fid2 = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, clazz), - "instanceInt", "I"); - if (fid2 == NULL) { - printf("Cannot find Field ID for instanceInt\n"); - result = STATUS_FAILED; - } - - if (caps.can_generate_field_access_events && fid2 != NULL) { - err = (*jvmti)->SetFieldAccessWatch(jvmti, clazz, fid2); - if (err != JVMTI_ERROR_NONE) { - printf("(SetFieldAccessWatch) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable FIELD_ACCESS event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - accessEventsExpected++; - } - } - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass027_check(JNIEnv *env, jclass cls) { - if (bpEventsCount != bpEventsExpected) { - printf("Wrong number of breakpoint events: %d, expected: %d\n", - bpEventsCount, bpEventsExpected); - result = STATUS_FAILED; - } - if (stepEventsCount != stepEventsExpected) { - printf("Wrong number of step events: %d, expected: %d\n", - stepEventsCount, stepEventsExpected); - result = STATUS_FAILED; - } - if (modificationEventsCount != modificationEventsExpected) { - printf("Wrong number of modification watch events: %d, expected: %d\n", - modificationEventsCount, modificationEventsExpected); - result = STATUS_FAILED; - } - if (accessEventsCount != accessEventsExpected) { - printf("Wrong number of access watch events: %d, expected: %d\n", - accessEventsCount, accessEventsExpected); - result = STATUS_FAILED; - } - if (exceptionEventsCount != exceptionEventsExpected) { - printf("Wrong number of exception events: %d, expected: %d\n", - exceptionEventsCount, exceptionEventsExpected); - result = STATUS_FAILED; - } - if (catchEventsCount != catchEventsExpected) { - printf("Wrong number of catch exception events: %d, expected: %d\n", - catchEventsCount, catchEventsExpected); - result = STATUS_FAILED; - } - if (popEventsCount != popEventsExpected) { - printf("Wrong number of frame pop events: %d, expected: %d\n", - popEventsCount, popEventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/redefclass027.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/redefclass027.cpp new file mode 100644 index 00000000000..e596123c89c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass027/redefclass027.cpp @@ -0,0 +1,853 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + const char *sig; + jint value; +} var_info; + +typedef struct { + jboolean isObsolete; + const char *name; + const char *sig; + jint line; + jint count; + var_info *vars; + const char *desc; +} frame_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jbyteArray classBytes; +static jmethodID midRun = NULL; +static jmethodID mid1 = NULL; +static jmethodID mid2 = NULL; +static jfieldID fid1 = NULL; +static jfieldID fid2 = NULL; +static jint stepEventsExpected = 0; +static jint bpEventsExpected = 0; +static jint popEventsExpected = 0; +static jint accessEventsExpected = 0; +static jint modificationEventsExpected = 0; +static jint exceptionEventsExpected = 0; +static jint catchEventsExpected = 0; +static jint stepEventsCount = 0; +static jint bpEventsCount = 0; +static jint popEventsCount = 0; +static jint accessEventsCount = 0; +static jint modificationEventsCount = 0; +static jint exceptionEventsCount = 0; +static jint catchEventsCount = 0; +static jint redefinesCount = 0; + +static const char *cls_exp = "Lnsk/jvmti/RedefineClasses/redefclass027a;"; + +static var_info run[] = { + {"this", "Lnsk/jvmti/RedefineClasses/redefclass027a;", 0}, + {"localInt1", "I", 1} +}; + +static var_info method1[] = { + {"this", "Lnsk/jvmti/RedefineClasses/redefclass027a;", 0}, + {"argInt1", "I", 10}, + {"localInt2", "I", 2}, + {"ex", "Ljava/lang/Exception;", 0} +}; + +static var_info pop[] = { + {"this", "Lnsk/jvmti/RedefineClasses/redefclass027a;", 0}, + {"argInt1", "I", 10}, + {"localInt2", "I", 2}, + {"ex", "Ljava/lang/Exception;", 0} +}; + +static var_info method2[] = { + {"this", "Lnsk/jvmti/RedefineClasses/redefclass027a;", 0}, + {"argInt2", "I", 20}, + {"localInt4", "I", 4} +}; + +static frame_info frames[] = { + {JNI_FALSE, "run", "()V", 97, 2, run, "bp"}, + {JNI_FALSE, "run", "()V", 97, 2, run, "step"}, + {JNI_FALSE, "run", "()V", 99, 2, run, "mod"}, + {JNI_FALSE, "method2", "(I)V", 116, 3, method2, "acc"}, + {JNI_FALSE, "method2", "(I)V", 117, 3, method2, "exc"}, + {JNI_FALSE, "method1", "(I)V", 108, 4, method1, "catch"}, + {JNI_FALSE, "method1", "(I)V", 112, 4, pop, "pop"}, +}; + + +void check(jvmtiEnv *jvmti_env, jthread thr, jclass cls, jmethodID mid, + jlocation loc, jint i) { + jvmtiError err; + char *sigClass, *name = NULL, *sig = NULL, *generic; + const char *desc; + jboolean is_obsolete; + jvmtiLineNumberEntry *lines = NULL; + jvmtiLocalVariableEntry *table = NULL; + jint line = -1; + jint entryCount = 0; + jint varValue = -1; + jint j, k; + char buffer[32]; + + if (i >= (jint) (sizeof(frames)/sizeof(frame_info))) { + printf("%d -- too many frames\n", i); + result = STATUS_FAILED; + return; + } + + desc = frames[i].desc; + + err = jvmti_env->GetClassSignature(cls, &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%s) unexpected error: %s (%d)\n", + desc, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { + printf("(%s) wrong class sig: \"%s\",", desc, sigClass); + printf(" expected: \"%s\"\n", cls_exp); + if (sigClass != NULL) { + jvmti_env->Deallocate((unsigned char *)sigClass); + } + result = STATUS_FAILED; + } else { + err = jvmti_env->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%s) unexpected error: %s (%d)\n", + desc, TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->IsMethodObsolete(mid, &is_obsolete); + if (err != JVMTI_ERROR_NONE) { + printf("(IsMethodObsolete#%s) unexpected error: %s (%d)\n", + desc, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> %s: \"%s.%s%s\"%s", desc, sigClass, name, sig, + (is_obsolete == JNI_TRUE) ? " (obsolete)" : ""); + printf(", location=%s\n", jlong_to_string(loc, buffer)); + } + if (frames[i].isObsolete != is_obsolete) { + printf("(%s) %s obsolete method\n", desc, + (is_obsolete == JNI_TRUE) ? "unexpected" : "should be"); + result = STATUS_FAILED; + } + if (name == NULL || strcmp(name, frames[i].name) != 0) { + printf("(%s) wrong method name: \"%s\",", desc, name); + printf(" expected: \"%s\"\n", frames[i].name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, frames[i].sig) != 0) { + printf("(%s) wrong method sig: \"%s\",", desc, sig); + printf(" expected: \"%s\"\n", frames[i].sig); + result = STATUS_FAILED; + } + + err = jvmti_env->GetLineNumberTable(mid, + &entryCount, &lines); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLineNumberTable#%s) unexpected error: %s (%d)\n", + desc, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (lines != NULL && entryCount > 0) { + for (k = 0; k < entryCount; k++) { + if (loc < lines[k].start_location) { + break; + } + } + line = lines[k-1].line_number; + } + if (line != frames[i].line) { + printf("(%s) wrong line number: %d, expected: %d\n", + desc, line, frames[i].line); + result = STATUS_FAILED; + } + + err = jvmti_env->GetLocalVariableTable(mid, + &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable#%s) unexpected error: %s (%d)\n", + desc, TranslateError(err), err); + result = STATUS_FAILED; + } + + if (frames[i].count != entryCount) { + printf("(%s) wrong number of locals: %d, expected: %d\n", + desc, entryCount, frames[i].count); + result = STATUS_FAILED; + } + + if (table != NULL) { + for (k = 0; k < frames[i].count; k++) { + for (j = 0; j < entryCount; j++) { + if (strcmp(table[j].name, frames[i].vars[k].name) == 0 && + strcmp(table[j].signature, frames[i].vars[k].sig) == 0) { + if (printdump == JNI_TRUE) { + printf(">>> var \"%s:%s\": ", + table[j].name, table[j].signature); + printf("start_location=%s, length=%d", + jlong_to_string(table[j].start_location, buffer), + table[j].length); + } + if (table[j].signature[0] == 'I' && + loc >= table[j].start_location && + loc <= (table[j].start_location + table[j].length)) { + err = jvmti_env->GetLocalInt(thr, + 0, table[j].slot, &varValue); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#%s) unexpected error: %s (%d)\n", + desc, TranslateError(err), err); + result = STATUS_FAILED; + } + else { + if (printdump == JNI_TRUE) { + printf(", tvalue=%d\n", varValue); + } + if (varValue != frames[i].vars[k].value) { + printf("(%s) wrong local var \"%s:%s\" value: %d,", + desc, table[j].name, table[j].signature, + varValue); + printf(" expected: %d\n", frames[i].vars[k].value); + result = STATUS_FAILED; + } + } + } else if (printdump == JNI_TRUE) { + printf("\n"); + } + break; + } + } + if (j == entryCount) { + printf("(%s) var \"%s %s\" not found\n", + desc, frames[i].vars[k].name, frames[i].vars[k].sig); + result = STATUS_FAILED; + } + } + } + } + + if (sigClass != NULL) { + jvmti_env->Deallocate((unsigned char *)sigClass); + } + if (name != NULL) { + jvmti_env->Deallocate((unsigned char *)name); + } + if (sig != NULL) { + jvmti_env->Deallocate((unsigned char *)sig); + } + if (lines != NULL) { + jvmti_env->Deallocate((unsigned char *)lines); + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + jvmti_env->Deallocate((unsigned char *)(table[j].name)); + jvmti_env->Deallocate((unsigned char *)(table[j].signature)); + } + jvmti_env->Deallocate((unsigned char *)table); + } +} + +void redefine(jvmtiEnv *jvmti_env, JNIEnv *env, jclass cls) { + jvmtiClassDefinition classDef; + jvmtiError err; + + classDef.klass = cls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); + + if (printdump == JNI_TRUE) { + printf(">>> about to call RedefineClasses %d\n", redefinesCount); + } + + err = jvmti_env->RedefineClasses(1, &classDef); + if (err != JVMTI_ERROR_NONE) { + printf("(RedefineClasses#%d) unexpected error: %s (%d)\n", + redefinesCount, TranslateError(err), err); + result = STATUS_FAILED; + } + redefinesCount++; +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + jclass klass; + + if (midRun != method) { + printf("bp: don't know where we get called from\n"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> breakpoint in \"run\"\n"); + } + + err = jvmti_env->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + check(jvmti_env, thread, klass, method, location, 0); + bpEventsCount++; + + err = jvmti_env->ClearBreakpoint(midRun, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + redefine(jvmti_env, (JNIEnv *)env, klass); + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err == JVMTI_ERROR_NONE) { + stepEventsExpected++; + } else { + printf("Cannot enable single step: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jlocation location) { + jvmtiError err; + jclass klass; + + if (midRun != method) { + printf("step: don't know where we get called from\n"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> single step in \"run\"\n"); + } + + err = jvmti_env->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + check(jvmti_env, thread, klass, method, location, 1); + stepEventsCount++; + + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable single step: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + redefine(jvmti_env, (JNIEnv *)env, klass); + + if (caps.can_generate_exception_events) { + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_EXCEPTION, thread); + if (err == JVMTI_ERROR_NONE) { + exceptionEventsExpected++; + } else { + printf("Cannot enable exception: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location, + jclass field_klass, jobject obj, jfieldID field, char sig, jvalue new_value) { + jvmtiError err; + jclass klass; + + if (printdump == JNI_TRUE) { + printf(">>> field modification\n"); + } + + err = jvmti_env->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + check(jvmti_env, thread, klass, method, location, 2); + modificationEventsCount++; + + redefine(jvmti_env, (JNIEnv *)env, klass); +} + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location, + jclass field_klass, jobject obj, jfieldID field) { + jvmtiError err; + jclass klass; + + if (printdump == JNI_TRUE) { + printf(">>> field access\n"); + } + + err = jvmti_env->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + check(jvmti_env, thread, klass, method, location, 3); + accessEventsCount++; + + redefine(jvmti_env, (JNIEnv *)env, klass); +} + +void JNICALL Exception(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + jvmtiError err; + jclass klass; + + if (printdump == JNI_TRUE) { + printf(">>> exception\n"); + } + + err = jvmti_env->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + check(jvmti_env, thread, klass, method, location, 4); + exceptionEventsCount++; + + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_EXCEPTION, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable exception: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + redefine(jvmti_env, (JNIEnv *)env, klass); + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_EXCEPTION_CATCH, thread); + if (err == JVMTI_ERROR_NONE) { + catchEventsExpected++; + } else { + printf("Cannot enable exception catch: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location, jobject exception) { + jvmtiError err; + jclass klass; + + if (printdump == JNI_TRUE) { + printf(">>> catch\n"); + } + + err = jvmti_env->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + check(jvmti_env, thread, klass, method, location, 5); + catchEventsCount++; + + redefine(jvmti_env, (JNIEnv *)env, klass); + + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_EXCEPTION_CATCH, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable exception catch: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (caps.can_generate_frame_pop_events) { + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FRAME_POP, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + err = jvmti_env->NotifyFramePop(thread, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(NotifyFramePop) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + popEventsExpected++; + } + } + } +} + +void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean wasPopedByException) { + jvmtiError err; + jclass klass; + jmethodID mid; + jlocation loc; + + if (printdump == JNI_TRUE) { + printf(">>> frame pop\n"); + } + + err = jvmti_env->GetFrameLocation(thread, 0, &mid, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation#pop) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetMethodDeclaringClass(method, &klass); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + check(jvmti_env, thread, klass, method, loc, 6); + popEventsCount++; + + redefine(jvmti_env, (JNIEnv *)env, klass); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass027(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass027(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass027(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + if (!caps.can_get_line_numbers) { + printf("Warning: GetLineNumberTable is not implemented\n"); + } + + if (!caps.can_access_local_variables) { + printf("Warning: access to local variables is not implemented\n"); + } + + if (caps.can_redefine_classes) { + if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + } else { + printf("Warning: Breakpoint event is not implemented\n"); + } + if (caps.can_generate_single_step_events) { + callbacks.SingleStep = &SingleStep; + } else { + printf("Warning: SingleStep event is not implemented\n"); + } + if (caps.can_generate_exception_events) { + callbacks.Exception = &Exception; + callbacks.ExceptionCatch = &ExceptionCatch; + } else { + printf("Warning: exception events are not implemented\n"); + } + if (caps.can_generate_frame_pop_events) { + callbacks.FramePop = &FramePop; + } else { + printf("Warning: FramePop event is not implemented\n"); + } + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + } else { + printf("Warning: FieldAccess event is not implemented\n"); + } + if (caps.can_generate_field_modification_events) { + callbacks.FieldModification = &FieldModification; + } else { + printf("Warning: FieldModification event is not implemented\n"); + } + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass027_getReady(JNIEnv *env, jclass cls, + jclass clazz, jbyteArray bytes) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_redefine_classes || + !caps.can_get_line_numbers || + !caps.can_access_local_variables) return; + + classBytes = (jbyteArray) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes)); + + midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "run", "()V"); + if (midRun == NULL) { + printf("Cannot find Method ID for method run\n"); + result = STATUS_FAILED; + } + + mid1 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "method1", "(I)V"); + if (mid1 == NULL) { + printf("Cannot find Method ID for method1\n"); + result = STATUS_FAILED; + } + + mid2 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), + "method2", "(I)V"); + if (mid2 == NULL) { + printf("Cannot find Method ID for method2\n"); + result = STATUS_FAILED; + } + + if (caps.can_generate_breakpoint_events && midRun != NULL) { + err = jvmti->SetBreakpoint(midRun, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + bpEventsExpected++; + } + } + } + + fid1 = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, clazz), + "staticInt", "I"); + if (fid1 == NULL) { + printf("Cannot find Field ID for staticInt\n"); + result = STATUS_FAILED; + } + + if (caps.can_generate_field_modification_events && fid1 != NULL) { + err = jvmti->SetFieldModificationWatch(clazz, fid1); + if (err != JVMTI_ERROR_NONE) { + printf("(SetFieldModificationWatch) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_MODIFICATION, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable FIELD_MODIFICATION event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + modificationEventsExpected++; + } + } + } + + fid2 = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, clazz), + "instanceInt", "I"); + if (fid2 == NULL) { + printf("Cannot find Field ID for instanceInt\n"); + result = STATUS_FAILED; + } + + if (caps.can_generate_field_access_events && fid2 != NULL) { + err = jvmti->SetFieldAccessWatch(clazz, fid2); + if (err != JVMTI_ERROR_NONE) { + printf("(SetFieldAccessWatch) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable FIELD_ACCESS event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + accessEventsExpected++; + } + } + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass027_check(JNIEnv *env, jclass cls) { + if (bpEventsCount != bpEventsExpected) { + printf("Wrong number of breakpoint events: %d, expected: %d\n", + bpEventsCount, bpEventsExpected); + result = STATUS_FAILED; + } + if (stepEventsCount != stepEventsExpected) { + printf("Wrong number of step events: %d, expected: %d\n", + stepEventsCount, stepEventsExpected); + result = STATUS_FAILED; + } + if (modificationEventsCount != modificationEventsExpected) { + printf("Wrong number of modification watch events: %d, expected: %d\n", + modificationEventsCount, modificationEventsExpected); + result = STATUS_FAILED; + } + if (accessEventsCount != accessEventsExpected) { + printf("Wrong number of access watch events: %d, expected: %d\n", + accessEventsCount, accessEventsExpected); + result = STATUS_FAILED; + } + if (exceptionEventsCount != exceptionEventsExpected) { + printf("Wrong number of exception events: %d, expected: %d\n", + exceptionEventsCount, exceptionEventsExpected); + result = STATUS_FAILED; + } + if (catchEventsCount != catchEventsExpected) { + printf("Wrong number of catch exception events: %d, expected: %d\n", + catchEventsCount, catchEventsExpected); + result = STATUS_FAILED; + } + if (popEventsCount != popEventsExpected) { + printf("Wrong number of frame pop events: %d, expected: %d\n", + popEventsCount, popEventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/libredefclass028.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/libredefclass028.c deleted file mode 100644 index c1893f07207..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/libredefclass028.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass028.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/libredefclass028.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/libredefclass028.cpp new file mode 100644 index 00000000000..d37dd35cac0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/libredefclass028.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass028.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/redefclass028.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/redefclass028.c deleted file mode 100644 index aa32765d8bc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/redefclass028.c +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include - -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "native_thread.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define MAX_ATTEMPTS 15 - -static const char *expHSMethod = "redefclass028HotMethod"; -static const char *expHSSignature = "(I)V"; - -#define EVENTS_COUNT 2 -static jvmtiEvent eventsList[EVENTS_COUNT] = { - JVMTI_EVENT_COMPILED_METHOD_LOAD, - JVMTI_EVENT_COMPILED_METHOD_UNLOAD -}; - -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static volatile int fire = 0; /* CompiledMethodLoad received for hotspot method */ -static jmethodID hsMethodID; /* hotspot method ID */ - -static volatile int enteredHotMethod = 0; /* "hot" method is entered */ - -static jint bytesCount; /* number of bytes of a redefining class */ -static jbyte *clsBytes; /* bytes defining a redefining class */ - -/** pass info about redefinition to Java **/ -JNIEXPORT jboolean JNICALL Java_nsk_jvmti_RedefineClasses_redefclass028_isRedefinitionOccurred - (JNIEnv *jni_env, jclass cls) -{ - if (fire == 1) { - NSK_DISPLAY0("isRedefinitionOccurred is called: fired!\n"); - return JNI_TRUE; - } else { - return JNI_FALSE; - } -} - -/** notify native agent from Java when "hot" method is executed **/ -JNIEXPORT void JNICALL Java_nsk_jvmti_RedefineClasses_redefclass028_notifyNativeAgent - (JNIEnv *jni_env, jclass cls) -{ - if (enteredHotMethod == 0) { - NSK_DISPLAY0("notifyNativeAgent is called\n"); - enteredHotMethod = 1; - } -} - -/** pass bytecode to native agent for redefinition **/ -JNIEXPORT void JNICALL Java_nsk_jvmti_RedefineClasses_redefclass028_storeClassBytes - (JNIEnv *jni_env, jclass cls, jbyteArray classBytes) { - jboolean isCopy; - - bytesCount = NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes); - clsBytes = - NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, &isCopy); -} - -/** callback functions **/ -void JNICALL -CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map, - const void* compile_info) { - char *name; - char *sig; - - NSK_DISPLAY0("CompiledMethodLoad event received for:\n"); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &name, &sig, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY5("\tmethod: name=\"%s\" signature=\"%s\"\n" - "\tcompiled code size=%d\n" - "\tstarting native address=0x%p\n" - "\tnumber of address location map entries=%d\n", - name, sig, code_size, code_addr, map_length); - - if ((strcmp(name, expHSMethod) == 0) && - (strcmp(sig, expHSSignature) == 0)) { - NSK_DISPLAY0("CompiledMethodLoad: a tested hotspot method found\n"); - - // CR 6604375: check whether "hot" method was entered - if (enteredHotMethod) { - hsMethodID = method; - fire = 1; - } else { - NSK_DISPLAY0("Compilation occured before method execution. Ignoring.\n"); - } - } -} - -JNIEXPORT void JNICALL -CompiledMethodUnload(jvmtiEnv* jvmti_env, jmethodID method, - const void* code_addr) { - char *name; - char *sig; - jvmtiError err; - - NSK_DISPLAY0("CompiledMethodUnload event received\n"); - // Check for the case that the class has been unloaded - err = (*jvmti_env)->GetMethodName(jvmti_env, method, &name, &sig, NULL); - if (err == JVMTI_ERROR_NONE) { - NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", - name, sig, code_addr); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); - } -} -/************************/ - -/** agent's procedure **/ -static void JNICALL -agentProc(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg) { - int tries = 0; - jclass decl_cls; - char *cls_sig; - jvmtiClassDefinition classDef; - - /* testing sync */ - NSK_DISPLAY1("agentProc: waiting for the debuggee start for %d msecs...\n\n", - (int) timeout); - if (!nsk_jvmti_waitForSync(timeout)) - return; - NSK_DISPLAY0("agentProc: resuming the debuggee ...\n\n"); - if (!nsk_jvmti_resumeSync()) - return; - - /* at first, send all generated CompiledMethodLoad events */ - NSK_DISPLAY0("agentProc: sending all generated CompiledMethodLoad events ...\n\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(GenerateEvents, jvmti, JVMTI_EVENT_COMPILED_METHOD_LOAD))) { - nsk_jvmti_setFailStatus(); - nsk_jvmti_resumeSync(); - return; - } - - NSK_DISPLAY0("agentProc: waiting for hotspot method compilation...\n\n"); - do { - THREAD_sleep(1); - tries++; - if (tries > MAX_ATTEMPTS) { - printf("WARNING: CompiledMethodLoad event is still not received for \"%s\" after %d attempts\n" - "\tThe test has no results\n\n", - expHSMethod, MAX_ATTEMPTS); - nsk_jvmti_resumeSync(); - exit(95 + PASSED); - } - } while(fire == 0); - - NSK_DISPLAY0("agentProc: hotspot method compiled\n\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, hsMethodID, &decl_cls))) { - nsk_jvmti_setFailStatus(); - nsk_jvmti_resumeSync(); - return; - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, - jvmti_env, decl_cls, &cls_sig, NULL))) { - nsk_jvmti_setFailStatus(); - nsk_jvmti_resumeSync(); - return; - } else { - NSK_DISPLAY1("agentProc: hotspot method class signature: \"%s\"\n\n", - cls_sig); - } - - /* fill the structure jvmtiClassDefinition */ - classDef.klass = decl_cls; - classDef.class_byte_count = bytesCount; - classDef.class_bytes = (unsigned char*) clsBytes; - - NSK_DISPLAY1("agentProc: >>>>>>>> Invoke RedefineClasses():\n" - "\tnew class byte count=%d\n", - classDef.class_byte_count); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, - jvmti, 1, &classDef))) { - nsk_jvmti_setFailStatus(); - nsk_jvmti_resumeSync(); - return; - } - NSK_DISPLAY0("agentProc: <<<<<<<< RedefineClasses() is successfully done\n"); - - /* testing sync */ - NSK_DISPLAY1("agentProc: waiting for the debuggee finish for %d msecs...\n\n", - (int) timeout); - if (!nsk_jvmti_waitForSync(timeout)) - return; - NSK_DISPLAY0("agentProc: final resuming of the debuggee ...\n\n"); - if (!nsk_jvmti_resumeSync()) - return; - - NSK_DISPLAY0("agentProc: finished\n\n"); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass028(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass028(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass028(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiCapabilities caps; - jvmtiEventCallbacks callbacks; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - /* obtain WAITTIME parameter */ - timeout = nsk_jvmti_getWaitTime() * 60000; - NSK_DISPLAY1("waittime=%d msecs\n", (int) timeout); - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* add required capabilities */ - memset(&caps, 0, sizeof(jvmtiCapabilities)); - caps.can_generate_compiled_method_load_events = 1; - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, - jvmti, &caps))) - return JNI_ERR; - - /* set event callback */ - NSK_DISPLAY0("setting event callbacks ...\n"); - (void) memset(&callbacks, 0, sizeof(callbacks)); - callbacks.CompiledMethodLoad = &CompiledMethodLoad; - callbacks.CompiledMethodUnload = &CompiledMethodUnload; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - NSK_DISPLAY0("setting event callbacks done\nenabling events ...\n"); - if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, - eventsList, NULL)) - return JNI_ERR; - NSK_DISPLAY0("enabling the events done\n\n"); - - /* register agent proc */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/redefclass028.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/redefclass028.cpp new file mode 100644 index 00000000000..80c4a369dbf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass028/redefclass028.cpp @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include + +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "native_thread.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define MAX_ATTEMPTS 15 + +static const char *expHSMethod = "redefclass028HotMethod"; +static const char *expHSSignature = "(I)V"; + +#define EVENTS_COUNT 2 +static jvmtiEvent eventsList[EVENTS_COUNT] = { + JVMTI_EVENT_COMPILED_METHOD_LOAD, + JVMTI_EVENT_COMPILED_METHOD_UNLOAD +}; + +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static volatile int fire = 0; /* CompiledMethodLoad received for hotspot method */ +static jmethodID hsMethodID; /* hotspot method ID */ + +static volatile int enteredHotMethod = 0; /* "hot" method is entered */ + +static jint bytesCount; /* number of bytes of a redefining class */ +static jbyte *clsBytes; /* bytes defining a redefining class */ + +/** pass info about redefinition to Java **/ +JNIEXPORT jboolean JNICALL Java_nsk_jvmti_RedefineClasses_redefclass028_isRedefinitionOccurred + (JNIEnv *jni_env, jclass cls) +{ + if (fire == 1) { + NSK_DISPLAY0("isRedefinitionOccurred is called: fired!\n"); + return JNI_TRUE; + } else { + return JNI_FALSE; + } +} + +/** notify native agent from Java when "hot" method is executed **/ +JNIEXPORT void JNICALL Java_nsk_jvmti_RedefineClasses_redefclass028_notifyNativeAgent + (JNIEnv *jni_env, jclass cls) +{ + if (enteredHotMethod == 0) { + NSK_DISPLAY0("notifyNativeAgent is called\n"); + enteredHotMethod = 1; + } +} + +/** pass bytecode to native agent for redefinition **/ +JNIEXPORT void JNICALL Java_nsk_jvmti_RedefineClasses_redefclass028_storeClassBytes + (JNIEnv *jni_env, jclass cls, jbyteArray classBytes) { + jboolean isCopy; + + bytesCount = NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes); + clsBytes = + NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, &isCopy); +} + +/** callback functions **/ +void JNICALL +CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map, + const void* compile_info) { + char *name; + char *sig; + + NSK_DISPLAY0("CompiledMethodLoad event received for:\n"); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &name, &sig, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY5("\tmethod: name=\"%s\" signature=\"%s\"\n" + "\tcompiled code size=%d\n" + "\tstarting native address=0x%p\n" + "\tnumber of address location map entries=%d\n", + name, sig, code_size, code_addr, map_length); + + if ((strcmp(name, expHSMethod) == 0) && + (strcmp(sig, expHSSignature) == 0)) { + NSK_DISPLAY0("CompiledMethodLoad: a tested hotspot method found\n"); + + // CR 6604375: check whether "hot" method was entered + if (enteredHotMethod) { + hsMethodID = method; + fire = 1; + } else { + NSK_DISPLAY0("Compilation occured before method execution. Ignoring.\n"); + } + } +} + +JNIEXPORT void JNICALL +CompiledMethodUnload(jvmtiEnv* jvmti_env, jmethodID method, + const void* code_addr) { + char *name; + char *sig; + jvmtiError err; + + NSK_DISPLAY0("CompiledMethodUnload event received\n"); + // Check for the case that the class has been unloaded + err = jvmti_env->GetMethodName(method, &name, &sig, NULL); + if (err == JVMTI_ERROR_NONE) { + NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", + name, sig, code_addr); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); + } +} +/************************/ + +/** agent's procedure **/ +static void JNICALL +agentProc(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg) { + int tries = 0; + jclass decl_cls; + char *cls_sig; + jvmtiClassDefinition classDef; + + /* testing sync */ + NSK_DISPLAY1("agentProc: waiting for the debuggee start for %d msecs...\n\n", + (int) timeout); + if (!nsk_jvmti_waitForSync(timeout)) + return; + NSK_DISPLAY0("agentProc: resuming the debuggee ...\n\n"); + if (!nsk_jvmti_resumeSync()) + return; + + /* at first, send all generated CompiledMethodLoad events */ + NSK_DISPLAY0("agentProc: sending all generated CompiledMethodLoad events ...\n\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(GenerateEvents, jvmti, JVMTI_EVENT_COMPILED_METHOD_LOAD))) { + nsk_jvmti_setFailStatus(); + nsk_jvmti_resumeSync(); + return; + } + + NSK_DISPLAY0("agentProc: waiting for hotspot method compilation...\n\n"); + do { + THREAD_sleep(1); + tries++; + if (tries > MAX_ATTEMPTS) { + printf("WARNING: CompiledMethodLoad event is still not received for \"%s\" after %d attempts\n" + "\tThe test has no results\n\n", + expHSMethod, MAX_ATTEMPTS); + nsk_jvmti_resumeSync(); + exit(95 + PASSED); + } + } while(fire == 0); + + NSK_DISPLAY0("agentProc: hotspot method compiled\n\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, hsMethodID, &decl_cls))) { + nsk_jvmti_setFailStatus(); + nsk_jvmti_resumeSync(); + return; + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, + jvmti_env, decl_cls, &cls_sig, NULL))) { + nsk_jvmti_setFailStatus(); + nsk_jvmti_resumeSync(); + return; + } else { + NSK_DISPLAY1("agentProc: hotspot method class signature: \"%s\"\n\n", + cls_sig); + } + + /* fill the structure jvmtiClassDefinition */ + classDef.klass = decl_cls; + classDef.class_byte_count = bytesCount; + classDef.class_bytes = (unsigned char*) clsBytes; + + NSK_DISPLAY1("agentProc: >>>>>>>> Invoke RedefineClasses():\n" + "\tnew class byte count=%d\n", + classDef.class_byte_count); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, + jvmti, 1, &classDef))) { + nsk_jvmti_setFailStatus(); + nsk_jvmti_resumeSync(); + return; + } + NSK_DISPLAY0("agentProc: <<<<<<<< RedefineClasses() is successfully done\n"); + + /* testing sync */ + NSK_DISPLAY1("agentProc: waiting for the debuggee finish for %d msecs...\n\n", + (int) timeout); + if (!nsk_jvmti_waitForSync(timeout)) + return; + NSK_DISPLAY0("agentProc: final resuming of the debuggee ...\n\n"); + if (!nsk_jvmti_resumeSync()) + return; + + NSK_DISPLAY0("agentProc: finished\n\n"); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass028(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass028(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass028(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiCapabilities caps; + jvmtiEventCallbacks callbacks; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + /* obtain WAITTIME parameter */ + timeout = nsk_jvmti_getWaitTime() * 60000; + NSK_DISPLAY1("waittime=%d msecs\n", (int) timeout); + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* add required capabilities */ + memset(&caps, 0, sizeof(jvmtiCapabilities)); + caps.can_generate_compiled_method_load_events = 1; + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, + jvmti, &caps))) + return JNI_ERR; + + /* set event callback */ + NSK_DISPLAY0("setting event callbacks ...\n"); + (void) memset(&callbacks, 0, sizeof(callbacks)); + callbacks.CompiledMethodLoad = &CompiledMethodLoad; + callbacks.CompiledMethodUnload = &CompiledMethodUnload; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + NSK_DISPLAY0("setting event callbacks done\nenabling events ...\n"); + if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, + eventsList, NULL)) + return JNI_ERR; + NSK_DISPLAY0("enabling the events done\n\n"); + + /* register agent proc */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/libredefclass029.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/libredefclass029.c deleted file mode 100644 index a72528fb42f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/libredefclass029.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass029.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/libredefclass029.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/libredefclass029.cpp new file mode 100644 index 00000000000..ee21fb7a2a1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/libredefclass029.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass029.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/redefclass029.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/redefclass029.c deleted file mode 100644 index 9cf5ac17025..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/redefclass029.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include - -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "native_thread.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define MAX_ATTEMPTS 15 - -static const char *expHSMethod = "redefclass029HotMethod"; -static const char *expHSSignature = "(I)V"; - -#define EVENTS_COUNT 2 -static jvmtiEvent eventsList[EVENTS_COUNT] = { - JVMTI_EVENT_COMPILED_METHOD_LOAD, - JVMTI_EVENT_COMPILED_METHOD_UNLOAD -}; - -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static volatile int fire = 0; /* CompiledMethodLoad received for hotspot method */ -static jmethodID hsMethodID; /* hotspot method ID */ - -static volatile int enteredHotMethod = 0; /* "hot" method is entered */ - -static jint bytesCount; /* number of bytes of a redefining class */ -static jbyte *clsBytes; /* bytes defining a redefining class */ - -/** pass info about redefinition to Java **/ -JNIEXPORT jboolean JNICALL Java_nsk_jvmti_RedefineClasses_redefclass029_isRedefinitionOccurred - (JNIEnv *jni_env, jclass cls) -{ - if (fire == 1) { - NSK_DISPLAY0("isRedefinitionOccurred is called: fired!\n"); - return JNI_TRUE; - } else { - return JNI_FALSE; - } -} - -/** notify native agent from Java when "hot" method is executed **/ -JNIEXPORT void JNICALL Java_nsk_jvmti_RedefineClasses_redefclass029_notifyNativeAgent - (JNIEnv *jni_env, jclass cls) -{ - if (enteredHotMethod == 0) { - NSK_DISPLAY0("notifyNativeAgent is called\n"); - enteredHotMethod = 1; - } -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_RedefineClasses_redefclass029_storeClassBytes - (JNIEnv *jni_env, jclass cls, jbyteArray classBytes) { - jboolean isCopy; - - bytesCount = NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes); - clsBytes = - NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, &isCopy); -} - -/** callback functions **/ -void JNICALL -CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map, - const void* compile_info) { - char *name; - char *sig; - - NSK_DISPLAY0("CompiledMethodLoad event received for:\n"); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &name, &sig, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY5("\tmethod: name=\"%s\" signature=\"%s\"\n" - "\tcompiled code size=%d\n" - "\tstarting native address=0x%p\n" - "\tnumber of address location map entries=%d\n", - name, sig, code_size, code_addr, map_length); - - if ((strcmp(name, expHSMethod) == 0) && - (strcmp(sig, expHSSignature) == 0)) { - NSK_DISPLAY0("CompiledMethodLoad: a tested hotspot method found\n"); - - // CR 6604375: check whether "hot" method was entered - if (enteredHotMethod) { - hsMethodID = method; - fire = 1; - } else { - NSK_DISPLAY0("Compilation occured before method execution. Ignoring.\n"); - } - } -} - -JNIEXPORT void JNICALL -CompiledMethodUnload(jvmtiEnv* jvmti_env, jmethodID method, - const void* code_addr) { - char *name; - char *sig; - jvmtiError err; - - NSK_DISPLAY0("CompiledMethodUnload event received\n"); - // Check for the case that the class has been unloaded - err = (*jvmti_env)->GetMethodName(jvmti_env, method, &name, &sig, NULL); - if (err == JVMTI_ERROR_NONE) { - NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", - name, sig, code_addr); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); - } -} -/************************/ - -/** agent's procedure **/ -static void JNICALL -agentProc(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg) { - int tries = 0; - jclass decl_cls; - char *cls_sig; - jvmtiClassDefinition classDef; - - /* testing sync */ - NSK_DISPLAY1("agentProc: waiting for the debuggee start for %d msecs...\n\n", - (int) timeout); - if (!nsk_jvmti_waitForSync(timeout)) - return; - NSK_DISPLAY0("agentProc: resuming the debuggee ...\n\n"); - if (!nsk_jvmti_resumeSync()) - return; - - /* at first, send all generated CompiledMethodLoad events */ - NSK_DISPLAY0("agentProc: sending all generated CompiledMethodLoad events ...\n\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(GenerateEvents, jvmti, JVMTI_EVENT_COMPILED_METHOD_LOAD))) { - nsk_jvmti_setFailStatus(); - nsk_jvmti_resumeSync(); - return; - } - - NSK_DISPLAY0("agentProc: waiting for hotspot method compilation...\n\n"); - do { - THREAD_sleep(1); - tries++; - if (tries > MAX_ATTEMPTS) { - printf("WARNING: CompiledMethodLoad event is still not received for \"%s\" after %d attempts\n" - "\tThe test has no results\n\n", - expHSMethod, MAX_ATTEMPTS); - nsk_jvmti_resumeSync(); - exit(95 + PASSED); - } - } while(fire == 0); - - NSK_DISPLAY0("agentProc: hotspot method compiled\n\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, hsMethodID, &decl_cls))) { - nsk_jvmti_setFailStatus(); - nsk_jvmti_resumeSync(); - return; - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, - jvmti_env, decl_cls, &cls_sig, NULL))) { - nsk_jvmti_setFailStatus(); - nsk_jvmti_resumeSync(); - return; - } else { - NSK_DISPLAY1("agentProc: hotspot method class signature: \"%s\"\n\n", - cls_sig); - } - - /* fill the structure jvmtiClassDefinition */ - classDef.klass = decl_cls; - classDef.class_byte_count = bytesCount; - classDef.class_bytes = (unsigned char*) clsBytes; - - NSK_DISPLAY1("agentProc: >>>>>>>> Invoke RedefineClasses():\n" - "\tnew class byte count=%d\n", - classDef.class_byte_count); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, - jvmti, 1, &classDef))) { - nsk_jvmti_setFailStatus(); - nsk_jvmti_resumeSync(); - return; - } - NSK_DISPLAY0("agentProc: <<<<<<<< RedefineClasses() is successfully done\n"); - - /* testing sync */ - NSK_DISPLAY1("agentProc: waiting for the debuggee finish for %d msecs...\n\n", - (int) timeout); - if (!nsk_jvmti_waitForSync(timeout)) - return; - NSK_DISPLAY0("agentProc: final resuming of the debuggee ...\n\n"); - if (!nsk_jvmti_resumeSync()) - return; - - NSK_DISPLAY0("agentProc: finished\n\n"); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass029(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass029(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass029(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiCapabilities caps; - jvmtiEventCallbacks callbacks; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - /* obtain WAITTIME parameter */ - timeout = nsk_jvmti_getWaitTime() * 60000; - NSK_DISPLAY1("waittime=%d msecs\n", (int) timeout); - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* add required capabilities */ - memset(&caps, 0, sizeof(jvmtiCapabilities)); - caps.can_generate_compiled_method_load_events = 1; - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, - jvmti, &caps))) - return JNI_ERR; - - /* set event callback */ - NSK_DISPLAY0("setting event callbacks ...\n"); - (void) memset(&callbacks, 0, sizeof(callbacks)); - callbacks.CompiledMethodLoad = &CompiledMethodLoad; - callbacks.CompiledMethodUnload = &CompiledMethodUnload; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - NSK_DISPLAY0("setting event callbacks done\nenabling events ...\n"); - if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, - eventsList, NULL)) - return JNI_ERR; - NSK_DISPLAY0("enabling the events done\n\n"); - - /* register agent proc */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/redefclass029.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/redefclass029.cpp new file mode 100644 index 00000000000..b381264ac82 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/redefclass029.cpp @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include + +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "native_thread.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define MAX_ATTEMPTS 15 + +static const char *expHSMethod = "redefclass029HotMethod"; +static const char *expHSSignature = "(I)V"; + +#define EVENTS_COUNT 2 +static jvmtiEvent eventsList[EVENTS_COUNT] = { + JVMTI_EVENT_COMPILED_METHOD_LOAD, + JVMTI_EVENT_COMPILED_METHOD_UNLOAD +}; + +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static volatile int fire = 0; /* CompiledMethodLoad received for hotspot method */ +static jmethodID hsMethodID; /* hotspot method ID */ + +static volatile int enteredHotMethod = 0; /* "hot" method is entered */ + +static jint bytesCount; /* number of bytes of a redefining class */ +static jbyte *clsBytes; /* bytes defining a redefining class */ + +/** pass info about redefinition to Java **/ +JNIEXPORT jboolean JNICALL Java_nsk_jvmti_RedefineClasses_redefclass029_isRedefinitionOccurred + (JNIEnv *jni_env, jclass cls) +{ + if (fire == 1) { + NSK_DISPLAY0("isRedefinitionOccurred is called: fired!\n"); + return JNI_TRUE; + } else { + return JNI_FALSE; + } +} + +/** notify native agent from Java when "hot" method is executed **/ +JNIEXPORT void JNICALL Java_nsk_jvmti_RedefineClasses_redefclass029_notifyNativeAgent + (JNIEnv *jni_env, jclass cls) +{ + if (enteredHotMethod == 0) { + NSK_DISPLAY0("notifyNativeAgent is called\n"); + enteredHotMethod = 1; + } +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_RedefineClasses_redefclass029_storeClassBytes + (JNIEnv *jni_env, jclass cls, jbyteArray classBytes) { + jboolean isCopy; + + bytesCount = NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes); + clsBytes = + NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, &isCopy); +} + +/** callback functions **/ +void JNICALL +CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map, + const void* compile_info) { + char *name; + char *sig; + + NSK_DISPLAY0("CompiledMethodLoad event received for:\n"); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &name, &sig, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY5("\tmethod: name=\"%s\" signature=\"%s\"\n" + "\tcompiled code size=%d\n" + "\tstarting native address=0x%p\n" + "\tnumber of address location map entries=%d\n", + name, sig, code_size, code_addr, map_length); + + if ((strcmp(name, expHSMethod) == 0) && + (strcmp(sig, expHSSignature) == 0)) { + NSK_DISPLAY0("CompiledMethodLoad: a tested hotspot method found\n"); + + // CR 6604375: check whether "hot" method was entered + if (enteredHotMethod) { + hsMethodID = method; + fire = 1; + } else { + NSK_DISPLAY0("Compilation occured before method execution. Ignoring.\n"); + } + } +} + +JNIEXPORT void JNICALL +CompiledMethodUnload(jvmtiEnv* jvmti_env, jmethodID method, + const void* code_addr) { + char *name; + char *sig; + jvmtiError err; + + NSK_DISPLAY0("CompiledMethodUnload event received\n"); + // Check for the case that the class has been unloaded + err = jvmti_env->GetMethodName(method, &name, &sig, NULL); + if (err == JVMTI_ERROR_NONE) { + NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", + name, sig, code_addr); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); + } +} +/************************/ + +/** agent's procedure **/ +static void JNICALL +agentProc(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg) { + int tries = 0; + jclass decl_cls; + char *cls_sig; + jvmtiClassDefinition classDef; + + /* testing sync */ + NSK_DISPLAY1("agentProc: waiting for the debuggee start for %d msecs...\n\n", + (int) timeout); + if (!nsk_jvmti_waitForSync(timeout)) + return; + NSK_DISPLAY0("agentProc: resuming the debuggee ...\n\n"); + if (!nsk_jvmti_resumeSync()) + return; + + /* at first, send all generated CompiledMethodLoad events */ + NSK_DISPLAY0("agentProc: sending all generated CompiledMethodLoad events ...\n\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(GenerateEvents, jvmti, JVMTI_EVENT_COMPILED_METHOD_LOAD))) { + nsk_jvmti_setFailStatus(); + nsk_jvmti_resumeSync(); + return; + } + + NSK_DISPLAY0("agentProc: waiting for hotspot method compilation...\n\n"); + do { + THREAD_sleep(1); + tries++; + if (tries > MAX_ATTEMPTS) { + printf("WARNING: CompiledMethodLoad event is still not received for \"%s\" after %d attempts\n" + "\tThe test has no results\n\n", + expHSMethod, MAX_ATTEMPTS); + nsk_jvmti_resumeSync(); + exit(95 + PASSED); + } + } while(fire == 0); + + NSK_DISPLAY0("agentProc: hotspot method compiled\n\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, hsMethodID, &decl_cls))) { + nsk_jvmti_setFailStatus(); + nsk_jvmti_resumeSync(); + return; + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, + jvmti_env, decl_cls, &cls_sig, NULL))) { + nsk_jvmti_setFailStatus(); + nsk_jvmti_resumeSync(); + return; + } else { + NSK_DISPLAY1("agentProc: hotspot method class signature: \"%s\"\n\n", + cls_sig); + } + + /* fill the structure jvmtiClassDefinition */ + classDef.klass = decl_cls; + classDef.class_byte_count = bytesCount; + classDef.class_bytes = (unsigned char*) clsBytes; + + NSK_DISPLAY1("agentProc: >>>>>>>> Invoke RedefineClasses():\n" + "\tnew class byte count=%d\n", + classDef.class_byte_count); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, + jvmti, 1, &classDef))) { + nsk_jvmti_setFailStatus(); + nsk_jvmti_resumeSync(); + return; + } + NSK_DISPLAY0("agentProc: <<<<<<<< RedefineClasses() is successfully done\n"); + + /* testing sync */ + NSK_DISPLAY1("agentProc: waiting for the debuggee finish for %d msecs...\n\n", + (int) timeout); + if (!nsk_jvmti_waitForSync(timeout)) + return; + NSK_DISPLAY0("agentProc: final resuming of the debuggee ...\n\n"); + if (!nsk_jvmti_resumeSync()) + return; + + NSK_DISPLAY0("agentProc: finished\n\n"); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass029(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass029(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass029(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiCapabilities caps; + jvmtiEventCallbacks callbacks; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + /* obtain WAITTIME parameter */ + timeout = nsk_jvmti_getWaitTime() * 60000; + NSK_DISPLAY1("waittime=%d msecs\n", (int) timeout); + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* add required capabilities */ + memset(&caps, 0, sizeof(jvmtiCapabilities)); + caps.can_generate_compiled_method_load_events = 1; + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, + jvmti, &caps))) + return JNI_ERR; + + /* set event callback */ + NSK_DISPLAY0("setting event callbacks ...\n"); + (void) memset(&callbacks, 0, sizeof(callbacks)); + callbacks.CompiledMethodLoad = &CompiledMethodLoad; + callbacks.CompiledMethodUnload = &CompiledMethodUnload; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + NSK_DISPLAY0("setting event callbacks done\nenabling events ...\n"); + if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, + eventsList, NULL)) + return JNI_ERR; + NSK_DISPLAY0("enabling the events done\n\n"); + + /* register agent proc */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/libredefclass030.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/libredefclass030.c deleted file mode 100644 index 8d1b69f179e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/libredefclass030.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass030.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/libredefclass030.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/libredefclass030.cpp new file mode 100644 index 00000000000..fb59b4e69aa --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/libredefclass030.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass030.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/redefclass030.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/redefclass030.c deleted file mode 100644 index 84b91abd5f9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/redefclass030.c +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include - -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "native_thread.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define MAX_ATTEMPTS 15 - -static const char *expHSMethod = "redefclass030HotMethod"; -static const char *expHSSignature = "(I)V"; - -#define EVENTS_COUNT 2 -static jvmtiEvent eventsList[EVENTS_COUNT] = { - JVMTI_EVENT_COMPILED_METHOD_LOAD, - JVMTI_EVENT_COMPILED_METHOD_UNLOAD -}; - -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static volatile int fire = 0; /* CompiledMethodLoad received for hotspot method */ -static jmethodID hsMethodID; /* hotspot method ID */ - -static volatile int enteredHotMethod = 0; /* "hot" method is entered */ - -static jint bytesCount; /* number of bytes of a redefining class */ -static jbyte *clsBytes; /* bytes defining a redefining class */ - -/** pass info about redefinition to Java **/ -JNIEXPORT jboolean JNICALL Java_nsk_jvmti_RedefineClasses_redefclass030_isRedefinitionOccurred - (JNIEnv *jni_env, jclass cls) -{ - if (fire == 1) { - NSK_DISPLAY0("isRedefinitionOccurred is called: fired!\n"); - return JNI_TRUE; - } else { - return JNI_FALSE; - } -} - -/** notify native agent from Java when "hot" method is executed **/ -JNIEXPORT void JNICALL Java_nsk_jvmti_RedefineClasses_redefclass030_notifyNativeAgent - (JNIEnv *jni_env, jclass cls) -{ - if (enteredHotMethod == 0) { - NSK_DISPLAY0("notifyNativeAgent is called\n"); - enteredHotMethod = 1; - } -} - -/** pass bytecode to native agent for redefinition **/ -JNIEXPORT void JNICALL Java_nsk_jvmti_RedefineClasses_redefclass030_storeClassBytes - (JNIEnv *jni_env, jclass cls, jbyteArray classBytes) { - jboolean isCopy; - - bytesCount = NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes); - clsBytes = - NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, &isCopy); -} - -/** callback functions **/ -void JNICALL -CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map, - const void* compile_info) { - char *name; - char *sig; - - NSK_DISPLAY0("CompiledMethodLoad event received for:\n"); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &name, &sig, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY5("\tmethod: name=\"%s\" signature=\"%s\"\n" - "\tcompiled code size=%d\n" - "\tstarting native address=0x%p\n" - "\tnumber of address location map entries=%d\n", - name, sig, code_size, code_addr, map_length); - - if ((strcmp(name, expHSMethod) == 0) && - (strcmp(sig, expHSSignature) == 0)) { - NSK_DISPLAY0("CompiledMethodLoad: a tested hotspot method found\n"); - - // CR 6604375: check whether "hot" method was entered - if (enteredHotMethod) { - hsMethodID = method; - fire = 1; - } else { - NSK_DISPLAY0("Compilation occured before method execution. Ignoring.\n"); - } - } -} - -JNIEXPORT void JNICALL -CompiledMethodUnload(jvmtiEnv* jvmti_env, jmethodID method, - const void* code_addr) { - char *name; - char *sig; - jvmtiError err; - - NSK_DISPLAY0("CompiledMethodUnload event received\n"); - // Check for the case that the class has been unloaded - err = (*jvmti_env)->GetMethodName(jvmti_env, method, &name, &sig, NULL); - if (err == JVMTI_ERROR_NONE) { - NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", - name, sig, code_addr); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); - } -} -/************************/ - -/** agent's procedure **/ -static void JNICALL -agentProc(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg) { - int tries = 0; - jclass decl_cls; - char *cls_sig; - jvmtiClassDefinition classDef; - - /* testing sync */ - NSK_DISPLAY1("agentProc: waiting for the debuggee start for %d msecs...\n\n", - (int) timeout); - if (!nsk_jvmti_waitForSync(timeout)) - return; - NSK_DISPLAY0("agentProc: resuming the debuggee ...\n\n"); - if (!nsk_jvmti_resumeSync()) - return; - - /* at first, send all generated CompiledMethodLoad events */ - NSK_DISPLAY0("agentProc: sending all generated CompiledMethodLoad events ...\n\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(GenerateEvents, jvmti, JVMTI_EVENT_COMPILED_METHOD_LOAD))) { - nsk_jvmti_setFailStatus(); - nsk_jvmti_resumeSync(); - return; - } - - NSK_DISPLAY0("agentProc: waiting for hotspot method compilation...\n\n"); - do { - THREAD_sleep(1); - tries++; - if (tries > MAX_ATTEMPTS) { - printf("WARNING: CompiledMethodLoad event is still not received for \"%s\" after %d attempts\n" - "\tThe test has no results\n\n", - expHSMethod, MAX_ATTEMPTS); - nsk_jvmti_resumeSync(); - exit(95 + PASSED); - } - } while(fire == 0); - - NSK_DISPLAY0("agentProc: hotspot method compiled\n\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, hsMethodID, &decl_cls))) { - nsk_jvmti_setFailStatus(); - nsk_jvmti_resumeSync(); - return; - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, - jvmti_env, decl_cls, &cls_sig, NULL))) { - nsk_jvmti_setFailStatus(); - nsk_jvmti_resumeSync(); - return; - } else { - NSK_DISPLAY1("agentProc: hotspot method class signature: \"%s\"\n\n", - cls_sig); - } - - /* fill the structure jvmtiClassDefinition */ - classDef.klass = decl_cls; - classDef.class_byte_count = bytesCount; - classDef.class_bytes = (unsigned char*) clsBytes; - - NSK_DISPLAY1("agentProc: >>>>>>>> Invoke RedefineClasses():\n" - "\tnew class byte count=%d\n", - classDef.class_byte_count); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, - jvmti, 1, &classDef))) { - nsk_jvmti_setFailStatus(); - nsk_jvmti_resumeSync(); - return; - } - NSK_DISPLAY0("agentProc: <<<<<<<< RedefineClasses() is successfully done\n"); - - /* testing sync */ - NSK_DISPLAY1("agentProc: waiting for the debuggee finish for %d msecs...\n\n", - (int) timeout); - if (!nsk_jvmti_waitForSync(timeout)) - return; - NSK_DISPLAY0("agentProc: final resuming of the debuggee ...\n\n"); - if (!nsk_jvmti_resumeSync()) - return; - - NSK_DISPLAY0("agentProc: finished\n\n"); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass030(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass030(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass030(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiCapabilities caps; - jvmtiEventCallbacks callbacks; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - /* obtain WAITTIME parameter */ - timeout = nsk_jvmti_getWaitTime() * 60000; - NSK_DISPLAY1("waittime=%d msecs\n", (int) timeout); - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* add required capabilities */ - memset(&caps, 0, sizeof(jvmtiCapabilities)); - caps.can_generate_compiled_method_load_events = 1; - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, - jvmti, &caps))) - return JNI_ERR; - - /* set event callback */ - NSK_DISPLAY0("setting event callbacks ...\n"); - (void) memset(&callbacks, 0, sizeof(callbacks)); - callbacks.CompiledMethodLoad = &CompiledMethodLoad; - callbacks.CompiledMethodUnload = &CompiledMethodUnload; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - NSK_DISPLAY0("setting event callbacks done\nenabling events ...\n"); - if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, - eventsList, NULL)) - return JNI_ERR; - NSK_DISPLAY0("enabling the events done\n\n"); - - /* register agent proc */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/redefclass030.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/redefclass030.cpp new file mode 100644 index 00000000000..7f72c4910c6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass030/redefclass030.cpp @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include + +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "native_thread.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define MAX_ATTEMPTS 15 + +static const char *expHSMethod = "redefclass030HotMethod"; +static const char *expHSSignature = "(I)V"; + +#define EVENTS_COUNT 2 +static jvmtiEvent eventsList[EVENTS_COUNT] = { + JVMTI_EVENT_COMPILED_METHOD_LOAD, + JVMTI_EVENT_COMPILED_METHOD_UNLOAD +}; + +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static volatile int fire = 0; /* CompiledMethodLoad received for hotspot method */ +static jmethodID hsMethodID; /* hotspot method ID */ + +static volatile int enteredHotMethod = 0; /* "hot" method is entered */ + +static jint bytesCount; /* number of bytes of a redefining class */ +static jbyte *clsBytes; /* bytes defining a redefining class */ + +/** pass info about redefinition to Java **/ +JNIEXPORT jboolean JNICALL Java_nsk_jvmti_RedefineClasses_redefclass030_isRedefinitionOccurred + (JNIEnv *jni_env, jclass cls) +{ + if (fire == 1) { + NSK_DISPLAY0("isRedefinitionOccurred is called: fired!\n"); + return JNI_TRUE; + } else { + return JNI_FALSE; + } +} + +/** notify native agent from Java when "hot" method is executed **/ +JNIEXPORT void JNICALL Java_nsk_jvmti_RedefineClasses_redefclass030_notifyNativeAgent + (JNIEnv *jni_env, jclass cls) +{ + if (enteredHotMethod == 0) { + NSK_DISPLAY0("notifyNativeAgent is called\n"); + enteredHotMethod = 1; + } +} + +/** pass bytecode to native agent for redefinition **/ +JNIEXPORT void JNICALL Java_nsk_jvmti_RedefineClasses_redefclass030_storeClassBytes + (JNIEnv *jni_env, jclass cls, jbyteArray classBytes) { + jboolean isCopy; + + bytesCount = NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes); + clsBytes = + NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, &isCopy); +} + +/** callback functions **/ +void JNICALL +CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map, + const void* compile_info) { + char *name; + char *sig; + + NSK_DISPLAY0("CompiledMethodLoad event received for:\n"); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &name, &sig, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY5("\tmethod: name=\"%s\" signature=\"%s\"\n" + "\tcompiled code size=%d\n" + "\tstarting native address=0x%p\n" + "\tnumber of address location map entries=%d\n", + name, sig, code_size, code_addr, map_length); + + if ((strcmp(name, expHSMethod) == 0) && + (strcmp(sig, expHSSignature) == 0)) { + NSK_DISPLAY0("CompiledMethodLoad: a tested hotspot method found\n"); + + // CR 6604375: check whether "hot" method was entered + if (enteredHotMethod) { + hsMethodID = method; + fire = 1; + } else { + NSK_DISPLAY0("Compilation occured before method execution. Ignoring.\n"); + } + } +} + +JNIEXPORT void JNICALL +CompiledMethodUnload(jvmtiEnv* jvmti_env, jmethodID method, + const void* code_addr) { + char *name; + char *sig; + jvmtiError err; + + NSK_DISPLAY0("CompiledMethodUnload event received\n"); + // Check for the case that the class has been unloaded + err = jvmti_env->GetMethodName(method, &name, &sig, NULL); + if (err == JVMTI_ERROR_NONE) { + NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", + name, sig, code_addr); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); + } +} +/************************/ + +/** agent's procedure **/ +static void JNICALL +agentProc(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg) { + int tries = 0; + jclass decl_cls; + char *cls_sig; + jvmtiClassDefinition classDef; + + /* testing sync */ + NSK_DISPLAY1("agentProc: waiting for the debuggee start for %d msecs...\n\n", + (int) timeout); + if (!nsk_jvmti_waitForSync(timeout)) + return; + NSK_DISPLAY0("agentProc: resuming the debuggee ...\n\n"); + if (!nsk_jvmti_resumeSync()) + return; + + /* at first, send all generated CompiledMethodLoad events */ + NSK_DISPLAY0("agentProc: sending all generated CompiledMethodLoad events ...\n\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(GenerateEvents, jvmti, JVMTI_EVENT_COMPILED_METHOD_LOAD))) { + nsk_jvmti_setFailStatus(); + nsk_jvmti_resumeSync(); + return; + } + + NSK_DISPLAY0("agentProc: waiting for hotspot method compilation...\n\n"); + do { + THREAD_sleep(1); + tries++; + if (tries > MAX_ATTEMPTS) { + printf("WARNING: CompiledMethodLoad event is still not received for \"%s\" after %d attempts\n" + "\tThe test has no results\n\n", + expHSMethod, MAX_ATTEMPTS); + nsk_jvmti_resumeSync(); + exit(95 + PASSED); + } + } while(fire == 0); + + NSK_DISPLAY0("agentProc: hotspot method compiled\n\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, hsMethodID, &decl_cls))) { + nsk_jvmti_setFailStatus(); + nsk_jvmti_resumeSync(); + return; + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, + jvmti_env, decl_cls, &cls_sig, NULL))) { + nsk_jvmti_setFailStatus(); + nsk_jvmti_resumeSync(); + return; + } else { + NSK_DISPLAY1("agentProc: hotspot method class signature: \"%s\"\n\n", + cls_sig); + } + + /* fill the structure jvmtiClassDefinition */ + classDef.klass = decl_cls; + classDef.class_byte_count = bytesCount; + classDef.class_bytes = (unsigned char*) clsBytes; + + NSK_DISPLAY1("agentProc: >>>>>>>> Invoke RedefineClasses():\n" + "\tnew class byte count=%d\n", + classDef.class_byte_count); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, + jvmti, 1, &classDef))) { + nsk_jvmti_setFailStatus(); + nsk_jvmti_resumeSync(); + return; + } + NSK_DISPLAY0("agentProc: <<<<<<<< RedefineClasses() is successfully done\n"); + + /* testing sync */ + NSK_DISPLAY1("agentProc: waiting for the debuggee finish for %d msecs...\n\n", + (int) timeout); + if (!nsk_jvmti_waitForSync(timeout)) + return; + NSK_DISPLAY0("agentProc: final resuming of the debuggee ...\n\n"); + if (!nsk_jvmti_resumeSync()) + return; + + NSK_DISPLAY0("agentProc: finished\n\n"); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass030(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass030(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass030(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiCapabilities caps; + jvmtiEventCallbacks callbacks; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + /* obtain WAITTIME parameter */ + timeout = nsk_jvmti_getWaitTime() * 60000; + NSK_DISPLAY1("waittime=%d msecs\n", (int) timeout); + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* add required capabilities */ + memset(&caps, 0, sizeof(jvmtiCapabilities)); + caps.can_generate_compiled_method_load_events = 1; + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, + jvmti, &caps))) + return JNI_ERR; + + /* set event callback */ + NSK_DISPLAY0("setting event callbacks ...\n"); + (void) memset(&callbacks, 0, sizeof(callbacks)); + callbacks.CompiledMethodLoad = &CompiledMethodLoad; + callbacks.CompiledMethodUnload = &CompiledMethodUnload; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + NSK_DISPLAY0("setting event callbacks done\nenabling events ...\n"); + if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, + eventsList, NULL)) + return JNI_ERR; + NSK_DISPLAY0("enabling the events done\n\n"); + + /* register agent proc */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/libredefclass031.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/libredefclass031.c deleted file mode 100644 index 6cb2ce338a6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/libredefclass031.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "redefclass031.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/libredefclass031.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/libredefclass031.cpp new file mode 100644 index 00000000000..57d53a7f576 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/libredefclass031.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "redefclass031.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/redefclass031.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/redefclass031.c deleted file mode 100644 index b4e89af88b2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/redefclass031.c +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static int watch_ev = 0; /* ignore JVMTI events by default */ -static int gen_ev = 0; /* number of generated events */ -static int result = PASSED; /* total result of the test */ - -static jrawMonitorID watch_ev_monitor; - -static void set_watch_ev(int value) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - watch_ev = value; - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -void JNICALL -NativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jmethodID methodID, void * pAddress, void ** pNewAddress) { - (*jvmti)->RawMonitorEnter(jvmti, watch_ev_monitor); - - if (watch_ev && isThreadExpected(jvmti_env, thr)) { - printf("#### JVMTI_EVENT_NATIVE_METHOD_BIND occured ####\n"); - gen_ev++; - } - - (*jvmti)->RawMonitorExit(jvmti, watch_ev_monitor); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_redefclass031(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_redefclass031(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_redefclass031(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), - JVMTI_VERSION_1_1)) != JNI_OK) { - printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - callbacks.NativeMethodBind = &NativeMethodBind; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "watch_ev_monitor", &watch_ev_monitor); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass031_makeRedefinition(JNIEnv *env, - jclass cls, jint vrb, jclass redefCls, jbyteArray classBytes) { - jvmtiError err; - jvmtiClassDefinition classDef; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_redefine_classes) { - return PASSED; - } - - if ((err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_NATIVE_METHOD_BIND, NULL)) != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_NATIVE_METHOD_BIND: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - -/* filling the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); - - set_watch_ev(1); /* watch JVMTI events */ - - if (vrb == 1) - printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", - classDef.class_byte_count); - if ((err = ((*jvmti)->RedefineClasses(jvmti, 1, &classDef))) != JVMTI_ERROR_NONE) { - printf("TEST FAILED: the function RedefineClasses() returned error %d: %s\n", - err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - result = STATUS_FAILED; - } - else if (vrb == 1) - printf("Check #1 PASSED: RedefineClasses() is successfully done\n"); - - set_watch_ev(0); /* again ignore JVMTI events */ - - if (gen_ev) { - printf("TEST FAILED: %d unexpected JVMTI events were generated by the function RedefineClasses()\n", - gen_ev); - result = STATUS_FAILED; - } else if (vrb == 1) - printf("Check #2 PASSED: No unexpected JVMTI events were generated by the function RedefineClasses()\n"); - - return(result); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_RedefineClasses_redefclass031r_nativeMethod(JNIEnv * pEnv, jclass klass) -{ - printf("redefclass031r::nativeMethod is called.\n"); -} - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/redefclass031.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/redefclass031.cpp new file mode 100644 index 00000000000..0b24f5b20c1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass031/redefclass031.cpp @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static int watch_ev = 0; /* ignore JVMTI events by default */ +static int gen_ev = 0; /* number of generated events */ +static int result = PASSED; /* total result of the test */ + +static jrawMonitorID watch_ev_monitor; + +static void set_watch_ev(int value) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + watch_ev = value; + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +void JNICALL +NativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jmethodID methodID, void * pAddress, void ** pNewAddress) { + jvmti->RawMonitorEnter(watch_ev_monitor); + + if (watch_ev && isThreadExpected(jvmti_env, thr)) { + printf("#### JVMTI_EVENT_NATIVE_METHOD_BIND occured ####\n"); + gen_ev++; + } + + jvmti->RawMonitorExit(watch_ev_monitor); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_redefclass031(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_redefclass031(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_redefclass031(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), + JVMTI_VERSION_1_1)) != JNI_OK) { + printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + callbacks.NativeMethodBind = &NativeMethodBind; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->CreateRawMonitor("watch_ev_monitor", &watch_ev_monitor); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass031_makeRedefinition(JNIEnv *env, + jclass cls, jint vrb, jclass redefCls, jbyteArray classBytes) { + jvmtiError err; + jvmtiClassDefinition classDef; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_redefine_classes) { + return PASSED; + } + + if ((err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_NATIVE_METHOD_BIND, NULL)) != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_NATIVE_METHOD_BIND: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + +/* filling the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), NULL); + + set_watch_ev(1); /* watch JVMTI events */ + + if (vrb == 1) + printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", + classDef.class_byte_count); + if ((err = (jvmti->RedefineClasses(1, &classDef))) != JVMTI_ERROR_NONE) { + printf("TEST FAILED: the function RedefineClasses() returned error %d: %s\n", + err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + result = STATUS_FAILED; + } + else if (vrb == 1) + printf("Check #1 PASSED: RedefineClasses() is successfully done\n"); + + set_watch_ev(0); /* again ignore JVMTI events */ + + if (gen_ev) { + printf("TEST FAILED: %d unexpected JVMTI events were generated by the function RedefineClasses()\n", + gen_ev); + result = STATUS_FAILED; + } else if (vrb == 1) + printf("Check #2 PASSED: No unexpected JVMTI events were generated by the function RedefineClasses()\n"); + + return(result); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_RedefineClasses_redefclass031r_nativeMethod(JNIEnv * pEnv, jclass klass) +{ + printf("redefclass031r::nativeMethod is called.\n"); +} + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/librelcaps001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/librelcaps001.c deleted file mode 100644 index 9ce455df48d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/librelcaps001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "relcaps001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/librelcaps001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/librelcaps001.cpp new file mode 100644 index 00000000000..ff7aa1045bb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/librelcaps001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "relcaps001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/relcaps001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/relcaps001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/relcaps001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps001/relcaps001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/librelcaps002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/librelcaps002.c deleted file mode 100644 index cfc17dadfd8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/librelcaps002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "relcaps002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/librelcaps002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/librelcaps002.cpp new file mode 100644 index 00000000000..bb4242f5919 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/librelcaps002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "relcaps002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/relcaps002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/relcaps002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/relcaps002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/RelinquishCapabilities/relcaps002/relcaps002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/libresexhausted.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/libresexhausted.c deleted file mode 100644 index bac7c1bdd99..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/libresexhausted.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "resexhausted.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/libresexhausted.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/libresexhausted.cpp new file mode 100644 index 00000000000..3b8ddcba44d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/libresexhausted.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "resexhausted.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/libresumethrd001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/libresumethrd001.c deleted file mode 100644 index ce0ccc46904..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/libresumethrd001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "resumethrd001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/libresumethrd001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/libresumethrd001.cpp new file mode 100644 index 00000000000..a87f9d64264 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/libresumethrd001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "resumethrd001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/resumethrd001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/resumethrd001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/resumethrd001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd001/resumethrd001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/libresumethrd002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/libresumethrd002.c deleted file mode 100644 index 82ec705b0d0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/libresumethrd002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "resumethrd002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/libresumethrd002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/libresumethrd002.cpp new file mode 100644 index 00000000000..a9a511c459d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/libresumethrd002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "resumethrd002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/resumethrd002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/resumethrd002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/resumethrd002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThread/resumethrd002/resumethrd002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/libresumethrdlst001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/libresumethrdlst001.c deleted file mode 100644 index 548ba58b157..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/libresumethrdlst001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "resumethrdlst001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/libresumethrdlst001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/libresumethrdlst001.cpp new file mode 100644 index 00000000000..0b6aad178b5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/libresumethrdlst001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "resumethrdlst001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/resumethrdlst001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/resumethrdlst001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/resumethrdlst001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst001/resumethrdlst001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/libresumethrdlst002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/libresumethrdlst002.c deleted file mode 100644 index 61191a14ac8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/libresumethrdlst002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "resumethrdlst002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/libresumethrdlst002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/libresumethrdlst002.cpp new file mode 100644 index 00000000000..496e15ebe33 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/libresumethrdlst002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "resumethrdlst002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/resumethrdlst002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/resumethrdlst002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/resumethrdlst002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResumeThreadList/resumethrdlst002/resumethrdlst002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/libretransform002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/libretransform002.c deleted file mode 100644 index 5ba85a4d31c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/libretransform002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "retransform002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/libretransform002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/libretransform002.cpp new file mode 100644 index 00000000000..93cbf7783eb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/libretransform002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "retransform002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/retransform002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/retransform002.c deleted file mode 100644 index b82cfbfb22b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/retransform002.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include -#include "agent_common.h" -#include -#include "JVMTITools.h" - -static jvmtiEnv *jvmti = NULL; - -/* ============================================================================= */ - -/* Used to explicitly initiate class retransformation process from Java code - * - * Parameters: - * jclass klass - class, which possess this native method - * (nsk.jvmti.RetransformClasses.retransform002) - * - * jclass class_for_retransformation - class, which should be retransformed */ -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_RetransformClasses_retransform002_forceLoadedClassesRetransformation( - JNIEnv *jni - , jclass klass - , jclass class_for_retransformation - ) -{ - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - RetransformClasses - , jvmti - , 1 - , &class_for_retransformation - ) - ) - ) - return JNI_FALSE; - - return JNI_TRUE; -} - - -/* ============================================================================= */ - -/* Dummy retransformation hook, which actually doesn't perform any modifications */ -static void JNICALL -ClassFileLoadHook ( - jvmtiEnv *jvmti - , JNIEnv *jni - , jclass class_being_redefined - , jobject loader - , const char* name - , jobject protection_domain - , jint class_data_len - , const unsigned char* class_data - , jint *new_class_data_len - , unsigned char** new_class_data - ) -{ -} - -/* ============================================================================= */ - -/* Agent initialization procedure */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_retransform002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_retransform002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_retransform002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) -{ - jvmtiEventCallbacks callbacks; - jvmtiCapabilities caps; - - if (!NSK_VERIFY( - nsk_jvmti_parseOptions(options) - ) - ) - return JNI_ERR; - - if (!NSK_VERIFY( - (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL - ) - ) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - GetCapabilities - , jvmti - , &caps) - ) - ) - return JNI_ERR; - - caps.can_retransform_classes = 1; - - // Register all necessary JVM capabilities - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - AddCapabilities - , jvmti - , &caps) - ) - ) - return JNI_ERR; - - // Register all necessary event callbacks - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - SetEventCallbacks - , jvmti - , &callbacks - , sizeof(callbacks) - ) - ) - ) - return JNI_ERR; - - // Enable class retransformation - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4( - SetEventNotificationMode - , jvmti - , JVMTI_ENABLE - , JVMTI_EVENT_CLASS_FILE_LOAD_HOOK - , NULL - ) - ) - ) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/retransform002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/retransform002.cpp new file mode 100644 index 00000000000..8fda5023c02 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform002/retransform002.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include +#include "agent_common.h" +#include +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jvmtiEnv *jvmti = NULL; + +/* ============================================================================= */ + +/* Used to explicitly initiate class retransformation process from Java code + * + * Parameters: + * jclass klass - class, which possess this native method + * (nsk.jvmti.RetransformClasses.retransform002) + * + * jclass class_for_retransformation - class, which should be retransformed */ +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_RetransformClasses_retransform002_forceLoadedClassesRetransformation( + JNIEnv *jni + , jclass klass + , jclass class_for_retransformation + ) +{ + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + RetransformClasses + , jvmti + , 1 + , &class_for_retransformation + ) + ) + ) + return JNI_FALSE; + + return JNI_TRUE; +} + + +/* ============================================================================= */ + +/* Dummy retransformation hook, which actually doesn't perform any modifications */ +static void JNICALL +ClassFileLoadHook ( + jvmtiEnv *jvmti + , JNIEnv *jni + , jclass class_being_redefined + , jobject loader + , const char* name + , jobject protection_domain + , jint class_data_len + , const unsigned char* class_data + , jint *new_class_data_len + , unsigned char** new_class_data + ) +{ +} + +/* ============================================================================= */ + +/* Agent initialization procedure */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_retransform002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_retransform002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_retransform002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) +{ + jvmtiEventCallbacks callbacks; + jvmtiCapabilities caps; + + if (!NSK_VERIFY( + nsk_jvmti_parseOptions(options) + ) + ) + return JNI_ERR; + + if (!NSK_VERIFY( + (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL + ) + ) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + GetCapabilities + , jvmti + , &caps) + ) + ) + return JNI_ERR; + + caps.can_retransform_classes = 1; + + // Register all necessary JVM capabilities + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + AddCapabilities + , jvmti + , &caps) + ) + ) + return JNI_ERR; + + // Register all necessary event callbacks + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + SetEventCallbacks + , jvmti + , &callbacks + , sizeof(callbacks) + ) + ) + ) + return JNI_ERR; + + // Enable class retransformation + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4( + SetEventNotificationMode + , jvmti + , JVMTI_ENABLE + , JVMTI_EVENT_CLASS_FILE_LOAD_HOOK + , NULL + ) + ) + ) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif + +/* ============================================================================= */ diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/libretransform003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/libretransform003.c deleted file mode 100644 index 61b7fffc715..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/libretransform003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "retransform003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/libretransform003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/libretransform003.cpp new file mode 100644 index 00000000000..ad9693b4e86 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/libretransform003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "retransform003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/retransform003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/retransform003.c deleted file mode 100644 index bd8dd1da254..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/retransform003.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include -#include "agent_common.h" -#include -#include "JVMTITools.h" - -/* ============================================================================= */ - -static jvmtiEnv *jvmti = NULL; - -/* Class, which contains the following callback method: - * static public void callback(String className, int agentID) */ -static char *CALLBACK_CLASS_NAME = "nsk.jvmti.RetransformClasses.retransform003"; - -/* Classes, belonging to the package defined in the TRIGGER variable will be retransformed */ -static char *TRIGGER = "nsk/share/jvmti/RetransformClasses"; // - -/* Agent identifier */ -static jint agent_id = -1; - - -/* ============================================================================= */ - -/* Used to explicitly initiate class retransformation process from Java code - * - * Parameters: - * jclass klass - class, which possess this native method - * (nsk.jvmti.RetransformClasses.retransform003) - * - * jclass class_for_retransformation - class, which should be retransformed - */ -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_RetransformClasses_retransform003_forceLoadedClassesRetransformation( - JNIEnv *jni - , jclass klass - , jclass class_for_retransformation - ) -{ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - RetransformClasses - , jvmti - , 1 - , &class_for_retransformation - ) - ) - ) - return JNI_FALSE; - - return JNI_TRUE; -} - - -/* ============================================================================= */ - -/* Class retransformation hook */ -static void JNICALL -ClassFileLoadHook ( - jvmtiEnv *jvmti - , JNIEnv *jni - , jclass class_being_redefined - , jobject loader - , const char* name - , jobject protection_domain - , jint class_data_len - , const unsigned char* class_data - , jint *new_class_data_len - , unsigned char** new_class_data - ) -{ - jclass loader_class; - jclass callback_class; - jmethodID method_id; - jstring class_name_string; - - // Check whether currently retransformed class belongs to the package we are interested in - if (name == NULL || strncmp(TRIGGER, name,strlen(name) < strlen(TRIGGER) ? strlen(name) : strlen(TRIGGER))) - { - return; - } - - // Get ant the invoke callback function - if (!NSK_VERIFY( - (loader_class = NSK_CPP_STUB2( - GetObjectClass - , jni - , loader - ) - ) != NULL - ) - ) - return; - - if (!NSK_VERIFY( - (method_id = NSK_CPP_STUB4( - GetMethodID - , jni - , loader_class - , "loadClass" - , "(Ljava/lang/String;)Ljava/lang/Class;" - ) - ) != NULL - ) - ) - return; - - if (!NSK_VERIFY( - (class_name_string = - NSK_CPP_STUB2( - NewStringUTF - , jni - , CALLBACK_CLASS_NAME - ) - ) != NULL - ) - ) - return; - - if (!NSK_VERIFY( - (callback_class = NSK_CPP_STUB4( - CallObjectMethod - , jni - , loader - , method_id - , class_name_string - ) - ) != NULL - ) - ) - return; - - if (!NSK_VERIFY( - (method_id = NSK_CPP_STUB4( - GetStaticMethodID - , jni - , callback_class - , "callback" - , "(Ljava/lang/String;I)V" - ) - ) != NULL - ) - ) - return; - - if (!NSK_VERIFY( - (class_name_string = - NSK_CPP_STUB2( - NewStringUTF - , jni - , name - ) - ) != NULL - ) - ) - return; - - NSK_CPP_STUB5( - CallStaticObjectMethod - , jni - , callback_class - , method_id - , class_name_string - , agent_id - ); -} - - -/* ============================================================================= */ - -/* Agent initialization procedure */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_retransform003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_retransform003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_retransform003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) -{ - jvmtiEventCallbacks callbacks; - jvmtiCapabilities caps; - - if (!NSK_VERIFY( - nsk_jvmti_parseOptions(options) - ) - ) - return JNI_ERR; - - agent_id= nsk_jvmti_findOptionIntValue("id", -1); - - if (!NSK_VERIFY( - (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL - ) - ) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - GetCapabilities - , jvmti - , &caps) - ) - ) - return JNI_ERR; - - if(nsk_jvmti_findOptionIntValue("can_retransform_classes", 1)) { - caps.can_retransform_classes = 1; - } else { - caps.can_retransform_classes = 0; - } - - - // Register all necessary JVM capabilities - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - AddCapabilities - , jvmti - , &caps) - ) - ) - return JNI_ERR; - - // Register all necessary event callbacks - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - SetEventCallbacks - , jvmti - , &callbacks - , sizeof(callbacks) - ) - ) - ) - return JNI_ERR; - - // Enable class retransformation - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4( - SetEventNotificationMode - , jvmti - , JVMTI_ENABLE - , JVMTI_EVENT_CLASS_FILE_LOAD_HOOK - , NULL - ) - ) - ) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/retransform003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/retransform003.cpp new file mode 100644 index 00000000000..dbdac9bad41 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform003/retransform003.cpp @@ -0,0 +1,291 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include +#include "agent_common.h" +#include +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jvmtiEnv *jvmti = NULL; + +/* Class, which contains the following callback method: + * static public void callback(String className, int agentID) */ +static const char *CALLBACK_CLASS_NAME = "nsk.jvmti.RetransformClasses.retransform003"; + +/* Classes, belonging to the package defined in the TRIGGER variable will be retransformed */ +static const char *TRIGGER = "nsk/share/jvmti/RetransformClasses"; // + +/* Agent identifier */ +static jint agent_id = -1; + + +/* ============================================================================= */ + +/* Used to explicitly initiate class retransformation process from Java code + * + * Parameters: + * jclass klass - class, which possess this native method + * (nsk.jvmti.RetransformClasses.retransform003) + * + * jclass class_for_retransformation - class, which should be retransformed + */ +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_RetransformClasses_retransform003_forceLoadedClassesRetransformation( + JNIEnv *jni + , jclass klass + , jclass class_for_retransformation + ) +{ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + RetransformClasses + , jvmti + , 1 + , &class_for_retransformation + ) + ) + ) + return JNI_FALSE; + + return JNI_TRUE; +} + + +/* ============================================================================= */ + +/* Class retransformation hook */ +static void JNICALL +ClassFileLoadHook ( + jvmtiEnv *jvmti + , JNIEnv *jni + , jclass class_being_redefined + , jobject loader + , const char* name + , jobject protection_domain + , jint class_data_len + , const unsigned char* class_data + , jint *new_class_data_len + , unsigned char** new_class_data + ) +{ + jclass loader_class; + jclass callback_class; + jmethodID method_id; + jstring class_name_string; + + // Check whether currently retransformed class belongs to the package we are interested in + if (name == NULL || strncmp(TRIGGER, name,strlen(name) < strlen(TRIGGER) ? strlen(name) : strlen(TRIGGER))) + { + return; + } + + // Get ant the invoke callback function + if (!NSK_VERIFY( + (loader_class = NSK_CPP_STUB2( + GetObjectClass + , jni + , loader + ) + ) != NULL + ) + ) + return; + + if (!NSK_VERIFY( + (method_id = NSK_CPP_STUB4( + GetMethodID + , jni + , loader_class + , "loadClass" + , "(Ljava/lang/String;)Ljava/lang/Class;" + ) + ) != NULL + ) + ) + return; + + if (!NSK_VERIFY( + (class_name_string = + NSK_CPP_STUB2( + NewStringUTF + , jni + , CALLBACK_CLASS_NAME + ) + ) != NULL + ) + ) + return; + + if (!NSK_VERIFY( + (callback_class = (jclass) NSK_CPP_STUB4( + CallObjectMethod + , jni + , loader + , method_id + , class_name_string + ) + ) != NULL + ) + ) + return; + + if (!NSK_VERIFY( + (method_id = NSK_CPP_STUB4( + GetStaticMethodID + , jni + , callback_class + , "callback" + , "(Ljava/lang/String;I)V" + ) + ) != NULL + ) + ) + return; + + if (!NSK_VERIFY( + (class_name_string = + NSK_CPP_STUB2( + NewStringUTF + , jni + , name + ) + ) != NULL + ) + ) + return; + + NSK_CPP_STUB5( + CallStaticObjectMethod + , jni + , callback_class + , method_id + , class_name_string + , agent_id + ); +} + + +/* ============================================================================= */ + +/* Agent initialization procedure */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_retransform003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_retransform003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_retransform003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) +{ + jvmtiEventCallbacks callbacks; + jvmtiCapabilities caps; + + if (!NSK_VERIFY( + nsk_jvmti_parseOptions(options) + ) + ) + return JNI_ERR; + + agent_id= nsk_jvmti_findOptionIntValue("id", -1); + + if (!NSK_VERIFY( + (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL + ) + ) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + GetCapabilities + , jvmti + , &caps) + ) + ) + return JNI_ERR; + + if(nsk_jvmti_findOptionIntValue("can_retransform_classes", 1)) { + caps.can_retransform_classes = 1; + } else { + caps.can_retransform_classes = 0; + } + + + // Register all necessary JVM capabilities + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + AddCapabilities + , jvmti + , &caps) + ) + ) + return JNI_ERR; + + // Register all necessary event callbacks + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + SetEventCallbacks + , jvmti + , &callbacks + , sizeof(callbacks) + ) + ) + ) + return JNI_ERR; + + // Enable class retransformation + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4( + SetEventNotificationMode + , jvmti + , JVMTI_ENABLE + , JVMTI_EVENT_CLASS_FILE_LOAD_HOOK + , NULL + ) + ) + ) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif + +/* ============================================================================= */ diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/libretransform004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/libretransform004.c deleted file mode 100644 index 858b96f2636..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/libretransform004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "retransform004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/libretransform004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/libretransform004.cpp new file mode 100644 index 00000000000..a6143372af6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/libretransform004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "retransform004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/retransform004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/retransform004.c deleted file mode 100644 index 32d0c0362ca..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/retransform004.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include -#include "agent_common.h" -#include -#include "JVMTITools.h" - -/* ============================================================================= */ - -static jvmtiEnv *jvmti = NULL; - -/* ============================================================================= */ - -/* Used to explicitly initiate class retransformation process from Java code - * - * Parameters: - * jclass klass - class, which possess this native method - * (nsk.jvmti.RetransformClasses.retransform004) - * - * jclass class_for_retransformation - class, which should be retransformed - */ -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_RetransformClasses_retransform004_forceLoadedClassesRetransformation( - JNIEnv *jni - , jclass klass - , jclass class_for_retransformation - ) -{ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - RetransformClasses - , jvmti - , 1 - , &class_for_retransformation - ) - ) - ) - return JNI_FALSE; - - return JNI_TRUE; -} - - -/* ============================================================================= */ - -/* Class retransformation hook */ -static void JNICALL -ClassFileLoadHook ( - jvmtiEnv *jvmti - , JNIEnv *jni - , jclass class_being_redefined - , jobject loader - , const char* name - , jobject protection_domain - , jint class_data_len - , const unsigned char* class_data - , jint *new_class_data_len - , unsigned char** new_class_data - ) -{ - // Allocate space for "retransformed" class version - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - Allocate - , jvmti - , class_data_len - , new_class_data - ) - ) - ) - return; - - // Copy old code - memcpy(*new_class_data, class_data, class_data_len); - *new_class_data_len = class_data_len; -} - - -/* ============================================================================= */ - -/* Agent initialization procedure */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_retransform004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_retransform004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_retransform004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) -{ - jvmtiEventCallbacks callbacks; - jvmtiCapabilities caps; - - if (!NSK_VERIFY( - (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL - ) - ) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - GetCapabilities - , jvmti - , &caps) - ) - ) - return JNI_ERR; - - caps.can_retransform_classes = 1; - - // Register all necessary JVM capabilities - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - AddCapabilities - , jvmti - , &caps) - ) - ) - return JNI_ERR; - - // Register all necessary event callbacks - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - SetEventCallbacks - , jvmti - , &callbacks - , sizeof(callbacks) - ) - ) - ) - return JNI_ERR; - - // Enable class retransformation - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4( - SetEventNotificationMode - , jvmti - , JVMTI_ENABLE - , JVMTI_EVENT_CLASS_FILE_LOAD_HOOK - , NULL - ) - ) - ) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/retransform004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/retransform004.cpp new file mode 100644 index 00000000000..46403639bd8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RetransformClasses/retransform004/retransform004.cpp @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include +#include "agent_common.h" +#include +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jvmtiEnv *jvmti = NULL; + +/* ============================================================================= */ + +/* Used to explicitly initiate class retransformation process from Java code + * + * Parameters: + * jclass klass - class, which possess this native method + * (nsk.jvmti.RetransformClasses.retransform004) + * + * jclass class_for_retransformation - class, which should be retransformed + */ +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_RetransformClasses_retransform004_forceLoadedClassesRetransformation( + JNIEnv *jni + , jclass klass + , jclass class_for_retransformation + ) +{ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + RetransformClasses + , jvmti + , 1 + , &class_for_retransformation + ) + ) + ) + return JNI_FALSE; + + return JNI_TRUE; +} + + +/* ============================================================================= */ + +/* Class retransformation hook */ +static void JNICALL +ClassFileLoadHook ( + jvmtiEnv *jvmti + , JNIEnv *jni + , jclass class_being_redefined + , jobject loader + , const char* name + , jobject protection_domain + , jint class_data_len + , const unsigned char* class_data + , jint *new_class_data_len + , unsigned char** new_class_data + ) +{ + // Allocate space for "retransformed" class version + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + Allocate + , jvmti + , class_data_len + , new_class_data + ) + ) + ) + return; + + // Copy old code + memcpy(*new_class_data, class_data, class_data_len); + *new_class_data_len = class_data_len; +} + + +/* ============================================================================= */ + +/* Agent initialization procedure */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_retransform004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_retransform004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_retransform004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) +{ + jvmtiEventCallbacks callbacks; + jvmtiCapabilities caps; + + if (!NSK_VERIFY( + (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL + ) + ) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + GetCapabilities + , jvmti + , &caps) + ) + ) + return JNI_ERR; + + caps.can_retransform_classes = 1; + + // Register all necessary JVM capabilities + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + AddCapabilities + , jvmti + , &caps) + ) + ) + return JNI_ERR; + + // Register all necessary event callbacks + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + SetEventCallbacks + , jvmti + , &callbacks + , sizeof(callbacks) + ) + ) + ) + return JNI_ERR; + + // Enable class retransformation + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4( + SetEventNotificationMode + , jvmti + , JVMTI_ENABLE + , JVMTI_EVENT_CLASS_FILE_LOAD_HOOK + , NULL + ) + ) + ) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif + +/* ============================================================================= */ diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/agentthr001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/agentthr001.c deleted file mode 100644 index 462e27777fc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/agentthr001.c +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define WAIT_TIME (jlong)100 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int eventsCount = 0; -static int count = 0; -static jrawMonitorID cpu_lock; -static int thr1_was_started = 0; - -jthread jthr(JNIEnv *env) { - jclass thrClass; - jmethodID cid; - jthread res; - - thrClass = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, "java/lang/Thread")); - cid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, thrClass), "", "()V"); - res = JNI_ENV_PTR(env)->NewObject(JNI_ENV_ARG(env, thrClass), cid); - return res; -} - -static void JNICALL -sys_thread_4(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { - jvmtiError err; - - err = (*jvmti)->RawMonitorEnter(jvmti, cpu_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#4) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - count |= 0x10; - err = (*jvmti)->RawMonitorWait(jvmti, cpu_lock, WAIT_TIME); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait#4) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - count |= 0x20; - err = (*jvmti)->RawMonitorExit(jvmti, cpu_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#4) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -static void JNICALL -sys_thread_1(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { - jvmtiError err; - - err = (*jvmti)->RawMonitorEnter(jvmti, cpu_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - count |= 0x01; - - err = (*jvmti)->RunAgentThread(jvmti, jthr(jni), sys_thread_4, NULL, - JVMTI_THREAD_MAX_PRIORITY); - if (err != JVMTI_ERROR_NONE) { - printf("(RunAgentThread#4) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - count |= 0x02; - err = (*jvmti)->RawMonitorExit(jvmti, cpu_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -static void JNICALL -sys_thread_2(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { - jvmtiError err; - - err = (*jvmti)->RawMonitorEnter(jvmti, cpu_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#2) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - count |= 0x04; - err = (*jvmti)->RawMonitorWait(jvmti, cpu_lock, WAIT_TIME); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait#2) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - count |= 0x08; - err = (*jvmti)->RawMonitorExit(jvmti, cpu_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#2) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -static void JNICALL -sys_thread_3(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { - while (1) { - } -} - -static void JNICALL -sys_thread_5(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { - jvmtiError err; - - err = (*jvmti)->RawMonitorEnter(jvmti, cpu_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter#5) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - count |= 0x40; - err = (*jvmti)->RawMonitorWait(jvmti, cpu_lock, WAIT_TIME); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait#5) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - count |= 0x80; - err = (*jvmti)->RawMonitorExit(jvmti, cpu_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit#5) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - jvmtiError err; - - if (printdump == JNI_TRUE) { - printf(">>> VMInit: enabling ThreadStart\n"); - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_THREAD_START, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_THREAD_START: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL -ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - jvmtiError err; - jvmtiThreadInfo thrInfo; - - eventsCount++; - err = (*jvmti_env)->GetThreadInfo(jvmti_env, thread, &thrInfo); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo#%d) unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> ThreadStart: %s\n", thrInfo.name); - } - /* workaround to avoid bug: - * 4334503 THREAD_START event is still sent twice for user-defined thread */ - if (strcmp(thrInfo.name, "thr1") == 0 && !thr1_was_started) { - thr1_was_started = 1; - err = (*jvmti_env)->RunAgentThread(jvmti_env, jthr((JNIEnv *)env), - sys_thread_1, NULL, JVMTI_THREAD_MAX_PRIORITY); - if (err != JVMTI_ERROR_NONE) { - printf("(RunAgentThread#1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->RunAgentThread(jvmti_env, jthr((JNIEnv *)env), - sys_thread_2, NULL, JVMTI_THREAD_NORM_PRIORITY); - if (err != JVMTI_ERROR_NONE) { - printf("(RunAgentThread#2) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->RunAgentThread(jvmti_env, jthr((JNIEnv *)env), - sys_thread_3, NULL, JVMTI_THREAD_MIN_PRIORITY); - if (err != JVMTI_ERROR_NONE) { - printf("(RunAgentThread#3) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_agentthr001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_agentthr001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_agentthr001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "_CPU lock", &cpu_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - callbacks.ThreadStart = &ThreadStart; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_RunAgentThread_agentthr001_startSysThr(JNIEnv *env, jclass cls) { - jvmtiError err; - - err = (*jvmti)->RunAgentThread(jvmti, jthr(env), sys_thread_5, NULL, - JVMTI_THREAD_MAX_PRIORITY); - if (err != JVMTI_ERROR_NONE) { - printf("(RunAgentThread#5) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_RunAgentThread_agentthr001_isOver(JNIEnv *env, jclass cls) { - return (count == 0xFF ? JNI_TRUE : JNI_FALSE); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RunAgentThread_agentthr001_getRes(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (printdump == JNI_TRUE) { - printf(">>> getRes: disabling ThreadStart\n"); - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_THREAD_START, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_THREAD_START: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (count != 0xFF) { - printf("Some of the threads have not started (0x%x) !\n", count); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> total of thread start events: %d\n", eventsCount); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/agentthr001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/agentthr001.cpp new file mode 100644 index 00000000000..59126fe4a45 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/agentthr001.cpp @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define WAIT_TIME (jlong)100 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int eventsCount = 0; +static int count = 0; +static jrawMonitorID cpu_lock; +static int thr1_was_started = 0; + +jthread jthr(JNIEnv *env) { + jclass thrClass; + jmethodID cid; + jthread res; + + thrClass = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, "java/lang/Thread")); + cid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, thrClass), "", "()V"); + res = JNI_ENV_PTR(env)->NewObject(JNI_ENV_ARG(env, thrClass), cid); + return res; +} + +static void JNICALL +sys_thread_4(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { + jvmtiError err; + + err = jvmti->RawMonitorEnter(cpu_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#4) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + count |= 0x10; + err = jvmti->RawMonitorWait(cpu_lock, WAIT_TIME); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait#4) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + count |= 0x20; + err = jvmti->RawMonitorExit(cpu_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#4) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +static void JNICALL +sys_thread_1(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { + jvmtiError err; + + err = jvmti->RawMonitorEnter(cpu_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + count |= 0x01; + + err = jvmti->RunAgentThread(jthr(jni), sys_thread_4, NULL, + JVMTI_THREAD_MAX_PRIORITY); + if (err != JVMTI_ERROR_NONE) { + printf("(RunAgentThread#4) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + count |= 0x02; + err = jvmti->RawMonitorExit(cpu_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +static void JNICALL +sys_thread_2(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { + jvmtiError err; + + err = jvmti->RawMonitorEnter(cpu_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#2) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + count |= 0x04; + err = jvmti->RawMonitorWait(cpu_lock, WAIT_TIME); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait#2) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + count |= 0x08; + err = jvmti->RawMonitorExit(cpu_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#2) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +static void JNICALL +sys_thread_3(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { + while (1) { + } +} + +static void JNICALL +sys_thread_5(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { + jvmtiError err; + + err = jvmti->RawMonitorEnter(cpu_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter#5) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + count |= 0x40; + err = jvmti->RawMonitorWait(cpu_lock, WAIT_TIME); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait#5) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + count |= 0x80; + err = jvmti->RawMonitorExit(cpu_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit#5) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + jvmtiError err; + + if (printdump == JNI_TRUE) { + printf(">>> VMInit: enabling ThreadStart\n"); + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_THREAD_START, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_THREAD_START: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL +ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + jvmtiError err; + jvmtiThreadInfo thrInfo; + + eventsCount++; + err = jvmti_env->GetThreadInfo(thread, &thrInfo); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo#%d) unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> ThreadStart: %s\n", thrInfo.name); + } + /* workaround to avoid bug: + * 4334503 THREAD_START event is still sent twice for user-defined thread */ + if (strcmp(thrInfo.name, "thr1") == 0 && !thr1_was_started) { + thr1_was_started = 1; + err = jvmti_env->RunAgentThread(jthr((JNIEnv *)env), + sys_thread_1, NULL, JVMTI_THREAD_MAX_PRIORITY); + if (err != JVMTI_ERROR_NONE) { + printf("(RunAgentThread#1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->RunAgentThread(jthr((JNIEnv *)env), + sys_thread_2, NULL, JVMTI_THREAD_NORM_PRIORITY); + if (err != JVMTI_ERROR_NONE) { + printf("(RunAgentThread#2) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->RunAgentThread(jthr((JNIEnv *)env), + sys_thread_3, NULL, JVMTI_THREAD_MIN_PRIORITY); + if (err != JVMTI_ERROR_NONE) { + printf("(RunAgentThread#3) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_agentthr001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_agentthr001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_agentthr001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->CreateRawMonitor("_CPU lock", &cpu_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + callbacks.ThreadStart = &ThreadStart; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_RunAgentThread_agentthr001_startSysThr(JNIEnv *env, jclass cls) { + jvmtiError err; + + err = jvmti->RunAgentThread(jthr(env), sys_thread_5, NULL, + JVMTI_THREAD_MAX_PRIORITY); + if (err != JVMTI_ERROR_NONE) { + printf("(RunAgentThread#5) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_RunAgentThread_agentthr001_isOver(JNIEnv *env, jclass cls) { + return (count == 0xFF ? JNI_TRUE : JNI_FALSE); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RunAgentThread_agentthr001_getRes(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (printdump == JNI_TRUE) { + printf(">>> getRes: disabling ThreadStart\n"); + } + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_THREAD_START, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_THREAD_START: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (count != 0xFF) { + printf("Some of the threads have not started (0x%x) !\n", count); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> total of thread start events: %d\n", eventsCount); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/libagentthr001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/libagentthr001.c deleted file mode 100644 index 765b41aed04..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/libagentthr001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "agentthr001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/libagentthr001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/libagentthr001.cpp new file mode 100644 index 00000000000..943a09acd07 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/libagentthr001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "agentthr001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/agentthr002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/agentthr002.c deleted file mode 100644 index eabf899f56b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/agentthr002.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jrawMonitorID wait_lock; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_agentthr002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_agentthr002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_agentthr002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -static void JNICALL -debug_thread(jvmtiEnv* jvmti, JNIEnv* jni, void *unused) { - jvmtiError err; - - err = (*jvmti)->RawMonitorEnter(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorWait(jvmti, wait_lock, (jlong)0); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorExit(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RunAgentThread_agentthr002_check(JNIEnv *env, jclass cls, jthread thr) { - jvmtiError err; - jvmtiThreadInfo inf; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "_wait_lock", &wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> starting debug thread ...\n"); - } - err = (*jvmti)->RunAgentThread(jvmti, thr, debug_thread, NULL, - JVMTI_THREAD_NORM_PRIORITY); - if (err != JVMTI_ERROR_NONE) { - printf("(RunAgentThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> getting info about it ...\n"); - } - err = (*jvmti)->GetThreadInfo(jvmti, thr, &inf); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (inf.is_daemon != JNI_TRUE) { - printf("ERROR: thread is not a daemon thread!\n"); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorEnter(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorNotify(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorNotify) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorExit(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> done ...\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/agentthr002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/agentthr002.cpp new file mode 100644 index 00000000000..1654a1ec459 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/agentthr002.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jrawMonitorID wait_lock; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_agentthr002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_agentthr002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_agentthr002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +static void JNICALL +debug_thread(jvmtiEnv* jvmti, JNIEnv* jni, void *unused) { + jvmtiError err; + + err = jvmti->RawMonitorEnter(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorWait(wait_lock, (jlong)0); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorExit(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RunAgentThread_agentthr002_check(JNIEnv *env, jclass cls, jthread thr) { + jvmtiError err; + jvmtiThreadInfo inf; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->CreateRawMonitor("_wait_lock", &wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> starting debug thread ...\n"); + } + err = jvmti->RunAgentThread(thr, debug_thread, NULL, + JVMTI_THREAD_NORM_PRIORITY); + if (err != JVMTI_ERROR_NONE) { + printf("(RunAgentThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> getting info about it ...\n"); + } + err = jvmti->GetThreadInfo(thr, &inf); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (inf.is_daemon != JNI_TRUE) { + printf("ERROR: thread is not a daemon thread!\n"); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorEnter(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorNotify(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorNotify) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorExit(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> done ...\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/libagentthr002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/libagentthr002.c deleted file mode 100644 index 17306e01e02..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/libagentthr002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "agentthr002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/libagentthr002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/libagentthr002.cpp new file mode 100644 index 00000000000..98a1a892d57 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr002/libagentthr002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "agentthr002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/agentthr003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/agentthr003.c deleted file mode 100644 index ad3feeb5dd0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/agentthr003.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_agentthr003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_agentthr003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_agentthr003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -static void JNICALL -agent_thread(jvmtiEnv* jvmti, JNIEnv* jni, void *unused) { - if (printdump == JNI_TRUE) { - printf(">>> agent thread started ...\n"); - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_RunAgentThread_agentthr003_check(JNIEnv *env, jclass cls, jthread thr) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid thread check ...\n"); - } - err = (*jvmti)->RunAgentThread(jvmti, NULL, agent_thread, NULL, - JVMTI_THREAD_NORM_PRIORITY); - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->RunAgentThread(jvmti, thr, NULL, NULL, - JVMTI_THREAD_NORM_PRIORITY); - if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> less than JVMTI_THREAD_MIN_PRIORITY check ...\n"); - } - err = (*jvmti)->RunAgentThread(jvmti, thr, agent_thread, NULL, - JVMTI_THREAD_MIN_PRIORITY - 1); - if (err != JVMTI_ERROR_INVALID_PRIORITY) { - printf("Error expected: JVMTI_ERROR_INVALID_PRIORITY,\n"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> greater than JVMTI_THREAD_MAX_PRIORITY check ...\n"); - } - err = (*jvmti)->RunAgentThread(jvmti, thr, agent_thread, NULL, - JVMTI_THREAD_MAX_PRIORITY + 1); - if (err != JVMTI_ERROR_INVALID_PRIORITY) { - printf("Error expected: JVMTI_ERROR_INVALID_PRIORITY,\n"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/agentthr003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/agentthr003.cpp new file mode 100644 index 00000000000..6e92a02d6f4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/agentthr003.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_agentthr003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_agentthr003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_agentthr003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +static void JNICALL +agent_thread(jvmtiEnv* jvmti, JNIEnv* jni, void *unused) { + if (printdump == JNI_TRUE) { + printf(">>> agent thread started ...\n"); + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_RunAgentThread_agentthr003_check(JNIEnv *env, jclass cls, jthread thr) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid thread check ...\n"); + } + err = jvmti->RunAgentThread(NULL, agent_thread, NULL, + JVMTI_THREAD_NORM_PRIORITY); + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->RunAgentThread(thr, NULL, NULL, + JVMTI_THREAD_NORM_PRIORITY); + if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> less than JVMTI_THREAD_MIN_PRIORITY check ...\n"); + } + err = jvmti->RunAgentThread(thr, agent_thread, NULL, + JVMTI_THREAD_MIN_PRIORITY - 1); + if (err != JVMTI_ERROR_INVALID_PRIORITY) { + printf("Error expected: JVMTI_ERROR_INVALID_PRIORITY,\n"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> greater than JVMTI_THREAD_MAX_PRIORITY check ...\n"); + } + err = jvmti->RunAgentThread(thr, agent_thread, NULL, + JVMTI_THREAD_MAX_PRIORITY + 1); + if (err != JVMTI_ERROR_INVALID_PRIORITY) { + printf("Error expected: JVMTI_ERROR_INVALID_PRIORITY,\n"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/libagentthr003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/libagentthr003.c deleted file mode 100644 index ce44cabe4b7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/libagentthr003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "agentthr003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/libagentthr003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/libagentthr003.cpp new file mode 100644 index 00000000000..241b48c83e8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/RunAgentThread/agentthr003/libagentthr003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "agentthr003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/libsetbrk002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/libsetbrk002.c deleted file mode 100644 index 7f3053c19c1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/libsetbrk002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setbrk002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/libsetbrk002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/libsetbrk002.cpp new file mode 100644 index 00000000000..0520f9ba4da --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/libsetbrk002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setbrk002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/setbrk002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/setbrk002.c deleted file mode 100644 index a8851e96730..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/setbrk002.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setbrk002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setbrk002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setbrk002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_generate_breakpoint_events) { - printf("Warning: Breakpoint is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetBreakpoint_setbrk002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - jlocation start; - jlocation end; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_generate_breakpoint_events) { - return result; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I"); - if (mid == NULL) { - printf("Cannot find method run\n"); - return STATUS_FAILED; - } - - err=(*jvmti)->GetMethodLocation(jvmti, mid, &start, &end); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> location less then starting location check ...\n"); - } - err = (*jvmti)->SetBreakpoint(jvmti, mid, start - 1); - if (err != JVMTI_ERROR_INVALID_LOCATION) { - printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> location greater then ending location check ...\n"); - } - err = (*jvmti)->SetBreakpoint(jvmti, mid, end + 1); - if (err != JVMTI_ERROR_INVALID_LOCATION) { - printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/setbrk002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/setbrk002.cpp new file mode 100644 index 00000000000..3a867cd0e9a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk002/setbrk002.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setbrk002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setbrk002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setbrk002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_generate_breakpoint_events) { + printf("Warning: Breakpoint is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetBreakpoint_setbrk002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + jlocation start; + jlocation end; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_generate_breakpoint_events) { + return result; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I"); + if (mid == NULL) { + printf("Cannot find method run\n"); + return STATUS_FAILED; + } + + err=jvmti->GetMethodLocation(mid, &start, &end); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> location less then starting location check ...\n"); + } + err = jvmti->SetBreakpoint(mid, start - 1); + if (err != JVMTI_ERROR_INVALID_LOCATION) { + printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> location greater then ending location check ...\n"); + } + err = jvmti->SetBreakpoint(mid, end + 1); + if (err != JVMTI_ERROR_INVALID_LOCATION) { + printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/libsetbrk003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/libsetbrk003.c deleted file mode 100644 index aaf38862d8a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/libsetbrk003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setbrk003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/libsetbrk003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/libsetbrk003.cpp new file mode 100644 index 00000000000..38c3b6593cd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/libsetbrk003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setbrk003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/setbrk003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/setbrk003.c deleted file mode 100644 index 688e92de39b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/setbrk003.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setbrk003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setbrk003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setbrk003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_generate_breakpoint_events) { - printf("Warning: Breakpoint is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetBreakpoint_setbrk003_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_generate_breakpoint_events) { - return result; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "check", "()I"); - if (mid == NULL) { - printf("Cannot find method check\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> native method check ...\n"); - } - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_INVALID_LOCATION) { - printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/setbrk003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/setbrk003.cpp new file mode 100644 index 00000000000..f75d0df6a05 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk003/setbrk003.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setbrk003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setbrk003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setbrk003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_generate_breakpoint_events) { + printf("Warning: Breakpoint is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetBreakpoint_setbrk003_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_generate_breakpoint_events) { + return result; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "check", "()I"); + if (mid == NULL) { + printf("Cannot find method check\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> native method check ...\n"); + } + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_INVALID_LOCATION) { + printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/libsetbrk005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/libsetbrk005.c deleted file mode 100644 index 118259e422a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/libsetbrk005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setbrk005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/libsetbrk005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/libsetbrk005.cpp new file mode 100644 index 00000000000..e81a6244ca2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/libsetbrk005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setbrk005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/setbrk005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/setbrk005.c deleted file mode 100644 index 9d3d84c6cd0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/setbrk005.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setbrk005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setbrk005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setbrk005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_generate_breakpoint_events) { - printf("Warning: Breakpoint is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetBreakpoint_setbrk005_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_generate_breakpoint_events) { - return result; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "trial", "()I"); - if (mid == NULL) { - printf("Cannot find method trial\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> duplicate breakpoint check ...\n"); - } - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_DUPLICATE) { - printf("Error expected: JVMTI_ERROR_DUPLICATE,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/setbrk005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/setbrk005.cpp new file mode 100644 index 00000000000..b414b24212e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk005/setbrk005.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setbrk005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setbrk005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setbrk005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_generate_breakpoint_events) { + printf("Warning: Breakpoint is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetBreakpoint_setbrk005_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_generate_breakpoint_events) { + return result; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "trial", "()I"); + if (mid == NULL) { + printf("Cannot find method trial\n"); + return STATUS_FAILED; + } + + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> duplicate breakpoint check ...\n"); + } + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_DUPLICATE) { + printf("Error expected: JVMTI_ERROR_DUPLICATE,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/libsetbrk007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/libsetbrk007.c deleted file mode 100644 index c2146b0cc81..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/libsetbrk007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setbrk007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/libsetbrk007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/libsetbrk007.cpp new file mode 100644 index 00000000000..c62b5b189da --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/libsetbrk007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setbrk007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/setbrk007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/setbrk007.c deleted file mode 100644 index 83a8565a915..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/setbrk007.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setbrk007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setbrk007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setbrk007(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_generate_breakpoint_events) { - printf("Warning: Breakpoint is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetBreakpoint_setbrk007_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_generate_breakpoint_events) { - return result; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (mid == 0) { - printf("Cannot find Method ID for method checkPoint\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid method check ...\n"); - } - err = (*jvmti)->SetBreakpoint(jvmti, NULL, 0); - if (err != JVMTI_ERROR_INVALID_METHODID) { - printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); - printf("\tactual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/setbrk007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/setbrk007.cpp new file mode 100644 index 00000000000..4a15b8cdb23 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk007/setbrk007.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setbrk007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setbrk007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setbrk007(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_generate_breakpoint_events) { + printf("Warning: Breakpoint is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetBreakpoint_setbrk007_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_generate_breakpoint_events) { + return result; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (mid == 0) { + printf("Cannot find Method ID for method checkPoint\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid method check ...\n"); + } + err = jvmti->SetBreakpoint(NULL, 0); + if (err != JVMTI_ERROR_INVALID_METHODID) { + printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n"); + printf("\tactual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/libsetbrk008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/libsetbrk008.c deleted file mode 100644 index d9cee2bb14b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/libsetbrk008.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setbrk008.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/libsetbrk008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/libsetbrk008.cpp new file mode 100644 index 00000000000..b98f6cccf81 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/libsetbrk008.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setbrk008.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/setbrk008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/setbrk008.c deleted file mode 100644 index fad37cb2952..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/setbrk008.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int eventsCount = 0; -static int eventsExpected = 0; -static const char *exp_csig = "Lnsk/jvmti/SetBreakpoint/setbrk008;"; -static const char *exp_name = "checkPoint"; -static const char *exp_sig = "(I)V"; - - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation loc) { - jvmtiError err; - jclass cls; - char *cls_sig, *name, *sig, *generic; - - eventsCount++; - if (printdump == JNI_TRUE && eventsCount == 1) { - printf(">>> retrieving bp event info ...\n"); - } - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &cls_sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->GetMethodName(jvmti, method, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE && eventsCount == 1) { - printf(">>> class: \"%s\"\n", cls_sig); - printf(">>> method: \"%s%s\"\n", name, sig); - printf(">>> location: 0x%x%08x\n", (jint)(loc >> 32), (jint)loc); - } - if (name == NULL || strcmp(cls_sig, exp_csig) != 0) { - printf("(bp#%d) wrong class: \"%s\"", eventsCount, cls_sig); - printf(", expected: \"%s\"\n", exp_csig); - result = STATUS_FAILED; - } - if (name == NULL || strcmp(name, exp_name) != 0) { - printf("(bp#%d) wrong method name: \"%s\"", eventsCount, name); - printf(", expected: \"%s\"\n", exp_name); - result = STATUS_FAILED; - } - if (sig == NULL || strcmp(sig, exp_sig) != 0) { - printf("(bp#%d) wrong method sig: \"%s\"", eventsCount, sig); - printf(", expected: \"%s\"\n", exp_sig); - result = STATUS_FAILED; - } - if (loc != 0) { - printf("(bp#%d) wrong location: 0x%x%08x expected: 0x0\n", - eventsCount, (jint)(loc >> 32), (jint)loc); - result = STATUS_FAILED; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setbrk008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setbrk008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setbrk008(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetBreakpoint_setbrk008_getReady(JNIEnv *env, - jclass cls, jint n) { - jvmtiError err; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_generate_breakpoint_events) { - return; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - exp_name, exp_sig); - if (mid == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - result = STATUS_FAILED; - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> setting breakpoint ...\n"); - } - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err == JVMTI_ERROR_NONE) { - eventsExpected = n; - } else { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetBreakpoint_setbrk008_check(JNIEnv *env, jclass cls) { - if (printdump == JNI_TRUE) { - printf(">>> hitted %d breakpoints\n", eventsCount); - } - if (eventsCount != eventsExpected) { - printf("Wrong number of breakpoint events: %d, expected: %d\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/setbrk008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/setbrk008.cpp new file mode 100644 index 00000000000..ac39922bcd4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetBreakpoint/setbrk008/setbrk008.cpp @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int eventsCount = 0; +static int eventsExpected = 0; +static const char *exp_csig = "Lnsk/jvmti/SetBreakpoint/setbrk008;"; +static const char *exp_name = "checkPoint"; +static const char *exp_sig = "(I)V"; + + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation loc) { + jvmtiError err; + jclass cls; + char *cls_sig, *name, *sig, *generic; + + eventsCount++; + if (printdump == JNI_TRUE && eventsCount == 1) { + printf(">>> retrieving bp event info ...\n"); + } + + err = jvmti_env->GetMethodDeclaringClass(method, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->GetClassSignature(cls, &cls_sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->GetMethodName(method, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE && eventsCount == 1) { + printf(">>> class: \"%s\"\n", cls_sig); + printf(">>> method: \"%s%s\"\n", name, sig); + printf(">>> location: 0x%x%08x\n", (jint)(loc >> 32), (jint)loc); + } + if (name == NULL || strcmp(cls_sig, exp_csig) != 0) { + printf("(bp#%d) wrong class: \"%s\"", eventsCount, cls_sig); + printf(", expected: \"%s\"\n", exp_csig); + result = STATUS_FAILED; + } + if (name == NULL || strcmp(name, exp_name) != 0) { + printf("(bp#%d) wrong method name: \"%s\"", eventsCount, name); + printf(", expected: \"%s\"\n", exp_name); + result = STATUS_FAILED; + } + if (sig == NULL || strcmp(sig, exp_sig) != 0) { + printf("(bp#%d) wrong method sig: \"%s\"", eventsCount, sig); + printf(", expected: \"%s\"\n", exp_sig); + result = STATUS_FAILED; + } + if (loc != 0) { + printf("(bp#%d) wrong location: 0x%x%08x expected: 0x0\n", + eventsCount, (jint)(loc >> 32), (jint)loc); + result = STATUS_FAILED; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setbrk008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setbrk008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setbrk008(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetBreakpoint_setbrk008_getReady(JNIEnv *env, + jclass cls, jint n) { + jvmtiError err; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_generate_breakpoint_events) { + return; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + exp_name, exp_sig); + if (mid == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + result = STATUS_FAILED; + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> setting breakpoint ...\n"); + } + err = jvmti->SetBreakpoint(mid, 0); + if (err == JVMTI_ERROR_NONE) { + eventsExpected = n; + } else { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetBreakpoint_setbrk008_check(JNIEnv *env, jclass cls) { + if (printdump == JNI_TRUE) { + printf(">>> hitted %d breakpoints\n", eventsCount); + } + if (eventsCount != eventsExpected) { + printf("Wrong number of breakpoint events: %d, expected: %d\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/libsetenvstor001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/libsetenvstor001.c deleted file mode 100644 index 0dd7f4d087e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/libsetenvstor001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setenvstor001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/libsetenvstor001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/libsetenvstor001.cpp new file mode 100644 index 00000000000..69468da0030 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/libsetenvstor001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setenvstor001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/setenvstor001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/setenvstor001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/setenvstor001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor001/setenvstor001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/libsetenvstor002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/libsetenvstor002.c deleted file mode 100644 index 5d1491fe2b0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/libsetenvstor002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setenvstor002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/libsetenvstor002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/libsetenvstor002.cpp new file mode 100644 index 00000000000..515a8795c01 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/libsetenvstor002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setenvstor002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/setenvstor002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/setenvstor002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/setenvstor002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor002/setenvstor002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/libsetenvstor003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/libsetenvstor003.c deleted file mode 100644 index b04e3a313a7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/libsetenvstor003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setenvstor003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/libsetenvstor003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/libsetenvstor003.cpp new file mode 100644 index 00000000000..f655936b077 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/libsetenvstor003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setenvstor003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/setenvstor003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/setenvstor003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/setenvstor003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEnvironmentLocalStorage/setenvstor003/setenvstor003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/libsetevntcallb001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/libsetevntcallb001.c deleted file mode 100644 index 3b3723b74b2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/libsetevntcallb001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setevntcallb001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/libsetevntcallb001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/libsetevntcallb001.cpp new file mode 100644 index 00000000000..eb4da034941 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/libsetevntcallb001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setevntcallb001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/setevntcallb001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/setevntcallb001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/setevntcallb001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb001/setevntcallb001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/libsetevntcallb002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/libsetevntcallb002.c deleted file mode 100644 index 3969671b00c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/libsetevntcallb002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setevntcallb002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/libsetevntcallb002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/libsetevntcallb002.cpp new file mode 100644 index 00000000000..f5266348794 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/libsetevntcallb002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setevntcallb002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/setevntcallb002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/setevntcallb002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/setevntcallb002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb002/setevntcallb002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/libsetevntcallb003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/libsetevntcallb003.c deleted file mode 100644 index 33be41560a2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/libsetevntcallb003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setevntcallb003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/libsetevntcallb003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/libsetevntcallb003.cpp new file mode 100644 index 00000000000..3c95801fed2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/libsetevntcallb003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setevntcallb003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/setevntcallb003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/setevntcallb003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/setevntcallb003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventCallbacks/setevntcallb003/setevntcallb003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/libsetnotif001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/libsetnotif001.c deleted file mode 100644 index 2a24e5c4cbd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/libsetnotif001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setnotif001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/libsetnotif001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/libsetnotif001.cpp new file mode 100644 index 00000000000..bff752a2953 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/libsetnotif001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setnotif001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/setnotif001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/setnotif001.c deleted file mode 100644 index 789e508de34..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/setnotif001.c +++ /dev/null @@ -1,433 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define SCALE_SIZE (JVMTI_MAX_EVENT_TYPE_VAL + 1) - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jrawMonitorID access_lock; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int flag = 0; -static unsigned char enbl_scale[SCALE_SIZE]; -static unsigned char ev_scale[SCALE_SIZE]; - -void mark(jvmtiEnv *jvmti_env, jvmtiEvent kind) { - jvmtiError err; - - if (printdump == JNI_TRUE) { - printf(">>> catching %s\n", TranslateEvent(kind)); - } - err = (*jvmti_env)->RawMonitorEnter(jvmti_env, access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (enbl_scale[kind] != 1) { - printf("Wrong notification: event %s (%d) has not been enabled\n", - TranslateEvent(kind), kind); - result = STATUS_FAILED; - } - ev_scale[kind] = 1; - err = (*jvmti_env)->RawMonitorExit(jvmti_env, access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void disable(jvmtiEnv *jvmti_env, jvmtiEvent kind) { - jvmtiError err; - - if (printdump == JNI_TRUE) { - printf(">>> disabling %s\n", TranslateEvent(kind)); - } - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, - JVMTI_DISABLE, kind, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Fail to disable %s: %s (%d)\n", - TranslateEvent(kind), TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void enable(jvmtiEnv *jvmti_env, jvmtiEvent kind) { - jvmtiError err; - - if (printdump == JNI_TRUE) { - printf(">>> enabling %s\n", TranslateEvent(kind)); - } - err = (*jvmti_env)->RawMonitorEnter(jvmti_env, access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, - JVMTI_ENABLE, kind, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Fail to enable %s: %s (%d)\n", - TranslateEvent(kind), TranslateError(err), err); - result = STATUS_FAILED; - } else { - enbl_scale[kind] = 1; - } - err = (*jvmti_env)->RawMonitorExit(jvmti_env, access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void setWatches(jvmtiEnv *jvmti_env, JNIEnv *env, jclass cls) { - jvmtiError err; - jfieldID fid; - jmethodID mid; - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "meth01", "(I)V"); - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err == JVMTI_ERROR_NONE) { - enable(jvmti_env, JVMTI_EVENT_BREAKPOINT); - } else { - result = STATUS_FAILED; - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - } - - fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), "fld", "I"); - if (caps.can_generate_field_access_events) { - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, fid); - if (err == JVMTI_ERROR_NONE) { - enable(jvmti_env, JVMTI_EVENT_FIELD_ACCESS); - } else { - result = STATUS_FAILED; - printf("(SetFieldAccessWatch) unexpected error: %s (%d)\n", - TranslateError(err), err); - } - } else { - printf("Warning: SetFieldAccessWatch is not implemented\n"); - } - - if (caps.can_generate_field_modification_events) { - err = (*jvmti_env)->SetFieldModificationWatch(jvmti_env, cls, fid); - if (err == JVMTI_ERROR_NONE) { - enable(jvmti_env, JVMTI_EVENT_FIELD_MODIFICATION); - } else { - result = STATUS_FAILED; - printf("(SetFieldModificationWatch) unexpected error: %s (%d)\n", - TranslateError(err), err); - } - } else { - printf("Warning: SetFieldModificationWatch is not implemented\n"); - } -} - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - if (printdump == JNI_TRUE) { - printf(">>> VMInit\n"); - } - enable(jvmti_env, JVMTI_EVENT_SINGLE_STEP); - enable(jvmti_env, JVMTI_EVENT_EXCEPTION); - enable(jvmti_env, JVMTI_EVENT_EXCEPTION_CATCH); - mark(jvmti_env, JVMTI_EVENT_VM_INIT); - flag = 1; -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - if (flag) { - mark(jvmti_env, JVMTI_EVENT_SINGLE_STEP); - disable(jvmti_env, JVMTI_EVENT_SINGLE_STEP); - } -} - -void JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method) { - jvmtiError err; - jboolean isNative; - - if (flag) { - mark(jvmti_env, JVMTI_EVENT_METHOD_ENTRY); - err = (*jvmti_env)->IsMethodNative(jvmti_env, method, &isNative); - if (err != JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(IsMethodNative) unexpected error: %s (%d)\n", - TranslateError(err), err); - } - if (isNative == JNI_FALSE) { - err = (*jvmti_env)->NotifyFramePop(jvmti_env, thr, 0); - if (err == JVMTI_ERROR_NONE) { - enable(jvmti_env, JVMTI_EVENT_FRAME_POP); - } else { - result = STATUS_FAILED; - printf("(NotifyFramePop) unexpected error: %s (%d)\n", - TranslateError(err), err); - } - } - enable(jvmti_env, JVMTI_EVENT_CLASS_LOAD); - enable(jvmti_env, JVMTI_EVENT_CLASS_PREPARE); - disable(jvmti_env, JVMTI_EVENT_METHOD_ENTRY); - } -} - -void JNICALL ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, - jmethodID method, jlocation location, jobject exception) { - if (flag) { - mark(jvmti_env, JVMTI_EVENT_EXCEPTION_CATCH); - } -} - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jboolean was_poped_by_exc, jvalue return_value) { - if (flag) { - mark(jvmti_env, JVMTI_EVENT_METHOD_EXIT); - disable(jvmti_env, JVMTI_EVENT_METHOD_EXIT); - } -} - -void JNICALL ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread) { - if (flag) { - mark(jvmti_env, JVMTI_EVENT_THREAD_START); - } -} - -void JNICALL ThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread) { - if (flag) { - mark(jvmti_env, JVMTI_EVENT_THREAD_END); - } -} - -void JNICALL ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jclass klass) { - if (flag) { - mark(jvmti_env, JVMTI_EVENT_CLASS_LOAD); - } -} - -void JNICALL ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jclass klass) { - if (flag) { - mark(jvmti_env, JVMTI_EVENT_CLASS_PREPARE); - } -} - -void JNICALL Exception(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - if (flag) { - mark(jvmti_env, JVMTI_EVENT_EXCEPTION); - } -} - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, - jmethodID method, jlocation location, jclass field_klass, jobject obj, jfieldID field) { - if (flag) { - mark(jvmti_env, JVMTI_EVENT_FIELD_ACCESS); - } -} - -void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, - jfieldID field, char sig, jvalue new_value) { - if (flag) { - mark(jvmti_env, JVMTI_EVENT_FIELD_MODIFICATION); - } -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - if (flag) { - mark(jvmti_env, JVMTI_EVENT_BREAKPOINT); - } -} - -void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jboolean wasPopedByException) { - if (flag) { - mark(jvmti_env, JVMTI_EVENT_FRAME_POP); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setnotif001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setnotif001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setnotif001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - memset(enbl_scale, 0, SCALE_SIZE); - memset(ev_scale, 0, SCALE_SIZE); - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "_access_lock", &access_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - callbacks.ThreadStart = &ThreadStart; - callbacks.ThreadEnd = &ThreadEnd; - callbacks.ClassLoad = &ClassLoad; - callbacks.ClassPrepare = &ClassPrepare; - - if (caps.can_generate_method_entry_events) { - callbacks.MethodEntry = &MethodEntry; - } - if (caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - } - if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - } - if (caps.can_generate_single_step_events) { - callbacks.SingleStep = &SingleStep; - } - if (caps.can_generate_frame_pop_events) { - callbacks.FramePop = &FramePop; - } - if (caps.can_generate_exception_events) { - callbacks.Exception = &Exception; - callbacks.ExceptionCatch = &ExceptionCatch; - } - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - } - if (caps.can_generate_field_modification_events) { - callbacks.FieldModification = &FieldModification; - } - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - enable(jvmti, JVMTI_EVENT_VM_INIT); - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetEventNotificationMode_setnotif001_enableEv(JNIEnv *env, - jclass cls) { - setWatches(jvmti, env, cls); - enable(jvmti, JVMTI_EVENT_METHOD_ENTRY); - enable(jvmti, JVMTI_EVENT_METHOD_EXIT); - enable(jvmti, JVMTI_EVENT_THREAD_START); - enable(jvmti, JVMTI_EVENT_THREAD_END); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetEventNotificationMode_setnotif001_getRes(JNIEnv *env, - jclass cls) { - jint i; - - for (i = 0; i < SCALE_SIZE; i++) { - if (enbl_scale[i] == 1 && ev_scale[i] == 0) { - printf("No notification: event %s (%d)\n", TranslateEvent(i), i); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE && ev_scale[i] > 0) { - printf(">>> %s (%d), notifications: %d\n", - TranslateEvent(i), i, ev_scale[i]); - } - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/setnotif001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/setnotif001.cpp new file mode 100644 index 00000000000..663601cda37 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/setnotif001.cpp @@ -0,0 +1,434 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define SCALE_SIZE (JVMTI_MAX_EVENT_TYPE_VAL + 1) + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jrawMonitorID access_lock; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int flag = 0; +static unsigned char enbl_scale[SCALE_SIZE]; +static unsigned char ev_scale[SCALE_SIZE]; + +void mark(jvmtiEnv *jvmti_env, jvmtiEvent kind) { + jvmtiError err; + + if (printdump == JNI_TRUE) { + printf(">>> catching %s\n", TranslateEvent(kind)); + } + err = jvmti_env->RawMonitorEnter(access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (enbl_scale[kind] != 1) { + printf("Wrong notification: event %s (%d) has not been enabled\n", + TranslateEvent(kind), kind); + result = STATUS_FAILED; + } + ev_scale[kind] = 1; + err = jvmti_env->RawMonitorExit(access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void disable(jvmtiEnv *jvmti_env, jvmtiEvent kind) { + jvmtiError err; + + if (printdump == JNI_TRUE) { + printf(">>> disabling %s\n", TranslateEvent(kind)); + } + err = jvmti_env->SetEventNotificationMode( + JVMTI_DISABLE, kind, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Fail to disable %s: %s (%d)\n", + TranslateEvent(kind), TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void enable(jvmtiEnv *jvmti_env, jvmtiEvent kind) { + jvmtiError err; + + if (printdump == JNI_TRUE) { + printf(">>> enabling %s\n", TranslateEvent(kind)); + } + err = jvmti_env->RawMonitorEnter(access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->SetEventNotificationMode( + JVMTI_ENABLE, kind, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Fail to enable %s: %s (%d)\n", + TranslateEvent(kind), TranslateError(err), err); + result = STATUS_FAILED; + } else { + enbl_scale[kind] = 1; + } + err = jvmti_env->RawMonitorExit(access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void setWatches(jvmtiEnv *jvmti_env, JNIEnv *env, jclass cls) { + jvmtiError err; + jfieldID fid; + jmethodID mid; + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "meth01", "(I)V"); + err = jvmti->SetBreakpoint(mid, 0); + if (err == JVMTI_ERROR_NONE) { + enable(jvmti_env, JVMTI_EVENT_BREAKPOINT); + } else { + result = STATUS_FAILED; + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + } + + fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), "fld", "I"); + if (caps.can_generate_field_access_events) { + err = jvmti->SetFieldAccessWatch(cls, fid); + if (err == JVMTI_ERROR_NONE) { + enable(jvmti_env, JVMTI_EVENT_FIELD_ACCESS); + } else { + result = STATUS_FAILED; + printf("(SetFieldAccessWatch) unexpected error: %s (%d)\n", + TranslateError(err), err); + } + } else { + printf("Warning: SetFieldAccessWatch is not implemented\n"); + } + + if (caps.can_generate_field_modification_events) { + err = jvmti_env->SetFieldModificationWatch(cls, fid); + if (err == JVMTI_ERROR_NONE) { + enable(jvmti_env, JVMTI_EVENT_FIELD_MODIFICATION); + } else { + result = STATUS_FAILED; + printf("(SetFieldModificationWatch) unexpected error: %s (%d)\n", + TranslateError(err), err); + } + } else { + printf("Warning: SetFieldModificationWatch is not implemented\n"); + } +} + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + if (printdump == JNI_TRUE) { + printf(">>> VMInit\n"); + } + enable(jvmti_env, JVMTI_EVENT_SINGLE_STEP); + enable(jvmti_env, JVMTI_EVENT_EXCEPTION); + enable(jvmti_env, JVMTI_EVENT_EXCEPTION_CATCH); + mark(jvmti_env, JVMTI_EVENT_VM_INIT); + flag = 1; +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + if (flag) { + mark(jvmti_env, JVMTI_EVENT_SINGLE_STEP); + disable(jvmti_env, JVMTI_EVENT_SINGLE_STEP); + } +} + +void JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method) { + jvmtiError err; + jboolean isNative; + + if (flag) { + mark(jvmti_env, JVMTI_EVENT_METHOD_ENTRY); + err = jvmti_env->IsMethodNative(method, &isNative); + if (err != JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(IsMethodNative) unexpected error: %s (%d)\n", + TranslateError(err), err); + } + if (isNative == JNI_FALSE) { + err = jvmti_env->NotifyFramePop(thr, 0); + if (err == JVMTI_ERROR_NONE) { + enable(jvmti_env, JVMTI_EVENT_FRAME_POP); + } else { + result = STATUS_FAILED; + printf("(NotifyFramePop) unexpected error: %s (%d)\n", + TranslateError(err), err); + } + } + enable(jvmti_env, JVMTI_EVENT_CLASS_LOAD); + enable(jvmti_env, JVMTI_EVENT_CLASS_PREPARE); + disable(jvmti_env, JVMTI_EVENT_METHOD_ENTRY); + } +} + +void JNICALL ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, + jmethodID method, jlocation location, jobject exception) { + if (flag) { + mark(jvmti_env, JVMTI_EVENT_EXCEPTION_CATCH); + } +} + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jboolean was_poped_by_exc, jvalue return_value) { + if (flag) { + mark(jvmti_env, JVMTI_EVENT_METHOD_EXIT); + disable(jvmti_env, JVMTI_EVENT_METHOD_EXIT); + } +} + +void JNICALL ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread) { + if (flag) { + mark(jvmti_env, JVMTI_EVENT_THREAD_START); + } +} + +void JNICALL ThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread) { + if (flag) { + mark(jvmti_env, JVMTI_EVENT_THREAD_END); + } +} + +void JNICALL ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jclass klass) { + if (flag) { + mark(jvmti_env, JVMTI_EVENT_CLASS_LOAD); + } +} + +void JNICALL ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jclass klass) { + if (flag) { + mark(jvmti_env, JVMTI_EVENT_CLASS_PREPARE); + } +} + +void JNICALL Exception(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + if (flag) { + mark(jvmti_env, JVMTI_EVENT_EXCEPTION); + } +} + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, + jmethodID method, jlocation location, jclass field_klass, jobject obj, jfieldID field) { + if (flag) { + mark(jvmti_env, JVMTI_EVENT_FIELD_ACCESS); + } +} + +void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, + jfieldID field, char sig, jvalue new_value) { + if (flag) { + mark(jvmti_env, JVMTI_EVENT_FIELD_MODIFICATION); + } +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + if (flag) { + mark(jvmti_env, JVMTI_EVENT_BREAKPOINT); + } +} + +void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jboolean wasPopedByException) { + if (flag) { + mark(jvmti_env, JVMTI_EVENT_FRAME_POP); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setnotif001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setnotif001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setnotif001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + memset(enbl_scale, 0, SCALE_SIZE); + memset(ev_scale, 0, SCALE_SIZE); + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->CreateRawMonitor("_access_lock", &access_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + callbacks.ThreadStart = &ThreadStart; + callbacks.ThreadEnd = &ThreadEnd; + callbacks.ClassLoad = &ClassLoad; + callbacks.ClassPrepare = &ClassPrepare; + + if (caps.can_generate_method_entry_events) { + callbacks.MethodEntry = &MethodEntry; + } + if (caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + } + if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + } + if (caps.can_generate_single_step_events) { + callbacks.SingleStep = &SingleStep; + } + if (caps.can_generate_frame_pop_events) { + callbacks.FramePop = &FramePop; + } + if (caps.can_generate_exception_events) { + callbacks.Exception = &Exception; + callbacks.ExceptionCatch = &ExceptionCatch; + } + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + } + if (caps.can_generate_field_modification_events) { + callbacks.FieldModification = &FieldModification; + } + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + enable(jvmti, JVMTI_EVENT_VM_INIT); + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetEventNotificationMode_setnotif001_enableEv(JNIEnv *env, + jclass cls) { + setWatches(jvmti, env, cls); + enable(jvmti, JVMTI_EVENT_METHOD_ENTRY); + enable(jvmti, JVMTI_EVENT_METHOD_EXIT); + enable(jvmti, JVMTI_EVENT_THREAD_START); + enable(jvmti, JVMTI_EVENT_THREAD_END); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetEventNotificationMode_setnotif001_getRes(JNIEnv *env, + jclass cls) { + jint i; + + for (i = 0; i < SCALE_SIZE; i++) { + jvmtiEvent kind = (jvmtiEvent) i; + if (enbl_scale[i] == 1 && ev_scale[i] == 0) { + printf("No notification: event %s (%d)\n", TranslateEvent(kind), i); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE && ev_scale[i] > 0) { + printf(">>> %s (%d), notifications: %d\n", + TranslateEvent(kind), i, ev_scale[i]); + } + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/libsetextevent001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/libsetextevent001.c deleted file mode 100644 index 96872709676..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/libsetextevent001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setextevent001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/libsetextevent001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/libsetextevent001.cpp new file mode 100644 index 00000000000..6bfd649524d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/libsetextevent001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setextevent001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/setextevent001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/setextevent001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/setextevent001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetExtensionEventCallback/setextevent001/setextevent001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/libsetfldw001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/libsetfldw001.c deleted file mode 100644 index 6a4ee51dad0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/libsetfldw001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setfldw001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/libsetfldw001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/libsetfldw001.cpp new file mode 100644 index 00000000000..729b39efed3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/libsetfldw001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setfldw001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/setfldw001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/setfldw001.c deleted file mode 100644 index 3b9be64674d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/setfldw001.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *class; - char *name; - char *sig; - int stat; - jfieldID fid; - jfieldID thrown_fid; -} field; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static field fields[] = { - {"nsk/jvmti/SetFieldAccessWatch/setfldw001", "fld0", "I", 0, NULL, NULL}, - {"nsk/jvmti/SetFieldAccessWatch/setfldw001", "fld1", "I", 1, NULL, NULL}, - {"nsk/jvmti/SetFieldAccessWatch/setfldw001", "fld2", - "Lnsk/jvmti/SetFieldAccessWatch/setfldw001a;", 0, NULL, NULL}, - {"nsk/jvmti/SetFieldAccessWatch/setfldw001a", "fld3", "[I", 0, NULL, NULL}, - {"nsk/jvmti/SetFieldAccessWatch/setfldw001b", "fld4", "F", 0, NULL, NULL}, -}; - -void setWatch(JNIEnv *env, jint ind) { - jvmtiError err; - jclass cls; - field fld = fields[ind]; - - cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, fld.class)); - if (cls == NULL) { - printf("Cannot find class \"%s\"\n", fld.class); - result = STATUS_FAILED; - return; - } - if (fld.fid == NULL) { - if (fld.stat) { - fields[ind].fid = JNI_ENV_PTR(env)-> - GetStaticFieldID(JNI_ENV_ARG(env, cls), fld.name, fld.sig); - } else { - fields[ind].fid = JNI_ENV_PTR(env)-> - GetFieldID(JNI_ENV_ARG(env, cls), fld.name, fld.sig); - } - } - - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, fields[ind].fid); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_generate_field_access_events) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(SetFieldAccessWatch#%d) unexpected error: %s (%d)\n", - ind, TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jlocation location, jclass field_klass, jobject obj, jfieldID field) { - - char *fld_name = NULL; - jint fld_ind = 0; - size_t len = 0; - jvmtiError err = (*jvmti_env)->GetFieldName(jvmti_env, field_klass, field, - &fld_name, NULL, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Error in GetFieldName: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - return; - } - if (fld_name == NULL) { - printf("GetFieldName returned NULL field name\n"); - result = STATUS_FAILED; - return; - } - len = strlen(fld_name); - /* All field names have the same length and end with a digit. */ - if (len != strlen(fields[0].name) || !isdigit(fld_name[len - 1])) { - printf("GetFieldName returned unexpected field name: %s\n", fld_name); - result = STATUS_FAILED; - return; - } - fld_ind = (int)(fld_name[len - 1] - '0'); /* last digit is index in the array */ - fields[fld_ind].thrown_fid = field; - (*jvmti)->Deallocate(jvmti_env, (unsigned char*) fld_name); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setfldw001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setfldw001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setfldw001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldAccess watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw001_setWatch(JNIEnv *env, - jclass cls, jint fld_ind) { - setWatch(env, fld_ind); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw001_touchfld0(JNIEnv *env, - jobject obj) { - jint val; - - setWatch(env, (jint)0); - val = JNI_ENV_PTR(env)->GetIntField(JNI_ENV_ARG(env, obj), fields[0].fid); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw001_check(JNIEnv *env, - jclass cls, jint fld_ind, jboolean flag) { - jfieldID thrown_fid = fields[fld_ind].thrown_fid; - - if (caps.can_generate_field_access_events) { - if (flag == JNI_FALSE && thrown_fid != NULL) { - result = STATUS_FAILED; - printf("(Field %d) FIELD_ACCESS event without access watch set\n", - fld_ind); - } else if (flag == JNI_TRUE && thrown_fid != fields[fld_ind].fid) { - result = STATUS_FAILED; - printf("(Field %d) thrown field ID expected: 0x%p, got: 0x%p\n", - fld_ind, fields[fld_ind].fid, thrown_fid); - } - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/setfldw001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/setfldw001.cpp new file mode 100644 index 00000000000..018cf33b867 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/setfldw001.cpp @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *klass; + const char *name; + const char *sig; + int stat; + jfieldID fid; + jfieldID thrown_fid; +} field; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static field fields[] = { + {"nsk/jvmti/SetFieldAccessWatch/setfldw001", "fld0", "I", 0, NULL, NULL}, + {"nsk/jvmti/SetFieldAccessWatch/setfldw001", "fld1", "I", 1, NULL, NULL}, + {"nsk/jvmti/SetFieldAccessWatch/setfldw001", "fld2", + "Lnsk/jvmti/SetFieldAccessWatch/setfldw001a;", 0, NULL, NULL}, + {"nsk/jvmti/SetFieldAccessWatch/setfldw001a", "fld3", "[I", 0, NULL, NULL}, + {"nsk/jvmti/SetFieldAccessWatch/setfldw001b", "fld4", "F", 0, NULL, NULL}, +}; + +void setWatch(JNIEnv *env, jint ind) { + jvmtiError err; + jclass cls; + field fld = fields[ind]; + + cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, fld.klass)); + if (cls == NULL) { + printf("Cannot find class \"%s\"\n", fld.klass); + result = STATUS_FAILED; + return; + } + if (fld.fid == NULL) { + if (fld.stat) { + fields[ind].fid = JNI_ENV_PTR(env)-> + GetStaticFieldID(JNI_ENV_ARG(env, cls), fld.name, fld.sig); + } else { + fields[ind].fid = JNI_ENV_PTR(env)-> + GetFieldID(JNI_ENV_ARG(env, cls), fld.name, fld.sig); + } + } + + err = jvmti->SetFieldAccessWatch(cls, fields[ind].fid); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_generate_field_access_events) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(SetFieldAccessWatch#%d) unexpected error: %s (%d)\n", + ind, TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jlocation location, jclass field_klass, jobject obj, jfieldID field) { + + char *fld_name = NULL; + jint fld_ind = 0; + size_t len = 0; + jvmtiError err = jvmti_env->GetFieldName(field_klass, field, + &fld_name, NULL, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Error in GetFieldName: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + return; + } + if (fld_name == NULL) { + printf("GetFieldName returned NULL field name\n"); + result = STATUS_FAILED; + return; + } + len = strlen(fld_name); + /* All field names have the same length and end with a digit. */ + if (len != strlen(fields[0].name) || !isdigit(fld_name[len - 1])) { + printf("GetFieldName returned unexpected field name: %s\n", fld_name); + result = STATUS_FAILED; + return; + } + fld_ind = (int)(fld_name[len - 1] - '0'); /* last digit is index in the array */ + fields[fld_ind].thrown_fid = field; + jvmti_env->Deallocate((unsigned char*) fld_name); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setfldw001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setfldw001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setfldw001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldAccess watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw001_setWatch(JNIEnv *env, + jclass cls, jint fld_ind) { + setWatch(env, fld_ind); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw001_touchfld0(JNIEnv *env, + jobject obj) { + jint val; + + setWatch(env, (jint)0); + val = JNI_ENV_PTR(env)->GetIntField(JNI_ENV_ARG(env, obj), fields[0].fid); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw001_check(JNIEnv *env, + jclass cls, jint fld_ind, jboolean flag) { + jfieldID thrown_fid = fields[fld_ind].thrown_fid; + + if (caps.can_generate_field_access_events) { + if (flag == JNI_FALSE && thrown_fid != NULL) { + result = STATUS_FAILED; + printf("(Field %d) FIELD_ACCESS event without access watch set\n", + fld_ind); + } else if (flag == JNI_TRUE && thrown_fid != fields[fld_ind].fid) { + result = STATUS_FAILED; + printf("(Field %d) thrown field ID expected: 0x%p, got: 0x%p\n", + fld_ind, fields[fld_ind].fid, thrown_fid); + } + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/libsetfldw002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/libsetfldw002.c deleted file mode 100644 index 430d8ebbd2f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/libsetfldw002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setfldw002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/libsetfldw002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/libsetfldw002.cpp new file mode 100644 index 00000000000..b4505dbfebc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/libsetfldw002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setfldw002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/setfldw002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/setfldw002.c deleted file mode 100644 index b3f602e67c6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/setfldw002.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jlocation location, jclass field_klass, jobject obj, jfieldID field) { -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setfldw002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setfldw002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setfldw002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldAccess watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw002_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jfieldID fid; - - fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - "fld1", "I"); - - if (!caps.can_generate_field_access_events) { - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, fid); - if (err != JVMTI_ERROR_MUST_POSSESS_CAPABILITY) { - result = STATUS_FAILED; - printf("Failed to return JVMTI_ERROR_MUST_POSSESS_CAPABILITY:"); - printf(" %s (%d)\n", TranslateError(err), err); - } - } else { - err = (*jvmti)->SetFieldAccessWatch(jvmti, NULL, fid); - if (err != JVMTI_ERROR_INVALID_CLASS) { - result = STATUS_FAILED; - printf("Failed to return JVMTI_ERROR_INVALID_CLASS: %s (%d)\n", - TranslateError(err), err); - } - - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, NULL); - if (err != JVMTI_ERROR_INVALID_FIELDID) { - result = STATUS_FAILED; - printf("Failed to return JVMTI_ERROR_INVALID_FIELDID: %s (%d)\n", - TranslateError(err), err); - } - - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, fid); - if (err != JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(SetFieldAccessWatch) unexpected error: %s (%d)\n", - TranslateError(err), err); - } else { - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, fid); - if (err != JVMTI_ERROR_DUPLICATE) { - result = STATUS_FAILED; - printf("Failed to return JVMTI_ERROR_DUPLICATE: %s (%d)\n", - TranslateError(err), err); - } - } - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/setfldw002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/setfldw002.cpp new file mode 100644 index 00000000000..9fed43f551d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw002/setfldw002.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jlocation location, jclass field_klass, jobject obj, jfieldID field) { +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setfldw002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setfldw002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setfldw002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldAccess watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw002_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jfieldID fid; + + fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + "fld1", "I"); + + if (!caps.can_generate_field_access_events) { + err = jvmti->SetFieldAccessWatch(cls, fid); + if (err != JVMTI_ERROR_MUST_POSSESS_CAPABILITY) { + result = STATUS_FAILED; + printf("Failed to return JVMTI_ERROR_MUST_POSSESS_CAPABILITY:"); + printf(" %s (%d)\n", TranslateError(err), err); + } + } else { + err = jvmti->SetFieldAccessWatch(NULL, fid); + if (err != JVMTI_ERROR_INVALID_CLASS) { + result = STATUS_FAILED; + printf("Failed to return JVMTI_ERROR_INVALID_CLASS: %s (%d)\n", + TranslateError(err), err); + } + + err = jvmti->SetFieldAccessWatch(cls, NULL); + if (err != JVMTI_ERROR_INVALID_FIELDID) { + result = STATUS_FAILED; + printf("Failed to return JVMTI_ERROR_INVALID_FIELDID: %s (%d)\n", + TranslateError(err), err); + } + + err = jvmti->SetFieldAccessWatch(cls, fid); + if (err != JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(SetFieldAccessWatch) unexpected error: %s (%d)\n", + TranslateError(err), err); + } else { + err = jvmti->SetFieldAccessWatch(cls, fid); + if (err != JVMTI_ERROR_DUPLICATE) { + result = STATUS_FAILED; + printf("Failed to return JVMTI_ERROR_DUPLICATE: %s (%d)\n", + TranslateError(err), err); + } + } + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/libsetfldw003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/libsetfldw003.c deleted file mode 100644 index 1d71abc8f48..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/libsetfldw003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setfldw003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/libsetfldw003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/libsetfldw003.cpp new file mode 100644 index 00000000000..3a6471515c2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/libsetfldw003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setfldw003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/setfldw003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/setfldw003.c deleted file mode 100644 index e5643e318e3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/setfldw003.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jfieldID actual_fid = NULL; -static jfieldID fids[4] = {NULL, NULL, NULL, NULL}; - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jlocation location, jclass field_klass, jobject obj, jfieldID field) { - if (printdump == JNI_TRUE) { - printf(">>> FieldAccess event, fieldID: 0x%p\n", field); - } - actual_fid = field; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setfldw003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setfldw003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setfldw003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldAccess watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw003_getReady(JNIEnv *env, jclass cls) { - jvmtiError err; - size_t i; - - if (!caps.can_generate_field_access_events) { - return; - } - - fids[0] = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - "fld0", "I"); - fids[1] = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - "fld1", "I"); - fids[2] = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld2", "I"); - fids[3] = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld3", "I"); - for (i = 0; i < sizeof(fids) / sizeof(jfieldID); i++) { - if (fids[i] == NULL) { - printf("Unable to set field access watch on fld%" PRIuPTR ", fieldID=0", i); - } else { - if (printdump == JNI_TRUE) { - printf(">>> setting access watch on fld%" PRIuPTR, i); - printf(", FieldID=0x%p\n", fids[i]); - } - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, fids[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw003_check(JNIEnv *env, - jclass cls, jint ind) { - if (printdump == JNI_TRUE) { - printf(">>> checking on fld%d\n", ind); - } - if (actual_fid != fids[ind]) { - result = STATUS_FAILED; - printf("Field fld%d: thrown field ID expected=0x%p, actual=0x%p\n", - ind, fids[ind], actual_fid); - } - actual_fid = NULL; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw003_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/setfldw003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/setfldw003.cpp new file mode 100644 index 00000000000..38ff8b18c73 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw003/setfldw003.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jfieldID actual_fid = NULL; +static jfieldID fids[4] = {NULL, NULL, NULL, NULL}; + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jlocation location, jclass field_klass, jobject obj, jfieldID field) { + if (printdump == JNI_TRUE) { + printf(">>> FieldAccess event, fieldID: 0x%p\n", field); + } + actual_fid = field; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setfldw003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setfldw003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setfldw003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldAccess watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw003_getReady(JNIEnv *env, jclass cls) { + jvmtiError err; + size_t i; + + if (!caps.can_generate_field_access_events) { + return; + } + + fids[0] = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + "fld0", "I"); + fids[1] = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + "fld1", "I"); + fids[2] = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld2", "I"); + fids[3] = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld3", "I"); + for (i = 0; i < sizeof(fids) / sizeof(jfieldID); i++) { + if (fids[i] == NULL) { + printf("Unable to set field access watch on fld%" PRIuPTR ", fieldID=0", i); + } else { + if (printdump == JNI_TRUE) { + printf(">>> setting access watch on fld%" PRIuPTR, i); + printf(", FieldID=0x%p\n", fids[i]); + } + err = jvmti->SetFieldAccessWatch(cls, fids[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw003_check(JNIEnv *env, + jclass cls, jint ind) { + if (printdump == JNI_TRUE) { + printf(">>> checking on fld%d\n", ind); + } + if (actual_fid != fids[ind]) { + result = STATUS_FAILED; + printf("Field fld%d: thrown field ID expected=0x%p, actual=0x%p\n", + ind, fids[ind], actual_fid); + } + actual_fid = NULL; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw003_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/libsetfldw004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/libsetfldw004.c deleted file mode 100644 index cede711c88c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/libsetfldw004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setfldw004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/libsetfldw004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/libsetfldw004.cpp new file mode 100644 index 00000000000..63583742348 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/libsetfldw004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setfldw004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/setfldw004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/setfldw004.c deleted file mode 100644 index 7c3c5eed15a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/setfldw004.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jfieldID actual_fid = NULL; -static jfieldID fids[4] = {NULL, NULL, NULL, NULL}; - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jlocation location, jclass field_klass, jobject obj, jfieldID field) { - if (printdump == JNI_TRUE) { - printf(">>> FieldAccess, field: 0x%p\n", field); - } - actual_fid = field; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setfldw004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setfldw004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setfldw004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - if ((err = ((*jvmti)->GetCapabilities(jvmti, &caps))) != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldAccess watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw004_getReady(JNIEnv *env, jclass cls) { - jvmtiError err; - size_t i; - - if (!caps.can_generate_field_access_events) { - return; - } - - fids[0] = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - "fld0", "I"); - fids[1] = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - "fld1", "I"); - fids[2] = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld2", "I"); - fids[3] = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld3", "I"); - for (i = 0; i < sizeof(fids) / sizeof(jfieldID); i++) { - if (fids[i] == NULL) { - printf("Unable to set field access watch on fld%" PRIuPTR ", fieldID=0", i); - } else { - if (printdump == JNI_TRUE) { - printf(">>> setting access watch on fld%" PRIuPTR, i); - printf(", FieldID=0x%p\n", fids[i]); - } - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, fids[i]); - if (err != JVMTI_ERROR_NONE) { - printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw004_check(JNIEnv *env, - jclass cls, jint ind) { - if (printdump == JNI_TRUE) { - printf(">>> checking on fld%d\n", ind); - } - if (actual_fid != fids[ind]) { - result = STATUS_FAILED; - printf("Field %d: thrown field ID expected=0x%p, actual=0x%p\n", - ind, fids[ind], actual_fid); - } - actual_fid = NULL; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw004_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/setfldw004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/setfldw004.cpp new file mode 100644 index 00000000000..336a0d9cbdb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw004/setfldw004.cpp @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jfieldID actual_fid = NULL; +static jfieldID fids[4] = {NULL, NULL, NULL, NULL}; + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jlocation location, jclass field_klass, jobject obj, jfieldID field) { + if (printdump == JNI_TRUE) { + printf(">>> FieldAccess, field: 0x%p\n", field); + } + actual_fid = field; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setfldw004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setfldw004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setfldw004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + if ((err = (jvmti->GetCapabilities(&caps))) != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldAccess watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw004_getReady(JNIEnv *env, jclass cls) { + jvmtiError err; + size_t i; + + if (!caps.can_generate_field_access_events) { + return; + } + + fids[0] = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + "fld0", "I"); + fids[1] = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + "fld1", "I"); + fids[2] = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld2", "I"); + fids[3] = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), "fld3", "I"); + for (i = 0; i < sizeof(fids) / sizeof(jfieldID); i++) { + if (fids[i] == NULL) { + printf("Unable to set field access watch on fld%" PRIuPTR ", fieldID=0", i); + } else { + if (printdump == JNI_TRUE) { + printf(">>> setting access watch on fld%" PRIuPTR, i); + printf(", FieldID=0x%p\n", fids[i]); + } + err = jvmti->SetFieldAccessWatch(cls, fids[i]); + if (err != JVMTI_ERROR_NONE) { + printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw004_check(JNIEnv *env, + jclass cls, jint ind) { + if (printdump == JNI_TRUE) { + printf(">>> checking on fld%d\n", ind); + } + if (actual_fid != fids[ind]) { + result = STATUS_FAILED; + printf("Field %d: thrown field ID expected=0x%p, actual=0x%p\n", + ind, fids[ind], actual_fid); + } + actual_fid = NULL; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw004_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/libsetfldw005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/libsetfldw005.c deleted file mode 100644 index 34f302d5e90..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/libsetfldw005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setfldw005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/libsetfldw005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/libsetfldw005.cpp new file mode 100644 index 00000000000..266a605e769 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/libsetfldw005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setfldw005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/setfldw005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/setfldw005.c deleted file mode 100644 index b7c08767d8b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/setfldw005.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - const char *name; - const char *sig; - const jboolean stat; - jfieldID fid; - const char *descr; -} field; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jfieldID actual_fid = NULL; -static field fields[] = { - {"fld0", "J", JNI_TRUE, NULL, "static long"}, - {"fld1", "J", JNI_FALSE, NULL, "long"}, - {"fld2", "F", JNI_TRUE, NULL, "static float"}, - {"fld3", "F", JNI_FALSE, NULL, "float"}, - {"fld4", "D", JNI_TRUE, NULL, "static double"}, - {"fld5", "D", JNI_FALSE, NULL, "double"}, - {"fld6", "Ljava/lang/Object;", JNI_TRUE, NULL, "static Object"}, - {"fld7", "Ljava/lang/Object;", JNI_FALSE, NULL, "Object"}, - {"fld8", "Z", JNI_TRUE, NULL, "static boolean"}, - {"fld9", "Z", JNI_FALSE, NULL, "boolean"}, - {"fld10", "B", JNI_TRUE, NULL, "static byte"}, - {"fld11", "B", JNI_FALSE, NULL, "byte"}, - {"fld12", "S", JNI_TRUE, NULL, "static short"}, - {"fld13", "S", JNI_FALSE, NULL, "short"}, - {"fld14", "C", JNI_TRUE, NULL, "static char"}, - {"fld15", "C", JNI_FALSE, NULL, "char"} -}; - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jlocation location, jclass field_klass, jobject obj, jfieldID field) { - if (printdump == JNI_TRUE) { - printf(">>> FieldAccess, field: 0x%p\n", field); - } - actual_fid = field; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setfldw005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setfldw005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setfldw005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - if ((err = ((*jvmti)->GetCapabilities(jvmti, &caps))) != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldAccess watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw005_getReady(JNIEnv *env, jclass cls) { - jvmtiError err; - size_t i; - - if (!caps.can_generate_field_access_events) { - return; - } - - for (i = 0; i < sizeof(fields) / sizeof(field); i++) { - if (fields[i].stat == JNI_TRUE) { - fields[i].fid = JNI_ENV_PTR(env)-> - GetStaticFieldID(JNI_ENV_ARG(env, cls), - fields[i].name, fields[i].sig); - } else { - fields[i].fid = JNI_ENV_PTR(env)-> - GetFieldID(JNI_ENV_ARG(env, cls), - fields[i].name, fields[i].sig); - } - if (fields[i].fid == NULL) { - printf("Unable to set access watch on %s fld%" PRIuPTR ", fieldID=0", - fields[i].descr, i); - } else { - if (printdump == JNI_TRUE) { - printf(">>> setting access watch on %s fld%" PRIuPTR ", fieldID=0x%p\n", - fields[i].descr, i, fields[i].fid); - } - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, fields[i].fid); - if (err != JVMTI_ERROR_NONE) { - printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw005_check(JNIEnv *env, - jclass cls, jint ind) { - if (printdump == JNI_TRUE) { - printf(">>> checking on %s fld%d\n", fields[ind].descr, ind); - } - if (actual_fid != fields[ind].fid) { - result = STATUS_FAILED; - printf("Field %s fld%d: thrown field ID expected=0x%p, actual=0x%p\n", - fields[ind].descr, ind, fields[ind].fid, actual_fid); - } - actual_fid = NULL; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw005_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/setfldw005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/setfldw005.cpp new file mode 100644 index 00000000000..5a136757bac --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw005/setfldw005.cpp @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + const char *sig; + const jboolean stat; + jfieldID fid; + const char *descr; +} field; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jfieldID actual_fid = NULL; +static field fields[] = { + {"fld0", "J", JNI_TRUE, NULL, "static long"}, + {"fld1", "J", JNI_FALSE, NULL, "long"}, + {"fld2", "F", JNI_TRUE, NULL, "static float"}, + {"fld3", "F", JNI_FALSE, NULL, "float"}, + {"fld4", "D", JNI_TRUE, NULL, "static double"}, + {"fld5", "D", JNI_FALSE, NULL, "double"}, + {"fld6", "Ljava/lang/Object;", JNI_TRUE, NULL, "static Object"}, + {"fld7", "Ljava/lang/Object;", JNI_FALSE, NULL, "Object"}, + {"fld8", "Z", JNI_TRUE, NULL, "static boolean"}, + {"fld9", "Z", JNI_FALSE, NULL, "boolean"}, + {"fld10", "B", JNI_TRUE, NULL, "static byte"}, + {"fld11", "B", JNI_FALSE, NULL, "byte"}, + {"fld12", "S", JNI_TRUE, NULL, "static short"}, + {"fld13", "S", JNI_FALSE, NULL, "short"}, + {"fld14", "C", JNI_TRUE, NULL, "static char"}, + {"fld15", "C", JNI_FALSE, NULL, "char"} +}; + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jlocation location, jclass field_klass, jobject obj, jfieldID field) { + if (printdump == JNI_TRUE) { + printf(">>> FieldAccess, field: 0x%p\n", field); + } + actual_fid = field; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setfldw005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setfldw005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setfldw005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + if ((err = (jvmti->GetCapabilities(&caps))) != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldAccess watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw005_getReady(JNIEnv *env, jclass cls) { + jvmtiError err; + size_t i; + + if (!caps.can_generate_field_access_events) { + return; + } + + for (i = 0; i < sizeof(fields) / sizeof(field); i++) { + if (fields[i].stat == JNI_TRUE) { + fields[i].fid = JNI_ENV_PTR(env)-> + GetStaticFieldID(JNI_ENV_ARG(env, cls), + fields[i].name, fields[i].sig); + } else { + fields[i].fid = JNI_ENV_PTR(env)-> + GetFieldID(JNI_ENV_ARG(env, cls), + fields[i].name, fields[i].sig); + } + if (fields[i].fid == NULL) { + printf("Unable to set access watch on %s fld%" PRIuPTR ", fieldID=0", + fields[i].descr, i); + } else { + if (printdump == JNI_TRUE) { + printf(">>> setting access watch on %s fld%" PRIuPTR ", fieldID=0x%p\n", + fields[i].descr, i, fields[i].fid); + } + err = jvmti->SetFieldAccessWatch(cls, fields[i].fid); + if (err != JVMTI_ERROR_NONE) { + printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw005_check(JNIEnv *env, + jclass cls, jint ind) { + if (printdump == JNI_TRUE) { + printf(">>> checking on %s fld%d\n", fields[ind].descr, ind); + } + if (actual_fid != fields[ind].fid) { + result = STATUS_FAILED; + printf("Field %s fld%d: thrown field ID expected=0x%p, actual=0x%p\n", + fields[ind].descr, ind, fields[ind].fid, actual_fid); + } + actual_fid = NULL; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw005_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/libsetfldw006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/libsetfldw006.c deleted file mode 100644 index 519df48d5ed..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/libsetfldw006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setfldw006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/libsetfldw006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/libsetfldw006.cpp new file mode 100644 index 00000000000..532b1d1a591 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/libsetfldw006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setfldw006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/setfldw006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/setfldw006.c deleted file mode 100644 index ce1d863db13..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/setfldw006.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - jfieldID fid; - char *f_name; - char *f_sig; - jboolean is_static; - jint expected; - jint count; -} watch_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int missesCount = 0; -static watch_info watches[] = { - { NULL, "staticBoolean", "Z", JNI_TRUE, 0, 0 }, - { NULL, "staticByte", "B", JNI_TRUE, 0, 0 }, - { NULL, "staticShort", "S", JNI_TRUE, 0, 0 }, - { NULL, "staticInt", "I", JNI_TRUE, 0, 0 }, - { NULL, "staticLong", "J", JNI_TRUE, 0, 0 }, - { NULL, "staticFloat", "F", JNI_TRUE, 0, 0 }, - { NULL, "staticDouble", "D", JNI_TRUE, 0, 0 }, - { NULL, "staticChar", "C", JNI_TRUE, 0, 0 }, - { NULL, "staticObject", "Ljava/lang/Object;", JNI_TRUE, 0, 0 }, - { NULL, "staticArrInt", "[I", JNI_TRUE, 0, 0 }, - - { NULL, "instanceBoolean", "Z", JNI_FALSE, 0, 0 }, - { NULL, "instanceByte", "B", JNI_FALSE, 0, 0 }, - { NULL, "instanceShort", "S", JNI_FALSE, 0, 0 }, - { NULL, "instanceInt", "I", JNI_FALSE, 0, 0 }, - { NULL, "instanceLong", "J", JNI_FALSE, 0, 0 }, - { NULL, "instanceFloat", "F", JNI_FALSE, 0, 0 }, - { NULL, "instanceDouble", "D", JNI_FALSE, 0, 0 }, - { NULL, "instanceChar", "C", JNI_FALSE, 0, 0 }, - { NULL, "instanceObject", "Ljava/lang/Object;", JNI_FALSE, 0, 0 }, - { NULL, "instanceArrInt", "[I", JNI_FALSE, 0, 0 } -}; - - -void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jlocation location, jclass field_klass, jobject obj, jfieldID field) { - size_t i; - - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (field == watches[i].fid) { - watches[i].count++; - return; - } - } - missesCount++; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setfldw006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setfldw006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setfldw006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - if ((err = ((*jvmti)->GetCapabilities(jvmti, &caps))) != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_access_events) { - callbacks.FieldAccess = &FieldAccess; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldAccess watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw006_getReady(JNIEnv *env, - jclass cls, jint n) { - jvmtiError err; - size_t i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_generate_field_access_events) { - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> setting field access watches ...\n"); - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (watches[i].is_static == JNI_TRUE) { - watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } else { - watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( - JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); - } - err = (*jvmti)->SetFieldAccessWatch(jvmti, cls, watches[i].fid); - if (err == JVMTI_ERROR_NONE) { - watches[i].expected = n; - } else { - printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_ACCESS, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetFieldAccessWatch_setfldw006_check(JNIEnv *env, - jclass cls, jboolean flag) { - size_t i; - jint expected; - - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (printdump == JNI_TRUE && watches[i].count > 0) { - printf(">>> field %s accesses: %d\n", - watches[i].f_name, watches[i].count); - } - expected = (flag == JNI_TRUE) ? watches[i].expected : 0; - if (watches[i].count != expected) { - printf("(%s) wrong number of field access events: %d,", - watches[i].f_name, watches[i].count); - printf(" expected: %d\n", expected); - result = STATUS_FAILED; - } - watches[i].count = 0; - } - - if (missesCount != 0) { - printf("%d unexpected field access catches\n", missesCount); - missesCount = 0; - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/setfldw006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/setfldw006.cpp new file mode 100644 index 00000000000..599b7c870a6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw006/setfldw006.cpp @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + jfieldID fid; + const char *f_name; + const char *f_sig; + jboolean is_static; + jint expected; + jint count; +} watch_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int missesCount = 0; +static watch_info watches[] = { + { NULL, "staticBoolean", "Z", JNI_TRUE, 0, 0 }, + { NULL, "staticByte", "B", JNI_TRUE, 0, 0 }, + { NULL, "staticShort", "S", JNI_TRUE, 0, 0 }, + { NULL, "staticInt", "I", JNI_TRUE, 0, 0 }, + { NULL, "staticLong", "J", JNI_TRUE, 0, 0 }, + { NULL, "staticFloat", "F", JNI_TRUE, 0, 0 }, + { NULL, "staticDouble", "D", JNI_TRUE, 0, 0 }, + { NULL, "staticChar", "C", JNI_TRUE, 0, 0 }, + { NULL, "staticObject", "Ljava/lang/Object;", JNI_TRUE, 0, 0 }, + { NULL, "staticArrInt", "[I", JNI_TRUE, 0, 0 }, + + { NULL, "instanceBoolean", "Z", JNI_FALSE, 0, 0 }, + { NULL, "instanceByte", "B", JNI_FALSE, 0, 0 }, + { NULL, "instanceShort", "S", JNI_FALSE, 0, 0 }, + { NULL, "instanceInt", "I", JNI_FALSE, 0, 0 }, + { NULL, "instanceLong", "J", JNI_FALSE, 0, 0 }, + { NULL, "instanceFloat", "F", JNI_FALSE, 0, 0 }, + { NULL, "instanceDouble", "D", JNI_FALSE, 0, 0 }, + { NULL, "instanceChar", "C", JNI_FALSE, 0, 0 }, + { NULL, "instanceObject", "Ljava/lang/Object;", JNI_FALSE, 0, 0 }, + { NULL, "instanceArrInt", "[I", JNI_FALSE, 0, 0 } +}; + + +void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jlocation location, jclass field_klass, jobject obj, jfieldID field) { + size_t i; + + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (field == watches[i].fid) { + watches[i].count++; + return; + } + } + missesCount++; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setfldw006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setfldw006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setfldw006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + if ((err = (jvmti->GetCapabilities(&caps))) != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_access_events) { + callbacks.FieldAccess = &FieldAccess; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldAccess watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw006_getReady(JNIEnv *env, + jclass cls, jint n) { + jvmtiError err; + size_t i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_generate_field_access_events) { + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> setting field access watches ...\n"); + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (watches[i].is_static == JNI_TRUE) { + watches[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } else { + watches[i].fid = JNI_ENV_PTR(env)->GetFieldID( + JNI_ENV_ARG(env, cls), watches[i].f_name, watches[i].f_sig); + } + err = jvmti->SetFieldAccessWatch(cls, watches[i].fid); + if (err == JVMTI_ERROR_NONE) { + watches[i].expected = n; + } else { + printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_ACCESS, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetFieldAccessWatch_setfldw006_check(JNIEnv *env, + jclass cls, jboolean flag) { + size_t i; + jint expected; + + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (printdump == JNI_TRUE && watches[i].count > 0) { + printf(">>> field %s accesses: %d\n", + watches[i].f_name, watches[i].count); + } + expected = (flag == JNI_TRUE) ? watches[i].expected : 0; + if (watches[i].count != expected) { + printf("(%s) wrong number of field access events: %d,", + watches[i].f_name, watches[i].count); + printf(" expected: %d\n", expected); + result = STATUS_FAILED; + } + watches[i].count = 0; + } + + if (missesCount != 0) { + printf("%d unexpected field access catches\n", missesCount); + missesCount = 0; + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/libsetfmodw001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/libsetfmodw001.c deleted file mode 100644 index db2872b46fd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/libsetfmodw001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setfmodw001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/libsetfmodw001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/libsetfmodw001.cpp new file mode 100644 index 00000000000..444a44b647c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/libsetfmodw001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setfmodw001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/setfmodw001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/setfmodw001.c deleted file mode 100644 index 0844f00892f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/setfmodw001.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - char *class; - char *name; - char *sig; - int stat; - jfieldID fid; - jfieldID thrown_fid; -} field; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static field fields[] = { - {"nsk/jvmti/SetFieldModificationWatch/setfmodw001", "fld0", "I", 0, NULL, NULL}, - {"nsk/jvmti/SetFieldModificationWatch/setfmodw001", "fld1", "I", 1, NULL, NULL}, - {"nsk/jvmti/SetFieldModificationWatch/setfmodw001", "fld2", - "Lnsk/jvmti/SetFieldModificationWatch/setfmodw001a;", 0, NULL, NULL}, - {"nsk/jvmti/SetFieldModificationWatch/setfmodw001a", "fld3", "[I", 0, NULL, NULL}, - {"nsk/jvmti/SetFieldModificationWatch/setfmodw001b", "fld4", "F", 0, NULL, NULL}, -}; - -void setWatch(JNIEnv *env, jint ind) { - jclass cls; - jvmtiError err; - - cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, fields[ind].class)); - if (fields[ind].fid == NULL) { - if (fields[ind].stat) { - fields[ind].fid = - JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - fields[ind].name, fields[ind].sig); - } else { - fields[ind].fid = - JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), - fields[ind].name, fields[ind].sig); - } - } - - err = (*jvmti)->SetFieldModificationWatch(jvmti, cls, fields[ind].fid); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_generate_field_modification_events) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(SetFieldModificationWatch#%d) unexpected error: %s (%d)\n", - ind, TranslateError(err), err); - result = STATUS_FAILED; - } -} - -void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, - jfieldID field, char sig, jvalue new_value) { - - char *fld_name = NULL; - jint fld_ind = 0; - size_t len = 0; - jvmtiError err = (*jvmti_env)->GetFieldName(jvmti_env, field_klass, field, - &fld_name, NULL, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Error in GetFieldName: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - return; - } - if (fld_name == NULL) { - printf("GetFieldName returned NULL field name\n"); - result = STATUS_FAILED; - return; - } - len = strlen(fld_name); - /* All field names have the same length and end with a digit. */ - if (len != strlen(fields[0].name) || !isdigit(fld_name[len - 1])) { - printf("GetFieldName returned unexpected field name: %s\n", fld_name); - result = STATUS_FAILED; - return; - } - fld_ind = (int)(fld_name[len - 1] - '0'); /* last digit is index in the array */ - fields[fld_ind].thrown_fid = field; - (*jvmti)->Deallocate(jvmti_env, (unsigned char*) fld_name); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setfmodw001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setfmodw001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setfmodw001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_modification_events) { - callbacks.FieldModification = &FieldModification; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_MODIFICATION, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldModification watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw001_setWatch(JNIEnv *env, - jclass cls, jint fld_ind) { - setWatch(env, fld_ind); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw001_touchfld0(JNIEnv *env, - jclass cls) { - setWatch(env, (jint)0); - JNI_ENV_PTR(env)->SetIntField(JNI_ENV_ARG(env, cls), fields[0].fid, (jint)2000); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw001_check(JNIEnv *env, - jclass cls, jint fld_ind, jboolean flag) { - jfieldID thrown_fid = fields[fld_ind].thrown_fid; - - if (caps.can_generate_field_modification_events) { - if (flag == JNI_FALSE && thrown_fid != NULL) { - result = STATUS_FAILED; - printf("(Field %d) FieldModification without modification watch set\n", - fld_ind); - } else if (flag == JNI_TRUE && thrown_fid != fields[fld_ind].fid) { - result = STATUS_FAILED; - printf("(Field %d) thrown field ID expected: 0x%p, got: 0x%p\n", - fld_ind, fields[fld_ind].fid, thrown_fid); - } - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw001_getRes(JNIEnv *env, - jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/setfmodw001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/setfmodw001.cpp new file mode 100644 index 00000000000..e6bf872145a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw001/setfmodw001.cpp @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *klass; + const char *name; + const char *sig; + int stat; + jfieldID fid; + jfieldID thrown_fid; +} field; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static field fields[] = { + {"nsk/jvmti/SetFieldModificationWatch/setfmodw001", "fld0", "I", 0, NULL, NULL}, + {"nsk/jvmti/SetFieldModificationWatch/setfmodw001", "fld1", "I", 1, NULL, NULL}, + {"nsk/jvmti/SetFieldModificationWatch/setfmodw001", "fld2", + "Lnsk/jvmti/SetFieldModificationWatch/setfmodw001a;", 0, NULL, NULL}, + {"nsk/jvmti/SetFieldModificationWatch/setfmodw001a", "fld3", "[I", 0, NULL, NULL}, + {"nsk/jvmti/SetFieldModificationWatch/setfmodw001b", "fld4", "F", 0, NULL, NULL}, +}; + +void setWatch(JNIEnv *env, jint ind) { + jclass cls; + jvmtiError err; + + cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, fields[ind].klass)); + if (fields[ind].fid == NULL) { + if (fields[ind].stat) { + fields[ind].fid = + JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + fields[ind].name, fields[ind].sig); + } else { + fields[ind].fid = + JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), + fields[ind].name, fields[ind].sig); + } + } + + err = jvmti->SetFieldModificationWatch(cls, fields[ind].fid); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_generate_field_modification_events) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(SetFieldModificationWatch#%d) unexpected error: %s (%d)\n", + ind, TranslateError(err), err); + result = STATUS_FAILED; + } +} + +void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, + jfieldID field, char sig, jvalue new_value) { + + char *fld_name = NULL; + jint fld_ind = 0; + size_t len = 0; + jvmtiError err = jvmti_env->GetFieldName(field_klass, field, + &fld_name, NULL, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Error in GetFieldName: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + return; + } + if (fld_name == NULL) { + printf("GetFieldName returned NULL field name\n"); + result = STATUS_FAILED; + return; + } + len = strlen(fld_name); + /* All field names have the same length and end with a digit. */ + if (len != strlen(fields[0].name) || !isdigit(fld_name[len - 1])) { + printf("GetFieldName returned unexpected field name: %s\n", fld_name); + result = STATUS_FAILED; + return; + } + fld_ind = (int)(fld_name[len - 1] - '0'); /* last digit is index in the array */ + fields[fld_ind].thrown_fid = field; + jvmti_env->Deallocate((unsigned char*) fld_name); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setfmodw001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setfmodw001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setfmodw001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_modification_events) { + callbacks.FieldModification = &FieldModification; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_MODIFICATION, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldModification watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw001_setWatch(JNIEnv *env, + jclass cls, jint fld_ind) { + setWatch(env, fld_ind); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw001_touchfld0(JNIEnv *env, + jclass cls) { + setWatch(env, (jint)0); + JNI_ENV_PTR(env)->SetIntField(JNI_ENV_ARG(env, cls), fields[0].fid, (jint)2000); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw001_check(JNIEnv *env, + jclass cls, jint fld_ind, jboolean flag) { + jfieldID thrown_fid = fields[fld_ind].thrown_fid; + + if (caps.can_generate_field_modification_events) { + if (flag == JNI_FALSE && thrown_fid != NULL) { + result = STATUS_FAILED; + printf("(Field %d) FieldModification without modification watch set\n", + fld_ind); + } else if (flag == JNI_TRUE && thrown_fid != fields[fld_ind].fid) { + result = STATUS_FAILED; + printf("(Field %d) thrown field ID expected: 0x%p, got: 0x%p\n", + fld_ind, fields[fld_ind].fid, thrown_fid); + } + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw001_getRes(JNIEnv *env, + jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/libsetfmodw002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/libsetfmodw002.c deleted file mode 100644 index dc9cdeb6152..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/libsetfmodw002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setfmodw002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/libsetfmodw002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/libsetfmodw002.cpp new file mode 100644 index 00000000000..0caf7e34957 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/libsetfmodw002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setfmodw002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/setfmodw002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/setfmodw002.c deleted file mode 100644 index 8951243446c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/setfmodw002.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; - -void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, - jfieldID field, char sig, jvalue new_value) { -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setfmodw002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setfmodw002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setfmodw002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_modification_events) { - callbacks.FieldModification = &FieldModification; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_MODIFICATION, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldModification watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw002_check(JNIEnv *env, - jclass cls) { - jvmtiError err; - jfieldID fid; - - fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - "fld1", "I"); - - if (!caps.can_generate_field_modification_events) { - err = (*jvmti)->SetFieldModificationWatch(jvmti, cls, fid); - if (err != JVMTI_ERROR_MUST_POSSESS_CAPABILITY) { - result = STATUS_FAILED; - printf("Failed to return JVMTI_ERROR_MUST_POSSESS_CAPABILITY:"); - printf(" %s (%d)\n", TranslateError(err), err); - } - } else { - err = (*jvmti)->SetFieldModificationWatch(jvmti, NULL, fid); - if (err != JVMTI_ERROR_INVALID_CLASS) { - result = STATUS_FAILED; - printf("Failed to return JVMTI_ERROR_INVALID_CLASS: %s (%d)\n", - TranslateError(err), err); - } - - err = (*jvmti)->SetFieldModificationWatch(jvmti, cls, NULL); - if (err != JVMTI_ERROR_INVALID_FIELDID) { - result = STATUS_FAILED; - printf("Failed to return JVMTI_ERROR_INVALID_FIELDID: %s (%d)\n", - TranslateError(err), err); - } - - err = ((*jvmti)->SetFieldModificationWatch(jvmti, cls, fid)); - if (err != JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(SetFieldModificationWatch) unexpected error: %s (%d)\n", - TranslateError(err), err); - } else { - err = (*jvmti)->SetFieldModificationWatch(jvmti, cls, fid); - if (err != JVMTI_ERROR_DUPLICATE) { - result = STATUS_FAILED; - printf("Failed to return JVMTI_ERROR_DUPLICATE: %s (%d)\n", - TranslateError(err), err); - } - } - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/setfmodw002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/setfmodw002.cpp new file mode 100644 index 00000000000..373c240bf40 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw002/setfmodw002.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; + +void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, + jfieldID field, char sig, jvalue new_value) { +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setfmodw002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setfmodw002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setfmodw002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_modification_events) { + callbacks.FieldModification = &FieldModification; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_MODIFICATION, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldModification watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw002_check(JNIEnv *env, + jclass cls) { + jvmtiError err; + jfieldID fid; + + fid = JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + "fld1", "I"); + + if (!caps.can_generate_field_modification_events) { + err = jvmti->SetFieldModificationWatch(cls, fid); + if (err != JVMTI_ERROR_MUST_POSSESS_CAPABILITY) { + result = STATUS_FAILED; + printf("Failed to return JVMTI_ERROR_MUST_POSSESS_CAPABILITY:"); + printf(" %s (%d)\n", TranslateError(err), err); + } + } else { + err = jvmti->SetFieldModificationWatch(NULL, fid); + if (err != JVMTI_ERROR_INVALID_CLASS) { + result = STATUS_FAILED; + printf("Failed to return JVMTI_ERROR_INVALID_CLASS: %s (%d)\n", + TranslateError(err), err); + } + + err = jvmti->SetFieldModificationWatch(cls, NULL); + if (err != JVMTI_ERROR_INVALID_FIELDID) { + result = STATUS_FAILED; + printf("Failed to return JVMTI_ERROR_INVALID_FIELDID: %s (%d)\n", + TranslateError(err), err); + } + + err = (jvmti->SetFieldModificationWatch(cls, fid)); + if (err != JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(SetFieldModificationWatch) unexpected error: %s (%d)\n", + TranslateError(err), err); + } else { + err = jvmti->SetFieldModificationWatch(cls, fid); + if (err != JVMTI_ERROR_DUPLICATE) { + result = STATUS_FAILED; + printf("Failed to return JVMTI_ERROR_DUPLICATE: %s (%d)\n", + TranslateError(err), err); + } + } + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/libsetfmodw003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/libsetfmodw003.c deleted file mode 100644 index 163aac6df41..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/libsetfmodw003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setfmodw003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/libsetfmodw003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/libsetfmodw003.cpp new file mode 100644 index 00000000000..782ec5e8944 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/libsetfmodw003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setfmodw003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/setfmodw003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/setfmodw003.c deleted file mode 100644 index 411b4188323..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/setfmodw003.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - const char *name; - const char sig; - const jboolean stat; - const jint val; - jfieldID fid; -} field; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jfieldID actual_fid = NULL; -static char actual_sig = '\0'; -static jint actual_val = 0; -static field flds[] = { - {"fld0", 'I', JNI_TRUE, 42, NULL}, - {"fld1", 'I', JNI_TRUE, 43, NULL}, - {"fld2", 'I', JNI_FALSE, 44, NULL}, - {"fld3", 'I', JNI_FALSE, 45, NULL} -}; - -void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, - jfieldID field, char sig, jvalue new_value) { - if (printdump == JNI_TRUE) { - printf(">>> FieldModification, field: 0x%p", field); - printf(", signature: '%c', new value: %d\n", sig, new_value.i); - } - actual_fid = field; - actual_sig = sig; - actual_val = new_value.i; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setfmodw003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setfmodw003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setfmodw003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_modification_events) { - callbacks.FieldModification = &FieldModification; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldModification watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw003_getReady(JNIEnv *env, - jclass cls) { - jvmtiError err; - size_t i; - - if (!caps.can_generate_field_modification_events) { - return; - } - - for (i = 0; i < sizeof(flds) / sizeof(field); i++) { - if (flds[i].stat == JNI_TRUE) { - flds[i].fid = - JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - flds[i].name, "I"); - } else { - flds[i].fid = - JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), - flds[i].name, "I"); - } - if (flds[i].fid == NULL) { - printf("Unable to set field modif. watch on fld%" PRIuPTR ", fieldID=0", i); - } else { - if (printdump == JNI_TRUE) { - printf(">>> setting modification watch on fld%" PRIuPTR, i); - printf(", fieldID=0x%p\n", flds[i].fid); - } - err = (*jvmti)->SetFieldModificationWatch(jvmti, cls, flds[i].fid); - if (err != JVMTI_ERROR_NONE) { - printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error:", i); - printf(" %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_MODIFICATION, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw003_check(JNIEnv *env, - jclass cls, jint ind) { - if (!caps.can_generate_field_modification_events) { - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> checking on fld%d\n", ind); - } - if (actual_fid != flds[ind].fid) { - result = STATUS_FAILED; - printf("Field %s: thrown field ID expected=0x%p, actual=0x%p\n", - flds[ind].name, flds[ind].fid, actual_fid); - } - if (actual_sig != flds[ind].sig) { - result = STATUS_FAILED; - printf("Field %s: thrown sygnature type expected='%c', actual='%c'\n", - flds[ind].name, flds[ind].sig, actual_sig); - } - if (actual_val != flds[ind].val) { - result = STATUS_FAILED; - printf("Field %s: thrown new value expected=%d, actual=%d\n", - flds[ind].name, flds[ind].val, actual_val); - } - actual_fid = NULL; - actual_sig = '\0'; - actual_val = 0; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw003_getRes(JNIEnv *env, - jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/setfmodw003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/setfmodw003.cpp new file mode 100644 index 00000000000..0fb787a0c18 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw003/setfmodw003.cpp @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + const char sig; + const jboolean stat; + const jint val; + jfieldID fid; +} field; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jfieldID actual_fid = NULL; +static char actual_sig = '\0'; +static jint actual_val = 0; +static field flds[] = { + {"fld0", 'I', JNI_TRUE, 42, NULL}, + {"fld1", 'I', JNI_TRUE, 43, NULL}, + {"fld2", 'I', JNI_FALSE, 44, NULL}, + {"fld3", 'I', JNI_FALSE, 45, NULL} +}; + +void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, + jfieldID field, char sig, jvalue new_value) { + if (printdump == JNI_TRUE) { + printf(">>> FieldModification, field: 0x%p", field); + printf(", signature: '%c', new value: %d\n", sig, new_value.i); + } + actual_fid = field; + actual_sig = sig; + actual_val = new_value.i; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setfmodw003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setfmodw003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setfmodw003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_modification_events) { + callbacks.FieldModification = &FieldModification; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldModification watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw003_getReady(JNIEnv *env, + jclass cls) { + jvmtiError err; + size_t i; + + if (!caps.can_generate_field_modification_events) { + return; + } + + for (i = 0; i < sizeof(flds) / sizeof(field); i++) { + if (flds[i].stat == JNI_TRUE) { + flds[i].fid = + JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + flds[i].name, "I"); + } else { + flds[i].fid = + JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), + flds[i].name, "I"); + } + if (flds[i].fid == NULL) { + printf("Unable to set field modif. watch on fld%" PRIuPTR ", fieldID=0", i); + } else { + if (printdump == JNI_TRUE) { + printf(">>> setting modification watch on fld%" PRIuPTR, i); + printf(", fieldID=0x%p\n", flds[i].fid); + } + err = jvmti->SetFieldModificationWatch(cls, flds[i].fid); + if (err != JVMTI_ERROR_NONE) { + printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error:", i); + printf(" %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_MODIFICATION, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw003_check(JNIEnv *env, + jclass cls, jint ind) { + if (!caps.can_generate_field_modification_events) { + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> checking on fld%d\n", ind); + } + if (actual_fid != flds[ind].fid) { + result = STATUS_FAILED; + printf("Field %s: thrown field ID expected=0x%p, actual=0x%p\n", + flds[ind].name, flds[ind].fid, actual_fid); + } + if (actual_sig != flds[ind].sig) { + result = STATUS_FAILED; + printf("Field %s: thrown sygnature type expected='%c', actual='%c'\n", + flds[ind].name, flds[ind].sig, actual_sig); + } + if (actual_val != flds[ind].val) { + result = STATUS_FAILED; + printf("Field %s: thrown new value expected=%d, actual=%d\n", + flds[ind].name, flds[ind].val, actual_val); + } + actual_fid = NULL; + actual_sig = '\0'; + actual_val = 0; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw003_getRes(JNIEnv *env, + jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/libsetfmodw004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/libsetfmodw004.c deleted file mode 100644 index 4aeedd96b2f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/libsetfmodw004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setfmodw004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/libsetfmodw004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/libsetfmodw004.cpp new file mode 100644 index 00000000000..330e1d01ef8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/libsetfmodw004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setfmodw004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/setfmodw004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/setfmodw004.c deleted file mode 100644 index 0e0e4f20d29..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/setfmodw004.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - const char *name; - const char sig; - const jboolean stat; - const jint val; - jfieldID fid; -} field; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jfieldID actual_fid = NULL; -static char actual_sig = '\0'; -static jint actual_val = 0; -static field flds[] = { - {"fld0", 'I', JNI_TRUE, 96, NULL}, - {"fld1", 'I', JNI_TRUE, 97, NULL}, - {"fld2", 'I', JNI_FALSE, 98, NULL}, - {"fld3", 'I', JNI_FALSE, 99, NULL} -}; - -void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, - jfieldID field, char sig, jvalue new_value) { - if (printdump == JNI_TRUE) { - printf(">>> FieldModification, field: 0x%p", field); - printf(", signature: '%c', new value: %d\n", sig, new_value.i); - } - actual_fid = field; - actual_sig = sig; - actual_val = new_value.i; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setfmodw004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setfmodw004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setfmodw004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_modification_events) { - callbacks.FieldModification = &FieldModification; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldModification watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_SetFieldModificationWatch_setfmodw004_getReady(JNIEnv *env, jclass cls) { - jvmtiError err; - size_t i; - - if (!caps.can_generate_field_modification_events) { - return; - } - - for (i = 0; i < sizeof(flds) / sizeof(field); i++) { - if (flds[i].stat == JNI_TRUE) { - flds[i].fid = - JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - flds[i].name, "I"); - } else { - flds[i].fid = - JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), - flds[i].name, "I"); - } - if (flds[i].fid == NULL) { - printf("Unable to set field modif. watch on fld%" PRIuPTR ", fieldID=0", i); - } else { - if (printdump == JNI_TRUE) { - printf(">>> setting modification watch on fld%" PRIuPTR, i); - printf(", fieldID=0x%p\n", flds[i].fid); - } - err = (*jvmti)->SetFieldModificationWatch(jvmti, cls, flds[i].fid); - if (err != JVMTI_ERROR_NONE) { - printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error:", i); - printf(" %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_MODIFICATION, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw004_check(JNIEnv *env, - jclass cls, jint ind) { - if (!caps.can_generate_field_modification_events) { - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> checking on fld%d\n", ind); - } - if (actual_fid != flds[ind].fid) { - result = STATUS_FAILED; - printf("Field %s: thrown field ID expected=0x%p, actual=0x%p\n", - flds[ind].name, flds[ind].fid, actual_fid); - } - if (actual_sig != flds[ind].sig) { - result = STATUS_FAILED; - printf("Field %s: thrown sygnature type expected='%c', actual='%c'\n", - flds[ind].name, flds[ind].sig, actual_sig); - } - if (actual_val != flds[ind].val) { - result = STATUS_FAILED; - printf("Field %s: thrown new value expected=%d, actual=%d\n", - flds[ind].name, flds[ind].val, actual_val); - } - actual_fid = NULL; - actual_sig = '\0'; - actual_val = 0; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw004_getRes(JNIEnv *env, - jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/setfmodw004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/setfmodw004.cpp new file mode 100644 index 00000000000..fa1c7905281 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw004/setfmodw004.cpp @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + const char sig; + const jboolean stat; + const jint val; + jfieldID fid; +} field; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jfieldID actual_fid = NULL; +static char actual_sig = '\0'; +static jint actual_val = 0; +static field flds[] = { + {"fld0", 'I', JNI_TRUE, 96, NULL}, + {"fld1", 'I', JNI_TRUE, 97, NULL}, + {"fld2", 'I', JNI_FALSE, 98, NULL}, + {"fld3", 'I', JNI_FALSE, 99, NULL} +}; + +void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, + jfieldID field, char sig, jvalue new_value) { + if (printdump == JNI_TRUE) { + printf(">>> FieldModification, field: 0x%p", field); + printf(", signature: '%c', new value: %d\n", sig, new_value.i); + } + actual_fid = field; + actual_sig = sig; + actual_val = new_value.i; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setfmodw004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setfmodw004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setfmodw004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_modification_events) { + callbacks.FieldModification = &FieldModification; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldModification watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_SetFieldModificationWatch_setfmodw004_getReady(JNIEnv *env, jclass cls) { + jvmtiError err; + size_t i; + + if (!caps.can_generate_field_modification_events) { + return; + } + + for (i = 0; i < sizeof(flds) / sizeof(field); i++) { + if (flds[i].stat == JNI_TRUE) { + flds[i].fid = + JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + flds[i].name, "I"); + } else { + flds[i].fid = + JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), + flds[i].name, "I"); + } + if (flds[i].fid == NULL) { + printf("Unable to set field modif. watch on fld%" PRIuPTR ", fieldID=0", i); + } else { + if (printdump == JNI_TRUE) { + printf(">>> setting modification watch on fld%" PRIuPTR, i); + printf(", fieldID=0x%p\n", flds[i].fid); + } + err = jvmti->SetFieldModificationWatch(cls, flds[i].fid); + if (err != JVMTI_ERROR_NONE) { + printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error:", i); + printf(" %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_MODIFICATION, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw004_check(JNIEnv *env, + jclass cls, jint ind) { + if (!caps.can_generate_field_modification_events) { + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> checking on fld%d\n", ind); + } + if (actual_fid != flds[ind].fid) { + result = STATUS_FAILED; + printf("Field %s: thrown field ID expected=0x%p, actual=0x%p\n", + flds[ind].name, flds[ind].fid, actual_fid); + } + if (actual_sig != flds[ind].sig) { + result = STATUS_FAILED; + printf("Field %s: thrown sygnature type expected='%c', actual='%c'\n", + flds[ind].name, flds[ind].sig, actual_sig); + } + if (actual_val != flds[ind].val) { + result = STATUS_FAILED; + printf("Field %s: thrown new value expected=%d, actual=%d\n", + flds[ind].name, flds[ind].val, actual_val); + } + actual_fid = NULL; + actual_sig = '\0'; + actual_val = 0; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw004_getRes(JNIEnv *env, + jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/libsetfmodw005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/libsetfmodw005.c deleted file mode 100644 index 8a0958d1df2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/libsetfmodw005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setfmodw005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/libsetfmodw005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/libsetfmodw005.cpp new file mode 100644 index 00000000000..204d998c80e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/libsetfmodw005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setfmodw005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/setfmodw005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/setfmodw005.c deleted file mode 100644 index 71051eef7d7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/setfmodw005.c +++ /dev/null @@ -1,403 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - const char *name; - const char *sig; - const jboolean stat; - const char *descr; - jfieldID fid; - jvalue val; -} field; - -static jvmtiEnv *jvmti; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jfieldID actual_fid = NULL; -static char actual_sig = '\0'; -static jvalue actual_val = {0L}; -static field flds[] = { - {"fld0", "J", JNI_TRUE, "static long", NULL, {0} }, - {"fld1", "J", JNI_FALSE, "long", NULL, {0} }, - {"fld2", "F", JNI_TRUE, "static float", NULL, {0} }, - {"fld3", "F", JNI_FALSE, "float", NULL, {0} }, - {"fld4", "D", JNI_TRUE, "static double", NULL, {0} }, - {"fld5", "D", JNI_FALSE, "double", NULL, {0} }, - {"fld6", "Ljava/lang/Object;", JNI_TRUE, "static Object", NULL, {0} }, - {"fld7", "Ljava/lang/Object;", JNI_FALSE, "Object", NULL, {0} }, - {"fld8", "Z", JNI_TRUE, "static boolean", NULL, {0} }, - {"fld9", "Z", JNI_FALSE, "boolean", NULL, {0} }, - {"fld10", "B", JNI_TRUE, "static byte", NULL, {0} }, - {"fld11", "B", JNI_FALSE, "byte", NULL, {0} }, - {"fld12", "S", JNI_TRUE, "static short", NULL, {0} }, - {"fld13", "S", JNI_FALSE, "short", NULL, {0} }, - {"fld14", "C", JNI_TRUE, "static char", NULL, {0} }, - {"fld15", "C", JNI_FALSE, "char", NULL, {0} } -}; - -void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, - jfieldID field, char sig, jvalue new_value) { - actual_fid = field; - actual_sig = sig; - actual_val = new_value; - if (actual_sig == 'L') { - actual_val.l = - JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, - actual_val.l)); - } - if (printdump == JNI_TRUE) { - printf(">>> FieldModification, field: 0x%p", actual_fid); - switch (actual_sig) { - case 'J': - printf(", sig: 'J', val: 0x%x%08x\n", - (jint)(actual_val.j >> 32), (jint)actual_val.j); - break; - case 'F': - printf(", sig: 'F', val: %.3f\n", (double)actual_val.f); - break; - case 'D': - printf(", sig: 'D', val: %f\n", (double)actual_val.d); - break; - case 'L': - printf(", sig: 'L', val: 0x%p\n", actual_val.l); - break; - case 'Z': - printf(", sig: 'Z', val: 0x%x\n", actual_val.z); - break; - case 'B': - printf(", sig: 'B', val: %d\n", actual_val.b); - break; - case 'S': - printf(", sig: 'S', val: %d\n", actual_val.s); - break; - case 'C': - printf(", sig: 'C', val: 0x%x\n", actual_val.c); - break; - case 'I': - printf(", sig: 'I', val: %d\n", actual_val.i); - break; - default: - printf(", sig: , val: 0x%x%08x\n", - (jint)(actual_val.j >> 32), (jint)actual_val.j); - break; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setfmodw005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setfmodw005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setfmodw005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_modification_events) { - callbacks.FieldModification = &FieldModification; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldModification watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw005_getReady(JNIEnv *env, - jclass cls, jobject obj1, jobject obj2) { - jvmtiError err; - size_t i; - - if (!caps.can_generate_field_modification_events) { - return; - } - -#ifdef _MSC_VER - flds[0].val.j = 0x1234567890abcdefi64; - flds[1].val.j = 0xfedcba0987654321i64; -#else - flds[0].val.j = 0x1234567890abcdefULL; - flds[1].val.j = 0xfedcba0987654321ULL; -#endif - flds[2].val.f = 123.456F; - flds[3].val.f = 654.321F; - flds[4].val.d = 123456.654321; - flds[5].val.d = 654321.123456; - flds[6].val.l = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, obj1)); - flds[7].val.l = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, obj2)); - flds[8].val.z = JNI_TRUE; - flds[9].val.z = JNI_FALSE; - flds[10].val.b = 123; - flds[11].val.b = -123; - flds[12].val.s = 12345; - flds[13].val.s = -12345; - flds[14].val.c = 0xabcd; - flds[15].val.c = 0xdcba; - for (i = 0; i < sizeof(flds) / sizeof(field); i++) { - if (flds[i].stat == JNI_TRUE) { - flds[i].fid = - JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - flds[i].name, flds[i].sig); - } else { - flds[i].fid = - JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), - flds[i].name, flds[i].sig); - } - if (flds[i].fid == NULL) { - printf("Unable to set modification watch on %s fld%" PRIuPTR ", fieldID=0", - flds[i].descr, i); - } else { - if (printdump == JNI_TRUE) { - printf(">>> setting modification watch on %s", flds[i].descr); - printf(" fld%" PRIuPTR ", fieldID=0x%p\n", i, flds[i].fid); - } - err = (*jvmti)->SetFieldModificationWatch(jvmti, cls, flds[i].fid); - if (err != JVMTI_ERROR_NONE) { - printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error:", i); - printf(" %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_MODIFICATION, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw005_check(JNIEnv *env, - jclass cls, jint ind) { - int flag_err = 0; - - if (!caps.can_generate_field_modification_events) { - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> checking on %s fld%d\n", flds[ind].descr, ind); - printf(">>> new value expected=0x%08x%08x, actual=0x%08x%08x\n", - (jint)(flds[ind].val.j >> 32), (jint)flds[ind].val.j, - (jint)(actual_val.j >> 32), (jint)actual_val.j); - } - if (actual_fid != flds[ind].fid) { - result = STATUS_FAILED; - if (!flag_err) { - printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); - flag_err = 1; - } - printf(" field ID expected=0x%p, actual=0x%p\n", - flds[ind].fid, actual_fid); - } - if (actual_sig != flds[ind].sig[0]) { - result = STATUS_FAILED; - if (!flag_err) { - printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); - flag_err = 1; - } - printf(" signature expected=%c, actual=%c\n", - flds[ind].sig[0], actual_sig); - } - switch (flds[ind].sig[0]) { - case 'J': - if (actual_val.j != flds[ind].val.j) { - result = STATUS_FAILED; - if (!flag_err) { - printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); - flag_err = 1; - } - printf(" new value expected=0x%x%08x, actual=0x%x%08x\n", - (jint)(flds[ind].val.j >> 32), (jint)flds[ind].val.j, - (jint)(actual_val.j >> 32), (jint)actual_val.j); - } - break; - case 'F': - if (actual_val.f != flds[ind].val.f) { - result = STATUS_FAILED; - if (!flag_err) { - printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); - flag_err = 1; - } - printf(" new value expected=%f, actual=%f\n", - (double)flds[ind].val.f, (double)actual_val.f); - } - break; - case 'D': - if (actual_val.d != flds[ind].val.d) { - result = STATUS_FAILED; - if (!flag_err) { - printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); - flag_err = 1; - } - printf(" new value expected=%f, actual=%f\n", - (double)flds[ind].val.d, (double)actual_val.d); - } - break; - case 'L': - if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, actual_val.l), - flds[ind].val.l) != JNI_TRUE) { - result = STATUS_FAILED; - if (!flag_err) { - printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); - flag_err = 1; - } - printf(" new value is not the same as expected\n"); - } - break; - case 'Z': - if (actual_val.z != flds[ind].val.z) { - result = STATUS_FAILED; - if (!flag_err) { - printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); - flag_err = 1; - } - printf(" new value expected=0x%x, actual=0x%x\n", - flds[ind].val.z, actual_val.z); - } - break; - case 'B': - if (actual_val.b != flds[ind].val.b) { - result = STATUS_FAILED; - if (!flag_err) { - printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); - flag_err = 1; - } - printf(" new value expected=%d, actual=%d\n", - flds[ind].val.b, actual_val.b); - } - break; - case 'S': - if (actual_val.s != flds[ind].val.s) { - result = STATUS_FAILED; - if (!flag_err) { - printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); - flag_err = 1; - } - printf(" new value expected=%d, actual=%d\n", - flds[ind].val.s, actual_val.s); - } - break; - case 'C': - if (actual_val.c != flds[ind].val.c) { - result = STATUS_FAILED; - if (!flag_err) { - printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); - flag_err = 1; - } - printf(" new value expected=0x%x, actual=0x%x\n", - flds[ind].val.c, actual_val.c); - } - break; - default: - break; - } - actual_fid = NULL; - actual_sig = '\0'; - actual_val.j = 0L; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw005_getRes(JNIEnv *env, - jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/setfmodw005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/setfmodw005.cpp new file mode 100644 index 00000000000..c499a97d980 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw005/setfmodw005.cpp @@ -0,0 +1,403 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + const char *name; + const char *sig; + const jboolean stat; + const char *descr; + jfieldID fid; + jvalue val; +} field; + +static jvmtiEnv *jvmti; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jfieldID actual_fid = NULL; +static char actual_sig = '\0'; +static jvalue actual_val = {}; +static field flds[] = { + {"fld0", "J", JNI_TRUE, "static long", NULL, {} }, + {"fld1", "J", JNI_FALSE, "long", NULL, {} }, + {"fld2", "F", JNI_TRUE, "static float", NULL, {} }, + {"fld3", "F", JNI_FALSE, "float", NULL, {} }, + {"fld4", "D", JNI_TRUE, "static double", NULL, {} }, + {"fld5", "D", JNI_FALSE, "double", NULL, {} }, + {"fld6", "Ljava/lang/Object;", JNI_TRUE, "static Object", NULL, {} }, + {"fld7", "Ljava/lang/Object;", JNI_FALSE, "Object", NULL, {} }, + {"fld8", "Z", JNI_TRUE, "static boolean", NULL, {} }, + {"fld9", "Z", JNI_FALSE, "boolean", NULL, {} }, + {"fld10", "B", JNI_TRUE, "static byte", NULL, {} }, + {"fld11", "B", JNI_FALSE, "byte", NULL, {} }, + {"fld12", "S", JNI_TRUE, "static short", NULL, {} }, + {"fld13", "S", JNI_FALSE, "short", NULL, {} }, + {"fld14", "C", JNI_TRUE, "static char", NULL, {} }, + {"fld15", "C", JNI_FALSE, "char", NULL, {} } +}; + +void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, + jfieldID field, char sig, jvalue new_value) { + actual_fid = field; + actual_sig = sig; + actual_val = new_value; + if (actual_sig == 'L') { + actual_val.l = + JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG((JNIEnv *)env, + actual_val.l)); + } + if (printdump == JNI_TRUE) { + printf(">>> FieldModification, field: 0x%p", actual_fid); + switch (actual_sig) { + case 'J': + printf(", sig: 'J', val: 0x%x%08x\n", + (jint)(actual_val.j >> 32), (jint)actual_val.j); + break; + case 'F': + printf(", sig: 'F', val: %.3f\n", (double)actual_val.f); + break; + case 'D': + printf(", sig: 'D', val: %f\n", (double)actual_val.d); + break; + case 'L': + printf(", sig: 'L', val: 0x%p\n", actual_val.l); + break; + case 'Z': + printf(", sig: 'Z', val: 0x%x\n", actual_val.z); + break; + case 'B': + printf(", sig: 'B', val: %d\n", actual_val.b); + break; + case 'S': + printf(", sig: 'S', val: %d\n", actual_val.s); + break; + case 'C': + printf(", sig: 'C', val: 0x%x\n", actual_val.c); + break; + case 'I': + printf(", sig: 'I', val: %d\n", actual_val.i); + break; + default: + printf(", sig: , val: 0x%x%08x\n", + (jint)(actual_val.j >> 32), (jint)actual_val.j); + break; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setfmodw005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setfmodw005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setfmodw005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_modification_events) { + callbacks.FieldModification = &FieldModification; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldModification watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw005_getReady(JNIEnv *env, + jclass cls, jobject obj1, jobject obj2) { + jvmtiError err; + size_t i; + + if (!caps.can_generate_field_modification_events) { + return; + } + +#ifdef _MSC_VER + flds[0].val.j = 0x1234567890abcdefi64; + flds[1].val.j = 0xfedcba0987654321i64; +#else + flds[0].val.j = 0x1234567890abcdefULL; + flds[1].val.j = 0xfedcba0987654321ULL; +#endif + flds[2].val.f = 123.456F; + flds[3].val.f = 654.321F; + flds[4].val.d = 123456.654321; + flds[5].val.d = 654321.123456; + flds[6].val.l = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, obj1)); + flds[7].val.l = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, obj2)); + flds[8].val.z = JNI_TRUE; + flds[9].val.z = JNI_FALSE; + flds[10].val.b = 123; + flds[11].val.b = -123; + flds[12].val.s = 12345; + flds[13].val.s = -12345; + flds[14].val.c = 0xabcd; + flds[15].val.c = 0xdcba; + for (i = 0; i < sizeof(flds) / sizeof(field); i++) { + if (flds[i].stat == JNI_TRUE) { + flds[i].fid = + JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + flds[i].name, flds[i].sig); + } else { + flds[i].fid = + JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), + flds[i].name, flds[i].sig); + } + if (flds[i].fid == NULL) { + printf("Unable to set modification watch on %s fld%" PRIuPTR ", fieldID=0", + flds[i].descr, i); + } else { + if (printdump == JNI_TRUE) { + printf(">>> setting modification watch on %s", flds[i].descr); + printf(" fld%" PRIuPTR ", fieldID=0x%p\n", i, flds[i].fid); + } + err = jvmti->SetFieldModificationWatch(cls, flds[i].fid); + if (err != JVMTI_ERROR_NONE) { + printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error:", i); + printf(" %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_MODIFICATION, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw005_check(JNIEnv *env, + jclass cls, jint ind) { + int flag_err = 0; + + if (!caps.can_generate_field_modification_events) { + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> checking on %s fld%d\n", flds[ind].descr, ind); + printf(">>> new value expected=0x%08x%08x, actual=0x%08x%08x\n", + (jint)(flds[ind].val.j >> 32), (jint)flds[ind].val.j, + (jint)(actual_val.j >> 32), (jint)actual_val.j); + } + if (actual_fid != flds[ind].fid) { + result = STATUS_FAILED; + if (!flag_err) { + printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); + flag_err = 1; + } + printf(" field ID expected=0x%p, actual=0x%p\n", + flds[ind].fid, actual_fid); + } + if (actual_sig != flds[ind].sig[0]) { + result = STATUS_FAILED; + if (!flag_err) { + printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); + flag_err = 1; + } + printf(" signature expected=%c, actual=%c\n", + flds[ind].sig[0], actual_sig); + } + switch (flds[ind].sig[0]) { + case 'J': + if (actual_val.j != flds[ind].val.j) { + result = STATUS_FAILED; + if (!flag_err) { + printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); + flag_err = 1; + } + printf(" new value expected=0x%x%08x, actual=0x%x%08x\n", + (jint)(flds[ind].val.j >> 32), (jint)flds[ind].val.j, + (jint)(actual_val.j >> 32), (jint)actual_val.j); + } + break; + case 'F': + if (actual_val.f != flds[ind].val.f) { + result = STATUS_FAILED; + if (!flag_err) { + printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); + flag_err = 1; + } + printf(" new value expected=%f, actual=%f\n", + (double)flds[ind].val.f, (double)actual_val.f); + } + break; + case 'D': + if (actual_val.d != flds[ind].val.d) { + result = STATUS_FAILED; + if (!flag_err) { + printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); + flag_err = 1; + } + printf(" new value expected=%f, actual=%f\n", + (double)flds[ind].val.d, (double)actual_val.d); + } + break; + case 'L': + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, actual_val.l), + flds[ind].val.l) != JNI_TRUE) { + result = STATUS_FAILED; + if (!flag_err) { + printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); + flag_err = 1; + } + printf(" new value is not the same as expected\n"); + } + break; + case 'Z': + if (actual_val.z != flds[ind].val.z) { + result = STATUS_FAILED; + if (!flag_err) { + printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); + flag_err = 1; + } + printf(" new value expected=0x%x, actual=0x%x\n", + flds[ind].val.z, actual_val.z); + } + break; + case 'B': + if (actual_val.b != flds[ind].val.b) { + result = STATUS_FAILED; + if (!flag_err) { + printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); + flag_err = 1; + } + printf(" new value expected=%d, actual=%d\n", + flds[ind].val.b, actual_val.b); + } + break; + case 'S': + if (actual_val.s != flds[ind].val.s) { + result = STATUS_FAILED; + if (!flag_err) { + printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); + flag_err = 1; + } + printf(" new value expected=%d, actual=%d\n", + flds[ind].val.s, actual_val.s); + } + break; + case 'C': + if (actual_val.c != flds[ind].val.c) { + result = STATUS_FAILED; + if (!flag_err) { + printf("Field %s fld%d thrown error:\n", flds[ind].descr, ind); + flag_err = 1; + } + printf(" new value expected=0x%x, actual=0x%x\n", + flds[ind].val.c, actual_val.c); + } + break; + default: + break; + } + actual_fid = NULL; + actual_sig = '\0'; + actual_val.j = 0L; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw005_getRes(JNIEnv *env, + jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/libsetfmodw006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/libsetfmodw006.c deleted file mode 100644 index 801a38ce5ca..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/libsetfmodw006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setfmodw006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/libsetfmodw006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/libsetfmodw006.cpp new file mode 100644 index 00000000000..a5608287eef --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/libsetfmodw006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setfmodw006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/setfmodw006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/setfmodw006.c deleted file mode 100644 index a0a04854a78..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/setfmodw006.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -typedef struct { - jfieldID fid; - char *f_name; - char *f_sig; - jboolean is_static; - jint expected; - jint count; -} watch_info; - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int missesCount = 0; -static watch_info watches[] = { - { NULL, "staticBoolean", "Z", JNI_TRUE, 0, 0 }, - { NULL, "staticByte", "B", JNI_TRUE, 0, 0 }, - { NULL, "staticShort", "S", JNI_TRUE, 0, 0 }, - { NULL, "staticInt", "I", JNI_TRUE, 0, 0 }, - { NULL, "staticLong", "J", JNI_TRUE, 0, 0 }, - { NULL, "staticFloat", "F", JNI_TRUE, 0, 0 }, - { NULL, "staticDouble", "D", JNI_TRUE, 0, 0 }, - { NULL, "staticChar", "C", JNI_TRUE, 0, 0 }, - { NULL, "staticObject", "Ljava/lang/Object;", JNI_TRUE, 0, 0 }, - { NULL, "staticArrInt", "[I", JNI_TRUE, 0, 0 }, - - { NULL, "instanceBoolean", "Z", JNI_FALSE, 0, 0 }, - { NULL, "instanceByte", "B", JNI_FALSE, 0, 0 }, - { NULL, "instanceShort", "S", JNI_FALSE, 0, 0 }, - { NULL, "instanceInt", "I", JNI_FALSE, 0, 0 }, - { NULL, "instanceLong", "J", JNI_FALSE, 0, 0 }, - { NULL, "instanceFloat", "F", JNI_FALSE, 0, 0 }, - { NULL, "instanceDouble", "D", JNI_FALSE, 0, 0 }, - { NULL, "instanceChar", "C", JNI_FALSE, 0, 0 }, - { NULL, "instanceObject", "Ljava/lang/Object;", JNI_FALSE, 0, 0 }, - { NULL, "instanceArrInt", "[I", JNI_FALSE, 0, 0 } -}; - - -void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, - jfieldID field, char sig, jvalue new_value) { - size_t i; - - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (field == watches[i].fid) { - watches[i].count++; - return; - } - } - missesCount++; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setfmodw006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setfmodw006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setfmodw006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (caps.can_generate_field_modification_events) { - callbacks.FieldModification = &FieldModification; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FieldModification watch is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw006_getReady(JNIEnv *env, - jclass cls, jint n) { - jvmtiError err; - size_t i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_generate_field_modification_events) { - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> setting field modification watches ...\n"); - } - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (watches[i].is_static == JNI_TRUE) { - watches[i].fid = - JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), - watches[i].f_name, watches[i].f_sig); - } else { - watches[i].fid = - JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), - watches[i].f_name, watches[i].f_sig); - } - err = (*jvmti)->SetFieldModificationWatch(jvmti, cls, watches[i].fid); - if (err == JVMTI_ERROR_NONE) { - watches[i].expected = n; - } else { - printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - } - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FIELD_MODIFICATION, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetFieldModificationWatch_setfmodw006_check(JNIEnv *env, - jclass cls, jboolean flag) { - size_t i; - jint expected; - - for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { - if (printdump == JNI_TRUE && watches[i].count > 0) { - printf(">>> field %s modifications: %d\n", - watches[i].f_name, watches[i].count); - } - expected = (flag == JNI_TRUE) ? watches[i].expected : 0; - if (watches[i].count != expected) { - printf("(%s) wrong number of field modification events: %d,", - watches[i].f_name, watches[i].count); - printf(" expected: %d\n", expected); - result = STATUS_FAILED; - } - watches[i].count = 0; - } - - if (missesCount != 0) { - printf("%d unexpected field modification catches\n", missesCount); - missesCount = 0; - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/setfmodw006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/setfmodw006.cpp new file mode 100644 index 00000000000..2668f5a277b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetFieldModificationWatch/setfmodw006/setfmodw006.cpp @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +typedef struct { + jfieldID fid; + const char *f_name; + const char *f_sig; + jboolean is_static; + jint expected; + jint count; +} watch_info; + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int missesCount = 0; +static watch_info watches[] = { + { NULL, "staticBoolean", "Z", JNI_TRUE, 0, 0 }, + { NULL, "staticByte", "B", JNI_TRUE, 0, 0 }, + { NULL, "staticShort", "S", JNI_TRUE, 0, 0 }, + { NULL, "staticInt", "I", JNI_TRUE, 0, 0 }, + { NULL, "staticLong", "J", JNI_TRUE, 0, 0 }, + { NULL, "staticFloat", "F", JNI_TRUE, 0, 0 }, + { NULL, "staticDouble", "D", JNI_TRUE, 0, 0 }, + { NULL, "staticChar", "C", JNI_TRUE, 0, 0 }, + { NULL, "staticObject", "Ljava/lang/Object;", JNI_TRUE, 0, 0 }, + { NULL, "staticArrInt", "[I", JNI_TRUE, 0, 0 }, + + { NULL, "instanceBoolean", "Z", JNI_FALSE, 0, 0 }, + { NULL, "instanceByte", "B", JNI_FALSE, 0, 0 }, + { NULL, "instanceShort", "S", JNI_FALSE, 0, 0 }, + { NULL, "instanceInt", "I", JNI_FALSE, 0, 0 }, + { NULL, "instanceLong", "J", JNI_FALSE, 0, 0 }, + { NULL, "instanceFloat", "F", JNI_FALSE, 0, 0 }, + { NULL, "instanceDouble", "D", JNI_FALSE, 0, 0 }, + { NULL, "instanceChar", "C", JNI_FALSE, 0, 0 }, + { NULL, "instanceObject", "Ljava/lang/Object;", JNI_FALSE, 0, 0 }, + { NULL, "instanceArrInt", "[I", JNI_FALSE, 0, 0 } +}; + + +void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location, jclass field_klass, jobject obj, + jfieldID field, char sig, jvalue new_value) { + size_t i; + + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (field == watches[i].fid) { + watches[i].count++; + return; + } + } + missesCount++; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setfmodw006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setfmodw006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setfmodw006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (caps.can_generate_field_modification_events) { + callbacks.FieldModification = &FieldModification; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FieldModification watch is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw006_getReady(JNIEnv *env, + jclass cls, jint n) { + jvmtiError err; + size_t i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_generate_field_modification_events) { + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> setting field modification watches ...\n"); + } + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (watches[i].is_static == JNI_TRUE) { + watches[i].fid = + JNI_ENV_PTR(env)->GetStaticFieldID(JNI_ENV_ARG(env, cls), + watches[i].f_name, watches[i].f_sig); + } else { + watches[i].fid = + JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG(env, cls), + watches[i].f_name, watches[i].f_sig); + } + err = jvmti->SetFieldModificationWatch(cls, watches[i].fid); + if (err == JVMTI_ERROR_NONE) { + watches[i].expected = n; + } else { + printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + } + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FIELD_MODIFICATION, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventNotificationMode) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetFieldModificationWatch_setfmodw006_check(JNIEnv *env, + jclass cls, jboolean flag) { + size_t i; + jint expected; + + for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) { + if (printdump == JNI_TRUE && watches[i].count > 0) { + printf(">>> field %s modifications: %d\n", + watches[i].f_name, watches[i].count); + } + expected = (flag == JNI_TRUE) ? watches[i].expected : 0; + if (watches[i].count != expected) { + printf("(%s) wrong number of field modification events: %d,", + watches[i].f_name, watches[i].count); + printf(" expected: %d\n", expected); + result = STATUS_FAILED; + } + watches[i].count = 0; + } + + if (missesCount != 0) { + printf("%d unexpected field modification catches\n", missesCount); + missesCount = 0; + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/libsetjniftab001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/libsetjniftab001.c deleted file mode 100644 index 1ba25fb99fd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/libsetjniftab001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setjniftab001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/libsetjniftab001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/libsetjniftab001.cpp new file mode 100644 index 00000000000..01f1425f2ce --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/libsetjniftab001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setjniftab001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/setjniftab001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/setjniftab001.c deleted file mode 100644 index 9e133c59f16..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/setjniftab001.c +++ /dev/null @@ -1,473 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include - -#include -#include "agent_common.h" - -#include "JVMTITools.h" -#include "native_thread.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - #ifdef __cplusplus - #define JNI_ENV_ARG(x, y) y - #define JNI_ENV_PTR(x) x - #else - #define JNI_ENV_ARG(x, y) x, y - #define JNI_ENV_PTR(x) (*x) - #endif -#endif - -#ifndef JNI_ENV_ARG1 - #ifdef __cplusplus - #define JNI_ENV_ARG1(x) - #else - #define JNI_ENV_ARG1(x) x - #endif -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define TRIES 30 -#define MAX_THREADS 5 - -static const char *javaField = "_setjniftab001a"; -static const char *classSig = - "Lnsk/jvmti/SetJNIFunctionTable/setjniftab001a;"; - -static JavaVM *vm; -static jvmtiEnv *jvmti = NULL; - -static volatile int verbose = 0; - -static volatile jint result = PASSED; -static volatile int thrStarted[MAX_THREADS]; -static void *waitThr[MAX_THREADS]; -static int waitContElem[MAX_THREADS]; /* context of a particular waiting thread */ - -static volatile jobject clsObj; -static jrawMonitorID countLock; - -/* the original JNI function table */ -static jniNativeInterface *orig_jni_functions = NULL; - -/* the redirected JNI function table */ -static jniNativeInterface *redir_jni_functions = NULL; - -/* number of the redirected JNI function calls */ -static volatile int monent_calls = 0; - -static void lock() { - jvmtiError err; - - if ((err = (*jvmti)->RawMonitorEnter(jvmti, countLock)) != - JVMTI_ERROR_NONE) { - printf("(%s,%d): TEST FAILURE: RawMonitorEnter returns unexpected error: %s\n", - __FILE__, __LINE__, TranslateError(err)); - exit(STATUS_FAILED); - } -} - -static void unlock() { - jvmtiError err; - - if ((err = (*jvmti)->RawMonitorExit(jvmti, countLock)) - != JVMTI_ERROR_NONE) { - printf("(%s,%d): TEST FAILURE: RawMonitorExit returns unexpected error: %s\n", - __FILE__, __LINE__, TranslateError(err)); - exit(STATUS_FAILED); - } -} - -/** redirected JNI functions **/ -jint JNICALL MyMonitorEnter(JNIEnv *env, jobject obj) { - lock(); - - monent_calls++; - if (verbose) - printf("\nMyMonitorEnter: the function called successfully: number of calls=%d\n", - monent_calls); - - unlock(); - - return orig_jni_functions->MonitorEnter( - JNI_ENV_ARG(env, obj)); -} -/*****************************/ - -/* zeroing the interception counter */ -void zeroCounter() { - lock(); - monent_calls = 0; - unlock(); -} - -void doRedirect(JNIEnv *env) { - jvmtiError err; - - if (verbose) - printf("\ndoRedirect: obtaining the JNI function table ...\n"); - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &orig_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get original JNI function table")); - } - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &redir_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get redirected JNI function table")); - } - if (verbose) - printf("doRedirect: the JNI function table obtained successfully\n"); - - if (verbose) - printf("\ndoRedirect: overwriting the function MonitorEnter ...\n"); - redir_jni_functions->MonitorEnter = MyMonitorEnter; - - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, redir_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to set new JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to set new JNI function table")); - } - - if (verbose) - printf("\ndoRedirect: the functions are overwritten successfully\n"); -} - -void doRestore(JNIEnv *env) { - jvmtiError err; - - if (verbose) - printf("\ndoRestore: restoring the original JNI function table ...\n"); - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, orig_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to restore original JNI function table")); - } - if (verbose) - printf("doRestore: the original JNI function table is restored successfully\n"); -} - -void doExec(JNIEnv *env, int thrNum) { - jint res; - - if ((res = JNI_ENV_PTR(env)-> - MonitorEnter(JNI_ENV_ARG(env, clsObj))) != 0) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILURE: MonitorEnter() returns %d for thread #%d\n", - __FILE__, __LINE__, res, thrNum); - } - if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILURE: exception occured for thread #%d\n", - __FILE__, __LINE__, thrNum); - JNI_ENV_PTR(env)->ExceptionDescribe(JNI_ENV_ARG1(env)); - JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); - } - if (verbose) - printf("\ndoExec: thread #%d entered the monitor\n", - thrNum); - if ((res = JNI_ENV_PTR(env)-> - MonitorExit(JNI_ENV_ARG(env, clsObj))) != 0) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILURE: MonitorExit() returns %d for thread #%d\n", - __FILE__, __LINE__, res, thrNum); - } - if (verbose) - printf("doExec: thread #%d exited the monitor\n", - thrNum); -} - -void checkCall(int step, int exMonEntCalls, const char *msg) { - if (monent_calls == exMonEntCalls) { - if (verbose) - printf("\nCHECK PASSED: the %s JNI function MonitorEnter() has been %s inside %s:\n\t%d intercepted call(s) as expected\n", - (step==1)?"tested":"original", - (step==1)?"redirected":"restored", msg, - monent_calls); - } - else { - result = STATUS_FAILED; - printf("\nTEST FAILED: the %s JNI function MonitorEnter() has not been %s inside %s:\n\t%d intercepted call(s) instead of %d as expected\n", - (step==1)?"tested":"original", - (step==1)?"redirected":"restored", msg, - monent_calls, exMonEntCalls); - } -} - -/* thread procedures */ -static int waitingThread(void *context) { - JNIEnv *env; - int exitCode = PASSED; - jint res; - int tries = 0; - int indx = *((int *) context); - - if (verbose) - printf("\nwaitingThread: thread #%d started\n\tattaching the thread to the VM ...\n", - indx); - if ((res = - JNI_ENV_PTR(vm)->AttachCurrentThread( - JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) { - printf("(%s,%d): TEST FAILURE: waitingThread: AttachCurrentThread() returns: %d\n", - __FILE__, __LINE__, res); - return STATUS_FAILED; - } - - thrStarted[indx-1] = 1; - - doExec(env, indx); - - if ((res = - JNI_ENV_PTR(vm)->DetachCurrentThread( - JNI_ENV_ARG1(vm))) != 0) { - printf("(%s,%d): TEST FAILURE: waitingThread: DetachCurrentThread() returns: %d\n", - __FILE__, __LINE__, res); - return STATUS_FAILED; - } - if (verbose) - printf("waitingThread: the thread #%d exits with %d\n", - indx, exitCode); - return exitCode; -} -/*********************/ - -static jobject getObjectFromField(JNIEnv *env, jobject obj) { - jfieldID fid; - jclass _objCls; - - _objCls = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, obj)); - - if (verbose) - printf("\ngetObjectFromField: obtaining field ID for name=\"%s\" signature=\"%s\"...\n", - javaField, classSig); - if ((fid = JNI_ENV_PTR(env)->GetFieldID( - JNI_ENV_ARG(env, _objCls), javaField, classSig)) == 0) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILURE: failed to get ID for the field \"%s\"\n", - __FILE__, __LINE__, javaField); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get ID for the java field")); - } - - return JNI_ENV_PTR(env)->GetObjectField( - JNI_ENV_ARG(env, obj), fid); -} - -void startThreads() { - int i; - int tries = 0; - - for (i=0; i TRIES) { - printf("TEST FAILURE: waiting thread #%d is still not started\n", - i+1); - result = STATUS_FAILED; - } - } while(thrStarted[i] != 1); - if (verbose) - printf("\nthe waiting thread #%d started\n", - i+1); - } -} - -void waitThreads() { - int i; - - for (i=0; iNewGlobalRef( - JNI_ENV_ARG(env, getObjectFromField(env, obj)))) == NULL) { - printf("(%s,%d): TEST FAILURE: cannot create a new global reference of class \"%s\"\n", - __FILE__, __LINE__, classSig); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to create a new global reference")); - } - - doRedirect(env); - - /* 1: check the assertion inside current thread and new threads */ - if (verbose) - printf("\na) Checking the assertion inside current thread and new threads ...\n"); - doExec(env, 0); - checkCall(1, 1, "main thread"); - - zeroCounter(); - startThreads(); - waitThreads(); - checkCall(1, MAX_THREADS, "new threads"); - - /* 2: detach current thread then the attach it again and check the assertion - Note: the JNI spec says that the main thread can be detached from the VM - only since JDK 1.2 */ - if (verbose) - printf("\nb) Checking the assertion inside main thread detached and attached again ...\n\ndetaching the main thread ...\n"); - - if ((res = - JNI_ENV_PTR(vm)->DetachCurrentThread( - JNI_ENV_ARG1(vm))) != 0) - printf("(%s,%d): Warning: DetachCurrentThread() returns: %d\n\ -\tcheck with the detached main thread skipped\n", - __FILE__, __LINE__, res); - else { - if (verbose) - printf("\nattaching the main thread again ...\n"); - if ((res = - JNI_ENV_PTR(vm)->AttachCurrentThread( - JNI_ENV_ARG(vm, (void **) &nextEnv), (void *) 0)) != 0) { - printf("(%s,%d): TEST FAILURE: waitingThread: AttachCurrentThread() returns: %d\n", - __FILE__, __LINE__, res); - return STATUS_FAILED; - } - - zeroCounter(); - doExec(nextEnv, 0); - checkCall(1, 1, "main thread with new JNI env"); - } - - /* 3: restore the function, zeroing the interception counter - and check the assertion with current thread and new threads */ - if (verbose) - printf("\nc) Checking the restored JNI function table ...\n"); - doRestore((nextEnv==NULL)? env:nextEnv); - - zeroCounter(); - doExec((nextEnv==NULL)? env:nextEnv, 0); - checkCall(2, 0, "main thread"); - - zeroCounter(); - startThreads(); - waitThreads(); - checkCall(2, 0, "new threads"); - - JNI_ENV_PTR(env)->DeleteGlobalRef(JNI_ENV_ARG((nextEnv==NULL)? env:nextEnv, clsObj)); - - return result; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setjniftab001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setjniftab001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setjniftab001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "-verbose") == 0) - verbose = 1; - - if (verbose) - printf("verbose mode on\n"); - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); - return JNI_ERR; - } - - vm = jvm; - - if ((err = (*jvmti)->CreateRawMonitor(jvmti, "_counter_lock", - &countLock)) != JVMTI_ERROR_NONE) { - printf("(%s,%d): TEST FAILURE: CreateRawMonitor() returns unexpected error: %s\n", - __FILE__, __LINE__, TranslateError(err)); - return JNI_ERR; - } - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/setjniftab001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/setjniftab001.cpp new file mode 100644 index 00000000000..130477157fe --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/setjniftab001.cpp @@ -0,0 +1,472 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include + +#include +#include "agent_common.h" + +#include "JVMTITools.h" +#include "native_thread.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + #ifdef __cplusplus + #define JNI_ENV_ARG(x, y) y + #define JNI_ENV_PTR(x) x + #else + #define JNI_ENV_ARG(x, y) x, y + #define JNI_ENV_PTR(x) (*x) + #endif +#endif + +#ifndef JNI_ENV_ARG1 + #ifdef __cplusplus + #define JNI_ENV_ARG1(x) + #else + #define JNI_ENV_ARG1(x) x + #endif +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define TRIES 30 +#define MAX_THREADS 5 + +static const char *javaField = "_setjniftab001a"; +static const char *classSig = + "Lnsk/jvmti/SetJNIFunctionTable/setjniftab001a;"; + +static JavaVM *vm; +static jvmtiEnv *jvmti = NULL; + +static volatile int verbose = 0; + +static volatile jint result = PASSED; +static volatile int thrStarted[MAX_THREADS]; +static void *waitThr[MAX_THREADS]; +static int waitContElem[MAX_THREADS]; /* context of a particular waiting thread */ + +static volatile jobject clsObj; +static jrawMonitorID countLock; + +/* the original JNI function table */ +static jniNativeInterface *orig_jni_functions = NULL; + +/* the redirected JNI function table */ +static jniNativeInterface *redir_jni_functions = NULL; + +/* number of the redirected JNI function calls */ +static volatile int monent_calls = 0; + +static void lock() { + jvmtiError err; + + if ((err = jvmti->RawMonitorEnter(countLock)) != + JVMTI_ERROR_NONE) { + printf("(%s,%d): TEST FAILURE: RawMonitorEnter returns unexpected error: %s\n", + __FILE__, __LINE__, TranslateError(err)); + exit(STATUS_FAILED); + } +} + +static void unlock() { + jvmtiError err; + + if ((err = jvmti->RawMonitorExit(countLock)) + != JVMTI_ERROR_NONE) { + printf("(%s,%d): TEST FAILURE: RawMonitorExit returns unexpected error: %s\n", + __FILE__, __LINE__, TranslateError(err)); + exit(STATUS_FAILED); + } +} + +/** redirected JNI functions **/ +jint JNICALL MyMonitorEnter(JNIEnv *env, jobject obj) { + lock(); + + monent_calls++; + if (verbose) + printf("\nMyMonitorEnter: the function called successfully: number of calls=%d\n", + monent_calls); + + unlock(); + + return orig_jni_functions->MonitorEnter(env, obj); +} +/*****************************/ + +/* zeroing the interception counter */ +void zeroCounter() { + lock(); + monent_calls = 0; + unlock(); +} + +void doRedirect(JNIEnv *env) { + jvmtiError err; + + if (verbose) + printf("\ndoRedirect: obtaining the JNI function table ...\n"); + if ((err = jvmti->GetJNIFunctionTable(&orig_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get original JNI function table")); + } + if ((err = jvmti->GetJNIFunctionTable(&redir_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get redirected JNI function table")); + } + if (verbose) + printf("doRedirect: the JNI function table obtained successfully\n"); + + if (verbose) + printf("\ndoRedirect: overwriting the function MonitorEnter ...\n"); + redir_jni_functions->MonitorEnter = MyMonitorEnter; + + if ((err = jvmti->SetJNIFunctionTable(redir_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to set new JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to set new JNI function table")); + } + + if (verbose) + printf("\ndoRedirect: the functions are overwritten successfully\n"); +} + +void doRestore(JNIEnv *env) { + jvmtiError err; + + if (verbose) + printf("\ndoRestore: restoring the original JNI function table ...\n"); + if ((err = jvmti->SetJNIFunctionTable(orig_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to restore original JNI function table")); + } + if (verbose) + printf("doRestore: the original JNI function table is restored successfully\n"); +} + +void doExec(JNIEnv *env, int thrNum) { + jint res; + + if ((res = JNI_ENV_PTR(env)-> + MonitorEnter(JNI_ENV_ARG(env, clsObj))) != 0) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILURE: MonitorEnter() returns %d for thread #%d\n", + __FILE__, __LINE__, res, thrNum); + } + if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILURE: exception occured for thread #%d\n", + __FILE__, __LINE__, thrNum); + JNI_ENV_PTR(env)->ExceptionDescribe(JNI_ENV_ARG1(env)); + JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); + } + if (verbose) + printf("\ndoExec: thread #%d entered the monitor\n", + thrNum); + if ((res = JNI_ENV_PTR(env)-> + MonitorExit(JNI_ENV_ARG(env, clsObj))) != 0) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILURE: MonitorExit() returns %d for thread #%d\n", + __FILE__, __LINE__, res, thrNum); + } + if (verbose) + printf("doExec: thread #%d exited the monitor\n", + thrNum); +} + +void checkCall(int step, int exMonEntCalls, const char *msg) { + if (monent_calls == exMonEntCalls) { + if (verbose) + printf("\nCHECK PASSED: the %s JNI function MonitorEnter() has been %s inside %s:\n\t%d intercepted call(s) as expected\n", + (step==1)?"tested":"original", + (step==1)?"redirected":"restored", msg, + monent_calls); + } + else { + result = STATUS_FAILED; + printf("\nTEST FAILED: the %s JNI function MonitorEnter() has not been %s inside %s:\n\t%d intercepted call(s) instead of %d as expected\n", + (step==1)?"tested":"original", + (step==1)?"redirected":"restored", msg, + monent_calls, exMonEntCalls); + } +} + +/* thread procedures */ +static int waitingThread(void *context) { + JNIEnv *env; + int exitCode = PASSED; + jint res; + int tries = 0; + int indx = *((int *) context); + + if (verbose) + printf("\nwaitingThread: thread #%d started\n\tattaching the thread to the VM ...\n", + indx); + if ((res = + JNI_ENV_PTR(vm)->AttachCurrentThread( + JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) { + printf("(%s,%d): TEST FAILURE: waitingThread: AttachCurrentThread() returns: %d\n", + __FILE__, __LINE__, res); + return STATUS_FAILED; + } + + thrStarted[indx-1] = 1; + + doExec(env, indx); + + if ((res = + JNI_ENV_PTR(vm)->DetachCurrentThread( + JNI_ENV_ARG1(vm))) != 0) { + printf("(%s,%d): TEST FAILURE: waitingThread: DetachCurrentThread() returns: %d\n", + __FILE__, __LINE__, res); + return STATUS_FAILED; + } + if (verbose) + printf("waitingThread: the thread #%d exits with %d\n", + indx, exitCode); + return exitCode; +} +/*********************/ + +static jobject getObjectFromField(JNIEnv *env, jobject obj) { + jfieldID fid; + jclass _objCls; + + _objCls = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, obj)); + + if (verbose) + printf("\ngetObjectFromField: obtaining field ID for name=\"%s\" signature=\"%s\"...\n", + javaField, classSig); + if ((fid = JNI_ENV_PTR(env)->GetFieldID( + JNI_ENV_ARG(env, _objCls), javaField, classSig)) == 0) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILURE: failed to get ID for the field \"%s\"\n", + __FILE__, __LINE__, javaField); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get ID for the java field")); + } + + return JNI_ENV_PTR(env)->GetObjectField( + JNI_ENV_ARG(env, obj), fid); +} + +void startThreads() { + int i; + int tries = 0; + + for (i=0; i TRIES) { + printf("TEST FAILURE: waiting thread #%d is still not started\n", + i+1); + result = STATUS_FAILED; + } + } while(thrStarted[i] != 1); + if (verbose) + printf("\nthe waiting thread #%d started\n", + i+1); + } +} + +void waitThreads() { + int i; + + for (i=0; iNewGlobalRef( + JNI_ENV_ARG(env, getObjectFromField(env, obj)))) == NULL) { + printf("(%s,%d): TEST FAILURE: cannot create a new global reference of class \"%s\"\n", + __FILE__, __LINE__, classSig); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to create a new global reference")); + } + + doRedirect(env); + + /* 1: check the assertion inside current thread and new threads */ + if (verbose) + printf("\na) Checking the assertion inside current thread and new threads ...\n"); + doExec(env, 0); + checkCall(1, 1, "main thread"); + + zeroCounter(); + startThreads(); + waitThreads(); + checkCall(1, MAX_THREADS, "new threads"); + + /* 2: detach current thread then the attach it again and check the assertion + Note: the JNI spec says that the main thread can be detached from the VM + only since JDK 1.2 */ + if (verbose) + printf("\nb) Checking the assertion inside main thread detached and attached again ...\n\ndetaching the main thread ...\n"); + + if ((res = + JNI_ENV_PTR(vm)->DetachCurrentThread( + JNI_ENV_ARG1(vm))) != 0) + printf("(%s,%d): Warning: DetachCurrentThread() returns: %d\n\ +\tcheck with the detached main thread skipped\n", + __FILE__, __LINE__, res); + else { + if (verbose) + printf("\nattaching the main thread again ...\n"); + if ((res = + JNI_ENV_PTR(vm)->AttachCurrentThread( + JNI_ENV_ARG(vm, (void **) &nextEnv), (void *) 0)) != 0) { + printf("(%s,%d): TEST FAILURE: waitingThread: AttachCurrentThread() returns: %d\n", + __FILE__, __LINE__, res); + return STATUS_FAILED; + } + + zeroCounter(); + doExec(nextEnv, 0); + checkCall(1, 1, "main thread with new JNI env"); + } + + /* 3: restore the function, zeroing the interception counter + and check the assertion with current thread and new threads */ + if (verbose) + printf("\nc) Checking the restored JNI function table ...\n"); + doRestore((nextEnv==NULL)? env:nextEnv); + + zeroCounter(); + doExec((nextEnv==NULL)? env:nextEnv, 0); + checkCall(2, 0, "main thread"); + + zeroCounter(); + startThreads(); + waitThreads(); + checkCall(2, 0, "new threads"); + + JNI_ENV_PTR(env)->DeleteGlobalRef(JNI_ENV_ARG((nextEnv==NULL)? env:nextEnv, clsObj)); + + return result; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setjniftab001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setjniftab001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setjniftab001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "-verbose") == 0) + verbose = 1; + + if (verbose) + printf("verbose mode on\n"); + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); + return JNI_ERR; + } + + vm = jvm; + + if ((err = jvmti->CreateRawMonitor("_counter_lock", + &countLock)) != JVMTI_ERROR_NONE) { + printf("(%s,%d): TEST FAILURE: CreateRawMonitor() returns unexpected error: %s\n", + __FILE__, __LINE__, TranslateError(err)); + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/libsetjniftab002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/libsetjniftab002.c deleted file mode 100644 index 01ce727b826..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/libsetjniftab002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setjniftab002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/libsetjniftab002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/libsetjniftab002.cpp new file mode 100644 index 00000000000..5fa84672f26 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/libsetjniftab002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setjniftab002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/setjniftab002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/setjniftab002.c deleted file mode 100644 index ac056852f70..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/setjniftab002.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - #ifdef __cplusplus - #define JNI_ENV_ARG(x, y) y - #define JNI_ENV_PTR(x) x - #else - #define JNI_ENV_ARG(x, y) x, y - #define JNI_ENV_PTR(x) (*x) - #endif -#endif - -#ifndef JNI_ENV_ARG1 - #ifdef __cplusplus - #define JNI_ENV_ARG1(x) - #else - #define JNI_ENV_ARG1(x) x - #endif -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static JavaVM *vm; -static jvmtiEnv *jvmti = NULL; - -static int verbose = 0; -static jint result = PASSED; - -void redirect(JNIEnv *env, jvmtiError exError) { - jvmtiError err; - - if (verbose) - printf("\ntrying to overwrite the JNI function table expecting the error %s to be returned ...\n", - TranslateError(exError)); - - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, NULL)) != - exError) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: SetJNIFunctionTable() returns %s instead of %s as expected\n", - __FILE__, __LINE__, TranslateError(err), TranslateError(exError)); - return; - } - else if (verbose) - printf("CHECK PASSED: SetJNIFunctionTable() returns %s as expected\n", - TranslateError(err)); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetJNIFunctionTable_setjniftab002_check(JNIEnv *env, jobject obj) { - jvmtiError err; - JNIEnv *nextEnv = NULL; - - if (jvmti == NULL) { - printf("(%s,%d): TEST FAILURE: JVMTI client was not properly loaded\n", - __FILE__, __LINE__); - return STATUS_FAILED; - } - - /* a) Verifying the error JVMTI_ERROR_NULL_POINTER */ - if (verbose) - printf("\na) Checking the function with the parameter JVMTI_ERROR_NULL_POINTER ...\n"); - redirect(env, JVMTI_ERROR_NULL_POINTER); - - /* b) Verifying the error JVMTI_ERROR_UNATTACHED_THREAD - Note: the JNI spec says that the main thread can be detached from the VM - only since JDK 1.2 */ - if (verbose) - printf("\nb) Checking the function with the detached thread ...\n\ndetaching the main thread ...\n"); - if ((err = - JNI_ENV_PTR(vm)->DetachCurrentThread( - JNI_ENV_ARG1(vm))) != 0) - printf("(%s,%d): Warning: DetachCurrentThread() returns: %d\n\ -\tcheck with the detached main thread skipped\n", - __FILE__, __LINE__, err); - else { - redirect(env, JVMTI_ERROR_UNATTACHED_THREAD); - - if (verbose) - printf("\nattaching the main thread back ...\n"); - if ((err = - JNI_ENV_PTR(vm)->AttachCurrentThread( - JNI_ENV_ARG(vm, (void **) &nextEnv), (void *) 0)) != 0) { - printf("(%s,%d): TEST FAILURE: waitingThread: AttachCurrentThread() returns: %d\n", - __FILE__, __LINE__, err); - return STATUS_FAILED; - } - } - - return result; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setjniftab002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setjniftab002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setjniftab002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "-verbose") == 0) - verbose = 1; - - if (verbose) - printf("verbose mode on\n"); - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); - return JNI_ERR; - } - - vm = jvm; - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/setjniftab002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/setjniftab002.cpp new file mode 100644 index 00000000000..8ad50c2f1ff --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab002/setjniftab002.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + #ifdef __cplusplus + #define JNI_ENV_ARG(x, y) y + #define JNI_ENV_PTR(x) x + #else + #define JNI_ENV_ARG(x, y) x, y + #define JNI_ENV_PTR(x) (*x) + #endif +#endif + +#ifndef JNI_ENV_ARG1 + #ifdef __cplusplus + #define JNI_ENV_ARG1(x) + #else + #define JNI_ENV_ARG1(x) x + #endif +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static JavaVM *vm; +static jvmtiEnv *jvmti = NULL; + +static int verbose = 0; +static jint result = PASSED; + +void redirect(JNIEnv *env, jvmtiError exError) { + jvmtiError err; + + if (verbose) + printf("\ntrying to overwrite the JNI function table expecting the error %s to be returned ...\n", + TranslateError(exError)); + + if ((err = jvmti->SetJNIFunctionTable(NULL)) != + exError) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: SetJNIFunctionTable() returns %s instead of %s as expected\n", + __FILE__, __LINE__, TranslateError(err), TranslateError(exError)); + return; + } + else if (verbose) + printf("CHECK PASSED: SetJNIFunctionTable() returns %s as expected\n", + TranslateError(err)); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetJNIFunctionTable_setjniftab002_check(JNIEnv *env, jobject obj) { + jint res; + JNIEnv *nextEnv = NULL; + + if (jvmti == NULL) { + printf("(%s,%d): TEST FAILURE: JVMTI client was not properly loaded\n", + __FILE__, __LINE__); + return STATUS_FAILED; + } + + /* a) Verifying the error JVMTI_ERROR_NULL_POINTER */ + if (verbose) + printf("\na) Checking the function with the parameter JVMTI_ERROR_NULL_POINTER ...\n"); + redirect(env, JVMTI_ERROR_NULL_POINTER); + + /* b) Verifying the error JVMTI_ERROR_UNATTACHED_THREAD + Note: the JNI spec says that the main thread can be detached from the VM + only since JDK 1.2 */ + if (verbose) + printf("\nb) Checking the function with the detached thread ...\n\ndetaching the main thread ...\n"); + if ((res = + JNI_ENV_PTR(vm)->DetachCurrentThread( + JNI_ENV_ARG1(vm))) != JNI_OK) + printf("(%s,%d): Warning: DetachCurrentThread() returns: %d\n\ +\tcheck with the detached main thread skipped\n", + __FILE__, __LINE__, res); + else { + redirect(env, JVMTI_ERROR_UNATTACHED_THREAD); + + if (verbose) + printf("\nattaching the main thread back ...\n"); + if ((res = + JNI_ENV_PTR(vm)->AttachCurrentThread( + JNI_ENV_ARG(vm, (void **) &nextEnv), (void *) 0)) != JNI_OK) { + printf("(%s,%d): TEST FAILURE: waitingThread: AttachCurrentThread() returns: %d\n", + __FILE__, __LINE__, res); + return STATUS_FAILED; + } + } + + return result; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setjniftab002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setjniftab002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setjniftab002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "-verbose") == 0) + verbose = 1; + + if (verbose) + printf("verbose mode on\n"); + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); + return JNI_ERR; + } + + vm = jvm; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/libsetlocal001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/libsetlocal001.c deleted file mode 100644 index 957ce535f5d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/libsetlocal001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setlocal001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/libsetlocal001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/libsetlocal001.cpp new file mode 100644 index 00000000000..0b2f1d819b7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/libsetlocal001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setlocal001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/setlocal001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/setlocal001.c deleted file mode 100644 index c8d0d62bfa8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/setlocal001.c +++ /dev/null @@ -1,374 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jmethodID mid1, mid2, mid3, mid4; -static jlong longVal = 22L; -static jfloat floatVal; -static jdouble doubleVal; -static jobject objVal; -static jobject arrVal; - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - jvmtiError err; - jmethodID mid; - jlocation loc; - jint entryCount; - jvmtiLocalVariableEntry *table = NULL; - int i; - - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thr, 1, &mid, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, - &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", - TranslateError(err), err); - return; - } - - if (mid == mid1) { - for (i = 0; i < entryCount; i++) { - if (strcmp(table[i].name, "l") == 0) { - err = (*jvmti_env)->SetLocalLong(jvmti_env, thr, 1, - table[i].slot, longVal); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalLong) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "f") == 0) { - err = (*jvmti_env)->SetLocalFloat(jvmti_env, thr, 1, - table[i].slot, floatVal); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalFloat) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "d") == 0) { - err = (*jvmti_env)->SetLocalDouble(jvmti_env, thr, 1, - table[i].slot, doubleVal); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalDouble) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - } else if (mid == mid2) { - for (i = 0; i < entryCount; i++) { - if (strcmp(table[i].name, "i1") == 0) { - err = (*jvmti_env)->SetLocalInt(jvmti_env, thr, 1, - table[i].slot, 1); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalInt#i1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i2") == 0) { - err = (*jvmti_env)->SetLocalInt(jvmti_env, thr, 1, - table[i].slot, 1); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalInt#i2) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i3") == 0) { - err = (*jvmti_env)->SetLocalInt(jvmti_env, thr, 1, - table[i].slot, 1); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalInt#i3) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i4") == 0) { - err = (*jvmti_env)->SetLocalInt(jvmti_env, thr, 1, - table[i].slot, 1); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalInt#i4) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i5") == 0) { - err = (*jvmti_env)->SetLocalInt(jvmti_env, thr, 1, - table[i].slot, 1); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalInt#i5) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - } else if (mid == mid3) { - for (i = 0; i < entryCount; i++) { - if (strcmp(table[i].name, "ob1") == 0) { - err = (*jvmti_env)->SetLocalObject(jvmti_env, thr, 1, - table[i].slot, objVal); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalObject#ob1) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "ob2") == 0) { - err = (*jvmti_env)->SetLocalObject(jvmti_env, thr, 1, - table[i].slot, arrVal); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalObject#ob2) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - } else if (mid == mid4) { - for (i = 0; i < entryCount; i++) { - if (strcmp(table[i].name, "i1") == 0) { - err = (*jvmti_env)->SetLocalInt(jvmti_env, thr, 1, - table[i].slot, 1); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalInt#i1,param) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i2") == 0) { - err = (*jvmti_env)->SetLocalInt(jvmti_env, thr, 1, - table[i].slot, 2); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalInt#i2,param) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i3") == 0) { - err = (*jvmti_env)->SetLocalInt(jvmti_env, thr, 1, - table[i].slot, 3); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalInt#i3,param) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i4") == 0) { - err = (*jvmti_env)->SetLocalInt(jvmti_env, thr, 1, - table[i].slot, 4); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalInt#i4,param) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "b") == 0) { - err = (*jvmti_env)->SetLocalInt(jvmti_env, thr, 1, - table[i].slot, JNI_TRUE); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalInt#b,param) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "l") == 0) { - err = (*jvmti_env)->SetLocalLong(jvmti_env, thr, 1, - table[i].slot, longVal); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalLong,param) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "f") == 0) { - err = (*jvmti_env)->SetLocalFloat(jvmti_env, thr, 1, - table[i].slot, floatVal); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalFloat,param) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "d") == 0) { - err = (*jvmti_env)->SetLocalDouble(jvmti_env, thr, 1, - table[i].slot, doubleVal); - if (err != JVMTI_ERROR_NONE) { - printf("(SetLocalDouble,param) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - } else { - printf("ERROR: didn't know where we got called from"); - result = STATUS_FAILED; - } - - if (table != NULL) { - for (i = 0; i < entryCount; i++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table[i].name); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table[i].signature); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setlocal001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setlocal001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setlocal001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if ( res != JNI_OK || jvmti == NULL ) { - printf("Wrong result of a valid call to GetEnv !\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_access_local_variables) { - printf("Warning: access to local variables is not implemented\n"); - } else if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetLocalVariable_setlocal001_getMethReady(JNIEnv *env, - jclass cls, jfloat f, jdouble d, jobject o, jobject a) { - jvmtiError err; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_access_local_variables || - !caps.can_generate_breakpoint_events) return; - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - mid1 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "meth01", "()D"); - mid2 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "meth02", "(I)V"); - mid3 = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "meth03", "()V"); - mid4 = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "meth04", "(IJSDCFBZ)V"); - if (mid == 0 || mid1 == 0 || mid2 == 0 || mid3 == 0 || mid4 == 0) { - printf("Cannot find Method ID for a method\n"); - } - floatVal = f; - doubleVal = d; - objVal = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, o)); - arrVal = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, a)); - - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to SetBreakpoint: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetLocalVariable_setlocal001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/setlocal001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/setlocal001.cpp new file mode 100644 index 00000000000..805191f1add --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/setlocal001.cpp @@ -0,0 +1,374 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jmethodID mid1, mid2, mid3, mid4; +static jlong longVal = 22L; +static jfloat floatVal; +static jdouble doubleVal; +static jobject objVal; +static jobject arrVal; + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + jvmtiError err; + jmethodID mid; + jlocation loc; + jint entryCount; + jvmtiLocalVariableEntry *table = NULL; + int i; + + err = jvmti_env->GetFrameLocation(thr, 1, &mid, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->GetLocalVariableTable(mid, + &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", + TranslateError(err), err); + return; + } + + if (mid == mid1) { + for (i = 0; i < entryCount; i++) { + if (strcmp(table[i].name, "l") == 0) { + err = jvmti_env->SetLocalLong(thr, 1, + table[i].slot, longVal); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalLong) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "f") == 0) { + err = jvmti_env->SetLocalFloat(thr, 1, + table[i].slot, floatVal); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalFloat) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "d") == 0) { + err = jvmti_env->SetLocalDouble(thr, 1, + table[i].slot, doubleVal); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalDouble) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + } else if (mid == mid2) { + for (i = 0; i < entryCount; i++) { + if (strcmp(table[i].name, "i1") == 0) { + err = jvmti_env->SetLocalInt(thr, 1, + table[i].slot, 1); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalInt#i1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i2") == 0) { + err = jvmti_env->SetLocalInt(thr, 1, + table[i].slot, 1); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalInt#i2) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i3") == 0) { + err = jvmti_env->SetLocalInt(thr, 1, + table[i].slot, 1); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalInt#i3) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i4") == 0) { + err = jvmti_env->SetLocalInt(thr, 1, + table[i].slot, 1); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalInt#i4) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i5") == 0) { + err = jvmti_env->SetLocalInt(thr, 1, + table[i].slot, 1); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalInt#i5) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + } else if (mid == mid3) { + for (i = 0; i < entryCount; i++) { + if (strcmp(table[i].name, "ob1") == 0) { + err = jvmti_env->SetLocalObject(thr, 1, + table[i].slot, objVal); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalObject#ob1) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "ob2") == 0) { + err = jvmti_env->SetLocalObject(thr, 1, + table[i].slot, arrVal); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalObject#ob2) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + } else if (mid == mid4) { + for (i = 0; i < entryCount; i++) { + if (strcmp(table[i].name, "i1") == 0) { + err = jvmti_env->SetLocalInt(thr, 1, + table[i].slot, 1); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalInt#i1,param) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i2") == 0) { + err = jvmti_env->SetLocalInt(thr, 1, + table[i].slot, 2); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalInt#i2,param) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i3") == 0) { + err = jvmti_env->SetLocalInt(thr, 1, + table[i].slot, 3); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalInt#i3,param) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i4") == 0) { + err = jvmti_env->SetLocalInt(thr, 1, + table[i].slot, 4); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalInt#i4,param) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "b") == 0) { + err = jvmti_env->SetLocalInt(thr, 1, + table[i].slot, JNI_TRUE); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalInt#b,param) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "l") == 0) { + err = jvmti_env->SetLocalLong(thr, 1, + table[i].slot, longVal); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalLong,param) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "f") == 0) { + err = jvmti_env->SetLocalFloat(thr, 1, + table[i].slot, floatVal); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalFloat,param) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "d") == 0) { + err = jvmti_env->SetLocalDouble(thr, 1, + table[i].slot, doubleVal); + if (err != JVMTI_ERROR_NONE) { + printf("(SetLocalDouble,param) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + } else { + printf("ERROR: didn't know where we got called from"); + result = STATUS_FAILED; + } + + if (table != NULL) { + for (i = 0; i < entryCount; i++) { + jvmti_env->Deallocate((unsigned char*)table[i].name); + jvmti_env->Deallocate((unsigned char*)table[i].signature); + } + jvmti_env->Deallocate((unsigned char*)table); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setlocal001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setlocal001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setlocal001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if ( res != JNI_OK || jvmti == NULL ) { + printf("Wrong result of a valid call to GetEnv !\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_access_local_variables) { + printf("Warning: access to local variables is not implemented\n"); + } else if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetLocalVariable_setlocal001_getMethReady(JNIEnv *env, + jclass cls, jfloat f, jdouble d, jobject o, jobject a) { + jvmtiError err; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_access_local_variables || + !caps.can_generate_breakpoint_events) return; + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + mid1 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "meth01", "()D"); + mid2 = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "meth02", "(I)V"); + mid3 = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "meth03", "()V"); + mid4 = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "meth04", "(IJSDCFBZ)V"); + if (mid == 0 || mid1 == 0 || mid2 == 0 || mid3 == 0 || mid4 == 0) { + printf("Cannot find Method ID for a method\n"); + } + floatVal = f; + doubleVal = d; + objVal = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, o)); + arrVal = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, a)); + + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to SetBreakpoint: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetLocalVariable_setlocal001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/libsetlocal002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/libsetlocal002.c deleted file mode 100644 index 207a6fafc0a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/libsetlocal002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setlocal002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/libsetlocal002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/libsetlocal002.cpp new file mode 100644 index 00000000000..9d53e437f2a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/libsetlocal002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setlocal002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/setlocal002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/setlocal002.c deleted file mode 100644 index 10d250b5673..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/setlocal002.c +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setlocal002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setlocal002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setlocal002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_access_local_variables) { - printf("Warning: access to local variables is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetLocalVariable_setlocal002_check(JNIEnv *env, jclass cls, jthread thr) { - jvmtiError err; - jmethodID mid; - jint entryCount; - jvmtiLocalVariableEntry *table; - int i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_access_local_variables) { - return result; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I"); - if (mid == NULL) { - printf("Cannot find method \"run\"\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->GetLocalVariableTable(jvmti, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid thread check ...\n"); - } - for (i = 0; i < entryCount; i++) { - if (strcmp(table[i].name, "o") == 0) { - err = (*jvmti)->SetLocalObject(jvmti, cls, 1, - table[i].slot, (jobject)cls); - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i") == 0) { - err = (*jvmti)->SetLocalInt(jvmti, cls, 1, - table[i].slot, (jint)0); - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "l") == 0) { - err = (*jvmti)->SetLocalLong(jvmti, cls, 1, - table[i].slot, (jlong)0); - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "f") == 0) { - err = (*jvmti)->SetLocalFloat(jvmti, cls, 1, - table[i].slot, (jfloat)0); - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "d") == 0) { - err = (*jvmti)->SetLocalDouble(jvmti, cls, 1, - table[i].slot, (jdouble)0); - if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid frame check ...\n"); - } - for (i = 0; i < entryCount; i++) { - if (strcmp(table[i].name, "o") == 0) { - err = (*jvmti)->SetLocalObject(jvmti, thr, -1, - table[i].slot, (jobject)cls); - if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_FRAMEID,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i") == 0) { - err = (*jvmti)->SetLocalInt(jvmti, thr, -1, - table[i].slot, (jint)0); - if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_FRAMEID,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "l") == 0) { - err = (*jvmti)->SetLocalLong(jvmti, thr, -1, - table[i].slot, (jlong)0); - if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_FRAMEID,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "f") == 0) { - err = (*jvmti)->SetLocalFloat(jvmti, thr, -1, - table[i].slot, (jfloat)0); - if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_FRAMEID,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "d") == 0) { - err = (*jvmti)->SetLocalDouble(jvmti, thr, -1, - table[i].slot, (jdouble)0); - if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_FRAMEID,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - - if (printdump == JNI_TRUE) { - printf(">>> opague frame check ...\n"); - } - for (i = 0; i < entryCount; i++) { - if (strcmp(table[i].name, "o") == 0) { - err = (*jvmti)->SetLocalObject(jvmti, thr, 0, - table[i].slot, (jobject)cls); - if (err != JVMTI_ERROR_OPAQUE_FRAME) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i") == 0) { - err = (*jvmti)->SetLocalInt(jvmti, thr, 0, - table[i].slot, (jint)0); - if (err != JVMTI_ERROR_OPAQUE_FRAME) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "l") == 0) { - err = (*jvmti)->SetLocalLong(jvmti, thr, 0, - table[i].slot, (jlong)0); - if (err != JVMTI_ERROR_OPAQUE_FRAME) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "f") == 0) { - err = (*jvmti)->SetLocalFloat(jvmti, thr, 0, - table[i].slot, (jfloat)0); - if (err != JVMTI_ERROR_OPAQUE_FRAME) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "d") == 0) { - err = (*jvmti)->SetLocalDouble(jvmti, thr, 0, - table[i].slot, (jdouble)0); - if (err != JVMTI_ERROR_OPAQUE_FRAME) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/setlocal002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/setlocal002.cpp new file mode 100644 index 00000000000..c6049fe891e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/setlocal002.cpp @@ -0,0 +1,304 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setlocal002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setlocal002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setlocal002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_access_local_variables) { + printf("Warning: access to local variables is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetLocalVariable_setlocal002_check(JNIEnv *env, jclass cls, jthread thr) { + jvmtiError err; + jmethodID mid; + jint entryCount; + jvmtiLocalVariableEntry *table; + int i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_access_local_variables) { + return result; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I"); + if (mid == NULL) { + printf("Cannot find method \"run\"\n"); + return STATUS_FAILED; + } + + err = jvmti->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid thread check ...\n"); + } + for (i = 0; i < entryCount; i++) { + if (strcmp(table[i].name, "o") == 0) { + err = jvmti->SetLocalObject(cls, 1, + table[i].slot, (jobject)cls); + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i") == 0) { + err = jvmti->SetLocalInt(cls, 1, + table[i].slot, (jint)0); + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "l") == 0) { + err = jvmti->SetLocalLong(cls, 1, + table[i].slot, (jlong)0); + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "f") == 0) { + err = jvmti->SetLocalFloat(cls, 1, + table[i].slot, (jfloat)0); + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "d") == 0) { + err = jvmti->SetLocalDouble(cls, 1, + table[i].slot, (jdouble)0); + if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid frame check ...\n"); + } + for (i = 0; i < entryCount; i++) { + if (strcmp(table[i].name, "o") == 0) { + err = jvmti->SetLocalObject(thr, -1, + table[i].slot, (jobject)cls); + if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_FRAMEID,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i") == 0) { + err = jvmti->SetLocalInt(thr, -1, + table[i].slot, (jint)0); + if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_FRAMEID,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "l") == 0) { + err = jvmti->SetLocalLong(thr, -1, + table[i].slot, (jlong)0); + if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_FRAMEID,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "f") == 0) { + err = jvmti->SetLocalFloat(thr, -1, + table[i].slot, (jfloat)0); + if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_FRAMEID,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "d") == 0) { + err = jvmti->SetLocalDouble(thr, -1, + table[i].slot, (jdouble)0); + if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_FRAMEID,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + + if (printdump == JNI_TRUE) { + printf(">>> opague frame check ...\n"); + } + for (i = 0; i < entryCount; i++) { + if (strcmp(table[i].name, "o") == 0) { + err = jvmti->SetLocalObject(thr, 0, + table[i].slot, (jobject)cls); + if (err != JVMTI_ERROR_OPAQUE_FRAME) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i") == 0) { + err = jvmti->SetLocalInt(thr, 0, + table[i].slot, (jint)0); + if (err != JVMTI_ERROR_OPAQUE_FRAME) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "l") == 0) { + err = jvmti->SetLocalLong(thr, 0, + table[i].slot, (jlong)0); + if (err != JVMTI_ERROR_OPAQUE_FRAME) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "f") == 0) { + err = jvmti->SetLocalFloat(thr, 0, + table[i].slot, (jfloat)0); + if (err != JVMTI_ERROR_OPAQUE_FRAME) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "d") == 0) { + err = jvmti->SetLocalDouble(thr, 0, + table[i].slot, (jdouble)0); + if (err != JVMTI_ERROR_OPAQUE_FRAME) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_OPAQUE_FRAME,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/libsetlocal003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/libsetlocal003.c deleted file mode 100644 index 9d63c1f2243..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/libsetlocal003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setlocal003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/libsetlocal003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/libsetlocal003.cpp new file mode 100644 index 00000000000..a77c382ba0d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/libsetlocal003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setlocal003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/setlocal003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/setlocal003.c deleted file mode 100644 index 1f98758753f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/setlocal003.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define INV_SLOT (-1) - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - jvmtiError err; - jmethodID mid; - jlocation loc; - jint entryCount; - jvmtiLocalVariableEntry *table; - int i; - - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thr, 1, &mid, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> obtaining local variables mapping ...\n"); - } - - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", - TranslateError(err), err); - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> checking on invalid slot ...\n"); - } - for (i = 0; i < entryCount; i++) { - if (strcmp(table[i].name, "o") == 0) { - err = (*jvmti_env)->SetLocalObject(jvmti_env, thr, 1, - INV_SLOT, (jobject)thr); - if (err != JVMTI_ERROR_INVALID_SLOT) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_SLOT,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "i") == 0) { - err = (*jvmti_env)->SetLocalInt(jvmti_env, thr, 1, - INV_SLOT, (jint)0); - if (err != JVMTI_ERROR_INVALID_SLOT) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_SLOT,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "l") == 0) { - err = (*jvmti_env)->SetLocalLong(jvmti_env, thr, 1, - INV_SLOT, (jlong)0); - if (err != JVMTI_ERROR_INVALID_SLOT) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_SLOT,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "f") == 0) { - err = (*jvmti_env)->SetLocalFloat(jvmti_env, thr, 1, - INV_SLOT, (jfloat)0); - if (err != JVMTI_ERROR_INVALID_SLOT) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_SLOT,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } else if (strcmp(table[i].name, "d") == 0) { - err = (*jvmti_env)->SetLocalDouble(jvmti_env, thr, 1, - INV_SLOT, (jdouble)0); - if (err != JVMTI_ERROR_INVALID_SLOT) { - printf("(%s) ", table[i].name); - printf("Error expected: JVMTI_ERROR_INVALID_SLOT,\n"); - printf("\t actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setlocal003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setlocal003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setlocal003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_access_local_variables) { - printf("Warning: access to local variables is not implemented\n"); - } else if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetLocalVariable_setlocal003_getReady(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_access_local_variables || - !caps.can_generate_breakpoint_events) return; - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (mid == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to SetBreakpoint: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetLocalVariable_setlocal003_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/setlocal003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/setlocal003.cpp new file mode 100644 index 00000000000..42817ea4e43 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/setlocal003.cpp @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define INV_SLOT (-1) + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + jvmtiError err; + jmethodID mid; + jlocation loc; + jint entryCount; + jvmtiLocalVariableEntry *table; + int i; + + err = jvmti_env->GetFrameLocation(thr, 1, &mid, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> obtaining local variables mapping ...\n"); + } + + err = jvmti_env->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", + TranslateError(err), err); + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> checking on invalid slot ...\n"); + } + for (i = 0; i < entryCount; i++) { + if (strcmp(table[i].name, "o") == 0) { + err = jvmti_env->SetLocalObject(thr, 1, + INV_SLOT, (jobject)thr); + if (err != JVMTI_ERROR_INVALID_SLOT) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_SLOT,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "i") == 0) { + err = jvmti_env->SetLocalInt(thr, 1, + INV_SLOT, (jint)0); + if (err != JVMTI_ERROR_INVALID_SLOT) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_SLOT,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "l") == 0) { + err = jvmti_env->SetLocalLong(thr, 1, + INV_SLOT, (jlong)0); + if (err != JVMTI_ERROR_INVALID_SLOT) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_SLOT,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "f") == 0) { + err = jvmti_env->SetLocalFloat(thr, 1, + INV_SLOT, (jfloat)0); + if (err != JVMTI_ERROR_INVALID_SLOT) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_SLOT,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } else if (strcmp(table[i].name, "d") == 0) { + err = jvmti_env->SetLocalDouble(thr, 1, + INV_SLOT, (jdouble)0); + if (err != JVMTI_ERROR_INVALID_SLOT) { + printf("(%s) ", table[i].name); + printf("Error expected: JVMTI_ERROR_INVALID_SLOT,\n"); + printf("\t actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setlocal003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setlocal003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setlocal003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_access_local_variables) { + printf("Warning: access to local variables is not implemented\n"); + } else if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetLocalVariable_setlocal003_getReady(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_access_local_variables || + !caps.can_generate_breakpoint_events) return; + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (mid == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to SetBreakpoint: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetLocalVariable_setlocal003_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/libsetlocal004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/libsetlocal004.c deleted file mode 100644 index 9fc3690260b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/libsetlocal004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setlocal004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/libsetlocal004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/libsetlocal004.cpp new file mode 100644 index 00000000000..8a97b971db3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/libsetlocal004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setlocal004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/setlocal004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/setlocal004.c deleted file mode 100644 index 6428818c970..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/setlocal004.c +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define INV_SLOT (-1) - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, jlocation location) { - jvmtiError err; - jmethodID mid; - jlocation loc; - jint entryCount; - jvmtiLocalVariableEntry *table; - int i; - - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thr, 1, &mid, &loc); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFrameLocation) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> obtaining local variables mapping ...\n"); - } - - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", - TranslateError(err), err); - return; - } - - if (printdump == JNI_TRUE) { - printf(">>> checking on type mismatch ...\n"); - } - for (i = 0; i < entryCount; i++) { - if (strlen(table[i].name) != 1) continue; - if (strcmp(table[i].name, "o") != 0) { - err = (*jvmti_env)->SetLocalObject(jvmti_env, thr, 1, - table[i].slot, (jobject)thr); - if (err != JVMTI_ERROR_TYPE_MISMATCH) { - printf("\"%s\" against SetLocalObject:\n", table[i].name); - printf(" expected: JVMTI_ERROR_TYPE_MISMATCH,"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - if (strcmp(table[i].name, "i") != 0) { - err = (*jvmti_env)->SetLocalInt(jvmti_env, thr, 1, - table[i].slot, (jint)0); - if (err != JVMTI_ERROR_TYPE_MISMATCH) { - printf("\"%s\" against SetLocalInt:\n", table[i].name); - printf(" expected: JVMTI_ERROR_TYPE_MISMATCH,"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - if (strcmp(table[i].name, "l") != 0) { - err = (*jvmti_env)->SetLocalLong(jvmti_env, thr, 1, - table[i].slot, (jlong)0); - if (err != JVMTI_ERROR_TYPE_MISMATCH) { - printf("\"%s\" against SetLocalLong:\n", table[i].name); - printf(" expected: JVMTI_ERROR_TYPE_MISMATCH,"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - if (strcmp(table[i].name, "f") != 0) { - err = (*jvmti_env)->SetLocalFloat(jvmti_env, thr, 1, - table[i].slot, (jfloat)0); - if (err != JVMTI_ERROR_TYPE_MISMATCH) { - printf("\"%s\" against SetLocalFloat:\n", table[i].name); - printf(" expected: JVMTI_ERROR_TYPE_MISMATCH,"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - if (strcmp(table[i].name, "d") != 0) { - err = (*jvmti_env)->SetLocalDouble(jvmti_env, thr, 1, - table[i].slot, (jdouble)0); - if (err != JVMTI_ERROR_TYPE_MISMATCH) { - printf("\"%s\" against SetLocalDouble:\n", table[i].name); - printf(" expected: JVMTI_ERROR_TYPE_MISMATCH,"); - printf(" actual: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_setlocal004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_setlocal004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_setlocal004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_access_local_variables) { - printf("Warning: access to local variables is not implemented\n"); - } else if (caps.can_generate_breakpoint_events) { - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_SetLocalVariable_setlocal004_getReady(JNIEnv *env, jclass cls) { - jvmtiError err; - jmethodID mid; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_access_local_variables || - !caps.can_generate_breakpoint_events) return; - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (mid == 0) { - printf("Cannot find Method ID for method checkPoint\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetBreakpoint(jvmti, mid, 0); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to SetBreakpoint: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetLocalVariable_setlocal004_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/setlocal004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/setlocal004.cpp new file mode 100644 index 00000000000..fb6365d4aa6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/setlocal004.cpp @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define INV_SLOT (-1) + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, jlocation location) { + jvmtiError err; + jmethodID mid; + jlocation loc; + jint entryCount; + jvmtiLocalVariableEntry *table; + int i; + + err = jvmti_env->GetFrameLocation(thr, 1, &mid, &loc); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFrameLocation) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> obtaining local variables mapping ...\n"); + } + + err = jvmti_env->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", + TranslateError(err), err); + return; + } + + if (printdump == JNI_TRUE) { + printf(">>> checking on type mismatch ...\n"); + } + for (i = 0; i < entryCount; i++) { + if (strlen(table[i].name) != 1) continue; + if (strcmp(table[i].name, "o") != 0) { + err = jvmti_env->SetLocalObject(thr, 1, + table[i].slot, (jobject)thr); + if (err != JVMTI_ERROR_TYPE_MISMATCH) { + printf("\"%s\" against SetLocalObject:\n", table[i].name); + printf(" expected: JVMTI_ERROR_TYPE_MISMATCH,"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + if (strcmp(table[i].name, "i") != 0) { + err = jvmti_env->SetLocalInt(thr, 1, + table[i].slot, (jint)0); + if (err != JVMTI_ERROR_TYPE_MISMATCH) { + printf("\"%s\" against SetLocalInt:\n", table[i].name); + printf(" expected: JVMTI_ERROR_TYPE_MISMATCH,"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + if (strcmp(table[i].name, "l") != 0) { + err = jvmti_env->SetLocalLong(thr, 1, + table[i].slot, (jlong)0); + if (err != JVMTI_ERROR_TYPE_MISMATCH) { + printf("\"%s\" against SetLocalLong:\n", table[i].name); + printf(" expected: JVMTI_ERROR_TYPE_MISMATCH,"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + if (strcmp(table[i].name, "f") != 0) { + err = jvmti_env->SetLocalFloat(thr, 1, + table[i].slot, (jfloat)0); + if (err != JVMTI_ERROR_TYPE_MISMATCH) { + printf("\"%s\" against SetLocalFloat:\n", table[i].name); + printf(" expected: JVMTI_ERROR_TYPE_MISMATCH,"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + if (strcmp(table[i].name, "d") != 0) { + err = jvmti_env->SetLocalDouble(thr, 1, + table[i].slot, (jdouble)0); + if (err != JVMTI_ERROR_TYPE_MISMATCH) { + printf("\"%s\" against SetLocalDouble:\n", table[i].name); + printf(" expected: JVMTI_ERROR_TYPE_MISMATCH,"); + printf(" actual: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_setlocal004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_setlocal004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_setlocal004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_access_local_variables) { + printf("Warning: access to local variables is not implemented\n"); + } else if (caps.can_generate_breakpoint_events) { + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_SetLocalVariable_setlocal004_getReady(JNIEnv *env, jclass cls) { + jvmtiError err; + jmethodID mid; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_access_local_variables || + !caps.can_generate_breakpoint_events) return; + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (mid == 0) { + printf("Cannot find Method ID for method checkPoint\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetBreakpoint(mid, 0); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to SetBreakpoint: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetLocalVariable_setlocal004_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/SetNativeMethodPrefix001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/SetNativeMethodPrefix001.c deleted file mode 100644 index 51232d0265e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/SetNativeMethodPrefix001.c +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" -#include "jni_tools.h" - -#define FOO 1 -#define WRAPPED_FOO 2 - -/* ============================================================================= */ - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetNativeMethodPrefix_AutomaticResolution1_foo ( - JNIEnv *jni - , jclass klass - ) -{ - NSK_DISPLAY0(" >>> AutomaticResolution1.foo()\n"); - return FOO; -} - -/* ============================================================================= */ - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetNativeMethodPrefix_AutomaticResolution1_wrapped_1foo ( - JNIEnv *jni - , jclass klass - ) -{ - NSK_DISPLAY0(" >>> AutomaticResolution1.wrapped_foo()\n"); - return WRAPPED_FOO; -} - -/* ============================================================================= */ - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetNativeMethodPrefix_AutomaticResolution2_foo ( - JNIEnv *jni - , jclass klass - ) -{ - NSK_DISPLAY0(" >>> AutomaticResolution2.foo()\n"); - return FOO; -} - -/* ============================================================================= */ - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SetNativeMethodPrefix_AutomaticResolution3_foo ( - JNIEnv *jni - , jclass klass - ) -{ - NSK_DISPLAY0(" >>> AutomaticResolution3.foo()\n"); - return FOO; -} -/* ============================================================================= */ - -JNIEXPORT jint JNICALL foo (JNIEnv *jni, jclass klass) -{ - NSK_DISPLAY0(" >>> ::foo()\n"); - return FOO; -} - -/* ============================================================================= */ - -JNIEXPORT jint JNICALL wrapped_foo (JNIEnv *jni, jclass klass) -{ - NSK_DISPLAY0(" >>> ::wrapped_foo()\n"); - return WRAPPED_FOO; -} - -/* ============================================================================= */ - -#define METHODS_COUNT 2 -static const void *METHODS [METHODS_COUNT] = { - (void *) &foo, - (void *) &wrapped_foo, -}; - -/* ============================================================================= */ - -static jvmtiEnv *jvmti = NULL; - -/* ============================================================================= */ - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_SetNativeMethodPrefix_Binder_setMethodPrefix ( - JNIEnv *jni - , jclass klass - , jstring prefix - ) -{ - jboolean result = JNI_TRUE; - char *str = NULL; - - if (prefix != NULL) { - if (!NSK_VERIFY( - (str = (char *) NSK_CPP_STUB3( - GetStringUTFChars - , jni - , prefix - , 0 - ) - ) != NULL - ) - ) - { result = JNI_FALSE; goto finally; } - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - SetNativeMethodPrefix - , jvmti - , str - ) - ) - ) - { result = JNI_FALSE; goto finally; } - - if (str != NULL) { - NSK_DISPLAY1("New PREFIX is set: %s\n" - , str - ); - } else { - NSK_DISPLAY0("Old PREFIX is reset\n"); - } - -finally: - if (str != NULL) { - (*jni)->ReleaseStringUTFChars(jni, prefix, str); - } - - return JNI_TRUE; -} - -/* ============================================================================= */ - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_SetNativeMethodPrefix_Binder_setMultiplePrefixes ( - JNIEnv *jni - , jclass klass - , jstring prefix - ) -{ - jboolean result = JNI_TRUE; - char *str = NULL; - - if (prefix != NULL) { - if (!NSK_VERIFY( - (str = (char *) NSK_CPP_STUB3( - GetStringUTFChars - , jni - , prefix - , 0 - ) - ) != NULL - ) - ) - { result = JNI_FALSE; goto finally; } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - SetNativeMethodPrefixes - , jvmti - , 1 - , (char **) &str - ) - ) - ) - { result = JNI_FALSE; goto finally; } - - NSK_DISPLAY1("MultiplePrefixes: New PREFIX is set: %s\n" - , str - ); - } else { - char* prefixes[1]; - prefixes[0] = NULL; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - SetNativeMethodPrefixes - , jvmti - , 0 - , (char **)&prefixes - ) - ) - ) - { result = JNI_FALSE; goto finally; } - - NSK_DISPLAY0("Old PREFIX is reset\n"); - } - -finally: - if (str != NULL) { - (*jni)->ReleaseStringUTFChars(jni, prefix, str); - } - - return JNI_TRUE; -} - -/* ============================================================================= */ - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_SetNativeMethodPrefix_Binder_registerMethod ( - JNIEnv *jni - , jclass klass - , jclass bound_klass - , jstring method_name_obj - , jstring method_sig_obj - , jint native_method_number - ) -{ - JNINativeMethod method; - jboolean result = JNI_FALSE; - - if (native_method_number < 0 || native_method_number >= METHODS_COUNT) { - NSK_DISPLAY2("Method index is out of the bound: %d of %d" - , native_method_number - , METHODS_COUNT - ); - return JNI_FALSE; - } - - if (!NSK_VERIFY( - (method.name = - (char *) NSK_CPP_STUB3( - GetStringUTFChars - , jni - , method_name_obj - , 0 - ) - ) != NULL - ) - ) - { - goto finally; - } - - if (!NSK_VERIFY( - (method.signature = - (char *) NSK_CPP_STUB3( - GetStringUTFChars - , jni - , method_sig_obj - , 0 - ) - ) != NULL - ) - ) - { - goto finally; - } - - method.fnPtr = (void *) METHODS[native_method_number]; - - NSK_DISPLAY2(">>>> Register native method: %s %s\n" - , method.name - , method.signature - ); - - if ((*jni)->RegisterNatives(jni, bound_klass, (const JNINativeMethod*) &method, 1) != 0) - { - if ((*jni)->ExceptionOccurred(jni)) { - (*jni)->ExceptionClear(jni); - } - - goto finally; - } - - NSK_DISPLAY0("<<<< Finished native method registration\n"); - - result = JNI_TRUE; -finally: - if (method.name != NULL) { - (*jni)->ReleaseStringUTFChars(jni, method_name_obj, method.name); - } - - if (method.signature != NULL) { - (*jni)->ReleaseStringUTFChars(jni, method_sig_obj, method.signature); - } - - return result; -} - -/* ============================================================================= */ - -/* Agent initialization procedure */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_SetNativeMethodPrefix001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_SetNativeMethodPrefix001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_SetNativeMethodPrefix001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) -{ - jvmtiCapabilities caps; - - if (!NSK_VERIFY( - nsk_jvmti_parseOptions(options) - ) - ) - return JNI_ERR; - - if (!NSK_VERIFY( - (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL - ) - ) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - GetCapabilities - , jvmti - , &caps) - ) - ) - return JNI_ERR; - - // Register all necessary JVM capabilities - caps.can_set_native_method_prefix = 1; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - AddCapabilities - , jvmti - , &caps) - ) - ) - return JNI_ERR; - - return JNI_OK; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/SetNativeMethodPrefix001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/SetNativeMethodPrefix001.cpp new file mode 100644 index 00000000000..506a1f59faf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/SetNativeMethodPrefix001.cpp @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FOO 1 +#define WRAPPED_FOO 2 + +/* ============================================================================= */ + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetNativeMethodPrefix_AutomaticResolution1_foo ( + JNIEnv *jni + , jclass klass + ) +{ + NSK_DISPLAY0(" >>> AutomaticResolution1.foo()\n"); + return FOO; +} + +/* ============================================================================= */ + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetNativeMethodPrefix_AutomaticResolution1_wrapped_1foo ( + JNIEnv *jni + , jclass klass + ) +{ + NSK_DISPLAY0(" >>> AutomaticResolution1.wrapped_foo()\n"); + return WRAPPED_FOO; +} + +/* ============================================================================= */ + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetNativeMethodPrefix_AutomaticResolution2_foo ( + JNIEnv *jni + , jclass klass + ) +{ + NSK_DISPLAY0(" >>> AutomaticResolution2.foo()\n"); + return FOO; +} + +/* ============================================================================= */ + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SetNativeMethodPrefix_AutomaticResolution3_foo ( + JNIEnv *jni + , jclass klass + ) +{ + NSK_DISPLAY0(" >>> AutomaticResolution3.foo()\n"); + return FOO; +} +/* ============================================================================= */ + +JNIEXPORT jint JNICALL foo (JNIEnv *jni, jclass klass) +{ + NSK_DISPLAY0(" >>> ::foo()\n"); + return FOO; +} + +/* ============================================================================= */ + +JNIEXPORT jint JNICALL wrapped_foo (JNIEnv *jni, jclass klass) +{ + NSK_DISPLAY0(" >>> ::wrapped_foo()\n"); + return WRAPPED_FOO; +} + +/* ============================================================================= */ + +#define METHODS_COUNT 2 +static const void *METHODS [METHODS_COUNT] = { + (void *) &foo, + (void *) &wrapped_foo, +}; + +/* ============================================================================= */ + +static jvmtiEnv *jvmti = NULL; + +/* ============================================================================= */ + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_SetNativeMethodPrefix_Binder_setMethodPrefix ( + JNIEnv *jni + , jclass klass + , jstring prefix + ) +{ + jboolean result = JNI_TRUE; + char *str = NULL; + + if (prefix != NULL) { + if (!NSK_VERIFY( + (str = (char *) NSK_CPP_STUB3( + GetStringUTFChars + , jni + , prefix + , 0 + ) + ) != NULL + ) + ) + { result = JNI_FALSE; goto finally; } + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + SetNativeMethodPrefix + , jvmti + , str + ) + ) + ) + { result = JNI_FALSE; goto finally; } + + if (str != NULL) { + NSK_DISPLAY1("New PREFIX is set: %s\n" + , str + ); + } else { + NSK_DISPLAY0("Old PREFIX is reset\n"); + } + +finally: + if (str != NULL) { + jni->ReleaseStringUTFChars(prefix, str); + } + + return JNI_TRUE; +} + +/* ============================================================================= */ + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_SetNativeMethodPrefix_Binder_setMultiplePrefixes ( + JNIEnv *jni + , jclass klass + , jstring prefix + ) +{ + jboolean result = JNI_TRUE; + char *str = NULL; + + if (prefix != NULL) { + if (!NSK_VERIFY( + (str = (char *) NSK_CPP_STUB3( + GetStringUTFChars + , jni + , prefix + , 0 + ) + ) != NULL + ) + ) + { result = JNI_FALSE; goto finally; } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + SetNativeMethodPrefixes + , jvmti + , 1 + , (char **) &str + ) + ) + ) + { result = JNI_FALSE; goto finally; } + + NSK_DISPLAY1("MultiplePrefixes: New PREFIX is set: %s\n" + , str + ); + } else { + char* prefixes[1]; + prefixes[0] = NULL; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + SetNativeMethodPrefixes + , jvmti + , 0 + , (char **)&prefixes + ) + ) + ) + { result = JNI_FALSE; goto finally; } + + NSK_DISPLAY0("Old PREFIX is reset\n"); + } + +finally: + if (str != NULL) { + jni->ReleaseStringUTFChars(prefix, str); + } + + return JNI_TRUE; +} + +/* ============================================================================= */ + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_SetNativeMethodPrefix_Binder_registerMethod ( + JNIEnv *jni + , jclass klass + , jclass bound_klass + , jstring method_name_obj + , jstring method_sig_obj + , jint native_method_number + ) +{ + JNINativeMethod method; + jboolean result = JNI_FALSE; + + if (native_method_number < 0 || native_method_number >= METHODS_COUNT) { + NSK_DISPLAY2("Method index is out of the bound: %d of %d" + , native_method_number + , METHODS_COUNT + ); + return JNI_FALSE; + } + + if (!NSK_VERIFY( + (method.name = + (char *) NSK_CPP_STUB3( + GetStringUTFChars + , jni + , method_name_obj + , 0 + ) + ) != NULL + ) + ) + { + goto finally; + } + + if (!NSK_VERIFY( + (method.signature = + (char *) NSK_CPP_STUB3( + GetStringUTFChars + , jni + , method_sig_obj + , 0 + ) + ) != NULL + ) + ) + { + goto finally; + } + + method.fnPtr = (void *) METHODS[native_method_number]; + + NSK_DISPLAY2(">>>> Register native method: %s %s\n" + , method.name + , method.signature + ); + + if (jni->RegisterNatives(bound_klass, (const JNINativeMethod*) &method, 1) != 0) + { + if (jni->ExceptionOccurred() != NULL) { + jni->ExceptionClear(); + } + + goto finally; + } + + NSK_DISPLAY0("<<<< Finished native method registration\n"); + + result = JNI_TRUE; +finally: + if (method.name != NULL) { + jni->ReleaseStringUTFChars(method_name_obj, method.name); + } + + if (method.signature != NULL) { + jni->ReleaseStringUTFChars(method_sig_obj, method.signature); + } + + return result; +} + +/* ============================================================================= */ + +/* Agent initialization procedure */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_SetNativeMethodPrefix001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_SetNativeMethodPrefix001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_SetNativeMethodPrefix001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) +{ + jvmtiCapabilities caps; + + if (!NSK_VERIFY( + nsk_jvmti_parseOptions(options) + ) + ) + return JNI_ERR; + + if (!NSK_VERIFY( + (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL + ) + ) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + GetCapabilities + , jvmti + , &caps) + ) + ) + return JNI_ERR; + + // Register all necessary JVM capabilities + caps.can_set_native_method_prefix = 1; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + AddCapabilities + , jvmti + , &caps) + ) + ) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/libSetNativeMethodPrefix001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/libSetNativeMethodPrefix001.c deleted file mode 100644 index 582fe13fc1d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/libSetNativeMethodPrefix001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "SetNativeMethodPrefix001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/libSetNativeMethodPrefix001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/libSetNativeMethodPrefix001.cpp new file mode 100644 index 00000000000..76461266657 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/libSetNativeMethodPrefix001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "SetNativeMethodPrefix001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002.c deleted file mode 100644 index 155820db9d9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" -#include "jni_tools.h" - -/* ============================================================================= */ - -#define FOO 1 - -/* ============================================================================= */ - -static char *prefix = NULL; - -/* ============================================================================= */ - -static jvmtiEnv *jvmti = NULL; - -/* ============================================================================= */ - -JNIEXPORT int JNICALL -Java_nsk_jvmti_SetNativeMethodPrefix_SetNativeMethodPrefix002_foo ( - JNIEnv *jni - , jclass klass - ) -{ - NSK_DISPLAY1(" >>> SetNativeMethodPrefix002.foo() (Library: SetNativeMethodPrefix002).\n", prefix); - return FOO; -} - -/* ============================================================================= */ - -static jboolean setMethodPrefix (char *prefix) -{ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - SetNativeMethodPrefix - , jvmti - , prefix) - ) - ) - return JNI_FALSE; - - return JNI_TRUE; -} - -/* ============================================================================= */ - -/* Agent initialization procedure */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_SetNativeMethodPrefix002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_SetNativeMethodPrefix002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_SetNativeMethodPrefix002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) -{ - jvmtiCapabilities caps; - int apply; - - if (!NSK_VERIFY( - nsk_jvmti_parseOptions(options) - ) - ) - return JNI_ERR; - - // Parse additional parameters - - // Specify native method prefix - prefix = (char *)nsk_jvmti_findOptionValue("prefix"); - if (prefix != NULL) { - NSK_DISPLAY1("Prefix: %s\n", prefix); - } - - // Specify whether prefix should be applied or not - apply = nsk_jvmti_findOptionIntValue("apply", 1); - - if (!NSK_VERIFY( - (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL - ) - ) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - GetCapabilities - , jvmti - , &caps) - ) - ) - return JNI_ERR; - - // Register all necessary JVM capabilities - caps.can_set_native_method_prefix = 1; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - AddCapabilities - , jvmti - , &caps) - ) - ) - return JNI_ERR; - - - if (apply) { - if (!setMethodPrefix(prefix)) { - NSK_COMPLAIN0("Can't specify prefix for native method lookup."); - return JNI_ERR; - } - } - - return JNI_OK; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002.cpp new file mode 100644 index 00000000000..1e590d2fdd1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +#define FOO 1 + +/* ============================================================================= */ + +static char *prefix = NULL; + +/* ============================================================================= */ + +static jvmtiEnv *jvmti = NULL; + +/* ============================================================================= */ + +JNIEXPORT int JNICALL +Java_nsk_jvmti_SetNativeMethodPrefix_SetNativeMethodPrefix002_foo ( + JNIEnv *jni + , jclass klass + ) +{ + NSK_DISPLAY1(" >>> SetNativeMethodPrefix002.foo() (Library: SetNativeMethodPrefix002).\n", prefix); + return FOO; +} + +/* ============================================================================= */ + +static jboolean setMethodPrefix (char *prefix) +{ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + SetNativeMethodPrefix + , jvmti + , prefix) + ) + ) + return JNI_FALSE; + + return JNI_TRUE; +} + +/* ============================================================================= */ + +/* Agent initialization procedure */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_SetNativeMethodPrefix002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_SetNativeMethodPrefix002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_SetNativeMethodPrefix002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) +{ + jvmtiCapabilities caps; + int apply; + + if (!NSK_VERIFY( + nsk_jvmti_parseOptions(options) + ) + ) + return JNI_ERR; + + // Parse additional parameters + + // Specify native method prefix + prefix = (char *)nsk_jvmti_findOptionValue("prefix"); + if (prefix != NULL) { + NSK_DISPLAY1("Prefix: %s\n", prefix); + } + + // Specify whether prefix should be applied or not + apply = nsk_jvmti_findOptionIntValue("apply", 1); + + if (!NSK_VERIFY( + (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL + ) + ) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + GetCapabilities + , jvmti + , &caps) + ) + ) + return JNI_ERR; + + // Register all necessary JVM capabilities + caps.can_set_native_method_prefix = 1; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + AddCapabilities + , jvmti + , &caps) + ) + ) + return JNI_ERR; + + + if (apply) { + if (!setMethodPrefix(prefix)) { + NSK_COMPLAIN0("Can't specify prefix for native method lookup."); + return JNI_ERR; + } + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002Main.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002Main.c deleted file mode 100644 index b2317d6ab3d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002Main.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include - -#include "nsk_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" -#include "jni_tools.h" - -/* ============================================================================= */ - -#define FOO 1 - -/* ============================================================================= */ - -JNIEXPORT int JNICALL -Java_nsk_jvmti_SetNativeMethodPrefix_SetNativeMethodPrefix002_foo1 ( - JNIEnv *jni - , jclass klass - ) -{ - printf(" >>> SetNativeMethodPrefix002.foo1() (Library: SetNativeMethodPrefix002Main)\n"); - return FOO; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002Main.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002Main.cpp new file mode 100644 index 00000000000..ea35501d435 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/SetNativeMethodPrefix002Main.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include + +#include "nsk_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +#define FOO 1 + +/* ============================================================================= */ + +JNIEXPORT int JNICALL +Java_nsk_jvmti_SetNativeMethodPrefix_SetNativeMethodPrefix002_foo1 ( + JNIEnv *jni + , jclass klass + ) +{ + printf(" >>> SetNativeMethodPrefix002.foo1() (Library: SetNativeMethodPrefix002Main)\n"); + return FOO; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002.c deleted file mode 100644 index 54e8f76ce81..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "SetNativeMethodPrefix002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002.cpp new file mode 100644 index 00000000000..cc5951dd04e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "SetNativeMethodPrefix002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002Main.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002Main.c deleted file mode 100644 index e29bbcf02be..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002Main.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "SetNativeMethodPrefix002Main.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002Main.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002Main.cpp new file mode 100644 index 00000000000..a522d91cd20 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix002/libSetNativeMethodPrefix002Main.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "SetNativeMethodPrefix002Main.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/libsetsysprop002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/libsetsysprop002.c deleted file mode 100644 index d68520e7fa8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/libsetsysprop002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setsysprop002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/libsetsysprop002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/libsetsysprop002.cpp new file mode 100644 index 00000000000..55c960ae094 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/libsetsysprop002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setsysprop002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/setsysprop002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/setsysprop002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/setsysprop002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop002/setsysprop002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/libsetsysprop003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/libsetsysprop003.c deleted file mode 100644 index 4c04590915e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/libsetsysprop003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setsysprop003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/libsetsysprop003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/libsetsysprop003.cpp new file mode 100644 index 00000000000..8e05cdbc29f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/libsetsysprop003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setsysprop003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/setsysprop003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/setsysprop003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/setsysprop003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetSystemProperty/setsysprop003/setsysprop003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/libsettag001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/libsettag001.c deleted file mode 100644 index 46696f27787..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/libsettag001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "settag001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/libsettag001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/libsettag001.cpp new file mode 100644 index 00000000000..624f484a8ed --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/libsettag001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "settag001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/settag001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/settag001.c deleted file mode 100644 index 420e685a9d6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/settag001.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/SetTag/settag001" -#define OBJECT_CLASS_NAME "nsk/jvmti/SetTag/settag001TestedClass" -#define OBJECT_CLASS_SIG "L"OBJECT_CLASS_NAME";" -#define OBJECT_FIELD_NAME "testedObject" - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - NSK_DISPLAY0("Wait for object created\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - /* perform testing */ - { - jobject testedObject = NULL; - jlong objectTag = 111; - - NSK_DISPLAY0(">>> Obtain tested object from a static field of debugee class\n"); - { - jclass debugeeClass = NULL; - jfieldID objectField = NULL; - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); - - NSK_DISPLAY1("Find static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); - - NSK_DISPLAY1("Get object from static field: %s\n", OBJECT_FIELD_NAME); - if (!NSK_JNI_VERIFY(jni, (testedObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)testedObject); - - NSK_DISPLAY1("Create global reference for object: 0x%p\n", (void*)testedObject); - if (!NSK_JNI_VERIFY(jni, (testedObject = - NSK_CPP_STUB2(NewGlobalRef, jni, testedObject)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got reference: 0x%p\n", (void*)testedObject); - } - - NSK_DISPLAY0(">>> Testcase #1: set tag for the tested object\n"); - { - NSK_DISPLAY1("Set tag for object: 0x%p\n", (void*)testedObject); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, testedObject, objectTag))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... tag set: %ld\n", (long)objectTag); - } - - NSK_DISPLAY0(">>> Testcase #2: get tag of not changed object and compare with initial\n"); - { - jlong tag = 222; - - NSK_DISPLAY1("Get tag for object: 0x%p\n", (void*)testedObject); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetTag, jvmti, testedObject, &tag))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got tag: %ld\n", (long)tag); - - if (tag != objectTag) { - NSK_COMPLAIN2("GetTag() returns different tag for not changed object:\n" - "# got tag: %ld\n" - "# expected: %ld\n", - (long)tag, (long)objectTag); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY2("SUCCESS: Got tag is equal to initial: %ld = %ld\n", - (long)tag, (long)objectTag); - } - } - - NSK_DISPLAY0(">>> Testcase #3: get tag of changed object and compare with initial\n"); - { - jlong tag = 333; - - NSK_DISPLAY0("Let debugee to change object data\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_DISPLAY1("Get tag for object: 0x%p\n", (void*)testedObject); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetTag, jvmti, testedObject, &tag))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1(" ... got tag: %ld\n", (long)tag); - - if (tag != objectTag) { - NSK_COMPLAIN2("GetTag() returns different tag for changed object:\n" - "# got tag: %ld\n" - "# expected: %ld\n", - (long)tag, (long)objectTag); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY2("SUCCESS: Got tag is equal to initial: %ld = %ld\n", - (long)tag, (long)objectTag); - } - } - - NSK_DISPLAY0(">>> Clean used data\n"); - { - NSK_DISPLAY1("Delete object reference: 0x%p\n", (void*)testedObject); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedObject)); - } - } - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_settag001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_settag001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_settag001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* add required capabilities */ - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/settag001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/settag001.cpp new file mode 100644 index 00000000000..563e4e23d69 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/settag001.cpp @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/SetTag/settag001" +#define OBJECT_CLASS_NAME "nsk/jvmti/SetTag/settag001TestedClass" +#define OBJECT_CLASS_SIG "L" OBJECT_CLASS_NAME ";" +#define OBJECT_FIELD_NAME "testedObject" + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + NSK_DISPLAY0("Wait for object created\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + /* perform testing */ + { + jobject testedObject = NULL; + jlong objectTag = 111; + + NSK_DISPLAY0(">>> Obtain tested object from a static field of debugee class\n"); + { + jclass debugeeClass = NULL; + jfieldID objectField = NULL; + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... found class: 0x%p\n", (void*)debugeeClass); + + NSK_DISPLAY1("Find static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got fieldID: 0x%p\n", (void*)objectField); + + NSK_DISPLAY1("Get object from static field: %s\n", OBJECT_FIELD_NAME); + if (!NSK_JNI_VERIFY(jni, (testedObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got object: 0x%p\n", (void*)testedObject); + + NSK_DISPLAY1("Create global reference for object: 0x%p\n", (void*)testedObject); + if (!NSK_JNI_VERIFY(jni, (testedObject = + NSK_CPP_STUB2(NewGlobalRef, jni, testedObject)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got reference: 0x%p\n", (void*)testedObject); + } + + NSK_DISPLAY0(">>> Testcase #1: set tag for the tested object\n"); + { + NSK_DISPLAY1("Set tag for object: 0x%p\n", (void*)testedObject); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, testedObject, objectTag))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... tag set: %ld\n", (long)objectTag); + } + + NSK_DISPLAY0(">>> Testcase #2: get tag of not changed object and compare with initial\n"); + { + jlong tag = 222; + + NSK_DISPLAY1("Get tag for object: 0x%p\n", (void*)testedObject); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetTag, jvmti, testedObject, &tag))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got tag: %ld\n", (long)tag); + + if (tag != objectTag) { + NSK_COMPLAIN2("GetTag() returns different tag for not changed object:\n" + "# got tag: %ld\n" + "# expected: %ld\n", + (long)tag, (long)objectTag); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY2("SUCCESS: Got tag is equal to initial: %ld = %ld\n", + (long)tag, (long)objectTag); + } + } + + NSK_DISPLAY0(">>> Testcase #3: get tag of changed object and compare with initial\n"); + { + jlong tag = 333; + + NSK_DISPLAY0("Let debugee to change object data\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_DISPLAY1("Get tag for object: 0x%p\n", (void*)testedObject); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetTag, jvmti, testedObject, &tag))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1(" ... got tag: %ld\n", (long)tag); + + if (tag != objectTag) { + NSK_COMPLAIN2("GetTag() returns different tag for changed object:\n" + "# got tag: %ld\n" + "# expected: %ld\n", + (long)tag, (long)objectTag); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY2("SUCCESS: Got tag is equal to initial: %ld = %ld\n", + (long)tag, (long)objectTag); + } + } + + NSK_DISPLAY0(">>> Clean used data\n"); + { + NSK_DISPLAY1("Delete object reference: 0x%p\n", (void*)testedObject); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedObject)); + } + } + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_settag001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_settag001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_settag001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* add required capabilities */ + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/libsetthrdstor001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/libsetthrdstor001.c deleted file mode 100644 index 6b4acb6dcdf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/libsetthrdstor001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setthrdstor001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/libsetthrdstor001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/libsetthrdstor001.cpp new file mode 100644 index 00000000000..8a6ea7a13f0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/libsetthrdstor001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setthrdstor001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/setthrdstor001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/setthrdstor001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/setthrdstor001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor001/setthrdstor001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/libsetthrdstor002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/libsetthrdstor002.c deleted file mode 100644 index 2f872ebe18a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/libsetthrdstor002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setthrdstor002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/libsetthrdstor002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/libsetthrdstor002.cpp new file mode 100644 index 00000000000..15c912b5233 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/libsetthrdstor002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setthrdstor002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/setthrdstor002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/setthrdstor002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/setthrdstor002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor002/setthrdstor002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/libsetthrdstor003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/libsetthrdstor003.c deleted file mode 100644 index fa9506326a2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/libsetthrdstor003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setthrdstor003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/libsetthrdstor003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/libsetthrdstor003.cpp new file mode 100644 index 00000000000..3c573a4af8f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/libsetthrdstor003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setthrdstor003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/setthrdstor003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/setthrdstor003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/setthrdstor003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/setthrdstor003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/libsetvrbflag001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/libsetvrbflag001.c deleted file mode 100644 index 61939b17cec..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/libsetvrbflag001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setvrbflag001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/libsetvrbflag001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/libsetvrbflag001.cpp new file mode 100644 index 00000000000..306a2959da8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/libsetvrbflag001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setvrbflag001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/setvrbflag001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/setvrbflag001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/setvrbflag001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/setvrbflag001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/libsetvrbflag002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/libsetvrbflag002.c deleted file mode 100644 index 1fa82b0babe..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/libsetvrbflag002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "setvrbflag002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/libsetvrbflag002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/libsetvrbflag002.cpp new file mode 100644 index 00000000000..2740aa60750 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/libsetvrbflag002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "setvrbflag002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/setvrbflag002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/setvrbflag002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/setvrbflag002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/setvrbflag002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/libsinglestep001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/libsinglestep001.c deleted file mode 100644 index 83927b567b3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/libsinglestep001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "singlestep001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/libsinglestep001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/libsinglestep001.cpp new file mode 100644 index 00000000000..2922b2ba42d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/libsinglestep001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "singlestep001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/singlestep001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/singlestep001.c deleted file mode 100644 index f81bd74bf61..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep001/singlestep001.c +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" -#include "jni_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -#define METH_NUM 2 - -static const char *METHODS[] = { - "bpMethod", - "runThis" -}; - -static const char *METHOD_SIGS[] = { - "()V", - "([Ljava/lang/String;Ljava/io/PrintStream;)I" -}; - -static volatile long stepEv[] = {0, 0}; - -static const char *CLASS_SIG = - "Lnsk/jvmti/SingleStep/singlestep001;"; - -static volatile jint result = PASSED; -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; - -static int vm_started = 0; -static jrawMonitorID agent_lock; - -static void setBP(jvmtiEnv *jvmti_env, JNIEnv *env, jclass klass) { - jmethodID mid; - - if (!NSK_JNI_VERIFY(env, (mid = NSK_CPP_STUB4(GetMethodID, - env, klass, METHODS[0], METHOD_SIGS[0])) != NULL)) - NSK_CPP_STUB2(FatalError, env, - "failed to get ID for the java method\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetBreakpoint, - jvmti_env, mid, 0))) - NSK_CPP_STUB2(FatalError, env, - "failed to set breakpoint\n"); -} - -/** callback functions **/ -void JNICALL -ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, jclass klass) { - char *sig, *generic; - - (*jvmti)->RawMonitorEnter(jvmti, agent_lock); - - if (vm_started) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, - jvmti_env, klass, &sig, &generic))) - NSK_CPP_STUB2(FatalError, env, - "failed to obtain a class signature\n"); - - if (sig != NULL && (strcmp(sig, CLASS_SIG) == 0)) { - NSK_DISPLAY1("ClassLoad event received for the class \"%s\"\n\ -\tsetting breakpoint ...\n", - sig); - setBP(jvmti_env, env, klass); - } - } - - (*jvmti)->RawMonitorExit(jvmti, agent_lock); -} - -void JNICALL -Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jmethodID method, - jlocation loc) { - jclass klass; - char *sig, *generic; - - NSK_DISPLAY0("Breakpoint event received\n"); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, method, &klass))) - NSK_COMPLAIN0("TEST FAILURE: unable to get method declaring class\n\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, - jvmti_env, klass, &sig, &generic))) - NSK_CPP_STUB2(FatalError, env, - "Breakpoint: failed to obtain a class signature\n"); - - if (sig != NULL && (strcmp(sig, CLASS_SIG) == 0)) { - NSK_DISPLAY1("method declaring class \"%s\"\n\tenabling SingleStep events ...\n", - sig); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, thr))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILURE: cannot enable SingleStep events\n\n"); - } - } else { - result = STATUS_FAILED; - NSK_COMPLAIN1("TEST FAILURE: unexpected breakpoint event in method of class \"%s\"\n\n", - sig); - } -} - -void JNICALL -SingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - jclass klass; - char *sig, *generic, *methNam, *methSig; - - if (result == STATUS_FAILED) { - return; - } - - NSK_DISPLAY0(">>>> SingleStep event received\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &methNam, &methSig, NULL))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: unable to get method name during SingleStep callback\n\n"); - return; - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, method, &klass))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: unable to get method declaring class during SingleStep callback\n\n"); - return; - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, - jvmti_env, klass, &sig, &generic))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: unable to obtain a class signature during SingleStep callback\n\n"); - return; - } - - if (sig != NULL) { - NSK_DISPLAY3("\tmethod name: \"%s\"\n\tsignature: \"%s\"\n\ -\tmethod declaring class: \"%s\"\n", - methNam, methSig, sig); - - if (stepEv[1] == 1) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: SingleStep event received after disabling the event generation\n\n"); - } - else if ((strcmp(methNam,METHODS[0]) == 0) && - (strcmp(methSig,METHOD_SIGS[0]) == 0) && - (strcmp(sig,CLASS_SIG) == 0)) { - stepEv[0]++; - NSK_DISPLAY1("CHECK PASSED: SingleStep event received for the method \"%s\" as expected\n", - methNam); - } - else if ((strcmp(methNam,METHODS[1]) == 0) && - (strcmp(methSig,METHOD_SIGS[1]) == 0) && - (strcmp(sig,CLASS_SIG) == 0)) { - stepEv[1]++; - NSK_DISPLAY1("CHECK PASSED: SingleStep event received for the method \"%s\" as expected\n\ -\tdisabling the event generation\n", - methNam); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti_env, JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, thread))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: cannot disable SingleStep events\n\n"); - } - } - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*) methNam))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*) methSig))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method signature\n\n"); - } - - NSK_DISPLAY0("<<<<\n\n"); -} - -void JNICALL -VMStart(jvmtiEnv *jvmti_env, JNIEnv* jni_env) { - (*jvmti)->RawMonitorEnter(jvmti, agent_lock); - - vm_started = 1; - - (*jvmti)->RawMonitorExit(jvmti, agent_lock); -} -/************************/ - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_SingleStep_singlestep001_check( - JNIEnv *env, jobject obj) { - int i; - - for (i=0; i +#include +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +#define METH_NUM 2 + +static const char *METHODS[] = { + "bpMethod", + "runThis" +}; + +static const char *METHOD_SIGS[] = { + "()V", + "([Ljava/lang/String;Ljava/io/PrintStream;)I" +}; + +static volatile long stepEv[] = {0, 0}; + +static const char *CLASS_SIG = + "Lnsk/jvmti/SingleStep/singlestep001;"; + +static volatile jint result = PASSED; +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; + +static int vm_started = 0; +static jrawMonitorID agent_lock; + +static void setBP(jvmtiEnv *jvmti_env, JNIEnv *env, jclass klass) { + jmethodID mid; + + if (!NSK_JNI_VERIFY(env, (mid = NSK_CPP_STUB4(GetMethodID, + env, klass, METHODS[0], METHOD_SIGS[0])) != NULL)) + NSK_CPP_STUB2(FatalError, env, + "failed to get ID for the java method\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetBreakpoint, + jvmti_env, mid, 0))) + NSK_CPP_STUB2(FatalError, env, + "failed to set breakpoint\n"); +} + +/** callback functions **/ +void JNICALL +ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, jclass klass) { + char *sig, *generic; + + jvmti->RawMonitorEnter(agent_lock); + + if (vm_started) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, + jvmti_env, klass, &sig, &generic))) + NSK_CPP_STUB2(FatalError, env, + "failed to obtain a class signature\n"); + + if (sig != NULL && (strcmp(sig, CLASS_SIG) == 0)) { + NSK_DISPLAY1("ClassLoad event received for the class \"%s\"\n\ +\tsetting breakpoint ...\n", + sig); + setBP(jvmti_env, env, klass); + } + } + + jvmti->RawMonitorExit(agent_lock); +} + +void JNICALL +Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jmethodID method, + jlocation loc) { + jclass klass; + char *sig, *generic; + + NSK_DISPLAY0("Breakpoint event received\n"); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, method, &klass))) + NSK_COMPLAIN0("TEST FAILURE: unable to get method declaring class\n\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, + jvmti_env, klass, &sig, &generic))) + NSK_CPP_STUB2(FatalError, env, + "Breakpoint: failed to obtain a class signature\n"); + + if (sig != NULL && (strcmp(sig, CLASS_SIG) == 0)) { + NSK_DISPLAY1("method declaring class \"%s\"\n\tenabling SingleStep events ...\n", + sig); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, thr))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILURE: cannot enable SingleStep events\n\n"); + } + } else { + result = STATUS_FAILED; + NSK_COMPLAIN1("TEST FAILURE: unexpected breakpoint event in method of class \"%s\"\n\n", + sig); + } +} + +void JNICALL +SingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + jclass klass; + char *sig, *generic, *methNam, *methSig; + + if (result == STATUS_FAILED) { + return; + } + + NSK_DISPLAY0(">>>> SingleStep event received\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &methNam, &methSig, NULL))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: unable to get method name during SingleStep callback\n\n"); + return; + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, method, &klass))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: unable to get method declaring class during SingleStep callback\n\n"); + return; + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, + jvmti_env, klass, &sig, &generic))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: unable to obtain a class signature during SingleStep callback\n\n"); + return; + } + + if (sig != NULL) { + NSK_DISPLAY3("\tmethod name: \"%s\"\n\tsignature: \"%s\"\n\ +\tmethod declaring class: \"%s\"\n", + methNam, methSig, sig); + + if (stepEv[1] == 1) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: SingleStep event received after disabling the event generation\n\n"); + } + else if ((strcmp(methNam,METHODS[0]) == 0) && + (strcmp(methSig,METHOD_SIGS[0]) == 0) && + (strcmp(sig,CLASS_SIG) == 0)) { + stepEv[0]++; + NSK_DISPLAY1("CHECK PASSED: SingleStep event received for the method \"%s\" as expected\n", + methNam); + } + else if ((strcmp(methNam,METHODS[1]) == 0) && + (strcmp(methSig,METHOD_SIGS[1]) == 0) && + (strcmp(sig,CLASS_SIG) == 0)) { + stepEv[1]++; + NSK_DISPLAY1("CHECK PASSED: SingleStep event received for the method \"%s\" as expected\n\ +\tdisabling the event generation\n", + methNam); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti_env, JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, thread))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: cannot disable SingleStep events\n\n"); + } + } + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*) methNam))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*) methSig))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method signature\n\n"); + } + + NSK_DISPLAY0("<<<<\n\n"); +} + +void JNICALL +VMStart(jvmtiEnv *jvmti_env, JNIEnv* jni_env) { + jvmti->RawMonitorEnter(agent_lock); + + vm_started = 1; + + jvmti->RawMonitorExit(agent_lock); +} +/************************/ + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_SingleStep_singlestep001_check( + JNIEnv *env, jobject obj) { + int i; + + for (i=0; i -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_stopthrd006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_stopthrd006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_stopthrd006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_signal_thread) { - printf("Warning: InterruptThread is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_StopThread_stopthrd006_check(JNIEnv *env, - jclass cls, jthread thr, jobject ex) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> invalid thread check ...\n"); - } - err = (*jvmti)->StopThread(jvmti, NULL, ex); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_signal_thread) { - /* It is OK */ - } else if (err != JVMTI_ERROR_INVALID_THREAD) { - printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> null pointer check ...\n"); - } - err = (*jvmti)->StopThread(jvmti, thr, NULL); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_signal_thread) { - /* It is OK */ - } else if (err != JVMTI_ERROR_NULL_POINTER) { - printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); - printf(" got: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd006/stopthrd006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd006/stopthrd006.cpp new file mode 100644 index 00000000000..dffdcaa6c9c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd006/stopthrd006.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_stopthrd006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_stopthrd006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_stopthrd006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_signal_thread) { + printf("Warning: InterruptThread is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_StopThread_stopthrd006_check(JNIEnv *env, + jclass cls, jthread thr, jobject ex) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> invalid thread check ...\n"); + } + err = jvmti->StopThread(NULL, ex); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_signal_thread) { + /* It is OK */ + } else if (err != JVMTI_ERROR_INVALID_THREAD) { + printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> null pointer check ...\n"); + } + err = jvmti->StopThread(thr, NULL); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_signal_thread) { + /* It is OK */ + } else if (err != JVMTI_ERROR_NULL_POINTER) { + printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n"); + printf(" got: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/libstopthrd007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/libstopthrd007.c deleted file mode 100644 index ec86a2f0500..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/libstopthrd007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "stopthrd007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/libstopthrd007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/libstopthrd007.cpp new file mode 100644 index 00000000000..80ffd937409 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/libstopthrd007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "stopthrd007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/stopthrd007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/stopthrd007.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/stopthrd007.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/StopThread/stopthrd007/stopthrd007.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/libsuspendthrd001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/libsuspendthrd001.c deleted file mode 100644 index 81cad742056..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/libsuspendthrd001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "suspendthrd001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/libsuspendthrd001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/libsuspendthrd001.cpp new file mode 100644 index 00000000000..233d84ca071 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/libsuspendthrd001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "suspendthrd001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/suspendthrd001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/suspendthrd001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/suspendthrd001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/suspendthrd001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/libsuspendthrd002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/libsuspendthrd002.c deleted file mode 100644 index dbfdc4f204d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/libsuspendthrd002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "suspendthrd002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/libsuspendthrd002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/libsuspendthrd002.cpp new file mode 100644 index 00000000000..e482a2e4dbc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/libsuspendthrd002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "suspendthrd002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/suspendthrd002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/suspendthrd002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/suspendthrd002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd002/suspendthrd002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/libsuspendthrd003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/libsuspendthrd003.c deleted file mode 100644 index 43fcb7c6872..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/libsuspendthrd003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "suspendthrd003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/libsuspendthrd003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/libsuspendthrd003.cpp new file mode 100644 index 00000000000..175ebcc54ab --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/libsuspendthrd003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "suspendthrd003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/suspendthrd003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/suspendthrd003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/suspendthrd003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/suspendthrd003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/libsuspendthrdlst001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/libsuspendthrdlst001.c deleted file mode 100644 index e4ce8c0367c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/libsuspendthrdlst001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "suspendthrdlst001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/libsuspendthrdlst001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/libsuspendthrdlst001.cpp new file mode 100644 index 00000000000..dc2131e1317 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/libsuspendthrdlst001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "suspendthrdlst001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/suspendthrdlst001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/suspendthrdlst001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/suspendthrdlst001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/suspendthrdlst001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/libsuspendthrdlst002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/libsuspendthrdlst002.c deleted file mode 100644 index 7becec034c3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/libsuspendthrdlst002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "suspendthrdlst002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/libsuspendthrdlst002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/libsuspendthrdlst002.cpp new file mode 100644 index 00000000000..c2e7cd16963 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/libsuspendthrdlst002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "suspendthrdlst002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/suspendthrdlst002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/suspendthrdlst002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/suspendthrdlst002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst002/suspendthrdlst002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/libthreadend001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/libthreadend001.c deleted file mode 100644 index 76bb078f0fd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/libthreadend001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "threadend001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/libthreadend001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/libthreadend001.cpp new file mode 100644 index 00000000000..2b0db0f9a4a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/libthreadend001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "threadend001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/threadend001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/threadend001.c deleted file mode 100644 index cd230fe3650..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/threadend001.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int eventsCount = 0; -static int eventsExpected = 0; -static const char *prefix = NULL; - -void JNICALL ThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - jvmtiError err; - jvmtiThreadInfo inf; - char name[32]; - - err = (*jvmti_env)->GetThreadInfo(jvmti_env, thread, &inf); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo#%d) unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> %s\n", inf.name); - } - if (inf.name != NULL && strstr(inf.name, prefix) == inf.name) { - eventsCount++; - sprintf(name, "%s%d", prefix, eventsCount); - if (inf.name == NULL || strcmp(name, inf.name) != 0) { - printf("(#%d) wrong thread name: \"%s\"", - eventsCount, inf.name); - printf(", expected: \"%s\"\n", name); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_threadend001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_threadend001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_threadend001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.ThreadEnd = &ThreadEnd; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ThreadEnd_threadend001_getReady(JNIEnv *env, - jclass cls, jint i, jstring name) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return; - } - - prefix = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, name), NULL); - if (prefix == NULL) { - printf("Failed to copy UTF-8 string!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_THREAD_END, NULL); - if (err == JVMTI_ERROR_NONE) { - eventsExpected = i; - } else { - printf("Failed to enable JVMTI_EVENT_THREAD_END: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_ThreadEnd_threadend001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_THREAD_END, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_THREAD_END: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (eventsCount != eventsExpected) { - printf("Wrong number of thread end events: %d, expected: %d\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/threadend001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/threadend001.cpp new file mode 100644 index 00000000000..77ca8fba6d7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend001/threadend001.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int eventsCount = 0; +static int eventsExpected = 0; +static const char *prefix = NULL; + +void JNICALL ThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + jvmtiError err; + jvmtiThreadInfo inf; + char name[32]; + + err = jvmti_env->GetThreadInfo(thread, &inf); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo#%d) unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> %s\n", inf.name); + } + if (inf.name != NULL && strstr(inf.name, prefix) == inf.name) { + eventsCount++; + sprintf(name, "%s%d", prefix, eventsCount); + if (inf.name == NULL || strcmp(name, inf.name) != 0) { + printf("(#%d) wrong thread name: \"%s\"", + eventsCount, inf.name); + printf(", expected: \"%s\"\n", name); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_threadend001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_threadend001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_threadend001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.ThreadEnd = &ThreadEnd; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ThreadEnd_threadend001_getReady(JNIEnv *env, + jclass cls, jint i, jstring name) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return; + } + + prefix = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, name), NULL); + if (prefix == NULL) { + printf("Failed to copy UTF-8 string!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_THREAD_END, NULL); + if (err == JVMTI_ERROR_NONE) { + eventsExpected = i; + } else { + printf("Failed to enable JVMTI_EVENT_THREAD_END: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_ThreadEnd_threadend001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_THREAD_END, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_THREAD_END: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (eventsCount != eventsExpected) { + printf("Wrong number of thread end events: %d, expected: %d\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/libthreadend002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/libthreadend002.c deleted file mode 100644 index 161cbcac0d7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/libthreadend002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "threadend002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/libthreadend002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/libthreadend002.cpp new file mode 100644 index 00000000000..c1b13179216 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/libthreadend002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "threadend002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/threadend002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/threadend002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/threadend002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadEnd/threadend002/threadend002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/libthreadstart001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/libthreadstart001.c deleted file mode 100644 index 6fdbca951f9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/libthreadstart001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "threadstart001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/libthreadstart001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/libthreadstart001.cpp new file mode 100644 index 00000000000..50c9c4c969b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/libthreadstart001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "threadstart001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/threadstart001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/threadstart001.c deleted file mode 100644 index a2a3d665b03..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/threadstart001.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static int eventsCount = 0; -static int eventsExpected = 0; -static const char *prefix = NULL; - -void JNICALL ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - jvmtiError err; - jvmtiThreadInfo inf; - char name[32]; - - err = (*jvmti_env)->GetThreadInfo(jvmti_env, thread, &inf); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo#%d) unexpected error: %s (%d)\n", - eventsCount, TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> %s\n", inf.name); - } - if (inf.name != NULL && strstr(inf.name, prefix) == inf.name) { - sprintf(name, "%s%d", prefix, eventsCount); - if (strcmp(name, inf.name) != 0) { - printf("(#%d) wrong thread name: \"%s\"", - eventsCount, inf.name); - printf(", expected: \"%s\"\n", name); - result = STATUS_FAILED; - } - eventsCount++; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_threadstart001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_threadstart001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_threadstart001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.ThreadStart = &ThreadStart; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_ThreadStart_threadstart001_getReady(JNIEnv *env, - jclass cls, jint i, jstring name) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return; - } - - prefix = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, name), NULL); - if (prefix == NULL) { - printf("Failed to copy UTF-8 string!\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_THREAD_START, NULL); - if (err == JVMTI_ERROR_NONE) { - eventsExpected = i; - } else { - printf("Failed to enable JVMTI_EVENT_THREAD_START: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_ThreadStart_threadstart001_check(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_THREAD_START, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_THREAD_START: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (eventsCount != eventsExpected) { - printf("Wrong number of thread start events: %d, expected: %d\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/threadstart001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/threadstart001.cpp new file mode 100644 index 00000000000..d8fa212942e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart001/threadstart001.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static int eventsCount = 0; +static int eventsExpected = 0; +static const char *prefix = NULL; + +void JNICALL ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + jvmtiError err; + jvmtiThreadInfo inf; + char name[32]; + + err = jvmti_env->GetThreadInfo(thread, &inf); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo#%d) unexpected error: %s (%d)\n", + eventsCount, TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> %s\n", inf.name); + } + if (inf.name != NULL && strstr(inf.name, prefix) == inf.name) { + sprintf(name, "%s%d", prefix, eventsCount); + if (strcmp(name, inf.name) != 0) { + printf("(#%d) wrong thread name: \"%s\"", + eventsCount, inf.name); + printf(", expected: \"%s\"\n", name); + result = STATUS_FAILED; + } + eventsCount++; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_threadstart001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_threadstart001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_threadstart001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.ThreadStart = &ThreadStart; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_ThreadStart_threadstart001_getReady(JNIEnv *env, + jclass cls, jint i, jstring name) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return; + } + + prefix = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, name), NULL); + if (prefix == NULL) { + printf("Failed to copy UTF-8 string!\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_THREAD_START, NULL); + if (err == JVMTI_ERROR_NONE) { + eventsExpected = i; + } else { + printf("Failed to enable JVMTI_EVENT_THREAD_START: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_ThreadStart_threadstart001_check(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_THREAD_START, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_THREAD_START: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (eventsCount != eventsExpected) { + printf("Wrong number of thread start events: %d, expected: %d\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/libthreadstart002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/libthreadstart002.c deleted file mode 100644 index eb8f0245709..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/libthreadstart002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "threadstart002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/libthreadstart002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/libthreadstart002.cpp new file mode 100644 index 00000000000..e32550ee293 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/libthreadstart002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "threadstart002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/threadstart002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/threadstart002.c deleted file mode 100644 index e137caa0689..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/threadstart002.c +++ /dev/null @@ -1,547 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include - -#include "nsk_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" -#include "agent_common.h" -#include "jni_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define WAIT_TIME 2000 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -/* volatile variables */ -static jrawMonitorID agent_start_lock, thr_start_lock, thr_resume_lock, thr_event_lock; -static volatile jthread agent_thread = NULL; -static volatile jboolean terminate_debug_agent = JNI_FALSE; -static volatile jboolean debug_agent_timed_out = JNI_FALSE; -static volatile jboolean debug_agent_started = JNI_FALSE; -static volatile jthread next_thread = NULL; -static jvmtiThreadInfo inf; -static volatile int eventsCount = 0; -static volatile jint result = PASSED; - -/* - The agent runs special debugger agent (debug_agent) in a separate thread - that operates on behalf of other threads. - Upon receiving ThreadStart event, the debugger agent: - - suspends the new thread - - calls jni_DeleteGlobalRef with a jnienv * for that new thread - - resumes the new thread - Then the thread suspend status is checked in ThreadStart callback. - - The following monitors are used to synchronize debugger thread with other - threads: - 1. agent_start_lock - used to notify VMInit callback as well as ThreadStart callback - that agent thread has been started. - 2. thr_event_lock - used to guarantee that only one ThreadStart event is proceeded at - the time. - 3. thr_start_lock - used to notify agent thread that new thread has been started. - 4. thr_resume_lock - used to notify ThreadStart callback that agent thread finished - suspending and resuming the thread. - - So, the threads behaves as following: - -VMInit | debug_agent | ThreadStart -------------------------------------------------------------------------- - | | - agent_start_lock.enter | | agent_start_lock.enter - | | - ... create debug_agent | ... start | while (!debug_agent) - agent_start_lock.wait | | agent_start_lock.wait - | agent_start_lock.enter | - | agent_start_lock.notifyAll | - | agent_start_lock.exit | - agent_start_lock.exit | | agent_start_lock.exit - | | - | | thr_event_lock.enter - | | - | thr_start_lock.enter | thr_start_lock.enter - | if (!next_thread) | thr_resume_lock.enter - | thr_start_lock.wait | - | | ... next_thread = ... - | | thr_start_lock.notify - | | thr_start_lock.exit - | | - | ... suspend new thread | thr_resume_lock.wait - | ... resume new thread | - | | - | thr_resume_lock.enter | - | thr_resume_lock.notify | - | thr_resume_lock.exit | - | | ... check next_thread state - | | thr_resume_lock.exit - | thr_start_lock.exit | - | thr_event_lock.exit - - -*/ - -static void JNICALL -debug_agent(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { - JNIEnv *env = jni; - jint thrStat; - jobject temp; - - /* Notify VMInit callback as well as ThreadStart callback (if any) - * that agent thread has been started - */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, agent_start_lock))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("[agent] failed to acquire agent_start_lock\n"); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorNotifyAll, jvmti, agent_start_lock))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("[agent] failed to notify about agent_start_lock\n"); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, agent_start_lock))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("[agent] failed to release agent_start_lock\n"); - } - - NSK_DISPLAY0(">>> [agent] agent created\n"); - - debug_agent_started = JNI_TRUE; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, thr_start_lock))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("[agent] failed to enter thr_start_lock\n"); - } - - while (terminate_debug_agent != JNI_TRUE) { - - if (next_thread == NULL ) { - /* wait till new thread will be created and started */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RawMonitorWait, jvmti, thr_start_lock, (jlong)0))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("[agent] Failed while waiting thr_start_lock\n"); - } - } - - if (next_thread != NULL) { - /* hmm, why NewGlobalRef is called one more time??? - * next_thread = NSK_CPP_STUB2(NewGlobalRef, env, next_thread); - */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(SuspendThread, jvmti, next_thread))) { - result = STATUS_FAILED; - NSK_COMPLAIN1("[agent] Failed to suspend thread#%d\n", eventsCount); - } - - NSK_DISPLAY2(">>> [agent] thread#%d %s suspended ...\n", eventsCount, inf.name); - - /* these dummy calls provoke VM to hang */ - temp = NSK_CPP_STUB2(NewGlobalRef, env, next_thread); - NSK_CPP_STUB2(DeleteGlobalRef, env, temp); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(ResumeThread, jvmti, next_thread))) { - result = STATUS_FAILED; - NSK_COMPLAIN1("[agent] Failed to resume thread#%d\n", eventsCount); - } - - NSK_DISPLAY2(">>> [agent] thread#%d %s resumed ...\n", eventsCount, inf.name); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadState, jvmti, next_thread, &thrStat))) { - result = STATUS_FAILED; - NSK_COMPLAIN1("[agent] Failed to get thread state for thread#%d\n", eventsCount); - } - - NSK_DISPLAY3(">>> [agent] %s threadState=%s (%x)\n", - inf.name, TranslateState(thrStat), thrStat); - - if (thrStat & JVMTI_THREAD_STATE_SUSPENDED) { - NSK_COMPLAIN1("[agent] \"%s\" was not resumed\n", inf.name); - NSK_CPP_STUB2(FatalError, env, "[agent] could not recover"); - } - - NSK_CPP_STUB2(DeleteGlobalRef, env, next_thread); - next_thread = NULL; - - /* Notify ThreadStart callback that thread has been resumed */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, thr_resume_lock))) { - NSK_COMPLAIN0("[agent] Failed to acquire thr_resume_lock\n"); - result = STATUS_FAILED; - } - - debug_agent_timed_out = JNI_FALSE; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorNotify, jvmti, thr_resume_lock))) { - NSK_COMPLAIN0("[agent] Failed to notifing about thr_resume_lock\n"); - result = STATUS_FAILED; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, thr_resume_lock))) { - NSK_COMPLAIN0("[agent] Failed to release thr_resume_lock\n"); - result = STATUS_FAILED; - } - } - } - - /* - * We don't call RawMonitorExit(thr_start_lock) in the loop so we don't - * lose any notify calls. - */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, thr_start_lock))) { - NSK_COMPLAIN0("[agent] Failed to release thr_start_lock\n"); - result = STATUS_FAILED; - } - - NSK_DISPLAY0(">>> [agent] done.\n"); -} - -void JNICALL ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - jint thrStat; - jvmtiPhase phase; - - NSK_DISPLAY0(">>> [ThreadStart hook] start\n"); - - /* skip if thread is 'agent thread' */ - if (NSK_CPP_STUB3(IsSameObject, env, agent_thread, thread) == JNI_TRUE) { - NSK_DISPLAY0(">>> [ThreadStart hook] skip agent thread\n"); - NSK_DISPLAY0(">>> [ThreadStart hook] end\n"); - return; - } - - /* wait till agent thread is started - * (otherwise can fail while waiting on thr_resume_thread due to timeout) - */ - if (debug_agent_started != JNI_TRUE) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti_env, agent_start_lock))) { - NSK_COMPLAIN0("[ThreadStart hook] Failed to acquire agent_start_lock\n"); - result = STATUS_FAILED; - } - - while (debug_agent_started != JNI_TRUE) { - NSK_DISPLAY1(">>> [ThreadStart hook] waiting %dms for agent thread to start\n", WAIT_TIME); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RawMonitorWait, - jvmti_env, agent_start_lock, (jlong)WAIT_TIME))) { - NSK_COMPLAIN0("[ThreadStart hook] Failed to wait for agent_start_lock\n"); - result = STATUS_FAILED; - } - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti_env, agent_start_lock))) { - NSK_COMPLAIN0("[ThreadStart hook] Failed to release agent_start_lock\n"); - result = STATUS_FAILED; - } - } - - - /* get JVMTI phase */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - NSK_COMPLAIN0("[ThreadStart hook] Failed to get JVMTI phase\n"); - result = STATUS_FAILED; - } - - /* Acquire event lock, - * so only one StartThread callback could be proceeded at the time - */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti_env, thr_event_lock))) { - NSK_COMPLAIN0("[ThreadStart hook] Failed to acquire thr_event_lock\n"); - result = STATUS_FAILED; - } - - { - /* Get thread name */ - inf.name = "UNKNOWN"; - if (phase == JVMTI_PHASE_LIVE) { - /* GetThreadInfo may only be called during the live phase */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetThreadInfo, jvmti_env, thread, &inf))) { - NSK_COMPLAIN1("[ThreadStart hook] Failed to get thread infor for thread#%d\n", eventsCount); - result = STATUS_FAILED; - } - } - - NSK_DISPLAY2(">>> [ThreadStart hook] thread#%d: %s\n", eventsCount, inf.name); - - /* Acquire thr_start_lock */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti_env, thr_start_lock))) { - NSK_COMPLAIN1("[ThreadStart hook] thread#%d failed to acquire thr_start_lock\n", eventsCount); - result = STATUS_FAILED; - } - - /* Acquire thr_resume_lock before we release thr_start_lock to prevent - * debug agent from notifying us before we are ready. - */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti_env, thr_resume_lock))) { - NSK_COMPLAIN1("[ThreadStart hook] thread#%d failed to acquire thr_resume_lock\n", eventsCount); - result = STATUS_FAILED; - } - - /* Store thread */ - next_thread = NSK_CPP_STUB2(NewGlobalRef, env, thread); - debug_agent_timed_out = JNI_TRUE; - - /* Notify agent thread about new started thread and let agent thread to work with it */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorNotify, jvmti_env, thr_start_lock))) { - NSK_COMPLAIN1("[ThreadStart hook] thread#%d failed to notify about thr_start_lock\n", eventsCount); - result = STATUS_FAILED; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti_env, thr_start_lock))) { - NSK_COMPLAIN1("[ThreadStart hook] thread#%d failed to release thr_start_lock\n", eventsCount); - result = STATUS_FAILED; - } - - /* Wait till this started thread will be resumed by agent thread */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RawMonitorWait, - jvmti_env, thr_resume_lock, (jlong)WAIT_TIME ))) { - NSK_COMPLAIN1("[ThreadStart hook] thread#%d failed while waiting for thr_resume_lock\n", eventsCount); - result = STATUS_FAILED; - } - - if (debug_agent_timed_out == JNI_TRUE) { - NSK_COMPLAIN1("[ThreadStart hook] \"%s\": debug agent timed out\n", inf.name); - NSK_CPP_STUB2(FatalError, env, "[ThreadStart hook] could not recover"); - } - - /* Release thr_resume_lock lock */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti_env, thr_resume_lock))) { - NSK_COMPLAIN1("[ThreadStart hook] thread#%d failed to release thr_resume_lock\n", eventsCount); - result = STATUS_FAILED; - } - - /* check that thread is not in SUSPENDED state */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadState, jvmti_env, thread, &thrStat))) { - NSK_COMPLAIN1("[ThreadStart hook] Failed to get thread state for thread#%d\n", eventsCount); - result = STATUS_FAILED; - } - - NSK_DISPLAY2(">>> [ThreadStart hook] threadState=%s (%x)\n", - TranslateState(thrStat), thrStat); - - if (thrStat & JVMTI_THREAD_STATE_SUSPENDED) { - NSK_COMPLAIN1("[ThreadStart hook] \"%s\" was self-suspended\n", inf.name); - NSK_CPP_STUB2(FatalError, env, "[ThreadStart hook] could not recover"); - } - - eventsCount++; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti_env, thr_event_lock))) { - NSK_COMPLAIN0("[ThreadStart hook] Failed to release thr_event_lock\n"); - result = STATUS_FAILED; - } - - NSK_DISPLAY0(">>> [ThreadStart hook] end\n"); -} - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - jclass cls = NULL; - jmethodID mid = NULL; - - NSK_DISPLAY0(">>> VMInit event: start\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL))) { - NSK_COMPLAIN0("TEST FAILED: failed to enable JVMTI_EVENT_THREAD_START\n"); - return; - } - - /* Start agent thread */ - if (!NSK_VERIFY((cls = - NSK_CPP_STUB2(FindClass, env, "java/lang/Thread")) != NULL)) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: Cannot start agent thread: FindClass() failed\n"); - return; - } - - - if (!NSK_VERIFY((mid = - NSK_CPP_STUB4(GetMethodID, env, cls, "", "()V")) != NULL)) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: Cannot start agent thread: GetMethodID() failed\n"); - return; - } - - - if (!NSK_VERIFY((agent_thread = - NSK_CPP_STUB3(NewObject, env, cls, mid)) != NULL)) { - result = STATUS_FAILED; - NSK_COMPLAIN0("Cannot start agent thread: NewObject() failed\n"); - return; - } - - agent_thread = (jthread) NSK_CPP_STUB2(NewGlobalRef, env, agent_thread); - if (agent_thread == NULL) { - result = STATUS_FAILED; - NSK_COMPLAIN0("Cannot create global reference for agent_thread\n"); - return; - } - - /* - * Grab agent_start_lock before launching debug_agent to prevent - * debug_agent from notifying us before we are ready. - */ - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti_env, agent_start_lock))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: failed to enter agent_start_lock\n"); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(RunAgentThread, - jvmti_env, agent_thread, debug_agent, NULL, JVMTI_THREAD_NORM_PRIORITY))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: failed to create agent thread\n"); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RawMonitorWait, jvmti_env, agent_start_lock, (jlong)0))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: failed to wait agent_start_lock\n"); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti_env, agent_start_lock))) { - result = STATUS_FAILED; - NSK_COMPLAIN0("TEST FAILED: failed to exit agent_start_lock\n"); - } - - NSK_DISPLAY0(">>> VMInit event: end\n"); -} - -void JNICALL VMDeath(jvmtiEnv *jvmti_env, JNIEnv *env) { - NSK_DISPLAY0(">>> VMDeath event\n"); - - terminate_debug_agent = JNI_TRUE; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_threadstart002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_threadstart002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_threadstart002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) { - NSK_COMPLAIN0("TEST FAILED: failed to create JVMTIEnv\n"); - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPotentialCapabilities, jvmti, &caps))) { - NSK_COMPLAIN0("TEST FAILED: failed to get potential capabilities\n"); - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - NSK_COMPLAIN0("TEST FAILED: failed to add capabilities during agent load\n"); - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, jvmti, &caps))) { - NSK_COMPLAIN0("TEST FAILED: failed to get capabilities\n"); - return JNI_ERR; - } - - if (!caps.can_suspend) { - NSK_DISPLAY0("WARNING: suspend/resume is not implemented\n"); - } - - /* create raw monitors */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_agent_start_lock", &agent_start_lock))) { - NSK_COMPLAIN0("TEST FAILED: failed to create agent_start_lock\n"); - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_thr_event_lock", &thr_event_lock))) { - NSK_COMPLAIN0("TEST FAILED: failed to create thr_event_lock\n"); - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_thr_start_lock", &thr_start_lock))) { - NSK_COMPLAIN0("TEST FAILED: failed to create thr_start_lock\n"); - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_thr_resume_lock", &thr_resume_lock))) { - NSK_COMPLAIN0("TEST FAILED: failed to create thr_resume_lock\n"); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - callbacks.VMDeath = &VMDeath; - callbacks.ThreadStart = &ThreadStart; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, sizeof(callbacks)))) { - NSK_COMPLAIN0("TEST FAILED: failed to set event callbacks\n"); - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL))) { - NSK_COMPLAIN0("TEST FAILED: failed to enable JVMTI_EVENT_VM_INIT\n"); - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL))) { - NSK_COMPLAIN0("TEST FAILED: failed to enable JVMTI_EVENT_VM_DEATH\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_ThreadStart_threadstart002_check(JNIEnv *env, jclass cls) { - if (eventsCount == 0) { - NSK_COMPLAIN0("None of thread start events!\n"); - result = STATUS_FAILED; - } - - NSK_DISPLAY1(">>> total of thread start events: %d\n", eventsCount); - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/threadstart002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/threadstart002.cpp new file mode 100644 index 00000000000..8bfd67f78c1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart002/threadstart002.cpp @@ -0,0 +1,547 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include + +#include "nsk_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" +#include "agent_common.h" +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define WAIT_TIME 2000 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +/* volatile variables */ +static jrawMonitorID agent_start_lock, thr_start_lock, thr_resume_lock, thr_event_lock; +static volatile jthread agent_thread = NULL; +static volatile jboolean terminate_debug_agent = JNI_FALSE; +static volatile jboolean debug_agent_timed_out = JNI_FALSE; +static volatile jboolean debug_agent_started = JNI_FALSE; +static volatile jthread next_thread = NULL; +static jvmtiThreadInfo inf; +static volatile int eventsCount = 0; +static volatile jint result = PASSED; + +/* + The agent runs special debugger agent (debug_agent) in a separate thread + that operates on behalf of other threads. + Upon receiving ThreadStart event, the debugger agent: + - suspends the new thread + - calls jni_DeleteGlobalRef with a jnienv * for that new thread + - resumes the new thread + Then the thread suspend status is checked in ThreadStart callback. + + The following monitors are used to synchronize debugger thread with other + threads: + 1. agent_start_lock + used to notify VMInit callback as well as ThreadStart callback + that agent thread has been started. + 2. thr_event_lock + used to guarantee that only one ThreadStart event is proceeded at + the time. + 3. thr_start_lock + used to notify agent thread that new thread has been started. + 4. thr_resume_lock + used to notify ThreadStart callback that agent thread finished + suspending and resuming the thread. + + So, the threads behaves as following: + +VMInit | debug_agent | ThreadStart +------------------------------------------------------------------------- + | | + agent_start_lock.enter | | agent_start_lock.enter + | | + ... create debug_agent | ... start | while (!debug_agent) + agent_start_lock.wait | | agent_start_lock.wait + | agent_start_lock.enter | + | agent_start_lock.notifyAll | + | agent_start_lock.exit | + agent_start_lock.exit | | agent_start_lock.exit + | | + | | thr_event_lock.enter + | | + | thr_start_lock.enter | thr_start_lock.enter + | if (!next_thread) | thr_resume_lock.enter + | thr_start_lock.wait | + | | ... next_thread = ... + | | thr_start_lock.notify + | | thr_start_lock.exit + | | + | ... suspend new thread | thr_resume_lock.wait + | ... resume new thread | + | | + | thr_resume_lock.enter | + | thr_resume_lock.notify | + | thr_resume_lock.exit | + | | ... check next_thread state + | | thr_resume_lock.exit + | thr_start_lock.exit | + | thr_event_lock.exit + + +*/ + +static void JNICALL +debug_agent(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { + JNIEnv *env = jni; + jint thrStat; + jobject temp; + + /* Notify VMInit callback as well as ThreadStart callback (if any) + * that agent thread has been started + */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, agent_start_lock))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("[agent] failed to acquire agent_start_lock\n"); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorNotifyAll, jvmti, agent_start_lock))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("[agent] failed to notify about agent_start_lock\n"); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, agent_start_lock))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("[agent] failed to release agent_start_lock\n"); + } + + NSK_DISPLAY0(">>> [agent] agent created\n"); + + debug_agent_started = JNI_TRUE; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, thr_start_lock))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("[agent] failed to enter thr_start_lock\n"); + } + + while (terminate_debug_agent != JNI_TRUE) { + + if (next_thread == NULL ) { + /* wait till new thread will be created and started */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RawMonitorWait, jvmti, thr_start_lock, (jlong)0))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("[agent] Failed while waiting thr_start_lock\n"); + } + } + + if (next_thread != NULL) { + /* hmm, why NewGlobalRef is called one more time??? + * next_thread = NSK_CPP_STUB2(NewGlobalRef, env, next_thread); + */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(SuspendThread, jvmti, next_thread))) { + result = STATUS_FAILED; + NSK_COMPLAIN1("[agent] Failed to suspend thread#%d\n", eventsCount); + } + + NSK_DISPLAY2(">>> [agent] thread#%d %s suspended ...\n", eventsCount, inf.name); + + /* these dummy calls provoke VM to hang */ + temp = NSK_CPP_STUB2(NewGlobalRef, env, next_thread); + NSK_CPP_STUB2(DeleteGlobalRef, env, temp); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(ResumeThread, jvmti, next_thread))) { + result = STATUS_FAILED; + NSK_COMPLAIN1("[agent] Failed to resume thread#%d\n", eventsCount); + } + + NSK_DISPLAY2(">>> [agent] thread#%d %s resumed ...\n", eventsCount, inf.name); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadState, jvmti, next_thread, &thrStat))) { + result = STATUS_FAILED; + NSK_COMPLAIN1("[agent] Failed to get thread state for thread#%d\n", eventsCount); + } + + NSK_DISPLAY3(">>> [agent] %s threadState=%s (%x)\n", + inf.name, TranslateState(thrStat), thrStat); + + if (thrStat & JVMTI_THREAD_STATE_SUSPENDED) { + NSK_COMPLAIN1("[agent] \"%s\" was not resumed\n", inf.name); + NSK_CPP_STUB2(FatalError, env, "[agent] could not recover"); + } + + NSK_CPP_STUB2(DeleteGlobalRef, env, next_thread); + next_thread = NULL; + + /* Notify ThreadStart callback that thread has been resumed */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, thr_resume_lock))) { + NSK_COMPLAIN0("[agent] Failed to acquire thr_resume_lock\n"); + result = STATUS_FAILED; + } + + debug_agent_timed_out = JNI_FALSE; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorNotify, jvmti, thr_resume_lock))) { + NSK_COMPLAIN0("[agent] Failed to notifing about thr_resume_lock\n"); + result = STATUS_FAILED; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, thr_resume_lock))) { + NSK_COMPLAIN0("[agent] Failed to release thr_resume_lock\n"); + result = STATUS_FAILED; + } + } + } + + /* + * We don't call RawMonitorExit(thr_start_lock) in the loop so we don't + * lose any notify calls. + */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, thr_start_lock))) { + NSK_COMPLAIN0("[agent] Failed to release thr_start_lock\n"); + result = STATUS_FAILED; + } + + NSK_DISPLAY0(">>> [agent] done.\n"); +} + +void JNICALL ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + jint thrStat; + jvmtiPhase phase; + + NSK_DISPLAY0(">>> [ThreadStart hook] start\n"); + + /* skip if thread is 'agent thread' */ + if (NSK_CPP_STUB3(IsSameObject, env, agent_thread, thread) == JNI_TRUE) { + NSK_DISPLAY0(">>> [ThreadStart hook] skip agent thread\n"); + NSK_DISPLAY0(">>> [ThreadStart hook] end\n"); + return; + } + + /* wait till agent thread is started + * (otherwise can fail while waiting on thr_resume_thread due to timeout) + */ + if (debug_agent_started != JNI_TRUE) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti_env, agent_start_lock))) { + NSK_COMPLAIN0("[ThreadStart hook] Failed to acquire agent_start_lock\n"); + result = STATUS_FAILED; + } + + while (debug_agent_started != JNI_TRUE) { + NSK_DISPLAY1(">>> [ThreadStart hook] waiting %dms for agent thread to start\n", WAIT_TIME); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RawMonitorWait, + jvmti_env, agent_start_lock, (jlong)WAIT_TIME))) { + NSK_COMPLAIN0("[ThreadStart hook] Failed to wait for agent_start_lock\n"); + result = STATUS_FAILED; + } + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti_env, agent_start_lock))) { + NSK_COMPLAIN0("[ThreadStart hook] Failed to release agent_start_lock\n"); + result = STATUS_FAILED; + } + } + + + /* get JVMTI phase */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + NSK_COMPLAIN0("[ThreadStart hook] Failed to get JVMTI phase\n"); + result = STATUS_FAILED; + } + + /* Acquire event lock, + * so only one StartThread callback could be proceeded at the time + */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti_env, thr_event_lock))) { + NSK_COMPLAIN0("[ThreadStart hook] Failed to acquire thr_event_lock\n"); + result = STATUS_FAILED; + } + + { + /* Get thread name */ + inf.name = (char*) "UNKNOWN"; + if (phase == JVMTI_PHASE_LIVE) { + /* GetThreadInfo may only be called during the live phase */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetThreadInfo, jvmti_env, thread, &inf))) { + NSK_COMPLAIN1("[ThreadStart hook] Failed to get thread infor for thread#%d\n", eventsCount); + result = STATUS_FAILED; + } + } + + NSK_DISPLAY2(">>> [ThreadStart hook] thread#%d: %s\n", eventsCount, inf.name); + + /* Acquire thr_start_lock */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti_env, thr_start_lock))) { + NSK_COMPLAIN1("[ThreadStart hook] thread#%d failed to acquire thr_start_lock\n", eventsCount); + result = STATUS_FAILED; + } + + /* Acquire thr_resume_lock before we release thr_start_lock to prevent + * debug agent from notifying us before we are ready. + */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti_env, thr_resume_lock))) { + NSK_COMPLAIN1("[ThreadStart hook] thread#%d failed to acquire thr_resume_lock\n", eventsCount); + result = STATUS_FAILED; + } + + /* Store thread */ + next_thread = NSK_CPP_STUB2(NewGlobalRef, env, thread); + debug_agent_timed_out = JNI_TRUE; + + /* Notify agent thread about new started thread and let agent thread to work with it */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorNotify, jvmti_env, thr_start_lock))) { + NSK_COMPLAIN1("[ThreadStart hook] thread#%d failed to notify about thr_start_lock\n", eventsCount); + result = STATUS_FAILED; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti_env, thr_start_lock))) { + NSK_COMPLAIN1("[ThreadStart hook] thread#%d failed to release thr_start_lock\n", eventsCount); + result = STATUS_FAILED; + } + + /* Wait till this started thread will be resumed by agent thread */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RawMonitorWait, + jvmti_env, thr_resume_lock, (jlong)WAIT_TIME ))) { + NSK_COMPLAIN1("[ThreadStart hook] thread#%d failed while waiting for thr_resume_lock\n", eventsCount); + result = STATUS_FAILED; + } + + if (debug_agent_timed_out == JNI_TRUE) { + NSK_COMPLAIN1("[ThreadStart hook] \"%s\": debug agent timed out\n", inf.name); + NSK_CPP_STUB2(FatalError, env, "[ThreadStart hook] could not recover"); + } + + /* Release thr_resume_lock lock */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti_env, thr_resume_lock))) { + NSK_COMPLAIN1("[ThreadStart hook] thread#%d failed to release thr_resume_lock\n", eventsCount); + result = STATUS_FAILED; + } + + /* check that thread is not in SUSPENDED state */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadState, jvmti_env, thread, &thrStat))) { + NSK_COMPLAIN1("[ThreadStart hook] Failed to get thread state for thread#%d\n", eventsCount); + result = STATUS_FAILED; + } + + NSK_DISPLAY2(">>> [ThreadStart hook] threadState=%s (%x)\n", + TranslateState(thrStat), thrStat); + + if (thrStat & JVMTI_THREAD_STATE_SUSPENDED) { + NSK_COMPLAIN1("[ThreadStart hook] \"%s\" was self-suspended\n", inf.name); + NSK_CPP_STUB2(FatalError, env, "[ThreadStart hook] could not recover"); + } + + eventsCount++; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti_env, thr_event_lock))) { + NSK_COMPLAIN0("[ThreadStart hook] Failed to release thr_event_lock\n"); + result = STATUS_FAILED; + } + + NSK_DISPLAY0(">>> [ThreadStart hook] end\n"); +} + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + jclass cls = NULL; + jmethodID mid = NULL; + + NSK_DISPLAY0(">>> VMInit event: start\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL))) { + NSK_COMPLAIN0("TEST FAILED: failed to enable JVMTI_EVENT_THREAD_START\n"); + return; + } + + /* Start agent thread */ + if (!NSK_VERIFY((cls = + NSK_CPP_STUB2(FindClass, env, "java/lang/Thread")) != NULL)) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: Cannot start agent thread: FindClass() failed\n"); + return; + } + + + if (!NSK_VERIFY((mid = + NSK_CPP_STUB4(GetMethodID, env, cls, "", "()V")) != NULL)) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: Cannot start agent thread: GetMethodID() failed\n"); + return; + } + + + if (!NSK_VERIFY((agent_thread = + NSK_CPP_STUB3(NewObject, env, cls, mid)) != NULL)) { + result = STATUS_FAILED; + NSK_COMPLAIN0("Cannot start agent thread: NewObject() failed\n"); + return; + } + + agent_thread = (jthread) NSK_CPP_STUB2(NewGlobalRef, env, agent_thread); + if (agent_thread == NULL) { + result = STATUS_FAILED; + NSK_COMPLAIN0("Cannot create global reference for agent_thread\n"); + return; + } + + /* + * Grab agent_start_lock before launching debug_agent to prevent + * debug_agent from notifying us before we are ready. + */ + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti_env, agent_start_lock))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: failed to enter agent_start_lock\n"); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(RunAgentThread, + jvmti_env, agent_thread, debug_agent, NULL, JVMTI_THREAD_NORM_PRIORITY))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: failed to create agent thread\n"); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RawMonitorWait, jvmti_env, agent_start_lock, (jlong)0))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: failed to wait agent_start_lock\n"); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti_env, agent_start_lock))) { + result = STATUS_FAILED; + NSK_COMPLAIN0("TEST FAILED: failed to exit agent_start_lock\n"); + } + + NSK_DISPLAY0(">>> VMInit event: end\n"); +} + +void JNICALL VMDeath(jvmtiEnv *jvmti_env, JNIEnv *env) { + NSK_DISPLAY0(">>> VMDeath event\n"); + + terminate_debug_agent = JNI_TRUE; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_threadstart002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_threadstart002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_threadstart002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) { + NSK_COMPLAIN0("TEST FAILED: failed to create JVMTIEnv\n"); + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPotentialCapabilities, jvmti, &caps))) { + NSK_COMPLAIN0("TEST FAILED: failed to get potential capabilities\n"); + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + NSK_COMPLAIN0("TEST FAILED: failed to add capabilities during agent load\n"); + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, jvmti, &caps))) { + NSK_COMPLAIN0("TEST FAILED: failed to get capabilities\n"); + return JNI_ERR; + } + + if (!caps.can_suspend) { + NSK_DISPLAY0("WARNING: suspend/resume is not implemented\n"); + } + + /* create raw monitors */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_agent_start_lock", &agent_start_lock))) { + NSK_COMPLAIN0("TEST FAILED: failed to create agent_start_lock\n"); + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_thr_event_lock", &thr_event_lock))) { + NSK_COMPLAIN0("TEST FAILED: failed to create thr_event_lock\n"); + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_thr_start_lock", &thr_start_lock))) { + NSK_COMPLAIN0("TEST FAILED: failed to create thr_start_lock\n"); + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_thr_resume_lock", &thr_resume_lock))) { + NSK_COMPLAIN0("TEST FAILED: failed to create thr_resume_lock\n"); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + callbacks.VMDeath = &VMDeath; + callbacks.ThreadStart = &ThreadStart; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, sizeof(callbacks)))) { + NSK_COMPLAIN0("TEST FAILED: failed to set event callbacks\n"); + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL))) { + NSK_COMPLAIN0("TEST FAILED: failed to enable JVMTI_EVENT_VM_INIT\n"); + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL))) { + NSK_COMPLAIN0("TEST FAILED: failed to enable JVMTI_EVENT_VM_DEATH\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_ThreadStart_threadstart002_check(JNIEnv *env, jclass cls) { + if (eventsCount == 0) { + NSK_COMPLAIN0("None of thread start events!\n"); + result = STATUS_FAILED; + } + + NSK_DISPLAY1(">>> total of thread start events: %d\n", eventsCount); + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/libthreadstart003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/libthreadstart003.c deleted file mode 100644 index df8c8da117a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/libthreadstart003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "threadstart003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/libthreadstart003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/libthreadstart003.cpp new file mode 100644 index 00000000000..f6b5054cd4a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/libthreadstart003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "threadstart003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/threadstart003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/threadstart003.c deleted file mode 100644 index 5229020717e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/threadstart003.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define WAIT_TIME 1000 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jrawMonitorID wait_lock; -static const char *threadName = NULL; -static int startsCount = 0; -static int startsExpected = 0; -static int endsCount = 0; -static int endsExpected = 0; - -void JNICALL ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - jvmtiError err; - jvmtiThreadInfo inf; - - err = (*jvmti_env)->GetThreadInfo(jvmti_env, thread, &inf); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo, start) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> start: %s\n", inf.name); - } - if (inf.name != NULL && strcmp(inf.name, threadName) == 0) { - startsCount++; - } -} - -void JNICALL ThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - jvmtiError err; - jvmtiThreadInfo inf; - - err = (*jvmti_env)->GetThreadInfo(jvmti_env, thread, &inf); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo, end) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump == JNI_TRUE) { - printf(">>> end: %s\n", inf.name); - } - if (inf.name != NULL && strcmp(inf.name, threadName) == 0) { - endsCount++; - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_threadstart003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_threadstart003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_threadstart003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.ThreadStart = &ThreadStart; - callbacks.ThreadEnd = &ThreadEnd; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -static void JNICALL -threadProc(jvmtiEnv* jvmti, JNIEnv* jni, void *unused) { - jvmtiError err; - - err = (*jvmti)->RawMonitorEnter(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorNotify(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorNotify) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorExit(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_ThreadStart_threadstart003_check(JNIEnv *env, - jclass cls, jthread thr, jstring name) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - threadName = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, name), - NULL); - if (threadName == NULL) { - printf("Failed to copy UTF-8 string!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->CreateRawMonitor(jvmti, "_wait_lock", &wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_THREAD_START, NULL); - if (err == JVMTI_ERROR_NONE) { - startsExpected = 1; - } else { - printf("Failed to enable JVMTI_EVENT_THREAD_START: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_THREAD_END, NULL); - if (err == JVMTI_ERROR_NONE) { - endsExpected = 1; - } else { - printf("Failed to enable JVMTI_EVENT_THREAD_END: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> starting agent thread ...\n"); - } - err = (*jvmti)->RawMonitorEnter(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RunAgentThread(jvmti, thr, threadProc, - NULL, JVMTI_THREAD_MAX_PRIORITY); - if (err != JVMTI_ERROR_NONE) { - printf("(RunAgentThread) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorWait(jvmti, wait_lock, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorExit(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->RawMonitorEnter(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - // Wait for up to 3 seconds for the thread end event - { - int i; - for (i = 0; i < 3 ; i++) { - err = (*jvmti)->RawMonitorWait(jvmti, wait_lock, (jlong)WAIT_TIME); - if (endsCount == endsExpected || err != JVMTI_ERROR_NONE) { - break; - } - } - } - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RawMonitorExit(jvmti, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_THREAD_START, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_THREAD_START: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE, - JVMTI_EVENT_THREAD_END, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to disable JVMTI_EVENT_THREAD_END: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - if (startsCount != startsExpected) { - printf("Wrong number of thread start events: %d, expected: %d\n", - startsCount, startsExpected); - result = STATUS_FAILED; - } - - if (endsCount != endsExpected) { - printf("Wrong number of thread end events: %d, expected: %d\n", - endsCount, endsExpected); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/threadstart003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/threadstart003.cpp new file mode 100644 index 00000000000..4cd50d5e111 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/threadstart003.cpp @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define WAIT_TIME 1000 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jrawMonitorID wait_lock; +static const char *threadName = NULL; +static int startsCount = 0; +static int startsExpected = 0; +static int endsCount = 0; +static int endsExpected = 0; + +void JNICALL ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + jvmtiError err; + jvmtiThreadInfo inf; + + err = jvmti_env->GetThreadInfo(thread, &inf); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo, start) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> start: %s\n", inf.name); + } + if (inf.name != NULL && strcmp(inf.name, threadName) == 0) { + startsCount++; + } +} + +void JNICALL ThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + jvmtiError err; + jvmtiThreadInfo inf; + + err = jvmti_env->GetThreadInfo(thread, &inf); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo, end) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump == JNI_TRUE) { + printf(">>> end: %s\n", inf.name); + } + if (inf.name != NULL && strcmp(inf.name, threadName) == 0) { + endsCount++; + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_threadstart003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_threadstart003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_threadstart003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.ThreadStart = &ThreadStart; + callbacks.ThreadEnd = &ThreadEnd; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +static void JNICALL +threadProc(jvmtiEnv* jvmti, JNIEnv* jni, void *unused) { + jvmtiError err; + + err = jvmti->RawMonitorEnter(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorNotify(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorNotify) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorExit(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_ThreadStart_threadstart003_check(JNIEnv *env, + jclass cls, jthread thr, jstring name) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + threadName = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, name), + NULL); + if (threadName == NULL) { + printf("Failed to copy UTF-8 string!\n"); + return STATUS_FAILED; + } + + err = jvmti->CreateRawMonitor("_wait_lock", &wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_THREAD_START, NULL); + if (err == JVMTI_ERROR_NONE) { + startsExpected = 1; + } else { + printf("Failed to enable JVMTI_EVENT_THREAD_START: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_THREAD_END, NULL); + if (err == JVMTI_ERROR_NONE) { + endsExpected = 1; + } else { + printf("Failed to enable JVMTI_EVENT_THREAD_END: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> starting agent thread ...\n"); + } + err = jvmti->RawMonitorEnter(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RunAgentThread(thr, threadProc, + NULL, JVMTI_THREAD_MAX_PRIORITY); + if (err != JVMTI_ERROR_NONE) { + printf("(RunAgentThread) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorWait(wait_lock, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorExit(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->RawMonitorEnter(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + // Wait for up to 3 seconds for the thread end event + { + int i; + for (i = 0; i < 3 ; i++) { + err = jvmti->RawMonitorWait(wait_lock, (jlong)WAIT_TIME); + if (endsCount == endsExpected || err != JVMTI_ERROR_NONE) { + break; + } + } + } + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RawMonitorExit(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_THREAD_START, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_THREAD_START: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_THREAD_END, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to disable JVMTI_EVENT_THREAD_END: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + if (startsCount != startsExpected) { + printf("Wrong number of thread start events: %d, expected: %d\n", + startsCount, startsExpected); + result = STATUS_FAILED; + } + + if (endsCount != endsExpected) { + printf("Wrong number of thread end events: %d, expected: %d\n", + endsCount, endsExpected); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/libvmdeath001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/libvmdeath001.c deleted file mode 100644 index 4ca3488b9d8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/libvmdeath001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "vmdeath001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/libvmdeath001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/libvmdeath001.cpp new file mode 100644 index 00000000000..79006579249 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/libvmdeath001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "vmdeath001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/vmdeath001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/vmdeath001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/vmdeath001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/vmdeath001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/libvminit001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/libvminit001.c deleted file mode 100644 index dc594ae7f94..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/libvminit001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "vminit001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/libvminit001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/libvminit001.cpp new file mode 100644 index 00000000000..c5d645c7749 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/libvminit001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "vminit001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/vminit001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/vminit001.c deleted file mode 100644 index 60f5e1fd0cd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/vminit001.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define WAIT_TIME 1000 - -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static char *name = "main"; -static int mainStarted = 0; -static int eventsCount = 0; -static int eventsExpected = 1; - -void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { - jvmtiError err; - jrawMonitorID wait_lock; - - if (printdump == JNI_TRUE) { - printf(">>> VM init event #%d\n", eventsCount); - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_THREAD_START, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_THREAD_START: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - err = (*jvmti_env)->CreateRawMonitor(jvmti_env, "_wait_lock", &wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(CreateRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->RawMonitorEnter(jvmti_env, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorEnter) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->RawMonitorWait(jvmti_env, wait_lock, (jlong)WAIT_TIME); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorWait) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->RawMonitorExit(jvmti_env, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(RawMonitorExit) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti_env)->DestroyRawMonitor(jvmti_env, wait_lock); - if (err != JVMTI_ERROR_NONE) { - printf("(DestroyRawMonitor) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - - eventsCount++; -} - -void JNICALL ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - jvmtiError err; - jvmtiThreadInfo inf; - - err = (*jvmti_env)->GetThreadInfo(jvmti_env, thread, &inf); - if (err != JVMTI_ERROR_NONE) { - printf("(GetThreadInfo) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - if (printdump == JNI_TRUE) { - printf(">>> thread start: %s\n", inf.name); - } - if (inf.name != NULL && strcmp(name, inf.name) == 0) { - mainStarted++; - if (eventsCount == 0) { - printf("ThreadStart event for the main thread occurs\n"); - printf("before the VMInit event does return.\n"); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_vminit001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_vminit001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_vminit001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.VMInit = &VMInit; - callbacks.ThreadStart = &ThreadStart; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_VMInit_vminit001_check(JNIEnv *env, jclass cls) { - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (eventsCount != eventsExpected) { - printf("Wrong number of VM init events: %d, expected: %d\n", - eventsCount, eventsExpected); - result = STATUS_FAILED; - } - - if (!mainStarted) { - printf("Missing ThreadStart event for the main thread\n"); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/vminit001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/vminit001.cpp new file mode 100644 index 00000000000..ae7dc4054fa --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/vminit001.cpp @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define WAIT_TIME 1000 + +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static const char *name = "main"; +static int mainStarted = 0; +static int eventsCount = 0; +static int eventsExpected = 1; + +void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) { + jvmtiError err; + jrawMonitorID wait_lock; + + if (printdump == JNI_TRUE) { + printf(">>> VM init event #%d\n", eventsCount); + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_THREAD_START, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_THREAD_START: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + err = jvmti_env->CreateRawMonitor("_wait_lock", &wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(CreateRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->RawMonitorEnter(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorEnter) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->RawMonitorWait(wait_lock, (jlong)WAIT_TIME); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorWait) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->RawMonitorExit(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(RawMonitorExit) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti_env->DestroyRawMonitor(wait_lock); + if (err != JVMTI_ERROR_NONE) { + printf("(DestroyRawMonitor) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + + eventsCount++; +} + +void JNICALL ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + jvmtiError err; + jvmtiThreadInfo inf; + + err = jvmti_env->GetThreadInfo(thread, &inf); + if (err != JVMTI_ERROR_NONE) { + printf("(GetThreadInfo) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + if (printdump == JNI_TRUE) { + printf(">>> thread start: %s\n", inf.name); + } + if (inf.name != NULL && strcmp(name, inf.name) == 0) { + mainStarted++; + if (eventsCount == 0) { + printf("ThreadStart event for the main thread occurs\n"); + printf("before the VMInit event does return.\n"); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_vminit001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_vminit001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_vminit001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.VMInit = &VMInit; + callbacks.ThreadStart = &ThreadStart; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_VMInit_vminit001_check(JNIEnv *env, jclass cls) { + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (eventsCount != eventsExpected) { + printf("Wrong number of VM init events: %d, expected: %d\n", + eventsCount, eventsExpected); + result = STATUS_FAILED; + } + + if (!mainStarted) { + printf("Missing ThreadStart event for the main thread\n"); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/libvmobjalloc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/libvmobjalloc001.c deleted file mode 100644 index c5abe931070..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/libvmobjalloc001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "vmobjalloc001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/libvmobjalloc001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/libvmobjalloc001.cpp new file mode 100644 index 00000000000..b1660c50b3e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/libvmobjalloc001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "vmobjalloc001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/vmobjalloc001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/vmobjalloc001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/vmobjalloc001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/vmobjalloc001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/ap01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/ap01t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/ap01t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/ap01t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/libap01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/libap01t001.c deleted file mode 100644 index a56dc81d362..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/libap01t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap01t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/libap01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/libap01t001.cpp new file mode 100644 index 00000000000..f877203d49a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/libap01t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap01t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/ap02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/ap02t001.c deleted file mode 100644 index 6c1dd8a047d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/ap02t001.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "jni_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define TESTED_CLASS "ap02t001Exception" - -static JNIEnv *jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; - -static volatile int obj_count = 0; -static int first_count = 0; - -static jlong timeout = 0; -static int user_data = 0; -static const char* TESTED_CLASS_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP02/ap02t001Exception;"; -static const jlong TESTED_CLASS_TAG = (jlong)1024; -static jclass testedClass = NULL; - -jvmtiIterationControl JNICALL -heapObjectCallback(jlong class_tag, - jlong size, - jlong* tag_ptr, - void* user_data) { - - if (class_tag == TESTED_CLASS_TAG) { - obj_count++; - } - - return JVMTI_ITERATION_CONTINUE; -} - -jvmtiIterationControl JNICALL -stackReferenceCallback( jvmtiHeapRootKind root_kind, - jlong class_tag, - jlong size, - jlong* tag_ptr, - jlong thread_tag, - jint depth, - jmethodID method, - jint slot, - void* user_data) { - - if (class_tag == TESTED_CLASS_TAG) { - obj_count++; - } - - return JVMTI_ITERATION_CONTINUE; -} - -/************************/ - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP02_ap02t001_throwException( JNIEnv* jni, - jclass cls, - jclass exception_cls ) { - jint result; - - result = NSK_CPP_STUB3(ThrowNew, jni, - exception_cls, - "Got expected exception thrown from native code" ); - if (result != 0) { - NSK_COMPLAIN1("throwException: Unable to throw exception in native code: %d\n\n", result ); - nsk_jvmti_setFailStatus(); - } else { - NSK_DISPLAY0("throwException: ThrowNew returned success code: 0\n\n"); - } -} - -static void runIterations (jvmtiEnv* jvmti, jclass testedClass, jint exp_count) { - NSK_DISPLAY0("Calling IterateOverInstancesOfClass with filter JVMTI_HEAP_OBJECT_EITHER\n"); - obj_count = 0; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverInstancesOfClass, - jvmti, - testedClass, - JVMTI_HEAP_OBJECT_EITHER, - heapObjectCallback, - &user_data))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (obj_count != exp_count) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN3("IterateOverInstancesOfClass found unexpected number of %s objects: %d\n\t\ -expected number: %d\n\n", TESTED_CLASS, obj_count, exp_count); - } else { - NSK_DISPLAY2("Number of %s objects IterateOverInstancesOfClass has found: %d\n\n", TESTED_CLASS, - obj_count); - } - - NSK_DISPLAY0("Calling IterateOverHeap with filter JVMTI_HEAP_OBJECT_EITHER\n"); - obj_count = 0; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverHeap, - jvmti, - JVMTI_HEAP_OBJECT_EITHER, - heapObjectCallback, - &user_data))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (obj_count != exp_count) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN3("IterateOverHeap found unexpected number of %s objects: %d\n\t\ -expected number: %d\n\n", TESTED_CLASS, obj_count, exp_count); - } else { - NSK_DISPLAY2("Number of %s objects IterateOverHeap has found: %d\n\n", TESTED_CLASS, obj_count); - } - - NSK_DISPLAY0("Calling IterateOverReachableObjects\n"); - obj_count = 0; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverReachableObjects, jvmti, - NULL /*heapRootCallback*/, - stackReferenceCallback, - NULL /*objectReferenceCallback*/, - &user_data))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (obj_count != exp_count) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN3("IterateOverReachableObjects found unexpected number of %s objects: %d\n\t\ -expected number: %d\n\n", TESTED_CLASS, obj_count, exp_count); - } else { - NSK_DISPLAY2("Number of %s objects IterateOverReachableObjects has found: %d\n\n", TESTED_CLASS, - obj_count); - } - - first_count = obj_count; -} - -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - NSK_DISPLAY0("Wait for debugee start\n\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_DISPLAY1("Find tested class: %s\n", TESTED_CLASS_SIGNATURE); - testedClass = nsk_jvmti_classBySignature(TESTED_CLASS_SIGNATURE); - if (testedClass == NULL) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) - return; - - NSK_DISPLAY0("Set tag for tested class\n\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, - testedClass, - TESTED_CLASS_TAG ))) { - nsk_jvmti_setFailStatus(); - return; - } - - runIterations (jvmti, testedClass, 1); - - NSK_DISPLAY0("Go to next case\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - runIterations (jvmti, testedClass, 2); - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ap02t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ap02t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ap02t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - memset(&caps, 0, sizeof(jvmtiCapabilities)); - caps.can_tag_objects = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, - jvmti, &caps))) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, - jvmti, &caps))) - return JNI_ERR; - - if (!caps.can_tag_objects) - NSK_DISPLAY0("Warning: tagging objects is not implemented\n"); - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - NSK_DISPLAY0("agentProc has been set\n\n"); - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/ap02t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/ap02t001.cpp new file mode 100644 index 00000000000..583354ed648 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/ap02t001.cpp @@ -0,0 +1,261 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "jni_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define TESTED_CLASS "ap02t001Exception" + +static JNIEnv *jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; + +static volatile int obj_count = 0; +static int first_count = 0; + +static jlong timeout = 0; +static int user_data = 0; +static const char* TESTED_CLASS_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP02/ap02t001Exception;"; +static const jlong TESTED_CLASS_TAG = (jlong)1024; +static jclass testedClass = NULL; + +jvmtiIterationControl JNICALL +heapObjectCallback(jlong class_tag, + jlong size, + jlong* tag_ptr, + void* user_data) { + + if (class_tag == TESTED_CLASS_TAG) { + obj_count++; + } + + return JVMTI_ITERATION_CONTINUE; +} + +jvmtiIterationControl JNICALL +stackReferenceCallback( jvmtiHeapRootKind root_kind, + jlong class_tag, + jlong size, + jlong* tag_ptr, + jlong thread_tag, + jint depth, + jmethodID method, + jint slot, + void* user_data) { + + if (class_tag == TESTED_CLASS_TAG) { + obj_count++; + } + + return JVMTI_ITERATION_CONTINUE; +} + +/************************/ + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP02_ap02t001_throwException( JNIEnv* jni, + jclass cls, + jclass exception_cls ) { + jint result; + + result = NSK_CPP_STUB3(ThrowNew, jni, + exception_cls, + "Got expected exception thrown from native code" ); + if (result != 0) { + NSK_COMPLAIN1("throwException: Unable to throw exception in native code: %d\n\n", result ); + nsk_jvmti_setFailStatus(); + } else { + NSK_DISPLAY0("throwException: ThrowNew returned success code: 0\n\n"); + } +} + +static void runIterations (jvmtiEnv* jvmti, jclass testedClass, jint exp_count) { + NSK_DISPLAY0("Calling IterateOverInstancesOfClass with filter JVMTI_HEAP_OBJECT_EITHER\n"); + obj_count = 0; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverInstancesOfClass, + jvmti, + testedClass, + JVMTI_HEAP_OBJECT_EITHER, + heapObjectCallback, + &user_data))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (obj_count != exp_count) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN3("IterateOverInstancesOfClass found unexpected number of %s objects: %d\n\t\ +expected number: %d\n\n", TESTED_CLASS, obj_count, exp_count); + } else { + NSK_DISPLAY2("Number of %s objects IterateOverInstancesOfClass has found: %d\n\n", TESTED_CLASS, + obj_count); + } + + NSK_DISPLAY0("Calling IterateOverHeap with filter JVMTI_HEAP_OBJECT_EITHER\n"); + obj_count = 0; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverHeap, + jvmti, + JVMTI_HEAP_OBJECT_EITHER, + heapObjectCallback, + &user_data))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (obj_count != exp_count) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN3("IterateOverHeap found unexpected number of %s objects: %d\n\t\ +expected number: %d\n\n", TESTED_CLASS, obj_count, exp_count); + } else { + NSK_DISPLAY2("Number of %s objects IterateOverHeap has found: %d\n\n", TESTED_CLASS, obj_count); + } + + NSK_DISPLAY0("Calling IterateOverReachableObjects\n"); + obj_count = 0; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverReachableObjects, jvmti, + NULL /*heapRootCallback*/, + stackReferenceCallback, + NULL /*objectReferenceCallback*/, + &user_data))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (obj_count != exp_count) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN3("IterateOverReachableObjects found unexpected number of %s objects: %d\n\t\ +expected number: %d\n\n", TESTED_CLASS, obj_count, exp_count); + } else { + NSK_DISPLAY2("Number of %s objects IterateOverReachableObjects has found: %d\n\n", TESTED_CLASS, + obj_count); + } + + first_count = obj_count; +} + +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + NSK_DISPLAY0("Wait for debugee start\n\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_DISPLAY1("Find tested class: %s\n", TESTED_CLASS_SIGNATURE); + testedClass = nsk_jvmti_classBySignature(TESTED_CLASS_SIGNATURE); + if (testedClass == NULL) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) + return; + + NSK_DISPLAY0("Set tag for tested class\n\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, + testedClass, + TESTED_CLASS_TAG ))) { + nsk_jvmti_setFailStatus(); + return; + } + + runIterations (jvmti, testedClass, 1); + + NSK_DISPLAY0("Go to next case\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + runIterations (jvmti, testedClass, 2); + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ap02t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ap02t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ap02t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + memset(&caps, 0, sizeof(jvmtiCapabilities)); + caps.can_tag_objects = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, + jvmti, &caps))) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, + jvmti, &caps))) + return JNI_ERR; + + if (!caps.can_tag_objects) + NSK_DISPLAY0("Warning: tagging objects is not implemented\n"); + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + NSK_DISPLAY0("agentProc has been set\n\n"); + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/libap02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/libap02t001.c deleted file mode 100644 index 9e6932343bc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/libap02t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap02t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/libap02t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/libap02t001.cpp new file mode 100644 index 00000000000..e2a96904a61 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/libap02t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap02t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/ap03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/ap03t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/ap03t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/ap03t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/libap03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/libap03t001.c deleted file mode 100644 index c24066272fd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/libap03t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap03t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/libap03t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/libap03t001.cpp new file mode 100644 index 00000000000..b47dd8d3992 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/libap03t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap03t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/ap04t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/ap04t001.c deleted file mode 100644 index 5a88ec931e9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/ap04t001.c +++ /dev/null @@ -1,535 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "jni_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define OBJ_MAX_COUNT 100000 - -static JNIEnv *jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; - -static jlong timeout = 0; - -static const char* DEBUGEE_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP04/ap04t001;"; -static const char* ROOT_SIGNATURE = "[Lnsk/jvmti/scenarios/allocation/AP04/ap04t001;"; - -static const int eventsCount = 3; -static jvmtiEvent events[] = { - JVMTI_EVENT_OBJECT_FREE, - JVMTI_EVENT_GARBAGE_COLLECTION_START, - JVMTI_EVENT_GARBAGE_COLLECTION_FINISH -}; - -static jclass debugeeClass = NULL; -static jfieldID rootFieldID = NULL; -static jmethodID unlockSecondaryID = NULL; - -static volatile int eventCount = 0; -static volatile int iterationCount = 0; -static volatile int errorCount = 0; - -/***********************************************************************/ - -static jrawMonitorID counterMonitor_ptr = NULL; - -static void increaseCounter(volatile int* counterPtr) { - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } - - (*counterPtr)++; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } -} - -static void setCounter(volatile int* counterPtr, int value) { - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } - - *counterPtr = value; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } -} - -static int getCounter(volatile int* counterPtr) { - int result; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } - - result = *counterPtr; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } - - return result; -} - -/***********************************************************************/ - -jvmtiIterationControl JNICALL -heapObjectCallback( jlong class_tag, - jlong size, - jlong* tag_ptr, - void* user_data) { - - int count = 0; - - /* clean eventCount on first iteration */ - if (getCounter(&iterationCount) == 0) { - setCounter(&eventCount, 0); - } - increaseCounter(&iterationCount); - - /* check if eventCount is 0 for each iteration */ - count = getCounter(&eventCount); - if (count > 0) { - increaseCounter(&errorCount); - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* jvmtiHeapRootCallback */ -jvmtiIterationControl JNICALL -heapRootCallback( jvmtiHeapRootKind root_kind, - jlong class_tag, - jlong size, - jlong* tag_ptr, - void* user_data) { - - int count = 0; - - /* clean eventCount on first iteration */ - if (getCounter(&iterationCount) == 0) { - setCounter(&eventCount, 0); - } - increaseCounter(&iterationCount); - - /* check if eventCount is 0 for each iteration */ - count = getCounter(&eventCount); - if (count > 0) { - increaseCounter(&errorCount); - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* jvmtiStackReferenceCallback */ -jvmtiIterationControl JNICALL -stackReferenceCallback( jvmtiHeapRootKind root_kind, - jlong class_tag, - jlong size, - jlong* tag_ptr, - jlong thread_tag, - jint depth, - jmethodID method, - jint slot, - void* user_data) { - - int count = 0; - - /* clean eventCount on first iteration */ - if (getCounter(&iterationCount) == 0) { - setCounter(&eventCount, 0); - } - increaseCounter(&iterationCount); - - /* check if eventCount is 0 for each iteration */ - count = getCounter(&eventCount); - if (count > 0) { - increaseCounter(&errorCount); - } - - return JVMTI_ITERATION_CONTINUE; -} - - -/* jvmtiObjectReferenceCallback */ -jvmtiIterationControl JNICALL -objectReferenceCallback( jvmtiObjectReferenceKind reference_kind, - jlong class_tag, - jlong size, - jlong* tag_ptr, - jlong referrer_tag, - jint referrer_index, - void* user_data) { - - int count = 0; - - /* clean eventCount on first iteration */ - if (getCounter(&iterationCount) == 0) { - setCounter(&eventCount, 0); - } - increaseCounter(&iterationCount); - - /* check if eventCount is 0 for each iteration */ - count = getCounter(&eventCount); - if (count > 0) { - increaseCounter(&errorCount); - } - - return JVMTI_ITERATION_CONTINUE; -} - - -/***********************************************************************/ - -void JNICALL -ObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - increaseCounter(&eventCount); -// NSK_DISPLAY0(" event: ObjectFree\n"); -} - -void JNICALL -GarbageCollectionStart(jvmtiEnv *jvmti_env) { - increaseCounter(&eventCount); - NSK_DISPLAY0(" event: GarbageCollectionStart\n"); -} - -void JNICALL -GarbageCollectionFinish(jvmtiEnv *jvmti_env) { - increaseCounter(&eventCount); - NSK_DISPLAY0(" event: GarbageCollectionFinish\n"); -} - -/***********************************************************************/ - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t001_setTag( JNIEnv* jni, - jclass klass, - jobject target, /* object to be tagged */ - jlong tag ) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, target, tag))) { - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t001_forceGC( JNIEnv* jni, - jclass klass) { - -NSK_DISPLAY0(" run: ForceGarbageCollection\n"); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB1(ForceGarbageCollection, jvmti))) { - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t001_runIterateOverHeap( JNIEnv* jni, - jclass klass ) { - int count = 0; - - setCounter(&errorCount, 0); - setCounter(&eventCount, 0); - setCounter(&iterationCount, 0); - - NSK_DISPLAY0("Calling IterateOverHeap...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_TAGGED, - heapObjectCallback, - NULL /*user_data*/))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY0("IterateOverHeap finished.\n"); - - NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); - NSK_DISPLAY1("Events count: %d\n", getCounter(&eventCount)); - - count = getCounter(&errorCount); - NSK_DISPLAY1("Errors detected: %d\n", count); - if (count > 0) { - NSK_COMPLAIN1("Events detected during heap iteration: %d\n", count); - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t001_runIterateOverReachableObjects( JNIEnv* jni, - jclass klass ) { - int count = 0; - - setCounter(&errorCount, 0); - setCounter(&eventCount, 0); - setCounter(&iterationCount, 0); - - NSK_DISPLAY0("Calling IterateOverReachableObjects...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverReachableObjects, jvmti, - heapRootCallback, - stackReferenceCallback, - objectReferenceCallback, - NULL /*user_data*/))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY0("IterateOverReachableObjects finished.\n"); - - NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); - NSK_DISPLAY1("Events count: %d\n", getCounter(&eventCount)); - - count = getCounter(&errorCount); - NSK_DISPLAY1("Errors detected: %d\n", count); - if (count > 0) { - NSK_COMPLAIN1("Events detected during heap iteration: %d\n", count); - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t001_runIterateOverInstancesOfClass( JNIEnv* jni, - jclass klass ) { - int count = 0; - - setCounter(&errorCount, 0); - setCounter(&eventCount, 0); - setCounter(&iterationCount, 0); - - NSK_DISPLAY0("Calling IterateOverInstancesOfClass...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - debugeeClass, - JVMTI_HEAP_OBJECT_TAGGED, - heapObjectCallback, - NULL /*user_data*/))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY0("IterateOverInstancesOfClass finished.\n"); - - NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); - NSK_DISPLAY1("Events count: %d\n", getCounter(&eventCount)); - - count = getCounter(&errorCount); - NSK_DISPLAY1("Errors detected: %d\n", count); - if (count > 0) { - NSK_COMPLAIN1("Events detected during heap iteration: %d\n", count); - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t001_runIterateOverObjectsReachableFromObject( JNIEnv* jni, - jclass klass ) { - - jobject root = NULL; - int count = 0; - - if (!NSK_JNI_VERIFY(jni, (root = - NSK_CPP_STUB3(GetStaticObjectField, jni, - debugeeClass, - rootFieldID )) != NULL )) { - NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n"); - nsk_jvmti_setFailStatus(); - return; - } - - // release secondary lock - NSK_CPP_STUB3(CallStaticVoidMethod, jni, debugeeClass, unlockSecondaryID); - - setCounter(&errorCount, 0); - setCounter(&eventCount, 0); - setCounter(&iterationCount, 0); - - NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverObjectsReachableFromObject, jvmti, - root, - objectReferenceCallback, - NULL /*user_data*/))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY0("IterateOverObjectsReachableFromObject finished.\n"); - - NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); - NSK_DISPLAY1("Events count: %d\n", getCounter(&eventCount)); - - count = getCounter(&errorCount); - NSK_DISPLAY1("Errors detected: %d\n", count); - if (count > 0) { - NSK_COMPLAIN1("Events detected during heap iteration: %d\n", count); - nsk_jvmti_setFailStatus(); - } -} - -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - NSK_DISPLAY0("Wait for debugee start\n\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_SIGNATURE); - debugeeClass = nsk_jvmti_classBySignature(DEBUGEE_SIGNATURE); - if (debugeeClass == NULL) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) - return; - - NSK_DISPLAY1("Find ID of 'root' field: %s\n", ROOT_SIGNATURE); - if (!NSK_JNI_VERIFY(jni, (rootFieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, - debugeeClass, - "root", - ROOT_SIGNATURE)) != NULL )) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY1("Find ID of 'unlockSecondary' method: %s\n", ROOT_SIGNATURE); - if (!NSK_JNI_VERIFY(jni, (unlockSecondaryID = - NSK_CPP_STUB4(GetStaticMethodID, jni, - debugeeClass, - "unlockSecondary", - "()V")) != NULL )) { - nsk_jvmti_setFailStatus(); - return; - } - - - NSK_DISPLAY0("Let debugee to run test cases\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - - NSK_DISPLAY0("Wait for completion of test cases\n\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - nsk_jvmti_enableEvents(JVMTI_DISABLE, eventsCount, events, NULL); - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); - NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, counterMonitor_ptr)); - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ap04t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ap04t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ap04t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "counterMonitor", &counterMonitor_ptr))) { - return JNI_ERR; - } - - memset(&caps, 0, sizeof(jvmtiCapabilities)); - caps.can_tag_objects = 1; - caps.can_generate_object_free_events = 1; - caps.can_generate_garbage_collection_events = 1; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, - jvmti, &caps))) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, - jvmti, &caps))) - return JNI_ERR; - - if (!caps.can_tag_objects) - NSK_DISPLAY0("Warning: tagging objects is not available\n"); - if (!caps.can_generate_object_free_events) - NSK_DISPLAY0("Warning: generation of object free events is not available\n"); - if (!caps.can_generate_garbage_collection_events) - NSK_DISPLAY0("Warning: generation of garbage collection events is not available\n"); - - /* set event callback */ - NSK_DISPLAY0("setting event callbacks ...\n"); - (void) memset(&callbacks, 0, sizeof(callbacks)); - - callbacks.ObjectFree = &ObjectFree; - callbacks.GarbageCollectionStart = &GarbageCollectionStart; - callbacks.GarbageCollectionFinish = &GarbageCollectionFinish; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - NSK_DISPLAY0("setting event callbacks done.\n"); - - NSK_DISPLAY0("enabling JVMTI events ...\n"); - if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, eventsCount, events, NULL)) { - return JNI_ERR; - } - NSK_DISPLAY0("enabling the events done.\n"); - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - NSK_DISPLAY0("agentProc has been set\n\n"); - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/ap04t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/ap04t001.cpp new file mode 100644 index 00000000000..4b5c2ef59be --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/ap04t001.cpp @@ -0,0 +1,535 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "jni_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define OBJ_MAX_COUNT 100000 + +static JNIEnv *jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; + +static jlong timeout = 0; + +static const char* DEBUGEE_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP04/ap04t001;"; +static const char* ROOT_SIGNATURE = "[Lnsk/jvmti/scenarios/allocation/AP04/ap04t001;"; + +static const int eventsCount = 3; +static jvmtiEvent events[] = { + JVMTI_EVENT_OBJECT_FREE, + JVMTI_EVENT_GARBAGE_COLLECTION_START, + JVMTI_EVENT_GARBAGE_COLLECTION_FINISH +}; + +static jclass debugeeClass = NULL; +static jfieldID rootFieldID = NULL; +static jmethodID unlockSecondaryID = NULL; + +static volatile int eventCount = 0; +static volatile int iterationCount = 0; +static volatile int errorCount = 0; + +/***********************************************************************/ + +static jrawMonitorID counterMonitor_ptr = NULL; + +static void increaseCounter(volatile int* counterPtr) { + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } + + (*counterPtr)++; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } +} + +static void setCounter(volatile int* counterPtr, int value) { + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } + + *counterPtr = value; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } +} + +static int getCounter(volatile int* counterPtr) { + int result; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } + + result = *counterPtr; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } + + return result; +} + +/***********************************************************************/ + +jvmtiIterationControl JNICALL +heapObjectCallback( jlong class_tag, + jlong size, + jlong* tag_ptr, + void* user_data) { + + int count = 0; + + /* clean eventCount on first iteration */ + if (getCounter(&iterationCount) == 0) { + setCounter(&eventCount, 0); + } + increaseCounter(&iterationCount); + + /* check if eventCount is 0 for each iteration */ + count = getCounter(&eventCount); + if (count > 0) { + increaseCounter(&errorCount); + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* jvmtiHeapRootCallback */ +jvmtiIterationControl JNICALL +heapRootCallback( jvmtiHeapRootKind root_kind, + jlong class_tag, + jlong size, + jlong* tag_ptr, + void* user_data) { + + int count = 0; + + /* clean eventCount on first iteration */ + if (getCounter(&iterationCount) == 0) { + setCounter(&eventCount, 0); + } + increaseCounter(&iterationCount); + + /* check if eventCount is 0 for each iteration */ + count = getCounter(&eventCount); + if (count > 0) { + increaseCounter(&errorCount); + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* jvmtiStackReferenceCallback */ +jvmtiIterationControl JNICALL +stackReferenceCallback( jvmtiHeapRootKind root_kind, + jlong class_tag, + jlong size, + jlong* tag_ptr, + jlong thread_tag, + jint depth, + jmethodID method, + jint slot, + void* user_data) { + + int count = 0; + + /* clean eventCount on first iteration */ + if (getCounter(&iterationCount) == 0) { + setCounter(&eventCount, 0); + } + increaseCounter(&iterationCount); + + /* check if eventCount is 0 for each iteration */ + count = getCounter(&eventCount); + if (count > 0) { + increaseCounter(&errorCount); + } + + return JVMTI_ITERATION_CONTINUE; +} + + +/* jvmtiObjectReferenceCallback */ +jvmtiIterationControl JNICALL +objectReferenceCallback( jvmtiObjectReferenceKind reference_kind, + jlong class_tag, + jlong size, + jlong* tag_ptr, + jlong referrer_tag, + jint referrer_index, + void* user_data) { + + int count = 0; + + /* clean eventCount on first iteration */ + if (getCounter(&iterationCount) == 0) { + setCounter(&eventCount, 0); + } + increaseCounter(&iterationCount); + + /* check if eventCount is 0 for each iteration */ + count = getCounter(&eventCount); + if (count > 0) { + increaseCounter(&errorCount); + } + + return JVMTI_ITERATION_CONTINUE; +} + + +/***********************************************************************/ + +void JNICALL +ObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + increaseCounter(&eventCount); +// NSK_DISPLAY0(" event: ObjectFree\n"); +} + +void JNICALL +GarbageCollectionStart(jvmtiEnv *jvmti_env) { + increaseCounter(&eventCount); + NSK_DISPLAY0(" event: GarbageCollectionStart\n"); +} + +void JNICALL +GarbageCollectionFinish(jvmtiEnv *jvmti_env) { + increaseCounter(&eventCount); + NSK_DISPLAY0(" event: GarbageCollectionFinish\n"); +} + +/***********************************************************************/ + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t001_setTag( JNIEnv* jni, + jclass klass, + jobject target, /* object to be tagged */ + jlong tag ) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, target, tag))) { + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t001_forceGC( JNIEnv* jni, + jclass klass) { + +NSK_DISPLAY0(" run: ForceGarbageCollection\n"); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB1(ForceGarbageCollection, jvmti))) { + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t001_runIterateOverHeap( JNIEnv* jni, + jclass klass ) { + int count = 0; + + setCounter(&errorCount, 0); + setCounter(&eventCount, 0); + setCounter(&iterationCount, 0); + + NSK_DISPLAY0("Calling IterateOverHeap...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_TAGGED, + heapObjectCallback, + NULL /*user_data*/))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY0("IterateOverHeap finished.\n"); + + NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); + NSK_DISPLAY1("Events count: %d\n", getCounter(&eventCount)); + + count = getCounter(&errorCount); + NSK_DISPLAY1("Errors detected: %d\n", count); + if (count > 0) { + NSK_COMPLAIN1("Events detected during heap iteration: %d\n", count); + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t001_runIterateOverReachableObjects( JNIEnv* jni, + jclass klass ) { + int count = 0; + + setCounter(&errorCount, 0); + setCounter(&eventCount, 0); + setCounter(&iterationCount, 0); + + NSK_DISPLAY0("Calling IterateOverReachableObjects...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverReachableObjects, jvmti, + heapRootCallback, + stackReferenceCallback, + objectReferenceCallback, + NULL /*user_data*/))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY0("IterateOverReachableObjects finished.\n"); + + NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); + NSK_DISPLAY1("Events count: %d\n", getCounter(&eventCount)); + + count = getCounter(&errorCount); + NSK_DISPLAY1("Errors detected: %d\n", count); + if (count > 0) { + NSK_COMPLAIN1("Events detected during heap iteration: %d\n", count); + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t001_runIterateOverInstancesOfClass( JNIEnv* jni, + jclass klass ) { + int count = 0; + + setCounter(&errorCount, 0); + setCounter(&eventCount, 0); + setCounter(&iterationCount, 0); + + NSK_DISPLAY0("Calling IterateOverInstancesOfClass...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + debugeeClass, + JVMTI_HEAP_OBJECT_TAGGED, + heapObjectCallback, + NULL /*user_data*/))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY0("IterateOverInstancesOfClass finished.\n"); + + NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); + NSK_DISPLAY1("Events count: %d\n", getCounter(&eventCount)); + + count = getCounter(&errorCount); + NSK_DISPLAY1("Errors detected: %d\n", count); + if (count > 0) { + NSK_COMPLAIN1("Events detected during heap iteration: %d\n", count); + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t001_runIterateOverObjectsReachableFromObject( JNIEnv* jni, + jclass klass ) { + + jobject root = NULL; + int count = 0; + + if (!NSK_JNI_VERIFY(jni, (root = + NSK_CPP_STUB3(GetStaticObjectField, jni, + debugeeClass, + rootFieldID )) != NULL )) { + NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n"); + nsk_jvmti_setFailStatus(); + return; + } + + // release secondary lock + NSK_CPP_STUB3(CallStaticVoidMethod, jni, debugeeClass, unlockSecondaryID); + + setCounter(&errorCount, 0); + setCounter(&eventCount, 0); + setCounter(&iterationCount, 0); + + NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverObjectsReachableFromObject, jvmti, + root, + objectReferenceCallback, + NULL /*user_data*/))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY0("IterateOverObjectsReachableFromObject finished.\n"); + + NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); + NSK_DISPLAY1("Events count: %d\n", getCounter(&eventCount)); + + count = getCounter(&errorCount); + NSK_DISPLAY1("Errors detected: %d\n", count); + if (count > 0) { + NSK_COMPLAIN1("Events detected during heap iteration: %d\n", count); + nsk_jvmti_setFailStatus(); + } +} + +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + NSK_DISPLAY0("Wait for debugee start\n\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_SIGNATURE); + debugeeClass = nsk_jvmti_classBySignature(DEBUGEE_SIGNATURE); + if (debugeeClass == NULL) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_JNI_VERIFY(jni, (debugeeClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) + return; + + NSK_DISPLAY1("Find ID of 'root' field: %s\n", ROOT_SIGNATURE); + if (!NSK_JNI_VERIFY(jni, (rootFieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, + debugeeClass, + "root", + ROOT_SIGNATURE)) != NULL )) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY1("Find ID of 'unlockSecondary' method: %s\n", ROOT_SIGNATURE); + if (!NSK_JNI_VERIFY(jni, (unlockSecondaryID = + NSK_CPP_STUB4(GetStaticMethodID, jni, + debugeeClass, + "unlockSecondary", + "()V")) != NULL )) { + nsk_jvmti_setFailStatus(); + return; + } + + + NSK_DISPLAY0("Let debugee to run test cases\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + + NSK_DISPLAY0("Wait for completion of test cases\n\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + nsk_jvmti_enableEvents(JVMTI_DISABLE, eventsCount, events, NULL); + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); + NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, counterMonitor_ptr)); + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ap04t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ap04t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ap04t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "counterMonitor", &counterMonitor_ptr))) { + return JNI_ERR; + } + + memset(&caps, 0, sizeof(jvmtiCapabilities)); + caps.can_tag_objects = 1; + caps.can_generate_object_free_events = 1; + caps.can_generate_garbage_collection_events = 1; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, + jvmti, &caps))) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, + jvmti, &caps))) + return JNI_ERR; + + if (!caps.can_tag_objects) + NSK_DISPLAY0("Warning: tagging objects is not available\n"); + if (!caps.can_generate_object_free_events) + NSK_DISPLAY0("Warning: generation of object free events is not available\n"); + if (!caps.can_generate_garbage_collection_events) + NSK_DISPLAY0("Warning: generation of garbage collection events is not available\n"); + + /* set event callback */ + NSK_DISPLAY0("setting event callbacks ...\n"); + (void) memset(&callbacks, 0, sizeof(callbacks)); + + callbacks.ObjectFree = &ObjectFree; + callbacks.GarbageCollectionStart = &GarbageCollectionStart; + callbacks.GarbageCollectionFinish = &GarbageCollectionFinish; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + NSK_DISPLAY0("setting event callbacks done.\n"); + + NSK_DISPLAY0("enabling JVMTI events ...\n"); + if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, eventsCount, events, NULL)) { + return JNI_ERR; + } + NSK_DISPLAY0("enabling the events done.\n"); + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + NSK_DISPLAY0("agentProc has been set\n\n"); + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/libap04t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/libap04t001.c deleted file mode 100644 index 4b1c1f4dbf5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/libap04t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap04t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/libap04t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/libap04t001.cpp new file mode 100644 index 00000000000..655579c61bc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t001/libap04t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap04t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/ap04t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/ap04t002.c deleted file mode 100644 index aac79409f70..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/ap04t002.c +++ /dev/null @@ -1,519 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "jni_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define OBJ_MAX_COUNT 100000 - -static JNIEnv *jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; - -static jlong timeout = 0; - -static const char* DEBUGEE_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP04/ap04t002;"; -static const char* ROOT_SIGNATURE = "[Lnsk/jvmti/scenarios/allocation/AP04/ap04t002;"; - -static volatile int modificationCount = 0; -static volatile int iterationCount = 0; -static volatile int errorCount = 0; - -static jclass debugeeClass = NULL; -static jfieldID rootFieldID; -static jfieldID modifiedFieldID; - -/***********************************************************************/ - -static jrawMonitorID counterMonitor_ptr = NULL; - -static void increaseCounter(volatile int* counterPtr) { - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } - - (*counterPtr)++; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } -} - -static void setCounter(volatile int* counterPtr, int value) { - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } - - *counterPtr = value; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } -} - -static int getCounter(volatile int* counterPtr) { - int result; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } - - result = *counterPtr; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } - - return result; -} - -/***********************************************************************/ - -jvmtiIterationControl JNICALL -heapObjectCallback( jlong class_tag, - jlong size, - jlong* tag_ptr, - void* user_data) { - - int count = 0; - - /* clean modificationCounter on first iteration */ - if (getCounter(&iterationCount) == 0) { - setCounter(&modificationCount, 0); - } - increaseCounter(&iterationCount); - - /* check if modificationCounter is 0 for each iteration */ - count = getCounter(&modificationCount); - if (count > 0) { - setCounter(&errorCount, count); - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* jvmtiHeapRootCallback */ -jvmtiIterationControl JNICALL -heapRootCallback( jvmtiHeapRootKind root_kind, - jlong class_tag, - jlong size, - jlong* tag_ptr, - void* user_data) { - - int count = 0; - - /* clean modificationCounter on first iteration */ - if (getCounter(&iterationCount) == 0) { - setCounter(&modificationCount, 0); - } - increaseCounter(&iterationCount); - - /* check if modificationCounter is 0 for each iteration */ - count = getCounter(&modificationCount); - if (count > 0) { - setCounter(&errorCount, count); - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* jvmtiStackReferenceCallback */ -jvmtiIterationControl JNICALL -stackReferenceCallback( jvmtiHeapRootKind root_kind, - jlong class_tag, - jlong size, - jlong* tag_ptr, - jlong thread_tag, - jint depth, - jmethodID method, - jint slot, - void* user_data) { - - int count = 0; - - /* clean modificationCounter on first iteration */ - if (getCounter(&iterationCount) == 0) { - setCounter(&modificationCount, 0); - } - increaseCounter(&iterationCount); - - /* check if modificationCounter is 0 for each iteration */ - count = getCounter(&modificationCount); - if (count > 0) { - setCounter(&errorCount, count); - } - - return JVMTI_ITERATION_CONTINUE; -} - - -/* jvmtiObjectReferenceCallback */ -jvmtiIterationControl JNICALL -objectReferenceCallback( jvmtiObjectReferenceKind reference_kind, - jlong class_tag, - jlong size, - jlong* tag_ptr, - jlong referrer_tag, - jint referrer_index, - void* user_data) { - - int count = 0; - - /* clean modificationCounter on first iteration */ - if (getCounter(&iterationCount) == 0) { - setCounter(&modificationCount, 0); - } - increaseCounter(&iterationCount); - - /* check if modificationCounter is 0 for each iteration */ - count = getCounter(&modificationCount); - if (count > 0) { - setCounter(&errorCount, count); - } - - return JVMTI_ITERATION_CONTINUE; -} - - -/***********************************************************************/ - -void JNICALL -FieldModification( jvmtiEnv *jvmti_env, - JNIEnv *env, - jthread thr, - jmethodID method, - jlocation location, - jclass field_klass, - jobject obj, - jfieldID field, - char sig, - jvalue new_value ) { - - increaseCounter(&modificationCount); -} - -/***********************************************************************/ - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t002_setTag( JNIEnv* jni, - jclass klass, - jobject target, /* object to be tagged */ - jlong tag ) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, target, tag))) { - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t002_runIterateOverHeap( JNIEnv* jni, - jclass klass ) { - int count = 0; - - setCounter(&errorCount, 0); - setCounter(&modificationCount, 0); - setCounter(&iterationCount, 0); - - NSK_DISPLAY0("Calling IterateOverHeap...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_TAGGED, - heapObjectCallback, - NULL /*user_data*/))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY0("IterateOverHeap finished.\n"); - - NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); - NSK_DISPLAY1("Modifications count: %d\n", getCounter(&modificationCount)); - - count = getCounter(&errorCount); - NSK_DISPLAY1("Errors detected: %d\n", count); - // because of racing in FieldModification event, one event can be fired before safepoint occures - if (count > 1) { - NSK_COMPLAIN1("FieldMofification events detected during heap iteration: %d\n", count); - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t002_runIterateOverReachableObjects( JNIEnv* jni, - jclass klass ) { - int count = 0; - - setCounter(&errorCount, 0); - setCounter(&modificationCount, 0); - setCounter(&iterationCount, 0); - - NSK_DISPLAY0("Calling IterateOverReachableObjects...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverReachableObjects, jvmti, - heapRootCallback, - stackReferenceCallback, - objectReferenceCallback, - NULL /*user_data*/))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY0("IterateOverReachableObjects finished.\n"); - - NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); - NSK_DISPLAY1("Modifications count: %d\n", getCounter(&modificationCount)); - - count = getCounter(&errorCount); - NSK_DISPLAY1("Errors detected: %d\n", count); - // because of racing in FieldModification event, one event can be fired before safepoint occures - if (count > 1) { - NSK_COMPLAIN1("FieldMofification events detected during heap iteration: %d\n", count); - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t002_runIterateOverInstancesOfClass( JNIEnv* jni, - jclass klass ) { - int count = 0; - - setCounter(&errorCount, 0); - setCounter(&modificationCount, 0); - setCounter(&iterationCount, 0); - - NSK_DISPLAY0("Calling IterateOverInstancesOfClass...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - debugeeClass, - JVMTI_HEAP_OBJECT_TAGGED, - heapObjectCallback, - NULL /*user_data*/))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY0("IterateOverInstancesOfClass finished.\n"); - - NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); - NSK_DISPLAY1("Modifications count: %d\n", getCounter(&modificationCount)); - - count = getCounter(&errorCount); - NSK_DISPLAY1("Errors detected: %d\n", count); - // because of racing in FieldModification event, one event can be fired before safepoint occures - if (count > 1) { - NSK_COMPLAIN1("FieldMofification events detected during heap iteration: %d\n", count); - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t002_runIterateOverObjectsReachableFromObject( JNIEnv* jni, - jclass klass ) { - jobject root = NULL; - int count = 0; - - if (!NSK_JNI_VERIFY(jni, (root = - NSK_CPP_STUB3(GetStaticObjectField, jni, - debugeeClass, - rootFieldID )) != NULL )) { - NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n"); - nsk_jvmti_setFailStatus(); - return; - } - - setCounter(&errorCount, 0); - setCounter(&modificationCount, 0); - setCounter(&iterationCount, 0); - - NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverObjectsReachableFromObject, jvmti, - root, - objectReferenceCallback, - NULL /*user_data*/))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY0("IterateOverObjectsReachableFromObject finished.\n"); - - NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); - NSK_DISPLAY1("Modifications count: %d\n", getCounter(&modificationCount)); - - count = getCounter(&errorCount); - NSK_DISPLAY1("Errors detected: %d\n", count); - // because of racing in FieldModification event, one event can be fired before safepoint occures - if (count > 1) { - NSK_COMPLAIN1("FieldMofification events detected during heap iteration: %d\n", count); - nsk_jvmti_setFailStatus(); - } -} - -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - NSK_DISPLAY0("Wait for debugee start\n\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_SIGNATURE); - debugeeClass = nsk_jvmti_classBySignature(DEBUGEE_SIGNATURE); - if (debugeeClass == NULL) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) - return; - - NSK_DISPLAY1("Find ID of 'root' field: %s\n", ROOT_SIGNATURE); - if (!NSK_JNI_VERIFY(jni, (rootFieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, - debugeeClass, - "root", - ROOT_SIGNATURE)) != NULL )) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Find ID of 'modified' field\n"); - if (!NSK_JNI_VERIFY(jni, (modifiedFieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, - debugeeClass, - "modified", - "I")) != NULL )) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Set FieldModification watchpoint for 'modified' field\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetFieldModificationWatch, jvmti, - debugeeClass, - modifiedFieldID))) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Let debugee to run test cases\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - - NSK_DISPLAY0("Wait for completion of test cases\n\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); - NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, counterMonitor_ptr)); - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ap04t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ap04t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ap04t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "counterMonitor", &counterMonitor_ptr))) { - return JNI_ERR; - } - - memset(&caps, 0, sizeof(jvmtiCapabilities)); - caps.can_tag_objects = 1; - caps.can_generate_field_modification_events = 1; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, - jvmti, &caps))) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, - jvmti, &caps))) - return JNI_ERR; - - if (!caps.can_tag_objects) - NSK_DISPLAY0("Warning: tagging objects is not available\n"); - if (!caps.can_generate_field_modification_events) - NSK_DISPLAY0("Warning: generation of field modification events is not available\n"); - - /* set event callback */ - NSK_DISPLAY0("setting event callbacks ...\n"); - (void) memset(&callbacks, 0, sizeof(callbacks)); - - callbacks.FieldModification = &FieldModification; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - NSK_DISPLAY0("setting event callbacks done.\n"); - - NSK_DISPLAY0("enabling JVMTI events ...\n"); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4( SetEventNotificationMode, - jvmti, - JVMTI_ENABLE, - JVMTI_EVENT_FIELD_MODIFICATION, - NULL))) - return JNI_ERR; - NSK_DISPLAY0("enabling the events done.\n"); - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - NSK_DISPLAY0("agentProc has been set\n\n"); - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/ap04t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/ap04t002.cpp new file mode 100644 index 00000000000..f1b106fd43b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/ap04t002.cpp @@ -0,0 +1,519 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "jni_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define OBJ_MAX_COUNT 100000 + +static JNIEnv *jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; + +static jlong timeout = 0; + +static const char* DEBUGEE_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP04/ap04t002;"; +static const char* ROOT_SIGNATURE = "[Lnsk/jvmti/scenarios/allocation/AP04/ap04t002;"; + +static volatile int modificationCount = 0; +static volatile int iterationCount = 0; +static volatile int errorCount = 0; + +static jclass debugeeClass = NULL; +static jfieldID rootFieldID; +static jfieldID modifiedFieldID; + +/***********************************************************************/ + +static jrawMonitorID counterMonitor_ptr = NULL; + +static void increaseCounter(volatile int* counterPtr) { + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } + + (*counterPtr)++; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } +} + +static void setCounter(volatile int* counterPtr, int value) { + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } + + *counterPtr = value; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } +} + +static int getCounter(volatile int* counterPtr) { + int result; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } + + result = *counterPtr; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } + + return result; +} + +/***********************************************************************/ + +jvmtiIterationControl JNICALL +heapObjectCallback( jlong class_tag, + jlong size, + jlong* tag_ptr, + void* user_data) { + + int count = 0; + + /* clean modificationCounter on first iteration */ + if (getCounter(&iterationCount) == 0) { + setCounter(&modificationCount, 0); + } + increaseCounter(&iterationCount); + + /* check if modificationCounter is 0 for each iteration */ + count = getCounter(&modificationCount); + if (count > 0) { + setCounter(&errorCount, count); + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* jvmtiHeapRootCallback */ +jvmtiIterationControl JNICALL +heapRootCallback( jvmtiHeapRootKind root_kind, + jlong class_tag, + jlong size, + jlong* tag_ptr, + void* user_data) { + + int count = 0; + + /* clean modificationCounter on first iteration */ + if (getCounter(&iterationCount) == 0) { + setCounter(&modificationCount, 0); + } + increaseCounter(&iterationCount); + + /* check if modificationCounter is 0 for each iteration */ + count = getCounter(&modificationCount); + if (count > 0) { + setCounter(&errorCount, count); + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* jvmtiStackReferenceCallback */ +jvmtiIterationControl JNICALL +stackReferenceCallback( jvmtiHeapRootKind root_kind, + jlong class_tag, + jlong size, + jlong* tag_ptr, + jlong thread_tag, + jint depth, + jmethodID method, + jint slot, + void* user_data) { + + int count = 0; + + /* clean modificationCounter on first iteration */ + if (getCounter(&iterationCount) == 0) { + setCounter(&modificationCount, 0); + } + increaseCounter(&iterationCount); + + /* check if modificationCounter is 0 for each iteration */ + count = getCounter(&modificationCount); + if (count > 0) { + setCounter(&errorCount, count); + } + + return JVMTI_ITERATION_CONTINUE; +} + + +/* jvmtiObjectReferenceCallback */ +jvmtiIterationControl JNICALL +objectReferenceCallback( jvmtiObjectReferenceKind reference_kind, + jlong class_tag, + jlong size, + jlong* tag_ptr, + jlong referrer_tag, + jint referrer_index, + void* user_data) { + + int count = 0; + + /* clean modificationCounter on first iteration */ + if (getCounter(&iterationCount) == 0) { + setCounter(&modificationCount, 0); + } + increaseCounter(&iterationCount); + + /* check if modificationCounter is 0 for each iteration */ + count = getCounter(&modificationCount); + if (count > 0) { + setCounter(&errorCount, count); + } + + return JVMTI_ITERATION_CONTINUE; +} + + +/***********************************************************************/ + +void JNICALL +FieldModification( jvmtiEnv *jvmti_env, + JNIEnv *env, + jthread thr, + jmethodID method, + jlocation location, + jclass field_klass, + jobject obj, + jfieldID field, + char sig, + jvalue new_value ) { + + increaseCounter(&modificationCount); +} + +/***********************************************************************/ + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t002_setTag( JNIEnv* jni, + jclass klass, + jobject target, /* object to be tagged */ + jlong tag ) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, target, tag))) { + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t002_runIterateOverHeap( JNIEnv* jni, + jclass klass ) { + int count = 0; + + setCounter(&errorCount, 0); + setCounter(&modificationCount, 0); + setCounter(&iterationCount, 0); + + NSK_DISPLAY0("Calling IterateOverHeap...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_TAGGED, + heapObjectCallback, + NULL /*user_data*/))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY0("IterateOverHeap finished.\n"); + + NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); + NSK_DISPLAY1("Modifications count: %d\n", getCounter(&modificationCount)); + + count = getCounter(&errorCount); + NSK_DISPLAY1("Errors detected: %d\n", count); + // because of racing in FieldModification event, one event can be fired before safepoint occures + if (count > 1) { + NSK_COMPLAIN1("FieldMofification events detected during heap iteration: %d\n", count); + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t002_runIterateOverReachableObjects( JNIEnv* jni, + jclass klass ) { + int count = 0; + + setCounter(&errorCount, 0); + setCounter(&modificationCount, 0); + setCounter(&iterationCount, 0); + + NSK_DISPLAY0("Calling IterateOverReachableObjects...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverReachableObjects, jvmti, + heapRootCallback, + stackReferenceCallback, + objectReferenceCallback, + NULL /*user_data*/))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY0("IterateOverReachableObjects finished.\n"); + + NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); + NSK_DISPLAY1("Modifications count: %d\n", getCounter(&modificationCount)); + + count = getCounter(&errorCount); + NSK_DISPLAY1("Errors detected: %d\n", count); + // because of racing in FieldModification event, one event can be fired before safepoint occures + if (count > 1) { + NSK_COMPLAIN1("FieldMofification events detected during heap iteration: %d\n", count); + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t002_runIterateOverInstancesOfClass( JNIEnv* jni, + jclass klass ) { + int count = 0; + + setCounter(&errorCount, 0); + setCounter(&modificationCount, 0); + setCounter(&iterationCount, 0); + + NSK_DISPLAY0("Calling IterateOverInstancesOfClass...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + debugeeClass, + JVMTI_HEAP_OBJECT_TAGGED, + heapObjectCallback, + NULL /*user_data*/))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY0("IterateOverInstancesOfClass finished.\n"); + + NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); + NSK_DISPLAY1("Modifications count: %d\n", getCounter(&modificationCount)); + + count = getCounter(&errorCount); + NSK_DISPLAY1("Errors detected: %d\n", count); + // because of racing in FieldModification event, one event can be fired before safepoint occures + if (count > 1) { + NSK_COMPLAIN1("FieldMofification events detected during heap iteration: %d\n", count); + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t002_runIterateOverObjectsReachableFromObject( JNIEnv* jni, + jclass klass ) { + jobject root = NULL; + int count = 0; + + if (!NSK_JNI_VERIFY(jni, (root = + NSK_CPP_STUB3(GetStaticObjectField, jni, + debugeeClass, + rootFieldID )) != NULL )) { + NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n"); + nsk_jvmti_setFailStatus(); + return; + } + + setCounter(&errorCount, 0); + setCounter(&modificationCount, 0); + setCounter(&iterationCount, 0); + + NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverObjectsReachableFromObject, jvmti, + root, + objectReferenceCallback, + NULL /*user_data*/))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY0("IterateOverObjectsReachableFromObject finished.\n"); + + NSK_DISPLAY1("Iterations count: %d\n", getCounter(&iterationCount)); + NSK_DISPLAY1("Modifications count: %d\n", getCounter(&modificationCount)); + + count = getCounter(&errorCount); + NSK_DISPLAY1("Errors detected: %d\n", count); + // because of racing in FieldModification event, one event can be fired before safepoint occures + if (count > 1) { + NSK_COMPLAIN1("FieldMofification events detected during heap iteration: %d\n", count); + nsk_jvmti_setFailStatus(); + } +} + +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + NSK_DISPLAY0("Wait for debugee start\n\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_SIGNATURE); + debugeeClass = nsk_jvmti_classBySignature(DEBUGEE_SIGNATURE); + if (debugeeClass == NULL) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_JNI_VERIFY(jni, (debugeeClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) + return; + + NSK_DISPLAY1("Find ID of 'root' field: %s\n", ROOT_SIGNATURE); + if (!NSK_JNI_VERIFY(jni, (rootFieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, + debugeeClass, + "root", + ROOT_SIGNATURE)) != NULL )) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Find ID of 'modified' field\n"); + if (!NSK_JNI_VERIFY(jni, (modifiedFieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, + debugeeClass, + "modified", + "I")) != NULL )) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Set FieldModification watchpoint for 'modified' field\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetFieldModificationWatch, jvmti, + debugeeClass, + modifiedFieldID))) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Let debugee to run test cases\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + + NSK_DISPLAY0("Wait for completion of test cases\n\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); + NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, counterMonitor_ptr)); + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ap04t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ap04t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ap04t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "counterMonitor", &counterMonitor_ptr))) { + return JNI_ERR; + } + + memset(&caps, 0, sizeof(jvmtiCapabilities)); + caps.can_tag_objects = 1; + caps.can_generate_field_modification_events = 1; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, + jvmti, &caps))) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, + jvmti, &caps))) + return JNI_ERR; + + if (!caps.can_tag_objects) + NSK_DISPLAY0("Warning: tagging objects is not available\n"); + if (!caps.can_generate_field_modification_events) + NSK_DISPLAY0("Warning: generation of field modification events is not available\n"); + + /* set event callback */ + NSK_DISPLAY0("setting event callbacks ...\n"); + (void) memset(&callbacks, 0, sizeof(callbacks)); + + callbacks.FieldModification = &FieldModification; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + NSK_DISPLAY0("setting event callbacks done.\n"); + + NSK_DISPLAY0("enabling JVMTI events ...\n"); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4( SetEventNotificationMode, + jvmti, + JVMTI_ENABLE, + JVMTI_EVENT_FIELD_MODIFICATION, + NULL))) + return JNI_ERR; + NSK_DISPLAY0("enabling the events done.\n"); + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + NSK_DISPLAY0("agentProc has been set\n\n"); + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/libap04t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/libap04t002.c deleted file mode 100644 index 7b5c0318e0d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/libap04t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap04t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/libap04t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/libap04t002.cpp new file mode 100644 index 00000000000..e425cdd4580 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t002/libap04t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap04t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.c deleted file mode 100644 index 83f5c272bce..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.c +++ /dev/null @@ -1,709 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "jni_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define OBJ_MAX_COUNT 100000 - -static JNIEnv *jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities caps; - -static jlong timeout = 0; - -static const char* DEBUGEE_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP04/ap04t003;"; -static const char* ROOT_SIGNATURE = "[Lnsk/jvmti/scenarios/allocation/AP04/ap04t003;"; - -static jclass debugeeClass = NULL; -static jfieldID rootFieldID; - -static jrawMonitorID startLock = NULL; -static jrawMonitorID runLock = NULL; -static jrawMonitorID endLock = NULL; - -static volatile int iterationCount = 0; -static volatile int objectCount = 0; - -/***********************************************************************/ - -static jrawMonitorID counterMonitor_ptr = NULL; - -static void increaseCounter(volatile int* counterPtr) { - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } - - (*counterPtr)++; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } -} - -static void setCounter(volatile int* counterPtr, int value) { - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } - - *counterPtr = value; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } -} - -static int getCounter(volatile int* counterPtr) { - int result; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } - - result = *counterPtr; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { - nsk_jvmti_setFailStatus(); - } - - return result; -} - -/***********************************************************************/ - -void notifyThread() { - - /* enter and notify runLock */ - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, runLock))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorNotify, jvmti, runLock))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, runLock))) { - nsk_jvmti_setFailStatus(); - } - } -} - -jvmtiIterationControl JNICALL -heapObjectCallback( jlong class_tag, - jlong size, - jlong* tag_ptr, - void* user_data) { - - if (getCounter(&iterationCount) == 0) { - notifyThread(); - } - increaseCounter(&iterationCount); - - if (*tag_ptr > 0) { - increaseCounter(&objectCount); - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* jvmtiHeapRootCallback */ -jvmtiIterationControl JNICALL -heapRootCallback( jvmtiHeapRootKind root_kind, - jlong class_tag, - jlong size, - jlong* tag_ptr, - void* user_data) { - - if (getCounter(&iterationCount) == 0) { - notifyThread(); - } - increaseCounter(&iterationCount); - - if (*tag_ptr > 0) { - increaseCounter(&objectCount); - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* jvmtiStackReferenceCallback */ -jvmtiIterationControl JNICALL -stackReferenceCallback( jvmtiHeapRootKind root_kind, - jlong class_tag, - jlong size, - jlong* tag_ptr, - jlong thread_tag, - jint depth, - jmethodID method, - jint slot, - void* user_data) { - - if (getCounter(&iterationCount) == 0) { - notifyThread(); - } - increaseCounter(&iterationCount); - - if (*tag_ptr > 0) { - increaseCounter(&objectCount); - } - - return JVMTI_ITERATION_CONTINUE; -} - - -/* jvmtiObjectReferenceCallback */ -jvmtiIterationControl JNICALL -objectReferenceCallback( jvmtiObjectReferenceKind reference_kind, - jlong class_tag, - jlong size, - jlong* tag_ptr, - jlong referrer_tag, - jint referrer_index, - void* user_data) { - - if (getCounter(&iterationCount) == 0) { - notifyThread(); - } - increaseCounter(&iterationCount); - - if (*tag_ptr > 0) { - increaseCounter(&objectCount); - } - - return JVMTI_ITERATION_CONTINUE; -} - -/********* Agent thread modifying tags of objects ************/ - -/** Body of new agent thread: modify tags of tagged object. */ -void JNICALL agent_start(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { - - jint taggedObjectsCount = 0; - jobject* taggedObjectsList = NULL; - - NSK_DISPLAY0("Agent thread: started.\n"); - - /* obtain tagged objects list */ - { - jlong tag = (jlong)1; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB6(GetObjectsWithTags, jvmti, - 1, &tag, - &taggedObjectsCount, - &taggedObjectsList, - NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - } - - NSK_DISPLAY1("Agent thread: got tagged objects: %d\n", (int)taggedObjectsCount); - - if (!NSK_VERIFY(taggedObjectsCount == OBJ_MAX_COUNT)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* enter runLock */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, runLock))) { - nsk_jvmti_setFailStatus(); - } - - /* enter and notify startLock */ - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, startLock))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorNotify, jvmti, startLock))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, startLock))) { - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0("Agent thread: wait for run notification\n"); - - /* wait on runLock */ - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RawMonitorWait, jvmti, runLock, timeout))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, runLock))) { - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0("Agent thread: modify tags of each even object.\n"); - - /* modify tags of each even object */ - { - int modified = 0; - int i; - for (i = 0; i < taggedObjectsCount; i+=2) { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, taggedObjectsList[i], 0))) { - nsk_jvmti_setFailStatus(); - continue; - } - modified++; - } - - NSK_DISPLAY2("Agent thread: tags modified: %d of %d\n", - modified, (int)taggedObjectsCount); - } - - /* destroy objects list */ - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)taggedObjectsList))) { - nsk_jvmti_setFailStatus(); - } - } - - /* enter and notify endLock */ - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, endLock))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorNotify, jvmti, endLock))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, endLock))) { - nsk_jvmti_setFailStatus(); - } - } - - NSK_DISPLAY0("Agent thread: finished.\n"); -} - -/***********************************************************************/ - -static int startThread(JNIEnv* jni, jthread threadObj) { - int success = NSK_TRUE; - - /* enter startLock */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, startLock))) { - nsk_jvmti_setFailStatus(); - } - - /* start thread */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(RunAgentThread, jvmti, - threadObj, - agent_start, - NULL, - JVMTI_THREAD_NORM_PRIORITY))) { - success = NSK_FALSE; - nsk_jvmti_setFailStatus(); - } else { - /* wait on startLock */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RawMonitorWait, jvmti, startLock, timeout))) { - nsk_jvmti_setFailStatus(); - } - } - - /* exit starLock */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, startLock))) { - nsk_jvmti_setFailStatus(); - } - - return success; -} - -/** Create thread object for new agent thread. */ -static jthread newThreadObj(JNIEnv* jni) { - jclass thrClass; - jmethodID cid; - jthread result = NULL; - - if (!NSK_JNI_VERIFY(jni, (thrClass = - NSK_CPP_STUB2(FindClass, jni, - "java/lang/Thread")) != NULL )) { - nsk_jvmti_setFailStatus(); - return result; - } - - if (!NSK_JNI_VERIFY(jni, (cid = - NSK_CPP_STUB4(GetMethodID, jni, - thrClass, - "", - "()V")) != NULL )) { - nsk_jvmti_setFailStatus(); - return result; - } - - if (!NSK_JNI_VERIFY(jni, (result = - NSK_CPP_STUB3(NewObject, jni, - thrClass, - cid )) != NULL )) { - nsk_jvmti_setFailStatus(); - return result; - } - - return result; -} - -/***********************************************************************/ - -/** Clean counters and start new agent thread with agent_start() body. */ -static int prepareToIteration (JNIEnv* jni) { - jthread threadObj = NULL; - - setCounter(&iterationCount, 0); - setCounter(&objectCount, 0); - - if (!NSK_VERIFY((threadObj = newThreadObj(jni)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - /* enter endLock */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorEnter, jvmti, endLock))) { - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY0("Starting new agent thread...\n"); - return startThread(jni, threadObj); -} - -/** Wait for new agent thread to complete. */ -static void afterIteration (JNIEnv* jni) { - - /* notify new agent thread (in case if not yet notified) */ - notifyThread(); - - NSK_DISPLAY0("Wait for new agent thread to complete\n"); - - /* wait on endLock */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RawMonitorWait, jvmti, endLock, timeout))) { - nsk_jvmti_setFailStatus(); - } - - /* exit endLock */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(RawMonitorExit, jvmti, endLock))) { - nsk_jvmti_setFailStatus(); - } -} - -/***********************************************************************/ - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_setTag( JNIEnv* jni, - jclass klass, - jobject target, /* object to be tagged */ - jlong tag ) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, target, tag))) { - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverHeap( JNIEnv* jni, - jclass klass ) { - int modified = 0; - int found = 0; - - if (!prepareToIteration(jni)) - return; - - NSK_DISPLAY0("Calling IterateOverHeap...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_TAGGED, - heapObjectCallback, - NULL /*user_data*/))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY0("IterateOverHeap finished.\n"); - - afterIteration(jni); - - found = getCounter(&objectCount); - NSK_DISPLAY1("Found tagged objects: %d\n", found); - - modified = OBJ_MAX_COUNT - found; - if (modified > 0) { - NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n", - modified, OBJ_MAX_COUNT); - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverReachableObjects( JNIEnv* jni, - jclass klass ) { - int modified = 0; - int found = 0; - - if (!prepareToIteration(jni)) - return; - - NSK_DISPLAY0("Calling IterateOverReachableObjects...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverReachableObjects, jvmti, - heapRootCallback, - stackReferenceCallback, - objectReferenceCallback, - NULL /*user_data*/))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY0("IterateOverReachableObjects finished.\n"); - - afterIteration(jni); - - found = getCounter(&objectCount); - NSK_DISPLAY1("Found tagged objects: %d\n", found); - - modified = OBJ_MAX_COUNT - found; - if (modified > 0) { - NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n", - modified, OBJ_MAX_COUNT); - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverInstancesOfClass( JNIEnv* jni, - jclass klass ) { - int modified = 0; - int found = 0; - - if (!prepareToIteration(jni)) - return; - - NSK_DISPLAY0("Calling IterateOverInstancesOfClass...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - debugeeClass, - JVMTI_HEAP_OBJECT_TAGGED, - heapObjectCallback, - NULL /*user_data*/))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY0("IterateOverInstancesOfClass finished.\n"); - - afterIteration(jni); - - found = getCounter(&objectCount); - NSK_DISPLAY1("Found tagged objects: %d\n", found); - - modified = OBJ_MAX_COUNT - found; - if (modified > 0) { - NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n", - modified, OBJ_MAX_COUNT); - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverObjectsReachableFromObject( JNIEnv* jni, - jclass klass ) { - jobject root = NULL; - int modified = 0; - int found = 0; - - if (!NSK_JNI_VERIFY(jni, (root = - NSK_CPP_STUB3(GetStaticObjectField, jni, - debugeeClass, - rootFieldID )) != NULL )) { - NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n"); - nsk_jvmti_setFailStatus(); - return; - } - - if (!prepareToIteration(jni)) - return; - - NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverObjectsReachableFromObject, jvmti, - root, - objectReferenceCallback, - NULL /*user_data*/))) { - nsk_jvmti_setFailStatus(); - } - NSK_DISPLAY0("IterateOverObjectsReachableFromObject finished.\n"); - - afterIteration(jni); - - found = getCounter(&objectCount); - NSK_DISPLAY1("Found tagged objects: %d\n", found); - - modified = OBJ_MAX_COUNT - found; - if (modified > 0) { - NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n", - modified, OBJ_MAX_COUNT); - nsk_jvmti_setFailStatus(); - } -} - -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - NSK_DISPLAY0("Wait for debugee start\n\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_SIGNATURE); - debugeeClass = nsk_jvmti_classBySignature(DEBUGEE_SIGNATURE); - if (debugeeClass == NULL) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) - return; - - NSK_DISPLAY1("Find ID of 'root' field: %s\n", ROOT_SIGNATURE); - if (!NSK_JNI_VERIFY(jni, (rootFieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, - debugeeClass, - "root", - ROOT_SIGNATURE)) != NULL )) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Let debugee to run test cases\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - - NSK_DISPLAY0("Wait for completion of test cases\n\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); - NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, counterMonitor_ptr)); - NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, startLock)); - NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, runLock)); - NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, endLock)); - - NSK_DISPLAY0("Let debugee to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ap04t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ap04t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ap04t003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "counterMonitor", &counterMonitor_ptr))) { - return JNI_ERR; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "startLock", &startLock))) { - return JNI_ERR; - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "runLock", &runLock))) { - return JNI_ERR; - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "endLock", &endLock))) { - return JNI_ERR; - } - - memset(&caps, 0, sizeof(jvmtiCapabilities)); - caps.can_tag_objects = 1; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, - jvmti, &caps))) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, - jvmti, &caps))) - return JNI_ERR; - - if (!caps.can_tag_objects) - NSK_DISPLAY0("Warning: tagging objects is not available\n"); - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - NSK_DISPLAY0("agentProc has been set\n\n"); - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.cpp new file mode 100644 index 00000000000..15155abe7f3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.cpp @@ -0,0 +1,709 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "jni_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define OBJ_MAX_COUNT 100000 + +static JNIEnv *jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities caps; + +static jlong timeout = 0; + +static const char* DEBUGEE_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP04/ap04t003;"; +static const char* ROOT_SIGNATURE = "[Lnsk/jvmti/scenarios/allocation/AP04/ap04t003;"; + +static jclass debugeeClass = NULL; +static jfieldID rootFieldID; + +static jrawMonitorID startLock = NULL; +static jrawMonitorID runLock = NULL; +static jrawMonitorID endLock = NULL; + +static volatile int iterationCount = 0; +static volatile int objectCount = 0; + +/***********************************************************************/ + +static jrawMonitorID counterMonitor_ptr = NULL; + +static void increaseCounter(volatile int* counterPtr) { + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } + + (*counterPtr)++; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } +} + +static void setCounter(volatile int* counterPtr, int value) { + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } + + *counterPtr = value; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } +} + +static int getCounter(volatile int* counterPtr) { + int result; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } + + result = *counterPtr; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, counterMonitor_ptr))) { + nsk_jvmti_setFailStatus(); + } + + return result; +} + +/***********************************************************************/ + +void notifyThread() { + + /* enter and notify runLock */ + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, runLock))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorNotify, jvmti, runLock))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, runLock))) { + nsk_jvmti_setFailStatus(); + } + } +} + +jvmtiIterationControl JNICALL +heapObjectCallback( jlong class_tag, + jlong size, + jlong* tag_ptr, + void* user_data) { + + if (getCounter(&iterationCount) == 0) { + notifyThread(); + } + increaseCounter(&iterationCount); + + if (*tag_ptr > 0) { + increaseCounter(&objectCount); + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* jvmtiHeapRootCallback */ +jvmtiIterationControl JNICALL +heapRootCallback( jvmtiHeapRootKind root_kind, + jlong class_tag, + jlong size, + jlong* tag_ptr, + void* user_data) { + + if (getCounter(&iterationCount) == 0) { + notifyThread(); + } + increaseCounter(&iterationCount); + + if (*tag_ptr > 0) { + increaseCounter(&objectCount); + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* jvmtiStackReferenceCallback */ +jvmtiIterationControl JNICALL +stackReferenceCallback( jvmtiHeapRootKind root_kind, + jlong class_tag, + jlong size, + jlong* tag_ptr, + jlong thread_tag, + jint depth, + jmethodID method, + jint slot, + void* user_data) { + + if (getCounter(&iterationCount) == 0) { + notifyThread(); + } + increaseCounter(&iterationCount); + + if (*tag_ptr > 0) { + increaseCounter(&objectCount); + } + + return JVMTI_ITERATION_CONTINUE; +} + + +/* jvmtiObjectReferenceCallback */ +jvmtiIterationControl JNICALL +objectReferenceCallback( jvmtiObjectReferenceKind reference_kind, + jlong class_tag, + jlong size, + jlong* tag_ptr, + jlong referrer_tag, + jint referrer_index, + void* user_data) { + + if (getCounter(&iterationCount) == 0) { + notifyThread(); + } + increaseCounter(&iterationCount); + + if (*tag_ptr > 0) { + increaseCounter(&objectCount); + } + + return JVMTI_ITERATION_CONTINUE; +} + +/********* Agent thread modifying tags of objects ************/ + +/** Body of new agent thread: modify tags of tagged object. */ +void JNICALL agent_start(jvmtiEnv* jvmti, JNIEnv* jni, void *p) { + + jint taggedObjectsCount = 0; + jobject* taggedObjectsList = NULL; + + NSK_DISPLAY0("Agent thread: started.\n"); + + /* obtain tagged objects list */ + { + jlong tag = (jlong)1; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB6(GetObjectsWithTags, jvmti, + 1, &tag, + &taggedObjectsCount, + &taggedObjectsList, + NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + } + + NSK_DISPLAY1("Agent thread: got tagged objects: %d\n", (int)taggedObjectsCount); + + if (!NSK_VERIFY(taggedObjectsCount == OBJ_MAX_COUNT)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* enter runLock */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, runLock))) { + nsk_jvmti_setFailStatus(); + } + + /* enter and notify startLock */ + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, startLock))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorNotify, jvmti, startLock))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, startLock))) { + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0("Agent thread: wait for run notification\n"); + + /* wait on runLock */ + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RawMonitorWait, jvmti, runLock, timeout))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, runLock))) { + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0("Agent thread: modify tags of each even object.\n"); + + /* modify tags of each even object */ + { + int modified = 0; + int i; + for (i = 0; i < taggedObjectsCount; i+=2) { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, taggedObjectsList[i], 0))) { + nsk_jvmti_setFailStatus(); + continue; + } + modified++; + } + + NSK_DISPLAY2("Agent thread: tags modified: %d of %d\n", + modified, (int)taggedObjectsCount); + } + + /* destroy objects list */ + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)taggedObjectsList))) { + nsk_jvmti_setFailStatus(); + } + } + + /* enter and notify endLock */ + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, endLock))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorNotify, jvmti, endLock))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, endLock))) { + nsk_jvmti_setFailStatus(); + } + } + + NSK_DISPLAY0("Agent thread: finished.\n"); +} + +/***********************************************************************/ + +static int startThread(JNIEnv* jni, jthread threadObj) { + int success = NSK_TRUE; + + /* enter startLock */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, startLock))) { + nsk_jvmti_setFailStatus(); + } + + /* start thread */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(RunAgentThread, jvmti, + threadObj, + agent_start, + NULL, + JVMTI_THREAD_NORM_PRIORITY))) { + success = NSK_FALSE; + nsk_jvmti_setFailStatus(); + } else { + /* wait on startLock */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RawMonitorWait, jvmti, startLock, timeout))) { + nsk_jvmti_setFailStatus(); + } + } + + /* exit starLock */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, startLock))) { + nsk_jvmti_setFailStatus(); + } + + return success; +} + +/** Create thread object for new agent thread. */ +static jthread newThreadObj(JNIEnv* jni) { + jclass thrClass; + jmethodID cid; + jthread result = NULL; + + if (!NSK_JNI_VERIFY(jni, (thrClass = + NSK_CPP_STUB2(FindClass, jni, + "java/lang/Thread")) != NULL )) { + nsk_jvmti_setFailStatus(); + return result; + } + + if (!NSK_JNI_VERIFY(jni, (cid = + NSK_CPP_STUB4(GetMethodID, jni, + thrClass, + "", + "()V")) != NULL )) { + nsk_jvmti_setFailStatus(); + return result; + } + + if (!NSK_JNI_VERIFY(jni, (result = + NSK_CPP_STUB3(NewObject, jni, + thrClass, + cid )) != NULL )) { + nsk_jvmti_setFailStatus(); + return result; + } + + return result; +} + +/***********************************************************************/ + +/** Clean counters and start new agent thread with agent_start() body. */ +static int prepareToIteration (JNIEnv* jni) { + jthread threadObj = NULL; + + setCounter(&iterationCount, 0); + setCounter(&objectCount, 0); + + if (!NSK_VERIFY((threadObj = newThreadObj(jni)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + /* enter endLock */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorEnter, jvmti, endLock))) { + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY0("Starting new agent thread...\n"); + return startThread(jni, threadObj); +} + +/** Wait for new agent thread to complete. */ +static void afterIteration (JNIEnv* jni) { + + /* notify new agent thread (in case if not yet notified) */ + notifyThread(); + + NSK_DISPLAY0("Wait for new agent thread to complete\n"); + + /* wait on endLock */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RawMonitorWait, jvmti, endLock, timeout))) { + nsk_jvmti_setFailStatus(); + } + + /* exit endLock */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(RawMonitorExit, jvmti, endLock))) { + nsk_jvmti_setFailStatus(); + } +} + +/***********************************************************************/ + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_setTag( JNIEnv* jni, + jclass klass, + jobject target, /* object to be tagged */ + jlong tag ) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, target, tag))) { + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverHeap( JNIEnv* jni, + jclass klass ) { + int modified = 0; + int found = 0; + + if (!prepareToIteration(jni)) + return; + + NSK_DISPLAY0("Calling IterateOverHeap...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_TAGGED, + heapObjectCallback, + NULL /*user_data*/))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY0("IterateOverHeap finished.\n"); + + afterIteration(jni); + + found = getCounter(&objectCount); + NSK_DISPLAY1("Found tagged objects: %d\n", found); + + modified = OBJ_MAX_COUNT - found; + if (modified > 0) { + NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n", + modified, OBJ_MAX_COUNT); + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverReachableObjects( JNIEnv* jni, + jclass klass ) { + int modified = 0; + int found = 0; + + if (!prepareToIteration(jni)) + return; + + NSK_DISPLAY0("Calling IterateOverReachableObjects...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverReachableObjects, jvmti, + heapRootCallback, + stackReferenceCallback, + objectReferenceCallback, + NULL /*user_data*/))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY0("IterateOverReachableObjects finished.\n"); + + afterIteration(jni); + + found = getCounter(&objectCount); + NSK_DISPLAY1("Found tagged objects: %d\n", found); + + modified = OBJ_MAX_COUNT - found; + if (modified > 0) { + NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n", + modified, OBJ_MAX_COUNT); + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverInstancesOfClass( JNIEnv* jni, + jclass klass ) { + int modified = 0; + int found = 0; + + if (!prepareToIteration(jni)) + return; + + NSK_DISPLAY0("Calling IterateOverInstancesOfClass...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + debugeeClass, + JVMTI_HEAP_OBJECT_TAGGED, + heapObjectCallback, + NULL /*user_data*/))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY0("IterateOverInstancesOfClass finished.\n"); + + afterIteration(jni); + + found = getCounter(&objectCount); + NSK_DISPLAY1("Found tagged objects: %d\n", found); + + modified = OBJ_MAX_COUNT - found; + if (modified > 0) { + NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n", + modified, OBJ_MAX_COUNT); + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverObjectsReachableFromObject( JNIEnv* jni, + jclass klass ) { + jobject root = NULL; + int modified = 0; + int found = 0; + + if (!NSK_JNI_VERIFY(jni, (root = + NSK_CPP_STUB3(GetStaticObjectField, jni, + debugeeClass, + rootFieldID )) != NULL )) { + NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n"); + nsk_jvmti_setFailStatus(); + return; + } + + if (!prepareToIteration(jni)) + return; + + NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverObjectsReachableFromObject, jvmti, + root, + objectReferenceCallback, + NULL /*user_data*/))) { + nsk_jvmti_setFailStatus(); + } + NSK_DISPLAY0("IterateOverObjectsReachableFromObject finished.\n"); + + afterIteration(jni); + + found = getCounter(&objectCount); + NSK_DISPLAY1("Found tagged objects: %d\n", found); + + modified = OBJ_MAX_COUNT - found; + if (modified > 0) { + NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n", + modified, OBJ_MAX_COUNT); + nsk_jvmti_setFailStatus(); + } +} + +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + NSK_DISPLAY0("Wait for debugee start\n\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_SIGNATURE); + debugeeClass = nsk_jvmti_classBySignature(DEBUGEE_SIGNATURE); + if (debugeeClass == NULL) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_JNI_VERIFY(jni, (debugeeClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) + return; + + NSK_DISPLAY1("Find ID of 'root' field: %s\n", ROOT_SIGNATURE); + if (!NSK_JNI_VERIFY(jni, (rootFieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, + debugeeClass, + "root", + ROOT_SIGNATURE)) != NULL )) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Let debugee to run test cases\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + + NSK_DISPLAY0("Wait for completion of test cases\n\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); + NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, counterMonitor_ptr)); + NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, startLock)); + NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, runLock)); + NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, endLock)); + + NSK_DISPLAY0("Let debugee to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ap04t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ap04t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ap04t003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "counterMonitor", &counterMonitor_ptr))) { + return JNI_ERR; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "startLock", &startLock))) { + return JNI_ERR; + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "runLock", &runLock))) { + return JNI_ERR; + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "endLock", &endLock))) { + return JNI_ERR; + } + + memset(&caps, 0, sizeof(jvmtiCapabilities)); + caps.can_tag_objects = 1; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, + jvmti, &caps))) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, + jvmti, &caps))) + return JNI_ERR; + + if (!caps.can_tag_objects) + NSK_DISPLAY0("Warning: tagging objects is not available\n"); + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + NSK_DISPLAY0("agentProc has been set\n\n"); + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/libap04t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/libap04t003.c deleted file mode 100644 index 8a1841d6662..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/libap04t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap04t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/libap04t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/libap04t003.cpp new file mode 100644 index 00000000000..b20411f954c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/libap04t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap04t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/ap05t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/ap05t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/ap05t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/ap05t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/libap05t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/libap05t001.c deleted file mode 100644 index b9e7dfd8732..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/libap05t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap05t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/libap05t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/libap05t001.cpp new file mode 100644 index 00000000000..1ec852415c1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t001/libap05t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap05t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/ap05t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/ap05t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/ap05t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/ap05t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/libap05t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/libap05t002.c deleted file mode 100644 index 8a66e5c7c3b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/libap05t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap05t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/libap05t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/libap05t002.cpp new file mode 100644 index 00000000000..ee4cfc78e6f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/libap05t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap05t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/ap06t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/ap06t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/ap06t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/ap06t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/libap06t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/libap06t001.c deleted file mode 100644 index 26fa11e096b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/libap06t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap06t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/libap06t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/libap06t001.cpp new file mode 100644 index 00000000000..7dad8ab2559 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP06/ap06t001/libap06t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap06t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/ap07t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/ap07t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/ap07t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/ap07t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/libap07t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/libap07t001.c deleted file mode 100644 index 06669125750..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/libap07t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap07t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/libap07t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/libap07t001.cpp new file mode 100644 index 00000000000..e9c7dacc15e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t001/libap07t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap07t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/ap07t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/ap07t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/ap07t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/ap07t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/libap07t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/libap07t002.c deleted file mode 100644 index 2824311e86e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/libap07t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap07t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/libap07t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/libap07t002.cpp new file mode 100644 index 00000000000..f4bc71b837f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP07/ap07t002/libap07t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap07t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/ap09t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/ap09t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/ap09t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/ap09t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/libap09t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/libap09t001.c deleted file mode 100644 index b0ccf196748..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/libap09t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap09t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/libap09t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/libap09t001.cpp new file mode 100644 index 00000000000..b9ddd6e2c91 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP09/ap09t001/libap09t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap09t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/ap10t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/ap10t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/ap10t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/ap10t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/libap10t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/libap10t001.c deleted file mode 100644 index 23dfc9418fd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/libap10t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap10t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/libap10t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/libap10t001.cpp new file mode 100644 index 00000000000..856af058190 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP10/ap10t001/libap10t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap10t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/ap11t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/ap11t001.c deleted file mode 100644 index 70d20aa24e2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/ap11t001.c +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* ========================================================================== */ - -static int lookup(jvmtiEnv* jvmti, - jint classCount, jclass *classes, const char *exp_sig) { - char *signature, *generic; - int found = NSK_FALSE; - jint i; - - for (i = 0; i < classCount && !found; i++) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti, - classes[i], &signature, &generic))) - break; - - if (signature != NULL && strcmp(signature, exp_sig) == 0) { - found = NSK_TRUE; - } - - if (signature != NULL) - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)signature); - - if (generic != NULL) - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)generic); - } - - return found; -} - -/* ========================================================================== */ - -JNIEXPORT void JNICALL -VMObjectAlloc(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jobject object, - jclass object_klass, jlong size) { - - char *signature, *generic; - jvmtiThreadInfo threadInfo; - - /* Check that event is received in Live phase - */ - { - jvmtiPhase phase; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti, &phase ))) { - nsk_jvmti_setFailStatus(); - return; - } - if (phase != JVMTI_PHASE_LIVE) { - NSK_COMPLAIN1("VMObjectAlloc event was received in wrong phase: %s\n", TranslatePhase(phase)); - return; - } - } - - do { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti, - object_klass, &signature, &generic))) { - nsk_jvmti_setFailStatus(); - break; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti, - thread, &threadInfo))) { - nsk_jvmti_setFailStatus(); - break; - } - - NSK_DISPLAY2("VMObjectAlloc in \"%s\" thread: \"%s\"\n", threadInfo.name, signature); - } while (0); - - /* Check that event's thread is live thread - */ - do { - jint threadCount; - jthread *threads; - jint i; - jboolean found = JNI_FALSE; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetAllThreads, jvmti, - &threadCount, &threads))) { - nsk_jvmti_setFailStatus(); - break; - } - - for (i = 0; i < threadCount && !found; i++) { - found = NSK_CPP_STUB3(IsSameObject, jni, threads[i], thread); - if (found == JNI_TRUE) { - break; - } - } - - if (!found) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN1("VMObjectAlloc: event's thread was found in the list of live threads: %s\n\n", threadInfo.name); - } - } while(0); - - - /* Check that object_klass is loaded class - */ - do { - jint classCount; - jclass *classes; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetLoadedClasses, jvmti, - &classCount, &classes))) { - nsk_jvmti_setFailStatus(); - break; - } - - if (!lookup(jvmti, classCount, classes, signature)) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN1("VMObjectAlloc: object_klass is not found in the list of loaded classes: %s\n", signature); - return; - } - - if (classes != NULL) - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)classes); - } while(0); - - - /* Check for object_klass - */ - { - jclass class; - class = NSK_CPP_STUB2(GetObjectClass, jni, object); - if (!(NSK_CPP_STUB3(IsSameObject, jni, object_klass, class))) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN1("VMObjectAlloc: unexpected object_klass : \"%s\"\n\n", signature); - } - } - - /* Check for object size - */ - - do { - jlong objSize; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetObjectSize, jvmti, - object, &objSize))) { - nsk_jvmti_setFailStatus(); - break; - } - - if (objSize != size) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN2("VMObjectAlloc: inconsistent object size data\n\t" - " size passed in to callback: %d\n\t size returned by GetObjectSize: %d\n\n", (long)size, (long)objSize); - } - } while(0); - - if (signature != NULL) - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)signature); - - if (generic != NULL) - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)generic); -} - -/* ========================================================================== */ - -/* agent algorithm */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - /* wait for debuggee start */ - if (!nsk_jvmti_waitForSync(timeout)) - return; - /* resume debugee after last sync */ - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/* agent library initialization */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ap11t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ap11t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ap11t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiCapabilities caps; - jvmtiEventCallbacks callbacks; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60000; - NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout); - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_vm_object_alloc_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.VMObjectAlloc= &VMObjectAlloc; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - /* enable VMObjectAlloc event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_OBJECT_ALLOC, NULL))) - return JNI_ERR; - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/ap11t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/ap11t001.cpp new file mode 100644 index 00000000000..2dae88fe5d5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/ap11t001.cpp @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* ========================================================================== */ + +static int lookup(jvmtiEnv* jvmti, + jint classCount, jclass *classes, const char *exp_sig) { + char *signature, *generic; + int found = NSK_FALSE; + jint i; + + for (i = 0; i < classCount && !found; i++) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti, + classes[i], &signature, &generic))) + break; + + if (signature != NULL && strcmp(signature, exp_sig) == 0) { + found = NSK_TRUE; + } + + if (signature != NULL) + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)signature); + + if (generic != NULL) + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)generic); + } + + return found; +} + +/* ========================================================================== */ + +JNIEXPORT void JNICALL +VMObjectAlloc(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jobject object, + jclass object_klass, jlong size) { + + char *signature, *generic; + jvmtiThreadInfo threadInfo; + + /* Check that event is received in Live phase + */ + { + jvmtiPhase phase; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti, &phase ))) { + nsk_jvmti_setFailStatus(); + return; + } + if (phase != JVMTI_PHASE_LIVE) { + NSK_COMPLAIN1("VMObjectAlloc event was received in wrong phase: %s\n", TranslatePhase(phase)); + return; + } + } + + do { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti, + object_klass, &signature, &generic))) { + nsk_jvmti_setFailStatus(); + break; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti, + thread, &threadInfo))) { + nsk_jvmti_setFailStatus(); + break; + } + + NSK_DISPLAY2("VMObjectAlloc in \"%s\" thread: \"%s\"\n", threadInfo.name, signature); + } while (0); + + /* Check that event's thread is live thread + */ + do { + jint threadCount; + jthread *threads; + jint i; + jboolean found = JNI_FALSE; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetAllThreads, jvmti, + &threadCount, &threads))) { + nsk_jvmti_setFailStatus(); + break; + } + + for (i = 0; i < threadCount && !found; i++) { + found = NSK_CPP_STUB3(IsSameObject, jni, threads[i], thread); + if (found == JNI_TRUE) { + break; + } + } + + if (!found) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN1("VMObjectAlloc: event's thread was found in the list of live threads: %s\n\n", threadInfo.name); + } + } while(0); + + + /* Check that object_klass is loaded class + */ + do { + jint classCount; + jclass *classes; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetLoadedClasses, jvmti, + &classCount, &classes))) { + nsk_jvmti_setFailStatus(); + break; + } + + if (!lookup(jvmti, classCount, classes, signature)) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN1("VMObjectAlloc: object_klass is not found in the list of loaded classes: %s\n", signature); + return; + } + + if (classes != NULL) + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)classes); + } while(0); + + + /* Check for object_klass + */ + { + jclass klass; + klass = NSK_CPP_STUB2(GetObjectClass, jni, object); + if (!(NSK_CPP_STUB3(IsSameObject, jni, object_klass, klass))) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN1("VMObjectAlloc: unexpected object_klass : \"%s\"\n\n", signature); + } + } + + /* Check for object size + */ + + do { + jlong objSize; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetObjectSize, jvmti, + object, &objSize))) { + nsk_jvmti_setFailStatus(); + break; + } + + if (objSize != size) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN2("VMObjectAlloc: inconsistent object size data\n\t" + " size passed in to callback: %d\n\t size returned by GetObjectSize: %d\n\n", (long)size, (long)objSize); + } + } while(0); + + if (signature != NULL) + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)signature); + + if (generic != NULL) + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)generic); +} + +/* ========================================================================== */ + +/* agent algorithm */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + /* wait for debuggee start */ + if (!nsk_jvmti_waitForSync(timeout)) + return; + /* resume debugee after last sync */ + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/* agent library initialization */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ap11t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ap11t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ap11t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiCapabilities caps; + jvmtiEventCallbacks callbacks; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60000; + NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout); + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_vm_object_alloc_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.VMObjectAlloc= &VMObjectAlloc; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + /* enable VMObjectAlloc event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, + JVMTI_EVENT_VM_OBJECT_ALLOC, NULL))) + return JNI_ERR; + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/libap11t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/libap11t001.c deleted file mode 100644 index cf3d6c583d0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/libap11t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap11t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/libap11t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/libap11t001.cpp new file mode 100644 index 00000000000..5858881e9a0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP11/ap11t001/libap11t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap11t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/ap12t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/ap12t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/ap12t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/ap12t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/libap12t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/libap12t001.c deleted file mode 100644 index c605d096d06..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/libap12t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ap12t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/libap12t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/libap12t001.cpp new file mode 100644 index 00000000000..eda33b8aa7a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP12/ap12t001/libap12t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ap12t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/bi01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/bi01t001.c deleted file mode 100644 index 5d284a4e81e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/bi01t001.c +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; - -#define TESTED_CLASS_NAME "nsk/jvmti/scenarios/bcinstr/BI01/bi01t001a" - -static jint newClassSize; -static unsigned char* newClassBytes; -static jvmtiClassDefinition oldClassDef; - -/* ============================================================================= */ -/* - * Class: nsk_jvmti_scenarios_bcinstr_BI01_bi01t001 - * Method: setNewByteCode - * Signature: ([B)Z - */ -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_bcinstr_BI01_bi01t001_setNewByteCode(JNIEnv *jni_env, - jobject this, jbyteArray byteCode) { - - jbyte* elements; - jboolean isCopy; - - if (!NSK_JNI_VERIFY(jni_env, (newClassSize = - NSK_CPP_STUB2(GetArrayLength, jni_env, byteCode)) > 0)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1("\t... got array size: %d\n", newClassSize); - - if (!NSK_JNI_VERIFY(jni_env, (elements = - NSK_CPP_STUB3(GetByteArrayElements, jni_env, byteCode, - &isCopy)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1("\t... got elements list: 0x%p\n", (void*)elements); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, - newClassSize, &newClassBytes))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1("\t... created bytes array: 0x%p\n", (void*)newClassBytes); - - { - int j; - for (j = 0; j < newClassSize; j++) - newClassBytes[j] = (unsigned char)elements[j]; - } - NSK_DISPLAY1("\t... copied bytecode: %d bytes\n", (int)newClassSize); - - NSK_DISPLAY1("\t... release elements list: 0x%p\n", (void*)elements); - NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni_env, byteCode, elements, JNI_ABORT)); - NSK_DISPLAY0("\t... released\n"); - return NSK_TRUE; -} - -/* ============================================================================= */ -/* - * Class: nsk_jvmti_scenarios_bcinstr_BI01_bi01t001 - * Method: setClass - * Signature: (Ljava/lang/Class;)V - */ -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_bcinstr_BI01_bi01t001_setClass(JNIEnv *jni_env, - jobject this, jclass cls) { - - if (!NSK_JNI_VERIFY(jni_env, (oldClassDef.klass = - NSK_CPP_STUB2(NewGlobalRef, jni_env, cls)) != NULL)) { - nsk_jvmti_setFailStatus(); - } -} - -/* ============================================================================= */ - -/** Callback function for ClassFileLoadHook event. */ -JNIEXPORT void JNICALL -cbClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv* jni_env, - jclass class_being_redefined, jobject loader, const char* name, - jobject protection_domain, jint class_data_len, - const unsigned char* class_data, jint* new_class_data_len, - unsigned char** new_class_data) { - - if ( name == NULL || strcmp(name, TESTED_CLASS_NAME) ) { - return; - } - - NSK_DISPLAY3("CLASS_FILE_LOAD_HOOK event: %s\n\treceived bytecode: 0x%p:%d\n", - name, (void *)class_data, class_data_len); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, class_data_len, class_data); - } - - { - /*store original byte code, it will be used to do final redefinition*/ - int j; - unsigned char *arr; - - oldClassDef.class_byte_count = class_data_len; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti_env, class_data_len, - &arr))) { - nsk_jvmti_setFailStatus(); - return; - } - for (j = 0; j < class_data_len; j++) { - arr[j] = class_data[j]; - } - oldClassDef.class_bytes = arr; - } - - *new_class_data_len = newClassSize; - *new_class_data = newClassBytes; - - NSK_DISPLAY2("Replace with new bytecode: 0x%p:%d\n", - (void*)newClassBytes, - (int)newClassSize); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, newClassSize, - newClassBytes); - } -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - /*Wait for debuggee to read new byte codes nsk_jvmti_waitForSync#1*/ - NSK_DISPLAY0("Wait for debuggee to read new byte codes nsk_jvmti_waitForSync#1\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!nsk_jvmti_resumeSync()) - return; - - NSK_DISPLAY0("Wait for debuggee to load tested class by classLoader\n"); - /*Wait for debuggee to load next class nsk_jvmti_waitForSync#2*/ - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!nsk_jvmti_resumeSync()) - return; - - /*Wait for debuggee to check instrumentation code works nsk_jvmti_waitForSync#3*/ - NSK_DISPLAY0("Wait for debuggee to check instrumentation code works nsk_jvmti_waitForSync#3\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("Notification disabled for CLASS_FILE_LOAD_HOOK event\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, - JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!nsk_jvmti_resumeSync()) - return; - - /*Wait for debuggee to set classes to be redefined nsk_jvmti_waitForSync#4*/ - NSK_DISPLAY0("Wait for debuggee to set classes to be redefined nsk_jvmti_waitForSync#4\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("Redfine class with old byte code\n"); - NSK_DISPLAY3("class definition:\n\t0x%p, 0x%p:%d\n", - oldClassDef.klass, - oldClassDef.class_bytes, - oldClassDef.class_byte_count); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, oldClassDef.class_byte_count, - oldClassDef.class_bytes); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &oldClassDef))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!nsk_jvmti_resumeSync()) - return; - - /*Wait for debuggee to check old byte code works nsk_jvmti_waitForSync#5*/ - NSK_DISPLAY0("Wait for debuggee to check old byte code works nsk_jvmti_waitForSync#5\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_CPP_STUB2(DeleteGlobalRef, agentJNI, oldClassDef.klass); - - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_bi01t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_bi01t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_bi01t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - NSK_DISPLAY0("Set callback for CLASS_FILE_LOAD_HOOK event\n"); - { - jvmtiEventCallbacks callbacks; - jint size = (jint)sizeof(callbacks); - - memset(&callbacks, 0, size); - callbacks.ClassFileLoadHook = cbClassFileLoadHook; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { - return JNI_ERR; - } - } - - NSK_DISPLAY0("Set notification enabled for CLASS_FILE_LOAD_HOOK event\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, - JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/bi01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/bi01t001.cpp new file mode 100644 index 00000000000..5bb9ff483a0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/bi01t001.cpp @@ -0,0 +1,297 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; + +#define TESTED_CLASS_NAME "nsk/jvmti/scenarios/bcinstr/BI01/bi01t001a" + +static jint newClassSize; +static unsigned char* newClassBytes; +static jvmtiClassDefinition oldClassDef; + +/* ============================================================================= */ +/* + * Class: nsk_jvmti_scenarios_bcinstr_BI01_bi01t001 + * Method: setNewByteCode + * Signature: ([B)Z + */ +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_bcinstr_BI01_bi01t001_setNewByteCode(JNIEnv *jni_env, + jobject o, jbyteArray byteCode) { + + jbyte* elements; + jboolean isCopy; + + if (!NSK_JNI_VERIFY(jni_env, (newClassSize = + NSK_CPP_STUB2(GetArrayLength, jni_env, byteCode)) > 0)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1("\t... got array size: %d\n", newClassSize); + + if (!NSK_JNI_VERIFY(jni_env, (elements = + NSK_CPP_STUB3(GetByteArrayElements, jni_env, byteCode, + &isCopy)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1("\t... got elements list: 0x%p\n", (void*)elements); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, + newClassSize, &newClassBytes))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1("\t... created bytes array: 0x%p\n", (void*)newClassBytes); + + { + int j; + for (j = 0; j < newClassSize; j++) + newClassBytes[j] = (unsigned char)elements[j]; + } + NSK_DISPLAY1("\t... copied bytecode: %d bytes\n", (int)newClassSize); + + NSK_DISPLAY1("\t... release elements list: 0x%p\n", (void*)elements); + NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni_env, byteCode, elements, JNI_ABORT)); + NSK_DISPLAY0("\t... released\n"); + return NSK_TRUE; +} + +/* ============================================================================= */ +/* + * Class: nsk_jvmti_scenarios_bcinstr_BI01_bi01t001 + * Method: setClass + * Signature: (Ljava/lang/Class;)V + */ +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_bcinstr_BI01_bi01t001_setClass(JNIEnv *jni_env, + jobject o, jclass cls) { + + if (!NSK_JNI_VERIFY(jni_env, (oldClassDef.klass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni_env, cls)) != NULL)) { + nsk_jvmti_setFailStatus(); + } +} + +/* ============================================================================= */ + +/** Callback function for ClassFileLoadHook event. */ +JNIEXPORT void JNICALL +cbClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv* jni_env, + jclass class_being_redefined, jobject loader, const char* name, + jobject protection_domain, jint class_data_len, + const unsigned char* class_data, jint* new_class_data_len, + unsigned char** new_class_data) { + + if ( name == NULL || strcmp(name, TESTED_CLASS_NAME) ) { + return; + } + + NSK_DISPLAY3("CLASS_FILE_LOAD_HOOK event: %s\n\treceived bytecode: 0x%p:%d\n", + name, (void *)class_data, class_data_len); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, class_data_len, class_data); + } + + { + /*store original byte code, it will be used to do final redefinition*/ + int j; + unsigned char *arr; + + oldClassDef.class_byte_count = class_data_len; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti_env, class_data_len, + &arr))) { + nsk_jvmti_setFailStatus(); + return; + } + for (j = 0; j < class_data_len; j++) { + arr[j] = class_data[j]; + } + oldClassDef.class_bytes = arr; + } + + *new_class_data_len = newClassSize; + *new_class_data = newClassBytes; + + NSK_DISPLAY2("Replace with new bytecode: 0x%p:%d\n", + (void*)newClassBytes, + (int)newClassSize); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, newClassSize, + newClassBytes); + } +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + /*Wait for debuggee to read new byte codes nsk_jvmti_waitForSync#1*/ + NSK_DISPLAY0("Wait for debuggee to read new byte codes nsk_jvmti_waitForSync#1\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!nsk_jvmti_resumeSync()) + return; + + NSK_DISPLAY0("Wait for debuggee to load tested class by classLoader\n"); + /*Wait for debuggee to load next class nsk_jvmti_waitForSync#2*/ + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!nsk_jvmti_resumeSync()) + return; + + /*Wait for debuggee to check instrumentation code works nsk_jvmti_waitForSync#3*/ + NSK_DISPLAY0("Wait for debuggee to check instrumentation code works nsk_jvmti_waitForSync#3\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("Notification disabled for CLASS_FILE_LOAD_HOOK event\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, + JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!nsk_jvmti_resumeSync()) + return; + + /*Wait for debuggee to set classes to be redefined nsk_jvmti_waitForSync#4*/ + NSK_DISPLAY0("Wait for debuggee to set classes to be redefined nsk_jvmti_waitForSync#4\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("Redfine class with old byte code\n"); + NSK_DISPLAY3("class definition:\n\t0x%p, 0x%p:%d\n", + oldClassDef.klass, + oldClassDef.class_bytes, + oldClassDef.class_byte_count); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, oldClassDef.class_byte_count, + oldClassDef.class_bytes); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &oldClassDef))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!nsk_jvmti_resumeSync()) + return; + + /*Wait for debuggee to check old byte code works nsk_jvmti_waitForSync#5*/ + NSK_DISPLAY0("Wait for debuggee to check old byte code works nsk_jvmti_waitForSync#5\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_CPP_STUB2(DeleteGlobalRef, agentJNI, oldClassDef.klass); + + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_bi01t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_bi01t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_bi01t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + NSK_DISPLAY0("Set callback for CLASS_FILE_LOAD_HOOK event\n"); + { + jvmtiEventCallbacks callbacks; + jint size = (jint)sizeof(callbacks); + + memset(&callbacks, 0, size); + callbacks.ClassFileLoadHook = cbClassFileLoadHook; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { + return JNI_ERR; + } + } + + NSK_DISPLAY0("Set notification enabled for CLASS_FILE_LOAD_HOOK event\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, + JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/libbi01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/libbi01t001.c deleted file mode 100644 index e49eea85d53..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/libbi01t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "bi01t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/libbi01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/libbi01t001.cpp new file mode 100644 index 00000000000..2fdd853b43f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/libbi01t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "bi01t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/bi01t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/bi01t002.c deleted file mode 100644 index 85b41503924..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/bi01t002.c +++ /dev/null @@ -1,311 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; - -#define TESTED_CLASS_NAME "nsk/jvmti/scenarios/bcinstr/BI01/bi01t002a" -#define TOTAL_INSTRUMENTED_CLASSES 2 - -static int clsLoadedIdx=0; -static jint newClassSize[TOTAL_INSTRUMENTED_CLASSES]; -static unsigned char* newClassBytes[TOTAL_INSTRUMENTED_CLASSES]; -static jvmtiClassDefinition oldClassDef[TOTAL_INSTRUMENTED_CLASSES]; - -/* ============================================================================= */ -/* - * Class: nsk_jvmti_scenarios_bcinstr_BI01_bi01t002 - * Method: setNewByteCode - * Signature: (I[B)Z - */ -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_bcinstr_BI01_bi01t002_setNewByteCode(JNIEnv *jni_env, - jobject this, jint ind, jbyteArray byteCode) { - - jbyte* elements; - jboolean isCopy; - - if (!NSK_JNI_VERIFY(jni_env, (newClassSize[ind] = - NSK_CPP_STUB2(GetArrayLength, jni_env, byteCode)) > 0)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1("\t... got array size: %d\n", newClassSize[ind]); - - if (!NSK_JNI_VERIFY(jni_env, (elements = - NSK_CPP_STUB3(GetByteArrayElements, jni_env, byteCode, - &isCopy)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1("\t... got elements list: 0x%p\n", (void*)elements); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, - newClassSize[ind], &newClassBytes[ind]))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - NSK_DISPLAY1("\t... created bytes array: 0x%p\n", (void*)newClassBytes[ind]); - - { - int j; - for (j = 0; j < newClassSize[ind]; j++) - newClassBytes[ind][j] = (unsigned char)elements[j]; - } - NSK_DISPLAY1("\t... copied bytecode: %d bytes\n", (int)newClassSize[ind]); - - NSK_DISPLAY1("\t... release elements list: 0x%p\n", (void*)elements); - NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni_env, byteCode, elements, JNI_ABORT)); - NSK_DISPLAY0("\t... released\n"); - return NSK_TRUE; -} - -/* ============================================================================= */ -/* - * Class: nsk_jvmti_scenarios_bcinstr_BI01_bi01t002 - * Method: setClass - * Signature: (ILjava/lang/Class;)V - */ -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_bcinstr_BI01_bi01t002_setClass(JNIEnv *jni_env, - jobject this, jint ind, jclass cls) { - - if (!NSK_JNI_VERIFY(jni_env, (oldClassDef[ind].klass = - NSK_CPP_STUB2(NewGlobalRef, jni_env, cls)) != NULL)) { - nsk_jvmti_setFailStatus(); - } -} - -/* ============================================================================= */ - -/** Callback function for ClassFileLoadHook event. */ -JNIEXPORT void JNICALL -cbClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv* jni_env, - jclass class_being_redefined, jobject loader, const char* name, - jobject protection_domain, jint class_data_len, - const unsigned char* class_data, jint* new_class_data_len, - unsigned char** new_class_data) { - - if ( name == NULL || strcmp(name, TESTED_CLASS_NAME) ) { - return; - } - - NSK_DISPLAY3("CLASS_FILE_LOAD_HOOK event: %s\n\treceived bytecode: 0x%p:%d\n", - name, (void *)class_data, class_data_len); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, class_data_len, class_data); - } - - { - /*store original byte code, it will be used to do final redefinition*/ - int j; - unsigned char *arr; - - oldClassDef[clsLoadedIdx].class_byte_count = class_data_len; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti_env, class_data_len, - &arr))) { - nsk_jvmti_setFailStatus(); - return; - } - for (j = 0; j < class_data_len; j++) { - arr[j] = class_data[j]; - } - oldClassDef[clsLoadedIdx].class_bytes = arr; - } - - *new_class_data_len = newClassSize[clsLoadedIdx]; - *new_class_data = newClassBytes[clsLoadedIdx]; - - NSK_DISPLAY2("Replace with new bytecode: 0x%p:%d\n", - (void*)newClassBytes[clsLoadedIdx], - (int)newClassSize[clsLoadedIdx]); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, newClassSize[clsLoadedIdx], - newClassBytes[clsLoadedIdx]); - } -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - int i; - - /*Wait for debuggee to read new byte codes nsk_jvmti_waitForSync#1*/ - NSK_DISPLAY0("Wait for debuggee to read new byte codes nsk_jvmti_waitForSync#1\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - for (clsLoadedIdx=0; clsLoadedIdx < TOTAL_INSTRUMENTED_CLASSES; clsLoadedIdx++) { - - if (!nsk_jvmti_resumeSync()) - return; - - NSK_DISPLAY1("Wait for debuggee to load tested class by classLoader[%d]\n", - (clsLoadedIdx+1)); - /*Wait for debuggee to load next class nsk_jvmti_waitForSync#2*/ - if (!nsk_jvmti_waitForSync(timeout)) - return; - } - - if (!nsk_jvmti_resumeSync()) - return; - - /*Wait for debuggee to check instrumentation code works nsk_jvmti_waitForSync#3*/ - NSK_DISPLAY0("Wait for debuggee to check instrumentation code works nsk_jvmti_waitForSync#3\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("Notification disabled for CLASS_FILE_LOAD_HOOK event\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, - JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!nsk_jvmti_resumeSync()) - return; - - /*Wait for debuggee to set classes to be redefined nsk_jvmti_waitForSync#4*/ - NSK_DISPLAY0("Wait for debuggee to set classes to be redefined nsk_jvmti_waitForSync#4\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("Redfine class with old byte code\n"); - for (i = 0; i < TOTAL_INSTRUMENTED_CLASSES; i++) { - NSK_DISPLAY4("class definition %d:\n\t0x%p, 0x%p:%d\n", - i, - oldClassDef[i].klass, - oldClassDef[i].class_bytes, - oldClassDef[i].class_byte_count); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, oldClassDef[i].class_byte_count, - oldClassDef[i].class_bytes); - } - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RedefineClasses, jvmti, TOTAL_INSTRUMENTED_CLASSES, - oldClassDef))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!nsk_jvmti_resumeSync()) - return; - - /*Wait for debuggee to check old byte code works nsk_jvmti_waitForSync#5*/ - NSK_DISPLAY0("Wait for debuggee to check old byte code works nsk_jvmti_waitForSync#5\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - for (i = 0; i < TOTAL_INSTRUMENTED_CLASSES; i++) { - NSK_CPP_STUB2(DeleteGlobalRef, agentJNI, oldClassDef[i].klass); - } - - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_bi01t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_bi01t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_bi01t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - NSK_DISPLAY0("Set callback for CLASS_FILE_LOAD_HOOK event\n"); - { - jvmtiEventCallbacks callbacks; - jint size = (jint)sizeof(callbacks); - - memset(&callbacks, 0, size); - callbacks.ClassFileLoadHook = cbClassFileLoadHook; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { - return JNI_ERR; - } - } - - NSK_DISPLAY0("Set notification enabled for CLASS_FILE_LOAD_HOOK event\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, - JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/bi01t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/bi01t002.cpp new file mode 100644 index 00000000000..cd381ddedf2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/bi01t002.cpp @@ -0,0 +1,311 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; + +#define TESTED_CLASS_NAME "nsk/jvmti/scenarios/bcinstr/BI01/bi01t002a" +#define TOTAL_INSTRUMENTED_CLASSES 2 + +static int clsLoadedIdx=0; +static jint newClassSize[TOTAL_INSTRUMENTED_CLASSES]; +static unsigned char* newClassBytes[TOTAL_INSTRUMENTED_CLASSES]; +static jvmtiClassDefinition oldClassDef[TOTAL_INSTRUMENTED_CLASSES]; + +/* ============================================================================= */ +/* + * Class: nsk_jvmti_scenarios_bcinstr_BI01_bi01t002 + * Method: setNewByteCode + * Signature: (I[B)Z + */ +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_bcinstr_BI01_bi01t002_setNewByteCode(JNIEnv *jni_env, + jobject o, jint ind, jbyteArray byteCode) { + + jbyte* elements; + jboolean isCopy; + + if (!NSK_JNI_VERIFY(jni_env, (newClassSize[ind] = + NSK_CPP_STUB2(GetArrayLength, jni_env, byteCode)) > 0)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1("\t... got array size: %d\n", newClassSize[ind]); + + if (!NSK_JNI_VERIFY(jni_env, (elements = + NSK_CPP_STUB3(GetByteArrayElements, jni_env, byteCode, + &isCopy)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1("\t... got elements list: 0x%p\n", (void*)elements); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, + newClassSize[ind], &newClassBytes[ind]))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + NSK_DISPLAY1("\t... created bytes array: 0x%p\n", (void*)newClassBytes[ind]); + + { + int j; + for (j = 0; j < newClassSize[ind]; j++) + newClassBytes[ind][j] = (unsigned char)elements[j]; + } + NSK_DISPLAY1("\t... copied bytecode: %d bytes\n", (int)newClassSize[ind]); + + NSK_DISPLAY1("\t... release elements list: 0x%p\n", (void*)elements); + NSK_TRACE(NSK_CPP_STUB4(ReleaseByteArrayElements, jni_env, byteCode, elements, JNI_ABORT)); + NSK_DISPLAY0("\t... released\n"); + return NSK_TRUE; +} + +/* ============================================================================= */ +/* + * Class: nsk_jvmti_scenarios_bcinstr_BI01_bi01t002 + * Method: setClass + * Signature: (ILjava/lang/Class;)V + */ +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_bcinstr_BI01_bi01t002_setClass(JNIEnv *jni_env, + jobject o, jint ind, jclass cls) { + + if (!NSK_JNI_VERIFY(jni_env, (oldClassDef[ind].klass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni_env, cls)) != NULL)) { + nsk_jvmti_setFailStatus(); + } +} + +/* ============================================================================= */ + +/** Callback function for ClassFileLoadHook event. */ +JNIEXPORT void JNICALL +cbClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv* jni_env, + jclass class_being_redefined, jobject loader, const char* name, + jobject protection_domain, jint class_data_len, + const unsigned char* class_data, jint* new_class_data_len, + unsigned char** new_class_data) { + + if ( name == NULL || strcmp(name, TESTED_CLASS_NAME) ) { + return; + } + + NSK_DISPLAY3("CLASS_FILE_LOAD_HOOK event: %s\n\treceived bytecode: 0x%p:%d\n", + name, (void *)class_data, class_data_len); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, class_data_len, class_data); + } + + { + /*store original byte code, it will be used to do final redefinition*/ + int j; + unsigned char *arr; + + oldClassDef[clsLoadedIdx].class_byte_count = class_data_len; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti_env, class_data_len, + &arr))) { + nsk_jvmti_setFailStatus(); + return; + } + for (j = 0; j < class_data_len; j++) { + arr[j] = class_data[j]; + } + oldClassDef[clsLoadedIdx].class_bytes = arr; + } + + *new_class_data_len = newClassSize[clsLoadedIdx]; + *new_class_data = newClassBytes[clsLoadedIdx]; + + NSK_DISPLAY2("Replace with new bytecode: 0x%p:%d\n", + (void*)newClassBytes[clsLoadedIdx], + (int)newClassSize[clsLoadedIdx]); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, newClassSize[clsLoadedIdx], + newClassBytes[clsLoadedIdx]); + } +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + int i; + + /*Wait for debuggee to read new byte codes nsk_jvmti_waitForSync#1*/ + NSK_DISPLAY0("Wait for debuggee to read new byte codes nsk_jvmti_waitForSync#1\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + for (clsLoadedIdx=0; clsLoadedIdx < TOTAL_INSTRUMENTED_CLASSES; clsLoadedIdx++) { + + if (!nsk_jvmti_resumeSync()) + return; + + NSK_DISPLAY1("Wait for debuggee to load tested class by classLoader[%d]\n", + (clsLoadedIdx+1)); + /*Wait for debuggee to load next class nsk_jvmti_waitForSync#2*/ + if (!nsk_jvmti_waitForSync(timeout)) + return; + } + + if (!nsk_jvmti_resumeSync()) + return; + + /*Wait for debuggee to check instrumentation code works nsk_jvmti_waitForSync#3*/ + NSK_DISPLAY0("Wait for debuggee to check instrumentation code works nsk_jvmti_waitForSync#3\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("Notification disabled for CLASS_FILE_LOAD_HOOK event\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, + JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!nsk_jvmti_resumeSync()) + return; + + /*Wait for debuggee to set classes to be redefined nsk_jvmti_waitForSync#4*/ + NSK_DISPLAY0("Wait for debuggee to set classes to be redefined nsk_jvmti_waitForSync#4\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("Redfine class with old byte code\n"); + for (i = 0; i < TOTAL_INSTRUMENTED_CLASSES; i++) { + NSK_DISPLAY4("class definition %d:\n\t0x%p, 0x%p:%d\n", + i, + oldClassDef[i].klass, + oldClassDef[i].class_bytes, + oldClassDef[i].class_byte_count); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, oldClassDef[i].class_byte_count, + oldClassDef[i].class_bytes); + } + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RedefineClasses, jvmti, TOTAL_INSTRUMENTED_CLASSES, + oldClassDef))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!nsk_jvmti_resumeSync()) + return; + + /*Wait for debuggee to check old byte code works nsk_jvmti_waitForSync#5*/ + NSK_DISPLAY0("Wait for debuggee to check old byte code works nsk_jvmti_waitForSync#5\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + for (i = 0; i < TOTAL_INSTRUMENTED_CLASSES; i++) { + NSK_CPP_STUB2(DeleteGlobalRef, agentJNI, oldClassDef[i].klass); + } + + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_bi01t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_bi01t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_bi01t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + NSK_DISPLAY0("Set callback for CLASS_FILE_LOAD_HOOK event\n"); + { + jvmtiEventCallbacks callbacks; + jint size = (jint)sizeof(callbacks); + + memset(&callbacks, 0, size); + callbacks.ClassFileLoadHook = cbClassFileLoadHook; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, &callbacks, size))) { + return JNI_ERR; + } + } + + NSK_DISPLAY0("Set notification enabled for CLASS_FILE_LOAD_HOOK event\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, + JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/libbi01t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/libbi01t002.c deleted file mode 100644 index 7e081e70c97..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/libbi01t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "bi01t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/libbi01t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/libbi01t002.cpp new file mode 100644 index 00000000000..6a948e37e1f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t002/libbi01t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "bi01t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/bi02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/bi02t001.c deleted file mode 100644 index 88c9f570d8e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/bi02t001.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#define PASSED 0 -#define STATUS_FAILED 2 - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* test objects */ -static jclass debugeeClass = NULL; -static jbyteArray classBytes = NULL; -static int ClassFileLoadHookEventFlag = NSK_FALSE; - -const char* CLASS_NAME = "nsk/jvmti/scenarios/bcinstr/BI02/bi02t001a"; - -/* ========================================================================== */ - -/** callback functions **/ - -static void JNICALL -ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jclass class_being_redefined, jobject loader, - const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - if (name != NULL && (strcmp(name, CLASS_NAME) == 0)) { - ClassFileLoadHookEventFlag = NSK_TRUE; - NSK_DISPLAY0("ClassFileLoadHook event\n"); - - if (class_being_redefined == NULL) { - /* sent by class load */ - - if (!NSK_JNI_VERIFY(jni_env, (*new_class_data_len = - NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes)) > 0)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_JNI_VERIFY(jni_env, (*new_class_data = (unsigned char*) - NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, NULL)) - != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - } - } -} - -/* ========================================================================== */ - -static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { - const char* DEBUGEE_CLASS_NAME = - "nsk/jvmti/scenarios/bcinstr/BI02/bi02t001"; - jfieldID field = NULL; - - NSK_DISPLAY1("Find class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (field = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - "newClassBytes", "[B")) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (classBytes = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, field)) - != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (classBytes = - NSK_CPP_STUB2(NewGlobalRef, jni, classBytes)) != NULL)) - return NSK_FALSE; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) - return JNI_ERR; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!prepare(jvmti, jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* resume debugee and wait for sync */ - if (!nsk_jvmti_resumeSync()) - return; - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { - NSK_COMPLAIN0("Missing ClassFileLoadHook event\n"); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) - nsk_jvmti_setFailStatus(); - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, classBytes)); - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_bi02t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_bi02t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_bi02t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiEventCallbacks callbacks; - jvmtiCapabilities caps; - - NSK_DISPLAY0("Agent_OnLoad\n"); - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_all_class_hook_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/bi02t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/bi02t001.cpp new file mode 100644 index 00000000000..885f796a4db --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/bi02t001.cpp @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#define PASSED 0 +#define STATUS_FAILED 2 + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* test objects */ +static jclass debugeeClass = NULL; +static jbyteArray classBytes = NULL; +static int ClassFileLoadHookEventFlag = NSK_FALSE; + +const char* CLASS_NAME = "nsk/jvmti/scenarios/bcinstr/BI02/bi02t001a"; + +/* ========================================================================== */ + +/** callback functions **/ + +static void JNICALL +ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jclass class_being_redefined, jobject loader, + const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + if (name != NULL && (strcmp(name, CLASS_NAME) == 0)) { + ClassFileLoadHookEventFlag = NSK_TRUE; + NSK_DISPLAY0("ClassFileLoadHook event\n"); + + if (class_being_redefined == NULL) { + /* sent by class load */ + + if (!NSK_JNI_VERIFY(jni_env, (*new_class_data_len = + NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes)) > 0)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_JNI_VERIFY(jni_env, (*new_class_data = (unsigned char*) + NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, NULL)) + != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + } + } +} + +/* ========================================================================== */ + +static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { + const char* DEBUGEE_CLASS_NAME = + "nsk/jvmti/scenarios/bcinstr/BI02/bi02t001"; + jfieldID field = NULL; + + NSK_DISPLAY1("Find class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (debugeeClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (field = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + "newClassBytes", "[B")) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (classBytes = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, field)) + != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (classBytes = (jbyteArray) + NSK_CPP_STUB2(NewGlobalRef, jni, classBytes)) != NULL)) + return NSK_FALSE; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) + return JNI_ERR; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!prepare(jvmti, jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* resume debugee and wait for sync */ + if (!nsk_jvmti_resumeSync()) + return; + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { + NSK_COMPLAIN0("Missing ClassFileLoadHook event\n"); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) + nsk_jvmti_setFailStatus(); + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, classBytes)); + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_bi02t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_bi02t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_bi02t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiEventCallbacks callbacks; + jvmtiCapabilities caps; + + NSK_DISPLAY0("Agent_OnLoad\n"); + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_all_class_hook_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/libbi02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/libbi02t001.c deleted file mode 100644 index 36c2d181725..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/libbi02t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "bi02t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/libbi02t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/libbi02t001.cpp new file mode 100644 index 00000000000..a85d7aa8372 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001/libbi02t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "bi02t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/bi02t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/bi02t002.c deleted file mode 100644 index a87a0fc599c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/bi02t002.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#define PASSED 0 -#define STATUS_FAILED 2 - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* test objects */ -static jclass debugeeClass = NULL; -static jclass testedClass = NULL; -static jbyteArray classBytes = NULL; - -const char* CLASS_NAME = "nsk/jvmti/scenarios/bcinstr/BI02/bi02t002a"; - -/* ========================================================================== */ - -static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { - const char* DEBUGEE_CLASS_NAME = - "nsk/jvmti/scenarios/bcinstr/BI02/bi02t002"; - jfieldID field = NULL; - - NSK_DISPLAY1("Find class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (field = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - "newClassBytes", "[B")) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (classBytes = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, field)) - != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (classBytes = - NSK_CPP_STUB2(NewGlobalRef, jni, classBytes)) != NULL)) - return NSK_FALSE; - - NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -static int redefine(jvmtiEnv* jvmti, JNIEnv* jni) { - jvmtiClassDefinition class_def; - - NSK_DISPLAY0("Redefining ...\n"); - - if (!NSK_JNI_VERIFY(jni, (class_def.class_byte_count = - NSK_CPP_STUB2(GetArrayLength, jni, classBytes)) > 0)) - return NSK_TRUE; - - if (!NSK_JNI_VERIFY(jni, (class_def.class_bytes = (unsigned char*) - NSK_CPP_STUB3(GetByteArrayElements, jni, classBytes, NULL)) - != NULL)) - return NSK_TRUE; - - class_def.klass = testedClass; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &class_def))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!prepare(jvmti, jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!redefine(jvmti, jni)) - nsk_jvmti_setFailStatus(); - - /* resume debugee and wait for sync */ - if (!nsk_jvmti_resumeSync()) - return; - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, classBytes)); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_bi02t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_bi02t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_bi02t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiCapabilities caps; - - NSK_DISPLAY0("Agent_OnLoad\n"); - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/bi02t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/bi02t002.cpp new file mode 100644 index 00000000000..2418c853473 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/bi02t002.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#define PASSED 0 +#define STATUS_FAILED 2 + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* test objects */ +static jclass debugeeClass = NULL; +static jclass testedClass = NULL; +static jbyteArray classBytes = NULL; + +const char* CLASS_NAME = "nsk/jvmti/scenarios/bcinstr/BI02/bi02t002a"; + +/* ========================================================================== */ + +static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { + const char* DEBUGEE_CLASS_NAME = + "nsk/jvmti/scenarios/bcinstr/BI02/bi02t002"; + jfieldID field = NULL; + + NSK_DISPLAY1("Find class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (debugeeClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (field = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + "newClassBytes", "[B")) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (classBytes = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, field)) + != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (classBytes = (jbyteArray) + NSK_CPP_STUB2(NewGlobalRef, jni, classBytes)) != NULL)) + return NSK_FALSE; + + NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (testedClass = + NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +static int redefine(jvmtiEnv* jvmti, JNIEnv* jni) { + jvmtiClassDefinition class_def; + + NSK_DISPLAY0("Redefining ...\n"); + + if (!NSK_JNI_VERIFY(jni, (class_def.class_byte_count = + NSK_CPP_STUB2(GetArrayLength, jni, classBytes)) > 0)) + return NSK_TRUE; + + if (!NSK_JNI_VERIFY(jni, (class_def.class_bytes = (unsigned char*) + NSK_CPP_STUB3(GetByteArrayElements, jni, classBytes, NULL)) + != NULL)) + return NSK_TRUE; + + class_def.klass = testedClass; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &class_def))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!prepare(jvmti, jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!redefine(jvmti, jni)) + nsk_jvmti_setFailStatus(); + + /* resume debugee and wait for sync */ + if (!nsk_jvmti_resumeSync()) + return; + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, classBytes)); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_bi02t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_bi02t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_bi02t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiCapabilities caps; + + NSK_DISPLAY0("Agent_OnLoad\n"); + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/libbi02t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/libbi02t002.c deleted file mode 100644 index 35a0f005db1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/libbi02t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "bi02t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/libbi02t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/libbi02t002.cpp new file mode 100644 index 00000000000..9eb0a7b27ca --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t002/libbi02t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "bi02t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/bi03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/bi03t001.c deleted file mode 100644 index 1e595a2ffd9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/bi03t001.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#define PASSED 0 -#define STATUS_FAILED 2 - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* test objects */ -static jclass debugeeClass = NULL; -static jbyteArray classBytes = NULL; -static int ClassFileLoadHookEventFlag = NSK_FALSE; - -const char* CLASS_NAME = "nsk/jvmti/scenarios/bcinstr/BI03/bi03t001a"; - -/* ========================================================================== */ - -/** callback functions **/ - -static void JNICALL -ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jclass class_being_redefined, jobject loader, - const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - if (name != NULL && (strcmp(name, CLASS_NAME) == 0)) { - ClassFileLoadHookEventFlag = NSK_TRUE; - NSK_DISPLAY0("ClassFileLoadHook event\n"); - - if (class_being_redefined == NULL) { - /* sent by class load */ - - if (!NSK_JNI_VERIFY(jni_env, (*new_class_data_len = - NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes)) > 0)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_JNI_VERIFY(jni_env, (*new_class_data = (unsigned char*) - NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, NULL)) - != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - } - } -} - -/* ========================================================================== */ - -static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { - const char* DEBUGEE_CLASS_NAME = - "nsk/jvmti/scenarios/bcinstr/BI03/bi03t001"; - jfieldID field = NULL; - - NSK_DISPLAY1("Find class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (field = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - "newClassBytes", "[B")) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (classBytes = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, field)) - != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (classBytes = - NSK_CPP_STUB2(NewGlobalRef, jni, classBytes)) != NULL)) - return NSK_FALSE; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) - return JNI_ERR; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!prepare(jvmti, jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* resume debugee and wait for sync */ - if (!nsk_jvmti_resumeSync()) - return; - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { - NSK_COMPLAIN0("Missing ClassFileLoadHook event\n"); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) - nsk_jvmti_setFailStatus(); - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, classBytes)); - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_bi03t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_bi03t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_bi03t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiEventCallbacks callbacks; - jvmtiCapabilities caps; - - NSK_DISPLAY0("Agent_OnLoad\n"); - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_all_class_hook_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/bi03t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/bi03t001.cpp new file mode 100644 index 00000000000..19a5d19e6bd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/bi03t001.cpp @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#define PASSED 0 +#define STATUS_FAILED 2 + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* test objects */ +static jclass debugeeClass = NULL; +static jbyteArray classBytes = NULL; +static int ClassFileLoadHookEventFlag = NSK_FALSE; + +const char* CLASS_NAME = "nsk/jvmti/scenarios/bcinstr/BI03/bi03t001a"; + +/* ========================================================================== */ + +/** callback functions **/ + +static void JNICALL +ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jclass class_being_redefined, jobject loader, + const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + if (name != NULL && (strcmp(name, CLASS_NAME) == 0)) { + ClassFileLoadHookEventFlag = NSK_TRUE; + NSK_DISPLAY0("ClassFileLoadHook event\n"); + + if (class_being_redefined == NULL) { + /* sent by class load */ + + if (!NSK_JNI_VERIFY(jni_env, (*new_class_data_len = + NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes)) > 0)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_JNI_VERIFY(jni_env, (*new_class_data = (unsigned char*) + NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, NULL)) + != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + } + } +} + +/* ========================================================================== */ + +static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { + const char* DEBUGEE_CLASS_NAME = + "nsk/jvmti/scenarios/bcinstr/BI03/bi03t001"; + jfieldID field = NULL; + + NSK_DISPLAY1("Find class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (debugeeClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (field = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + "newClassBytes", "[B")) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (classBytes = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, field)) + != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (classBytes = (jbyteArray) + NSK_CPP_STUB2(NewGlobalRef, jni, classBytes)) != NULL)) + return NSK_FALSE; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) + return JNI_ERR; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!prepare(jvmti, jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* resume debugee and wait for sync */ + if (!nsk_jvmti_resumeSync()) + return; + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { + NSK_COMPLAIN0("Missing ClassFileLoadHook event\n"); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) + nsk_jvmti_setFailStatus(); + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, classBytes)); + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_bi03t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_bi03t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_bi03t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiEventCallbacks callbacks; + jvmtiCapabilities caps; + + NSK_DISPLAY0("Agent_OnLoad\n"); + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_all_class_hook_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/libbi03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/libbi03t001.c deleted file mode 100644 index d5186be3e72..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/libbi03t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "bi03t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/libbi03t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/libbi03t001.cpp new file mode 100644 index 00000000000..9f1b5a74a0b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t001/libbi03t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "bi03t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/bi03t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/bi03t002.c deleted file mode 100644 index 4fa00d5339f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/bi03t002.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#define PASSED 0 -#define STATUS_FAILED 2 - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* test objects */ -static jclass debugeeClass = NULL; -static jclass testedClass = NULL; -static jbyteArray classBytes = NULL; - -const char* CLASS_NAME = "nsk/jvmti/scenarios/bcinstr/BI03/bi03t002a"; - -/* ========================================================================== */ - -static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { - const char* DEBUGEE_CLASS_NAME = - "nsk/jvmti/scenarios/bcinstr/BI03/bi03t002"; - jfieldID field = NULL; - - NSK_DISPLAY1("Find class: %s\n", DEBUGEE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (field = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - "newClassBytes", "[B")) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (classBytes = (jbyteArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, field)) - != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (classBytes = - NSK_CPP_STUB2(NewGlobalRef, jni, classBytes)) != NULL)) - return NSK_FALSE; - - NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -static int redefine(jvmtiEnv* jvmti, JNIEnv* jni) { - jvmtiClassDefinition class_def; - - NSK_DISPLAY0("Redefining ...\n"); - - if (!NSK_JNI_VERIFY(jni, (class_def.class_byte_count = - NSK_CPP_STUB2(GetArrayLength, jni, classBytes)) > 0)) - return NSK_TRUE; - - if (!NSK_JNI_VERIFY(jni, (class_def.class_bytes = (unsigned char*) - NSK_CPP_STUB3(GetByteArrayElements, jni, classBytes, NULL)) - != NULL)) - return NSK_TRUE; - - class_def.klass = testedClass; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &class_def))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!prepare(jvmti, jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!redefine(jvmti, jni)) - nsk_jvmti_setFailStatus(); - - /* resume debugee and wait for sync */ - if (!nsk_jvmti_resumeSync()) - return; - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, classBytes)); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_bi03t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_bi03t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_bi03t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiCapabilities caps; - - NSK_DISPLAY0("Agent_OnLoad\n"); - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/bi03t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/bi03t002.cpp new file mode 100644 index 00000000000..ac8d607bd0b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/bi03t002.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#define PASSED 0 +#define STATUS_FAILED 2 + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* test objects */ +static jclass debugeeClass = NULL; +static jclass testedClass = NULL; +static jbyteArray classBytes = NULL; + +const char* CLASS_NAME = "nsk/jvmti/scenarios/bcinstr/BI03/bi03t002a"; + +/* ========================================================================== */ + +static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { + const char* DEBUGEE_CLASS_NAME = + "nsk/jvmti/scenarios/bcinstr/BI03/bi03t002"; + jfieldID field = NULL; + + NSK_DISPLAY1("Find class: %s\n", DEBUGEE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (debugeeClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, debugeeClass)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (field = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + "newClassBytes", "[B")) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (classBytes = (jbyteArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, field)) + != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (classBytes = (jbyteArray) + NSK_CPP_STUB2(NewGlobalRef, jni, classBytes)) != NULL)) + return NSK_FALSE; + + NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (testedClass = + NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +static int redefine(jvmtiEnv* jvmti, JNIEnv* jni) { + jvmtiClassDefinition class_def; + + NSK_DISPLAY0("Redefining ...\n"); + + if (!NSK_JNI_VERIFY(jni, (class_def.class_byte_count = + NSK_CPP_STUB2(GetArrayLength, jni, classBytes)) > 0)) + return NSK_TRUE; + + if (!NSK_JNI_VERIFY(jni, (class_def.class_bytes = (unsigned char*) + NSK_CPP_STUB3(GetByteArrayElements, jni, classBytes, NULL)) + != NULL)) + return NSK_TRUE; + + class_def.klass = testedClass; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &class_def))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!prepare(jvmti, jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!redefine(jvmti, jni)) + nsk_jvmti_setFailStatus(); + + /* resume debugee and wait for sync */ + if (!nsk_jvmti_resumeSync()) + return; + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, debugeeClass)); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, classBytes)); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_bi03t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_bi03t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_bi03t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiCapabilities caps; + + NSK_DISPLAY0("Agent_OnLoad\n"); + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/libbi03t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/libbi03t002.c deleted file mode 100644 index 9ff5f969358..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/libbi03t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "bi03t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/libbi03t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/libbi03t002.cpp new file mode 100644 index 00000000000..42ba660eb67 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI03/bi03t002/libbi03t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "bi03t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/bi04t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/bi04t002.c deleted file mode 100644 index 770a7b2a936..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/bi04t002.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* scaffold objects */ -static jlong timeout = 0; - -#define PATH_TO_NEW_BYTECODE "pathToNewByteCode" -#define TESTED_CLASS_NAME "java/lang/Object" - -static jint newClassSize; -static unsigned char* newClassBytes; - -static jvmtiClassDefinition classDef; - -/* ============================================================================= */ - -int readNewBytecode(jvmtiEnv* jvmti) { - - char filename[256]; - FILE *bytecode; - const char *pathToByteCode = nsk_jvmti_findOptionValue(PATH_TO_NEW_BYTECODE); - jint read_bytes; - - if (pathToByteCode) - sprintf(filename,"%s/%s/%s.class", - pathToByteCode, "newclass02", TESTED_CLASS_NAME); - else - sprintf(filename,"%s/%s.class", - "newclass02", TESTED_CLASS_NAME); - - NSK_DISPLAY1("Reading new bytecode for java.lang.Object\n\tfile name: %s\n", - filename); - - bytecode = fopen(filename, "rb"); - if (bytecode == NULL) { - NSK_COMPLAIN0("error opening file\n"); - return NSK_FALSE; - } - - fseek(bytecode, 0, SEEK_END); - classDef.class_byte_count = ftell(bytecode); - rewind(bytecode); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, - classDef.class_byte_count, - &newClassBytes))) { - NSK_COMPLAIN0("buffer couldn't be allocated\n"); - return NSK_FALSE; - } - classDef.class_bytes = newClassBytes; - read_bytes = (jint) fread(newClassBytes, 1, - classDef.class_byte_count, bytecode); - fclose(bytecode); - if (read_bytes != classDef.class_byte_count) { - NSK_COMPLAIN0("error reading file\n"); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - /*Wait for debuggee to set classes to be redefined nsk_jvmti_waitForSync#4*/ - NSK_DISPLAY0("Wait for debuggee to set classes to be redefined nsk_jvmti_waitForSync#4\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY1("Find class: %s\n", TESTED_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (classDef.klass = - NSK_CPP_STUB2(FindClass, jni, TESTED_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_JNI_VERIFY(jni, (classDef.klass = - NSK_CPP_STUB2(NewGlobalRef, jni, classDef.klass)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Redfine class with new byte code\n"); - NSK_DISPLAY3("class definition:\n\t0x%p, 0x%p:%d\n", - classDef.klass, - classDef.class_bytes, - classDef.class_byte_count); - if (nsk_getVerboseMode()) { - nsk_printHexBytes(" ", 16, classDef.class_byte_count, - classDef.class_bytes); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &classDef))) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_CPP_STUB2(DeleteGlobalRef, jni, classDef.klass); - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_bi04t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_bi04t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_bi04t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv *jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_redefine_classes = 1; - caps.can_redefine_any_class = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - if (!NSK_VERIFY(readNewBytecode(jvmti))) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/bi04t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/bi04t002.cpp new file mode 100644 index 00000000000..8884535a8a6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/bi04t002.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* scaffold objects */ +static jlong timeout = 0; + +#define PATH_TO_NEW_BYTECODE "pathToNewByteCode" +#define TESTED_CLASS_NAME "java/lang/Object" + +static jint newClassSize; +static unsigned char* newClassBytes; + +static jvmtiClassDefinition classDef; + +/* ============================================================================= */ + +int readNewBytecode(jvmtiEnv* jvmti) { + + char filename[256]; + FILE *bytecode; + const char *pathToByteCode = nsk_jvmti_findOptionValue(PATH_TO_NEW_BYTECODE); + jint read_bytes; + + if (pathToByteCode) + sprintf(filename,"%s/%s/%s.class", + pathToByteCode, "newclass02", TESTED_CLASS_NAME); + else + sprintf(filename,"%s/%s.class", + "newclass02", TESTED_CLASS_NAME); + + NSK_DISPLAY1("Reading new bytecode for java.lang.Object\n\tfile name: %s\n", + filename); + + bytecode = fopen(filename, "rb"); + if (bytecode == NULL) { + NSK_COMPLAIN0("error opening file\n"); + return NSK_FALSE; + } + + fseek(bytecode, 0, SEEK_END); + classDef.class_byte_count = ftell(bytecode); + rewind(bytecode); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, + classDef.class_byte_count, + &newClassBytes))) { + NSK_COMPLAIN0("buffer couldn't be allocated\n"); + return NSK_FALSE; + } + classDef.class_bytes = newClassBytes; + read_bytes = (jint) fread(newClassBytes, 1, + classDef.class_byte_count, bytecode); + fclose(bytecode); + if (read_bytes != classDef.class_byte_count) { + NSK_COMPLAIN0("error reading file\n"); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + /*Wait for debuggee to set classes to be redefined nsk_jvmti_waitForSync#4*/ + NSK_DISPLAY0("Wait for debuggee to set classes to be redefined nsk_jvmti_waitForSync#4\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY1("Find class: %s\n", TESTED_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (classDef.klass = + NSK_CPP_STUB2(FindClass, jni, TESTED_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_JNI_VERIFY(jni, (classDef.klass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, classDef.klass)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Redfine class with new byte code\n"); + NSK_DISPLAY3("class definition:\n\t0x%p, 0x%p:%d\n", + classDef.klass, + classDef.class_bytes, + classDef.class_byte_count); + if (nsk_getVerboseMode()) { + nsk_printHexBytes(" ", 16, classDef.class_byte_count, + classDef.class_bytes); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &classDef))) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_CPP_STUB2(DeleteGlobalRef, jni, classDef.klass); + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_bi04t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_bi04t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_bi04t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv *jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_redefine_classes = 1; + caps.can_redefine_any_class = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + if (!NSK_VERIFY(readNewBytecode(jvmti))) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/libbi04t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/libbi04t002.c deleted file mode 100644 index 2eb13964419..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/libbi04t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "bi04t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/libbi04t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/libbi04t002.cpp new file mode 100644 index 00000000000..a40cc4316a0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/libbi04t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "bi04t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/cm01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/cm01t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/cm01t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/cm01t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/libcm01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/libcm01t001.c deleted file mode 100644 index 1bd8501f828..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/libcm01t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/libcm01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/libcm01t001.cpp new file mode 100644 index 00000000000..2afbbe48457 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t001/libcm01t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/cm01t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/cm01t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/cm01t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/cm01t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/libcm01t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/libcm01t002.c deleted file mode 100644 index 2ce647d2d77..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/libcm01t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/libcm01t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/libcm01t002.cpp new file mode 100644 index 00000000000..cf94b6c95b8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t002/libcm01t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/cm01t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/cm01t003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/cm01t003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/cm01t003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/libcm01t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/libcm01t003.c deleted file mode 100644 index 10a3ce5ee08..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/libcm01t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/libcm01t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/libcm01t003.cpp new file mode 100644 index 00000000000..5a2ea50dd08 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t003/libcm01t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/cm01t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/cm01t004.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/cm01t004.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/cm01t004.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/libcm01t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/libcm01t004.c deleted file mode 100644 index a9de7e696b7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/libcm01t004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/libcm01t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/libcm01t004.cpp new file mode 100644 index 00000000000..5a2b66fd4fc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t004/libcm01t004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/cm01t005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/cm01t005.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/cm01t005.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/cm01t005.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/libcm01t005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/libcm01t005.c deleted file mode 100644 index 2fbc04fce8b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/libcm01t005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/libcm01t005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/libcm01t005.cpp new file mode 100644 index 00000000000..079fdddde04 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t005/libcm01t005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/cm01t006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/cm01t006.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/cm01t006.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/cm01t006.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/libcm01t006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/libcm01t006.c deleted file mode 100644 index 02203402789..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/libcm01t006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/libcm01t006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/libcm01t006.cpp new file mode 100644 index 00000000000..54cd85e6e9c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t006/libcm01t006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/cm01t007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/cm01t007.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/cm01t007.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/cm01t007.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/libcm01t007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/libcm01t007.c deleted file mode 100644 index 12b6f1fdf75..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/libcm01t007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/libcm01t007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/libcm01t007.cpp new file mode 100644 index 00000000000..c0935977bce --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t007/libcm01t007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/cm01t008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/cm01t008.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/cm01t008.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/cm01t008.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/libcm01t008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/libcm01t008.c deleted file mode 100644 index 5f7815a91fd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/libcm01t008.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t008.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/libcm01t008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/libcm01t008.cpp new file mode 100644 index 00000000000..724665a7a34 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t008/libcm01t008.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t008.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/cm01t009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/cm01t009.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/cm01t009.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/cm01t009.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/libcm01t009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/libcm01t009.c deleted file mode 100644 index 939a4342a58..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/libcm01t009.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t009.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/libcm01t009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/libcm01t009.cpp new file mode 100644 index 00000000000..e8fe906c5ea --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t009/libcm01t009.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t009.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/cm01t010.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/cm01t010.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/cm01t010.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/cm01t010.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/libcm01t010.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/libcm01t010.c deleted file mode 100644 index bea1201b8f4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/libcm01t010.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t010.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/libcm01t010.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/libcm01t010.cpp new file mode 100644 index 00000000000..7bc8f92e78d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t010/libcm01t010.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t010.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/cm01t011.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/cm01t011.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/cm01t011.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/cm01t011.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/libcm01t011.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/libcm01t011.c deleted file mode 100644 index a610d3e074d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/libcm01t011.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t011.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/libcm01t011.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/libcm01t011.cpp new file mode 100644 index 00000000000..f9df009349d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t011/libcm01t011.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t011.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/cm01t012.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/cm01t012.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/cm01t012.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/cm01t012.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/libcm01t012.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/libcm01t012.c deleted file mode 100644 index 4744f16a377..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/libcm01t012.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t012.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/libcm01t012.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/libcm01t012.cpp new file mode 100644 index 00000000000..5bdb99eeb72 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t012/libcm01t012.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t012.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/cm01t013.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/cm01t013.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/cm01t013.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/cm01t013.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/libcm01t013.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/libcm01t013.c deleted file mode 100644 index d20f50d251a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/libcm01t013.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t013.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/libcm01t013.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/libcm01t013.cpp new file mode 100644 index 00000000000..e03d4519b0c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t013/libcm01t013.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t013.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/cm01t014.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/cm01t014.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/cm01t014.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/cm01t014.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/libcm01t014.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/libcm01t014.c deleted file mode 100644 index 5fec0f76573..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/libcm01t014.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t014.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/libcm01t014.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/libcm01t014.cpp new file mode 100644 index 00000000000..2a584015e2d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t014/libcm01t014.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t014.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/cm01t015.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/cm01t015.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/cm01t015.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/cm01t015.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/libcm01t015.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/libcm01t015.c deleted file mode 100644 index ae8759d2e65..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/libcm01t015.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t015.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/libcm01t015.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/libcm01t015.cpp new file mode 100644 index 00000000000..265cba0e3b0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t015/libcm01t015.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t015.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/cm01t016.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/cm01t016.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/cm01t016.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/cm01t016.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/libcm01t016.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/libcm01t016.c deleted file mode 100644 index 7f4877ebdc4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/libcm01t016.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t016.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/libcm01t016.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/libcm01t016.cpp new file mode 100644 index 00000000000..b3bcea3f86e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t016/libcm01t016.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t016.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/cm01t017.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/cm01t017.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/cm01t017.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/cm01t017.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/libcm01t017.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/libcm01t017.c deleted file mode 100644 index 8a6f6a4348d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/libcm01t017.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t017.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/libcm01t017.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/libcm01t017.cpp new file mode 100644 index 00000000000..8addde69070 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t017/libcm01t017.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t017.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/cm01t018.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/cm01t018.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/cm01t018.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/cm01t018.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/libcm01t018.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/libcm01t018.c deleted file mode 100644 index da1feb98ae8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/libcm01t018.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t018.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/libcm01t018.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/libcm01t018.cpp new file mode 100644 index 00000000000..f2647622955 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t018/libcm01t018.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t018.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/cm01t019.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/cm01t019.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/cm01t019.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/cm01t019.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/libcm01t019.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/libcm01t019.c deleted file mode 100644 index 4a7c5ff3eea..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/libcm01t019.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t019.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/libcm01t019.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/libcm01t019.cpp new file mode 100644 index 00000000000..2a23c7ae2aa --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t019/libcm01t019.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t019.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/cm01t020.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/cm01t020.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/cm01t020.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/cm01t020.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/libcm01t020.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/libcm01t020.c deleted file mode 100644 index 63e7539494e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/libcm01t020.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t020.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/libcm01t020.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/libcm01t020.cpp new file mode 100644 index 00000000000..83eb5a1b135 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t020/libcm01t020.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t020.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/cm01t021.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/cm01t021.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/cm01t021.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/cm01t021.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/libcm01t021.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/libcm01t021.c deleted file mode 100644 index c49c8fd0dfb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/libcm01t021.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm01t021.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/libcm01t021.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/libcm01t021.cpp new file mode 100644 index 00000000000..4626301f66e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM01/cm01t021/libcm01t021.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm01t021.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/cm02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/cm02t001.c deleted file mode 100644 index e4503ce9772..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/cm02t001.c +++ /dev/null @@ -1,781 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* The test adds all capabilities suitable for profiling at OnLoad phase: - * - * can_tag_objects - * can_get_owned_monitor_info - * can_get_current_contended_monitor - * can_get_monitor_info - * can_maintain_original_method_order - * can_get_current_thread_cpu_time - * can_get_thread_cpu_time - * can_generate_all_class_hook_events - * can_generate_compiled_method_load_events - * can_generate_monitor_events - * can_generate_vm_object_alloc_events - * can_generate_native_method_bind_events - * can_generate_garbage_collection_events - * can_generate_object_free_events - * - * and sets calbacks and enables events correspondent to capabilities above. - * Then checks that GetCapabilities returns correct list of possessed - * capabilities in Live phase, and checks that correspondent possessed - * functions works and requested events are generated. - */ - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* test objects */ -static jthread thread = NULL; -static jclass klass = NULL; - -/* event counts */ -static int ClassFileLoadHookEventsCount = 0; -static int CompiledMethodLoadEventsCount = 0; -static int CompiledMethodUnloadEventsCount = 0; -static int MonitorContendedEnterEventsCount = 0; -static int MonitorContendedEnteredEventsCount = 0; -static int MonitorWaitEventsCount = 0; -static int MonitorWaitedEventsCount = 0; -static int VMObjectAllocEventsCount = 0; -static int NativeMethodBindEventsCount = 0; -static int GarbageCollectionStartEventsCount = 0; -static int GarbageCollectionFinishEventsCount = 0; -static int ObjectFreeEventsCount = 0; - -/* ========================================================================== */ - -/** callback functions **/ - -static void JNICALL -ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jclass class_beeing_redefined, jobject loader, - const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - ClassFileLoadHookEventsCount++; - NSK_DISPLAY1("ClassFileLoadHook event: %s\n", name); -} - -static void JNICALL -CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, - jint code_size, const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - char *name = NULL; - char *signature = NULL; - - CompiledMethodLoadEventsCount++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &name, &signature, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY3("CompiledMethodLoad event: %s%s (0x%p)\n", - name, signature, code_addr); - if (name != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - if (signature != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); -} - -static void JNICALL -CompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - char *name = NULL; - char *sig = NULL; - jvmtiError err; - CompiledMethodUnloadEventsCount++; - - NSK_DISPLAY0("CompiledMethodUnload event received\n"); - // Check for the case that the class has been unloaded - err = (*jvmti_env)->GetMethodName(jvmti_env, method, &name, &sig, NULL); - if (err == JVMTI_ERROR_NONE) { - NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", - name, sig, code_addr); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); - } -} - -static void JNICALL -MonitorContendedEnter(jvmtiEnv *jvmti_env, JNIEnv* jni_env, - jthread thread, jobject object) { - jvmtiThreadInfo info; - - MonitorContendedEnterEventsCount++; - - /* get thread information */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti_env, - thread, &info))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY2("MonitorContendedEnter event: thread=\"%s\", object=0x%p\n", - info.name, object); -} - -static void JNICALL -MonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, - jthread thread, jobject object) { - jvmtiThreadInfo info; - - MonitorContendedEnteredEventsCount++; - - /* get thread information */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti_env, - thread, &info))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY2("MonitorContendedEntered event: thread=\"%s\", object=0x%p\n", - info.name, object); -} - -static void JNICALL -MonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, - jthread thread, jobject object, jlong timeout) { - jvmtiThreadInfo info; - - MonitorWaitEventsCount++; - - /* get thread information */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti_env, - thread, &info))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY2("MonitorWait event: thread=\"%s\", object=0x%p\n", - info.name, object); -} - -static void JNICALL -MonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, - jthread thread, jobject object, jboolean timed_out) { - jvmtiThreadInfo info; - - MonitorWaitedEventsCount++; - - /* get thread information */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti_env, - thread, &info))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY2("MonitorWaited event: thread=\"%s\", object=0x%p\n", - info.name, object); -} - -static void JNICALL -VMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, - jthread thread, jobject object, - jclass object_klass, jlong size) { - char *signature; - - VMObjectAllocEventsCount++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti_env, - object_klass, &signature, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY2("VMObjectAlloc: \"%s\", size=%d\n", signature, size); - if (signature != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); -} - -static void JNICALL -NativeMethodBind(jvmtiEnv* jvmti_env, JNIEnv *jni_env, - jthread thread, jmethodID method, void* func, void** func_ptr) { - jvmtiPhase phase; - char *name = NULL; - char *signature = NULL; - - NativeMethodBindEventsCount++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE) - return; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &name, &signature, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY2("NativeMethodBind event: %s%s\n", name, signature); - - if (name != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - if (signature != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); -} - -static void JNICALL -GarbageCollectionStart(jvmtiEnv *jvmti_env) { - GarbageCollectionStartEventsCount++; - NSK_DISPLAY0("GarbageCollectionStart\n"); -} - -static void JNICALL -GarbageCollectionFinish(jvmtiEnv *jvmti_env) { - GarbageCollectionFinishEventsCount++; - NSK_DISPLAY0("GarbageCollectionFinish\n"); -} - -static void JNICALL -ObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - char buffer[32]; - - ObjectFreeEventsCount++; - NSK_DISPLAY1("ObjectFree event: tag=%s\n", jlong_to_string(tag, buffer)); -} - -/* ========================================================================== */ - -static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { - const char* THREAD_NAME = "Debuggee Thread"; - jvmtiThreadInfo info; - jthread *threads = NULL; - jint threads_count = 0; - int i; - - NSK_DISPLAY0("Prepare: find tested thread\n"); - - /* get all live threads */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetAllThreads, jvmti, &threads_count, &threads))) - return NSK_FALSE; - - if (!NSK_VERIFY(threads_count > 0 && threads != NULL)) - return NSK_FALSE; - - /* find tested thread */ - for (i = 0; i < threads_count; i++) { - if (!NSK_VERIFY(threads[i] != NULL)) - return NSK_FALSE; - - /* get thread information */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetThreadInfo, jvmti, threads[i], &info))) - return NSK_FALSE; - - NSK_DISPLAY3(" thread #%d (%s): %p\n", i, info.name, threads[i]); - - /* find by name */ - if (info.name != NULL && (strcmp(info.name, THREAD_NAME) == 0)) { - thread = threads[i]; - } - } - - if (!NSK_JNI_VERIFY(jni, (thread = - NSK_CPP_STUB2(NewGlobalRef, jni, thread)) != NULL)) - return NSK_FALSE; - - /* deallocate threads list */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)threads))) - return NSK_FALSE; - - /* get tested thread class */ - if (!NSK_JNI_VERIFY(jni, (klass = - NSK_CPP_STUB2(GetObjectClass, jni, thread)) != NULL)) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/* Check GetCapabilities function - */ -static int checkGetCapabilities(jvmtiEnv* jvmti) { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, jvmti, &caps))) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_tag_objects)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_get_owned_monitor_info)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_get_current_contended_monitor)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_get_monitor_info)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_maintain_original_method_order)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_get_current_thread_cpu_time)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_get_thread_cpu_time)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_generate_all_class_hook_events)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_generate_compiled_method_load_events)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_generate_monitor_events)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_generate_vm_object_alloc_events)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_generate_native_method_bind_events)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_generate_garbage_collection_events)) - return NSK_FALSE; - if (!NSK_VERIFY(caps.can_generate_object_free_events)) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/* Check "can_get_owned_monitor_info" function - */ -static int checkGetOwnedMonitorInfo(jvmtiEnv* jvmti) { - jint count; - jobject *monitors = NULL; - - NSK_DISPLAY0("Checking positive: GetOwnedMonitorInfo\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetOwnedMonitorInfo, jvmti, thread, &count, &monitors))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* Check "can_get_current_contended_monitor" function - */ -static int checkGetCurrentContendedMonitor(jvmtiEnv* jvmti) { - jobject monitor = NULL; - - NSK_DISPLAY0("Checking positive: GetCurrentContendedMonitor\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetCurrentContendedMonitor, jvmti, thread, &monitor))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* Check "can_tag_objects" functions - */ - -static jvmtiIterationControl JNICALL -HeapObject(jlong class_tag, jlong size, jlong *tag_ptr, void *user_data) { - return JVMTI_ITERATION_CONTINUE; -} - -static jvmtiIterationControl JNICALL -HeapRoot(jvmtiHeapRootKind root_kind, jlong class_tag, jlong size, - jlong *tag_ptr, void *user_data) { - return JVMTI_ITERATION_CONTINUE; -} - -static jvmtiIterationControl JNICALL -StackReference(jvmtiHeapRootKind root_kind, jlong class_tag, jlong size, - jlong *tag_ptr, jlong thread_tag, jint depth, jmethodID method, - jint slot, void *user_data) { - return JVMTI_ITERATION_CONTINUE; -} - -static jvmtiIterationControl JNICALL -ObjectReference(jvmtiObjectReferenceKind reference_kind, jlong class_tag, - jlong size, jlong *tag_ptr, jlong referrer_tag, - jint referrer_index, void *user_data) { - return JVMTI_ITERATION_CONTINUE; -} - -static jvmtiIterationControl JNICALL -ThreadObjectReference(jvmtiObjectReferenceKind reference_kind, jlong class_tag, - jlong size, jlong *tag_ptr, jlong referrer_tag, - jint referrer_index, void *user_data) { - static jlong ThreadObjectReferenceTagCount; - *tag_ptr = ++ThreadObjectReferenceTagCount; - return JVMTI_ITERATION_CONTINUE; -} - -static int checkHeapFunctions(jvmtiEnv* jvmti) { - const jlong TAG_VALUE = (123456789L); - jlong tag; - jint count; - jobject *res_objects = NULL; - jlong *res_tags = NULL; - jint dummy_user_data = 0; - - NSK_DISPLAY0("Checking positive: SetTag\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetTag, jvmti, thread, TAG_VALUE))) - return NSK_FALSE; - - NSK_DISPLAY0("Checking positive: GetTag\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetTag, jvmti, thread, &tag))) - return NSK_FALSE; - - NSK_DISPLAY0("Checking positive: GetObjectsWithTags\n"); - tag = TAG_VALUE; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB6(GetObjectsWithTags, jvmti, 1, &tag, - &count, &res_objects, &res_tags))) - return NSK_FALSE; - - NSK_DISPLAY0("Checking positive: IterateOverHeap\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverHeap, jvmti, JVMTI_HEAP_OBJECT_TAGGED, - HeapObject, &dummy_user_data))) - return NSK_FALSE; - - NSK_DISPLAY0("Checking positive: IterateOverInstancesOfClass\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, klass, - JVMTI_HEAP_OBJECT_UNTAGGED, HeapObject, &dummy_user_data))) - return NSK_FALSE; - - NSK_DISPLAY0("Checking positive: IterateOverObjectsReachableFromObject\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(IterateOverObjectsReachableFromObject, jvmti, thread, - ThreadObjectReference, &dummy_user_data))) - return NSK_FALSE; - - NSK_DISPLAY0("Checking positive: IterateOverReachableObjects\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(IterateOverReachableObjects, jvmti, - HeapRoot, StackReference, ObjectReference, &dummy_user_data))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* Check "can_get_monitor_info" function - */ -static int checkGetObjectMonitorUsage(jvmtiEnv* jvmti) { - jvmtiMonitorUsage monitor_info; - - NSK_DISPLAY0("Checking positive: GetObjectMonitorUsage\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetObjectMonitorUsage, jvmti, thread, &monitor_info))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* Check "can_get_current_thread_cpu_time" function - */ -static int checkGetCurrentThreadCpuTime(jvmtiEnv* jvmti) { - jvmtiTimerInfo info; - jlong nanos; - - NSK_DISPLAY0("Checking positive: GetCurrentThreadCpuTimerInfo\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(GetCurrentThreadCpuTimerInfo, jvmti, &info))) - return NSK_FALSE; - - NSK_DISPLAY0("Checking positive: GetCurrentThreadCpuTime\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(GetCurrentThreadCpuTime, jvmti, &nanos))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* Check "can_get_thread_cpu_time" function - */ -static int checkGetThreadCpuTime(jvmtiEnv* jvmti) { - jvmtiTimerInfo info; - jlong nanos; - - NSK_DISPLAY0("Checking positive: GetThreadCpuTimerInfo\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(GetThreadCpuTimerInfo, jvmti, &info))) - return NSK_FALSE; - - NSK_DISPLAY0("Checking positive: checkGetThreadCpuTime\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetThreadCpuTime, jvmti, thread, &nanos))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/* Check generated events - */ -static int checkGeneratedEvents() { - int result = NSK_TRUE; - - NSK_DISPLAY1("ClassFileLoadHook events received: %d\n", - ClassFileLoadHookEventsCount); - if (!NSK_VERIFY(ClassFileLoadHookEventsCount != 0)) - result = NSK_FALSE; - - NSK_DISPLAY1("CompiledMethodLoad events received: %d\n", - CompiledMethodLoadEventsCount); - if (CompiledMethodLoadEventsCount == 0) { - NSK_DISPLAY0("# WARNING: no CompiledMethodLoad events\n"); - NSK_DISPLAY0("# (VM might not compile any methods at all)\n"); - } - - NSK_DISPLAY1("CompiledMethodUnload events received: %d\n", - CompiledMethodUnloadEventsCount); - if (CompiledMethodUnloadEventsCount == 0) { - NSK_DISPLAY0("# WARNING: no CompiledMethodUnload events\n"); - NSK_DISPLAY0("# (VM might not compile any methods at all)\n"); - } - - NSK_DISPLAY1("MonitorContendedEnter events received: %d\n", - MonitorContendedEnterEventsCount); - if (!NSK_VERIFY(MonitorContendedEnterEventsCount != 0)) - result = NSK_FALSE; - - NSK_DISPLAY1("MonitorContendedEntered events received: %d\n", - MonitorContendedEnteredEventsCount); - if (!NSK_VERIFY(MonitorContendedEnteredEventsCount != 0)) - result = NSK_FALSE; - - NSK_DISPLAY1("MonitorWait events received: %d\n", - MonitorWaitEventsCount); - if (!NSK_VERIFY(MonitorWaitEventsCount != 0)) - result = NSK_FALSE; - - NSK_DISPLAY1("MonitorWaited events received: %d\n", - MonitorWaitedEventsCount); - if (!NSK_VERIFY(MonitorWaitedEventsCount != 0)) - result = NSK_FALSE; - - NSK_DISPLAY1("VMObjectAlloc events received: %d\n", - VMObjectAllocEventsCount); - if (!NSK_VERIFY(VMObjectAllocEventsCount != 0)) - result = NSK_FALSE; - - NSK_DISPLAY1("NativeMethodBind events received: %d\n", - NativeMethodBindEventsCount); - if (!NSK_VERIFY(NativeMethodBindEventsCount != 0)) - result = NSK_FALSE; - - NSK_DISPLAY1("GarbageCollectionStart events received: %d\n", - GarbageCollectionStartEventsCount); - if (!NSK_VERIFY(GarbageCollectionStartEventsCount != 0)) - result = NSK_FALSE; - - NSK_DISPLAY1("GarbageCollectionFinish events received: %d\n", - GarbageCollectionFinishEventsCount); - if (!NSK_VERIFY(GarbageCollectionFinishEventsCount != 0)) - result = NSK_FALSE; - - NSK_DISPLAY1("ObjectFree events received: %d\n", - ObjectFreeEventsCount); - if (!NSK_VERIFY(ObjectFreeEventsCount != 0)) - result = NSK_FALSE; - - return result; -} - -/* ========================================================================== */ - -/* agent algorithm */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - /* wait for initial sync */ - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!prepare(jvmti, jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Testcase #1: check if GetCapabilities returns the capabilities\n"); - if (!checkGetCapabilities(jvmti)) { - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY0("Testcase #2: check if all correspondent functions work\n"); - if (!checkGetOwnedMonitorInfo(jvmti)) - nsk_jvmti_setFailStatus(); - if (!checkGetCurrentContendedMonitor(jvmti)) - nsk_jvmti_setFailStatus(); - if (!checkHeapFunctions(jvmti)) - nsk_jvmti_setFailStatus(); - if (!checkGetObjectMonitorUsage(jvmti)) - nsk_jvmti_setFailStatus(); - if (!checkGetCurrentThreadCpuTime(jvmti)) - nsk_jvmti_setFailStatus(); - if (!checkGetThreadCpuTime(jvmti)) - nsk_jvmti_setFailStatus(); - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, thread)); - - /* resume debugee and wait for sync */ - if (!nsk_jvmti_resumeSync()) - return; - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("Testcase #3: check if the events are generated\n"); - if (!checkGeneratedEvents()) { - nsk_jvmti_setFailStatus(); - } - - /* resume debugee after last sync */ - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/* agent library initialization */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_cm02t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_cm02t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_cm02t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiCapabilities caps; - jvmtiEventCallbacks callbacks; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60000; - NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout); - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* add capabilities */ - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - caps.can_get_owned_monitor_info = 1; - caps.can_get_current_contended_monitor = 1; - caps.can_get_monitor_info = 1; - caps.can_maintain_original_method_order = 1; - caps.can_get_current_thread_cpu_time = 1; - caps.can_get_thread_cpu_time = 1; - caps.can_generate_all_class_hook_events = 1; - caps.can_generate_compiled_method_load_events = 1; - caps.can_generate_monitor_events = 1; - caps.can_generate_vm_object_alloc_events = 1; - caps.can_generate_native_method_bind_events = 1; - caps.can_generate_garbage_collection_events = 1; - caps.can_generate_object_free_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - - /* set event callbacks */ - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - callbacks.CompiledMethodLoad = &CompiledMethodLoad; - callbacks.CompiledMethodUnload = &CompiledMethodUnload; - callbacks.MonitorContendedEnter = &MonitorContendedEnter; - callbacks.MonitorContendedEntered = &MonitorContendedEntered; - callbacks.MonitorWait = &MonitorWait; - callbacks.MonitorWaited = &MonitorWaited; - callbacks.VMObjectAlloc = &VMObjectAlloc; - callbacks.NativeMethodBind = &NativeMethodBind; - callbacks.GarbageCollectionStart = &GarbageCollectionStart; - callbacks.GarbageCollectionFinish = &GarbageCollectionFinish; - callbacks.ObjectFree = &ObjectFree; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - /* enable events */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_UNLOAD, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTER, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_WAIT, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_WAITED, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_OBJECT_ALLOC, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_NATIVE_METHOD_BIND, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_START, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL))) - return JNI_ERR; - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/cm02t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/cm02t001.cpp new file mode 100644 index 00000000000..4b25f33f336 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/cm02t001.cpp @@ -0,0 +1,781 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* The test adds all capabilities suitable for profiling at OnLoad phase: + * + * can_tag_objects + * can_get_owned_monitor_info + * can_get_current_contended_monitor + * can_get_monitor_info + * can_maintain_original_method_order + * can_get_current_thread_cpu_time + * can_get_thread_cpu_time + * can_generate_all_class_hook_events + * can_generate_compiled_method_load_events + * can_generate_monitor_events + * can_generate_vm_object_alloc_events + * can_generate_native_method_bind_events + * can_generate_garbage_collection_events + * can_generate_object_free_events + * + * and sets calbacks and enables events correspondent to capabilities above. + * Then checks that GetCapabilities returns correct list of possessed + * capabilities in Live phase, and checks that correspondent possessed + * functions works and requested events are generated. + */ + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* test objects */ +static jthread thread = NULL; +static jclass klass = NULL; + +/* event counts */ +static int ClassFileLoadHookEventsCount = 0; +static int CompiledMethodLoadEventsCount = 0; +static int CompiledMethodUnloadEventsCount = 0; +static int MonitorContendedEnterEventsCount = 0; +static int MonitorContendedEnteredEventsCount = 0; +static int MonitorWaitEventsCount = 0; +static int MonitorWaitedEventsCount = 0; +static int VMObjectAllocEventsCount = 0; +static int NativeMethodBindEventsCount = 0; +static int GarbageCollectionStartEventsCount = 0; +static int GarbageCollectionFinishEventsCount = 0; +static int ObjectFreeEventsCount = 0; + +/* ========================================================================== */ + +/** callback functions **/ + +static void JNICALL +ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jclass class_beeing_redefined, jobject loader, + const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + ClassFileLoadHookEventsCount++; + NSK_DISPLAY1("ClassFileLoadHook event: %s\n", name); +} + +static void JNICALL +CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, + jint code_size, const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + char *name = NULL; + char *signature = NULL; + + CompiledMethodLoadEventsCount++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &name, &signature, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY3("CompiledMethodLoad event: %s%s (0x%p)\n", + name, signature, code_addr); + if (name != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + if (signature != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); +} + +static void JNICALL +CompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + char *name = NULL; + char *sig = NULL; + jvmtiError err; + CompiledMethodUnloadEventsCount++; + + NSK_DISPLAY0("CompiledMethodUnload event received\n"); + // Check for the case that the class has been unloaded + err = jvmti_env->GetMethodName(method, &name, &sig, NULL); + if (err == JVMTI_ERROR_NONE) { + NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", + name, sig, code_addr); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); + } +} + +static void JNICALL +MonitorContendedEnter(jvmtiEnv *jvmti_env, JNIEnv* jni_env, + jthread thread, jobject object) { + jvmtiThreadInfo info; + + MonitorContendedEnterEventsCount++; + + /* get thread information */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti_env, + thread, &info))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY2("MonitorContendedEnter event: thread=\"%s\", object=0x%p\n", + info.name, object); +} + +static void JNICALL +MonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, + jthread thread, jobject object) { + jvmtiThreadInfo info; + + MonitorContendedEnteredEventsCount++; + + /* get thread information */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti_env, + thread, &info))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY2("MonitorContendedEntered event: thread=\"%s\", object=0x%p\n", + info.name, object); +} + +static void JNICALL +MonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, + jthread thread, jobject object, jlong timeout) { + jvmtiThreadInfo info; + + MonitorWaitEventsCount++; + + /* get thread information */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti_env, + thread, &info))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY2("MonitorWait event: thread=\"%s\", object=0x%p\n", + info.name, object); +} + +static void JNICALL +MonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, + jthread thread, jobject object, jboolean timed_out) { + jvmtiThreadInfo info; + + MonitorWaitedEventsCount++; + + /* get thread information */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti_env, + thread, &info))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY2("MonitorWaited event: thread=\"%s\", object=0x%p\n", + info.name, object); +} + +static void JNICALL +VMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, + jthread thread, jobject object, + jclass object_klass, jlong size) { + char *signature; + + VMObjectAllocEventsCount++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti_env, + object_klass, &signature, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY2("VMObjectAlloc: \"%s\", size=%d\n", signature, size); + if (signature != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); +} + +static void JNICALL +NativeMethodBind(jvmtiEnv* jvmti_env, JNIEnv *jni_env, + jthread thread, jmethodID method, void* func, void** func_ptr) { + jvmtiPhase phase; + char *name = NULL; + char *signature = NULL; + + NativeMethodBindEventsCount++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE) + return; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &name, &signature, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY2("NativeMethodBind event: %s%s\n", name, signature); + + if (name != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + if (signature != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); +} + +static void JNICALL +GarbageCollectionStart(jvmtiEnv *jvmti_env) { + GarbageCollectionStartEventsCount++; + NSK_DISPLAY0("GarbageCollectionStart\n"); +} + +static void JNICALL +GarbageCollectionFinish(jvmtiEnv *jvmti_env) { + GarbageCollectionFinishEventsCount++; + NSK_DISPLAY0("GarbageCollectionFinish\n"); +} + +static void JNICALL +ObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + char buffer[32]; + + ObjectFreeEventsCount++; + NSK_DISPLAY1("ObjectFree event: tag=%s\n", jlong_to_string(tag, buffer)); +} + +/* ========================================================================== */ + +static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { + const char* THREAD_NAME = "Debuggee Thread"; + jvmtiThreadInfo info; + jthread *threads = NULL; + jint threads_count = 0; + int i; + + NSK_DISPLAY0("Prepare: find tested thread\n"); + + /* get all live threads */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetAllThreads, jvmti, &threads_count, &threads))) + return NSK_FALSE; + + if (!NSK_VERIFY(threads_count > 0 && threads != NULL)) + return NSK_FALSE; + + /* find tested thread */ + for (i = 0; i < threads_count; i++) { + if (!NSK_VERIFY(threads[i] != NULL)) + return NSK_FALSE; + + /* get thread information */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetThreadInfo, jvmti, threads[i], &info))) + return NSK_FALSE; + + NSK_DISPLAY3(" thread #%d (%s): %p\n", i, info.name, threads[i]); + + /* find by name */ + if (info.name != NULL && (strcmp(info.name, THREAD_NAME) == 0)) { + thread = threads[i]; + } + } + + if (!NSK_JNI_VERIFY(jni, (thread = + NSK_CPP_STUB2(NewGlobalRef, jni, thread)) != NULL)) + return NSK_FALSE; + + /* deallocate threads list */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)threads))) + return NSK_FALSE; + + /* get tested thread class */ + if (!NSK_JNI_VERIFY(jni, (klass = + NSK_CPP_STUB2(GetObjectClass, jni, thread)) != NULL)) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/* Check GetCapabilities function + */ +static int checkGetCapabilities(jvmtiEnv* jvmti) { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, jvmti, &caps))) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_tag_objects)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_get_owned_monitor_info)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_get_current_contended_monitor)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_get_monitor_info)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_maintain_original_method_order)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_get_current_thread_cpu_time)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_get_thread_cpu_time)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_generate_all_class_hook_events)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_generate_compiled_method_load_events)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_generate_monitor_events)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_generate_vm_object_alloc_events)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_generate_native_method_bind_events)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_generate_garbage_collection_events)) + return NSK_FALSE; + if (!NSK_VERIFY(caps.can_generate_object_free_events)) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/* Check "can_get_owned_monitor_info" function + */ +static int checkGetOwnedMonitorInfo(jvmtiEnv* jvmti) { + jint count; + jobject *monitors = NULL; + + NSK_DISPLAY0("Checking positive: GetOwnedMonitorInfo\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetOwnedMonitorInfo, jvmti, thread, &count, &monitors))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* Check "can_get_current_contended_monitor" function + */ +static int checkGetCurrentContendedMonitor(jvmtiEnv* jvmti) { + jobject monitor = NULL; + + NSK_DISPLAY0("Checking positive: GetCurrentContendedMonitor\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetCurrentContendedMonitor, jvmti, thread, &monitor))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* Check "can_tag_objects" functions + */ + +static jvmtiIterationControl JNICALL +HeapObject(jlong class_tag, jlong size, jlong *tag_ptr, void *user_data) { + return JVMTI_ITERATION_CONTINUE; +} + +static jvmtiIterationControl JNICALL +HeapRoot(jvmtiHeapRootKind root_kind, jlong class_tag, jlong size, + jlong *tag_ptr, void *user_data) { + return JVMTI_ITERATION_CONTINUE; +} + +static jvmtiIterationControl JNICALL +StackReference(jvmtiHeapRootKind root_kind, jlong class_tag, jlong size, + jlong *tag_ptr, jlong thread_tag, jint depth, jmethodID method, + jint slot, void *user_data) { + return JVMTI_ITERATION_CONTINUE; +} + +static jvmtiIterationControl JNICALL +ObjectReference(jvmtiObjectReferenceKind reference_kind, jlong class_tag, + jlong size, jlong *tag_ptr, jlong referrer_tag, + jint referrer_index, void *user_data) { + return JVMTI_ITERATION_CONTINUE; +} + +static jvmtiIterationControl JNICALL +ThreadObjectReference(jvmtiObjectReferenceKind reference_kind, jlong class_tag, + jlong size, jlong *tag_ptr, jlong referrer_tag, + jint referrer_index, void *user_data) { + static jlong ThreadObjectReferenceTagCount; + *tag_ptr = ++ThreadObjectReferenceTagCount; + return JVMTI_ITERATION_CONTINUE; +} + +static int checkHeapFunctions(jvmtiEnv* jvmti) { + const jlong TAG_VALUE = (123456789L); + jlong tag; + jint count; + jobject *res_objects = NULL; + jlong *res_tags = NULL; + jint dummy_user_data = 0; + + NSK_DISPLAY0("Checking positive: SetTag\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetTag, jvmti, thread, TAG_VALUE))) + return NSK_FALSE; + + NSK_DISPLAY0("Checking positive: GetTag\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetTag, jvmti, thread, &tag))) + return NSK_FALSE; + + NSK_DISPLAY0("Checking positive: GetObjectsWithTags\n"); + tag = TAG_VALUE; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB6(GetObjectsWithTags, jvmti, 1, &tag, + &count, &res_objects, &res_tags))) + return NSK_FALSE; + + NSK_DISPLAY0("Checking positive: IterateOverHeap\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverHeap, jvmti, JVMTI_HEAP_OBJECT_TAGGED, + HeapObject, &dummy_user_data))) + return NSK_FALSE; + + NSK_DISPLAY0("Checking positive: IterateOverInstancesOfClass\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, klass, + JVMTI_HEAP_OBJECT_UNTAGGED, HeapObject, &dummy_user_data))) + return NSK_FALSE; + + NSK_DISPLAY0("Checking positive: IterateOverObjectsReachableFromObject\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(IterateOverObjectsReachableFromObject, jvmti, thread, + ThreadObjectReference, &dummy_user_data))) + return NSK_FALSE; + + NSK_DISPLAY0("Checking positive: IterateOverReachableObjects\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(IterateOverReachableObjects, jvmti, + HeapRoot, StackReference, ObjectReference, &dummy_user_data))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* Check "can_get_monitor_info" function + */ +static int checkGetObjectMonitorUsage(jvmtiEnv* jvmti) { + jvmtiMonitorUsage monitor_info; + + NSK_DISPLAY0("Checking positive: GetObjectMonitorUsage\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetObjectMonitorUsage, jvmti, thread, &monitor_info))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* Check "can_get_current_thread_cpu_time" function + */ +static int checkGetCurrentThreadCpuTime(jvmtiEnv* jvmti) { + jvmtiTimerInfo info; + jlong nanos; + + NSK_DISPLAY0("Checking positive: GetCurrentThreadCpuTimerInfo\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(GetCurrentThreadCpuTimerInfo, jvmti, &info))) + return NSK_FALSE; + + NSK_DISPLAY0("Checking positive: GetCurrentThreadCpuTime\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(GetCurrentThreadCpuTime, jvmti, &nanos))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* Check "can_get_thread_cpu_time" function + */ +static int checkGetThreadCpuTime(jvmtiEnv* jvmti) { + jvmtiTimerInfo info; + jlong nanos; + + NSK_DISPLAY0("Checking positive: GetThreadCpuTimerInfo\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(GetThreadCpuTimerInfo, jvmti, &info))) + return NSK_FALSE; + + NSK_DISPLAY0("Checking positive: checkGetThreadCpuTime\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetThreadCpuTime, jvmti, thread, &nanos))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/* Check generated events + */ +static int checkGeneratedEvents() { + int result = NSK_TRUE; + + NSK_DISPLAY1("ClassFileLoadHook events received: %d\n", + ClassFileLoadHookEventsCount); + if (!NSK_VERIFY(ClassFileLoadHookEventsCount != 0)) + result = NSK_FALSE; + + NSK_DISPLAY1("CompiledMethodLoad events received: %d\n", + CompiledMethodLoadEventsCount); + if (CompiledMethodLoadEventsCount == 0) { + NSK_DISPLAY0("# WARNING: no CompiledMethodLoad events\n"); + NSK_DISPLAY0("# (VM might not compile any methods at all)\n"); + } + + NSK_DISPLAY1("CompiledMethodUnload events received: %d\n", + CompiledMethodUnloadEventsCount); + if (CompiledMethodUnloadEventsCount == 0) { + NSK_DISPLAY0("# WARNING: no CompiledMethodUnload events\n"); + NSK_DISPLAY0("# (VM might not compile any methods at all)\n"); + } + + NSK_DISPLAY1("MonitorContendedEnter events received: %d\n", + MonitorContendedEnterEventsCount); + if (!NSK_VERIFY(MonitorContendedEnterEventsCount != 0)) + result = NSK_FALSE; + + NSK_DISPLAY1("MonitorContendedEntered events received: %d\n", + MonitorContendedEnteredEventsCount); + if (!NSK_VERIFY(MonitorContendedEnteredEventsCount != 0)) + result = NSK_FALSE; + + NSK_DISPLAY1("MonitorWait events received: %d\n", + MonitorWaitEventsCount); + if (!NSK_VERIFY(MonitorWaitEventsCount != 0)) + result = NSK_FALSE; + + NSK_DISPLAY1("MonitorWaited events received: %d\n", + MonitorWaitedEventsCount); + if (!NSK_VERIFY(MonitorWaitedEventsCount != 0)) + result = NSK_FALSE; + + NSK_DISPLAY1("VMObjectAlloc events received: %d\n", + VMObjectAllocEventsCount); + if (!NSK_VERIFY(VMObjectAllocEventsCount != 0)) + result = NSK_FALSE; + + NSK_DISPLAY1("NativeMethodBind events received: %d\n", + NativeMethodBindEventsCount); + if (!NSK_VERIFY(NativeMethodBindEventsCount != 0)) + result = NSK_FALSE; + + NSK_DISPLAY1("GarbageCollectionStart events received: %d\n", + GarbageCollectionStartEventsCount); + if (!NSK_VERIFY(GarbageCollectionStartEventsCount != 0)) + result = NSK_FALSE; + + NSK_DISPLAY1("GarbageCollectionFinish events received: %d\n", + GarbageCollectionFinishEventsCount); + if (!NSK_VERIFY(GarbageCollectionFinishEventsCount != 0)) + result = NSK_FALSE; + + NSK_DISPLAY1("ObjectFree events received: %d\n", + ObjectFreeEventsCount); + if (!NSK_VERIFY(ObjectFreeEventsCount != 0)) + result = NSK_FALSE; + + return result; +} + +/* ========================================================================== */ + +/* agent algorithm */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + /* wait for initial sync */ + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!prepare(jvmti, jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Testcase #1: check if GetCapabilities returns the capabilities\n"); + if (!checkGetCapabilities(jvmti)) { + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY0("Testcase #2: check if all correspondent functions work\n"); + if (!checkGetOwnedMonitorInfo(jvmti)) + nsk_jvmti_setFailStatus(); + if (!checkGetCurrentContendedMonitor(jvmti)) + nsk_jvmti_setFailStatus(); + if (!checkHeapFunctions(jvmti)) + nsk_jvmti_setFailStatus(); + if (!checkGetObjectMonitorUsage(jvmti)) + nsk_jvmti_setFailStatus(); + if (!checkGetCurrentThreadCpuTime(jvmti)) + nsk_jvmti_setFailStatus(); + if (!checkGetThreadCpuTime(jvmti)) + nsk_jvmti_setFailStatus(); + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, thread)); + + /* resume debugee and wait for sync */ + if (!nsk_jvmti_resumeSync()) + return; + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("Testcase #3: check if the events are generated\n"); + if (!checkGeneratedEvents()) { + nsk_jvmti_setFailStatus(); + } + + /* resume debugee after last sync */ + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/* agent library initialization */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_cm02t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_cm02t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_cm02t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiCapabilities caps; + jvmtiEventCallbacks callbacks; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60000; + NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout); + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* add capabilities */ + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + caps.can_get_owned_monitor_info = 1; + caps.can_get_current_contended_monitor = 1; + caps.can_get_monitor_info = 1; + caps.can_maintain_original_method_order = 1; + caps.can_get_current_thread_cpu_time = 1; + caps.can_get_thread_cpu_time = 1; + caps.can_generate_all_class_hook_events = 1; + caps.can_generate_compiled_method_load_events = 1; + caps.can_generate_monitor_events = 1; + caps.can_generate_vm_object_alloc_events = 1; + caps.can_generate_native_method_bind_events = 1; + caps.can_generate_garbage_collection_events = 1; + caps.can_generate_object_free_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + + /* set event callbacks */ + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + callbacks.CompiledMethodLoad = &CompiledMethodLoad; + callbacks.CompiledMethodUnload = &CompiledMethodUnload; + callbacks.MonitorContendedEnter = &MonitorContendedEnter; + callbacks.MonitorContendedEntered = &MonitorContendedEntered; + callbacks.MonitorWait = &MonitorWait; + callbacks.MonitorWaited = &MonitorWaited; + callbacks.VMObjectAlloc = &VMObjectAlloc; + callbacks.NativeMethodBind = &NativeMethodBind; + callbacks.GarbageCollectionStart = &GarbageCollectionStart; + callbacks.GarbageCollectionFinish = &GarbageCollectionFinish; + callbacks.ObjectFree = &ObjectFree; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + /* enable events */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_UNLOAD, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTER, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_WAIT, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_WAITED, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_OBJECT_ALLOC, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_NATIVE_METHOD_BIND, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_START, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL))) + return JNI_ERR; + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/libcm02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/libcm02t001.c deleted file mode 100644 index 37be222482d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/libcm02t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm02t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/libcm02t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/libcm02t001.cpp new file mode 100644 index 00000000000..7a020533fa3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM02/cm02t001/libcm02t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm02t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/cm03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/cm03t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/cm03t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/cm03t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/libcm03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/libcm03t001.c deleted file mode 100644 index 5a0ca01b892..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/libcm03t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "cm03t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/libcm03t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/libcm03t001.cpp new file mode 100644 index 00000000000..4a23bf60a20 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/libcm03t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "cm03t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/libtc01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/libtc01t001.c deleted file mode 100644 index 57f7287cf69..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/libtc01t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "tc01t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/libtc01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/libtc01t001.cpp new file mode 100644 index 00000000000..db10160f430 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/libtc01t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "tc01t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/tc01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/tc01t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/tc01t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC01/tc01t001/tc01t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/libtc02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/libtc02t001.c deleted file mode 100644 index 195817daa06..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/libtc02t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "tc02t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/libtc02t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/libtc02t001.cpp new file mode 100644 index 00000000000..5d9801e16f8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/libtc02t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "tc02t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/tc02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/tc02t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/tc02t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC02/tc02t001/tc02t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/libtc03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/libtc03t001.c deleted file mode 100644 index 07a438e5a1f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/libtc03t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "tc03t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/libtc03t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/libtc03t001.cpp new file mode 100644 index 00000000000..ce1a9598381 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/libtc03t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "tc03t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/tc03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/tc03t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/tc03t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t001/tc03t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/libtc03t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/libtc03t002.c deleted file mode 100644 index e2390bc3e35..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/libtc03t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "tc03t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/libtc03t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/libtc03t002.cpp new file mode 100644 index 00000000000..0e53a81b0af --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/libtc03t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "tc03t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/tc03t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/tc03t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/tc03t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC03/tc03t002/tc03t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/libtc04t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/libtc04t001.c deleted file mode 100644 index 067a67121d2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/libtc04t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "tc04t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/libtc04t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/libtc04t001.cpp new file mode 100644 index 00000000000..82361a104fc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/libtc04t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "tc04t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/tc04t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/tc04t001.c deleted file mode 100644 index 07df73684ce..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/tc04t001.c +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* test objects */ -static jclass object_M = NULL; -static volatile int waitEventsCount = 0; -static volatile int waitedEventsCount = 0; -static volatile int enterEventsCount = 0; -static volatile int enteredEventsCount = 0; -static jrawMonitorID syncLock = NULL; - - -static jboolean lockSyncLock(jvmtiEnv* jvmti) { - jboolean status = NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock)); - if (!status) - nsk_jvmti_setFailStatus(); - return status; -} - -static void unlockSyncLock(jvmtiEnv* jvmti) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); -} - - -/* ========================================================================== */ - -void JNICALL -MonitorWait(jvmtiEnv *jvmti, JNIEnv* jni, - jthread thr, jobject obj, jlong tout) { - - if (!NSK_VERIFY(thr != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_VERIFY(obj != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* check if event is for tested object */ - if (NSK_CPP_STUB3(IsInstanceOf, jni, obj, object_M)) { - if (lockSyncLock(jvmti)) { - waitEventsCount++; - unlockSyncLock(jvmti); - } - } -} - -void JNICALL -MonitorWaited(jvmtiEnv *jvmti, JNIEnv* jni, - jthread thr, jobject obj, jboolean timed_out) { - - if (!NSK_VERIFY(thr != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_VERIFY(obj != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* check if event is for tested object */ - if (NSK_CPP_STUB3(IsInstanceOf, jni, obj, object_M)) { - if (lockSyncLock(jvmti)) { - waitedEventsCount++; - unlockSyncLock(jvmti); - } - } -} - -void JNICALL -MonitorContendedEnter(jvmtiEnv *jvmti, JNIEnv* jni, jthread thr, jobject obj) { - - if (!NSK_VERIFY(thr != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_VERIFY(obj != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* check if event is for tested object */ - if (NSK_CPP_STUB3(IsSameObject, jni, object_M, obj)) { - jvmtiMonitorUsage usageInfo; - - if (lockSyncLock(jvmti)) { - enterEventsCount++; - unlockSyncLock(jvmti); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetObjectMonitorUsage, - jvmti, obj, &usageInfo))) { - nsk_jvmti_setFailStatus(); - } else if (usageInfo.owner != NULL) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2( - InterruptThread, jvmti, usageInfo.owner))) - nsk_jvmti_setFailStatus(); - } - } -} - -void JNICALL -MonitorContendedEntered(jvmtiEnv *jvmti, JNIEnv* jni, jthread thr, jobject obj) { - - if (!NSK_VERIFY(thr != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_VERIFY(obj != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* check if event is for tested object */ - if (NSK_CPP_STUB3(IsSameObject, jni, object_M, obj)) { - if (lockSyncLock(jvmti)) { - enteredEventsCount++; - unlockSyncLock(jvmti); - } - } -} - -/* ========================================================================== */ - -static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { - const char* CLASS_NAME = "nsk/jvmti/scenarios/contention/TC04/tc04t001Thread"; - - NSK_DISPLAY0("Obtain tested object from debugee thread class\n"); - - if (!NSK_JNI_VERIFY(jni, (object_M = - NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (object_M = - NSK_CPP_STUB2(NewGlobalRef, jni, object_M)) != NULL)) - return NSK_FALSE; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) - return NSK_FALSE; - - /* enable MonitorWait event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, - JVMTI_EVENT_MONITOR_WAIT, NULL))) - nsk_jvmti_setFailStatus(); - - /* enable MonitorWaited event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, - JVMTI_EVENT_MONITOR_WAITED, NULL))) - nsk_jvmti_setFailStatus(); - - /* enable MonitorContendedEnter event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, - JVMTI_EVENT_MONITOR_CONTENDED_ENTER, NULL))) - nsk_jvmti_setFailStatus(); - - /* enable MonitorContendedEntered event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, - JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, NULL))) - nsk_jvmti_setFailStatus(); - - return NSK_TRUE; -} - -static int clean(jvmtiEnv* jvmti, JNIEnv* jni) { - - /* disable MonitorWait event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, - JVMTI_EVENT_MONITOR_WAIT, NULL))) - nsk_jvmti_setFailStatus(); - - /* disable MonitorWaited event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, - JVMTI_EVENT_MONITOR_WAITED, NULL))) - nsk_jvmti_setFailStatus(); - - /* disable MonitorContendedEnter event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, - JVMTI_EVENT_MONITOR_CONTENDED_ENTER, NULL))) - nsk_jvmti_setFailStatus(); - - /* disable MonitorContendedEntered event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, - JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, NULL))) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/* agent algorithm */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - /* wait for initial sync */ - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!prepare(jvmti, jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* resume debugee */ - if (!(NSK_VERIFY(nsk_jvmti_resumeSync()) && - NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))) - return; - - // lock - if (lockSyncLock(jvmti)) { - NSK_DISPLAY1("Number of MonitorWait events: %d\n", waitEventsCount); - if (!NSK_VERIFY(waitEventsCount >= 200)) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN1("Number of MonitorWait events: %d\n", waitEventsCount); - } - - NSK_DISPLAY1("Number of MonitorWaited events: %d\n", waitedEventsCount); - if (!NSK_VERIFY(waitedEventsCount >= 200)) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN1("Number of MonitorWaited events: %d\n", waitedEventsCount); - } - - NSK_DISPLAY1("Number of MonitorContendedEnter events: %d\n", - enterEventsCount); - if (!NSK_VERIFY(enterEventsCount == 199)) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN1("Number of MonitorContendedEnter events: %d\n", - enterEventsCount); - } - - NSK_DISPLAY1("Number of MonitorContendedEntered events: %d\n", - enteredEventsCount); - if (!NSK_VERIFY(enteredEventsCount == 199)) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN1("Number of MonitorContendedEntered events: %d\n", - enteredEventsCount); - } - unlockSyncLock(jvmti); - } - - if (!clean(jvmti, jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* resume debugee after last sync */ - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/* agent library initialization */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_tc04t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_tc04t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_tc04t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiCapabilities caps; - jvmtiEventCallbacks callbacks; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60000; - NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout); - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* add capabilities */ - memset(&caps, 0, sizeof(caps)); - caps.can_generate_monitor_events = 1; - caps.can_get_monitor_info = 1; - caps.can_signal_thread = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.MonitorWait = &MonitorWait; - callbacks.MonitorWaited = &MonitorWaited; - callbacks.MonitorContendedEnter = &MonitorContendedEnter; - callbacks.MonitorContendedEntered = &MonitorContendedEntered; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/tc04t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/tc04t001.cpp new file mode 100644 index 00000000000..120ba7e8ebf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC04/tc04t001/tc04t001.cpp @@ -0,0 +1,364 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* test objects */ +static jclass object_M = NULL; +static volatile int waitEventsCount = 0; +static volatile int waitedEventsCount = 0; +static volatile int enterEventsCount = 0; +static volatile int enteredEventsCount = 0; +static jrawMonitorID syncLock = NULL; + + +static jboolean lockSyncLock(jvmtiEnv* jvmti) { + jboolean status = NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock)); + if (!status) + nsk_jvmti_setFailStatus(); + return status; +} + +static void unlockSyncLock(jvmtiEnv* jvmti) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); +} + + +/* ========================================================================== */ + +void JNICALL +MonitorWait(jvmtiEnv *jvmti, JNIEnv* jni, + jthread thr, jobject obj, jlong tout) { + + if (!NSK_VERIFY(thr != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_VERIFY(obj != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* check if event is for tested object */ + if (NSK_CPP_STUB3(IsInstanceOf, jni, obj, object_M)) { + if (lockSyncLock(jvmti)) { + waitEventsCount++; + unlockSyncLock(jvmti); + } + } +} + +void JNICALL +MonitorWaited(jvmtiEnv *jvmti, JNIEnv* jni, + jthread thr, jobject obj, jboolean timed_out) { + + if (!NSK_VERIFY(thr != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_VERIFY(obj != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* check if event is for tested object */ + if (NSK_CPP_STUB3(IsInstanceOf, jni, obj, object_M)) { + if (lockSyncLock(jvmti)) { + waitedEventsCount++; + unlockSyncLock(jvmti); + } + } +} + +void JNICALL +MonitorContendedEnter(jvmtiEnv *jvmti, JNIEnv* jni, jthread thr, jobject obj) { + + if (!NSK_VERIFY(thr != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_VERIFY(obj != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* check if event is for tested object */ + if (NSK_CPP_STUB3(IsSameObject, jni, object_M, obj)) { + jvmtiMonitorUsage usageInfo; + + if (lockSyncLock(jvmti)) { + enterEventsCount++; + unlockSyncLock(jvmti); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetObjectMonitorUsage, + jvmti, obj, &usageInfo))) { + nsk_jvmti_setFailStatus(); + } else if (usageInfo.owner != NULL) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2( + InterruptThread, jvmti, usageInfo.owner))) + nsk_jvmti_setFailStatus(); + } + } +} + +void JNICALL +MonitorContendedEntered(jvmtiEnv *jvmti, JNIEnv* jni, jthread thr, jobject obj) { + + if (!NSK_VERIFY(thr != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_VERIFY(obj != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* check if event is for tested object */ + if (NSK_CPP_STUB3(IsSameObject, jni, object_M, obj)) { + if (lockSyncLock(jvmti)) { + enteredEventsCount++; + unlockSyncLock(jvmti); + } + } +} + +/* ========================================================================== */ + +static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { + const char* CLASS_NAME = "nsk/jvmti/scenarios/contention/TC04/tc04t001Thread"; + + NSK_DISPLAY0("Obtain tested object from debugee thread class\n"); + + if (!NSK_JNI_VERIFY(jni, (object_M = + NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (object_M = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, object_M)) != NULL)) + return NSK_FALSE; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) + return NSK_FALSE; + + /* enable MonitorWait event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, + JVMTI_EVENT_MONITOR_WAIT, NULL))) + nsk_jvmti_setFailStatus(); + + /* enable MonitorWaited event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, + JVMTI_EVENT_MONITOR_WAITED, NULL))) + nsk_jvmti_setFailStatus(); + + /* enable MonitorContendedEnter event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, + JVMTI_EVENT_MONITOR_CONTENDED_ENTER, NULL))) + nsk_jvmti_setFailStatus(); + + /* enable MonitorContendedEntered event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, + JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, NULL))) + nsk_jvmti_setFailStatus(); + + return NSK_TRUE; +} + +static int clean(jvmtiEnv* jvmti, JNIEnv* jni) { + + /* disable MonitorWait event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, + JVMTI_EVENT_MONITOR_WAIT, NULL))) + nsk_jvmti_setFailStatus(); + + /* disable MonitorWaited event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, + JVMTI_EVENT_MONITOR_WAITED, NULL))) + nsk_jvmti_setFailStatus(); + + /* disable MonitorContendedEnter event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, + JVMTI_EVENT_MONITOR_CONTENDED_ENTER, NULL))) + nsk_jvmti_setFailStatus(); + + /* disable MonitorContendedEntered event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, + JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, NULL))) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/* agent algorithm */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + /* wait for initial sync */ + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!prepare(jvmti, jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* resume debugee */ + if (!(NSK_VERIFY(nsk_jvmti_resumeSync()) && + NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))) + return; + + // lock + if (lockSyncLock(jvmti)) { + NSK_DISPLAY1("Number of MonitorWait events: %d\n", waitEventsCount); + if (!NSK_VERIFY(waitEventsCount >= 200)) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN1("Number of MonitorWait events: %d\n", waitEventsCount); + } + + NSK_DISPLAY1("Number of MonitorWaited events: %d\n", waitedEventsCount); + if (!NSK_VERIFY(waitedEventsCount >= 200)) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN1("Number of MonitorWaited events: %d\n", waitedEventsCount); + } + + NSK_DISPLAY1("Number of MonitorContendedEnter events: %d\n", + enterEventsCount); + if (!NSK_VERIFY(enterEventsCount == 199)) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN1("Number of MonitorContendedEnter events: %d\n", + enterEventsCount); + } + + NSK_DISPLAY1("Number of MonitorContendedEntered events: %d\n", + enteredEventsCount); + if (!NSK_VERIFY(enteredEventsCount == 199)) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN1("Number of MonitorContendedEntered events: %d\n", + enteredEventsCount); + } + unlockSyncLock(jvmti); + } + + if (!clean(jvmti, jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* resume debugee after last sync */ + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/* agent library initialization */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_tc04t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_tc04t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_tc04t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiCapabilities caps; + jvmtiEventCallbacks callbacks; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60000; + NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout); + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* add capabilities */ + memset(&caps, 0, sizeof(caps)); + caps.can_generate_monitor_events = 1; + caps.can_get_monitor_info = 1; + caps.can_signal_thread = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.MonitorWait = &MonitorWait; + callbacks.MonitorWaited = &MonitorWaited; + callbacks.MonitorContendedEnter = &MonitorContendedEnter; + callbacks.MonitorContendedEntered = &MonitorContendedEntered; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/libtc05t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/libtc05t001.c deleted file mode 100644 index 329863c6e4d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/libtc05t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "tc05t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/libtc05t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/libtc05t001.cpp new file mode 100644 index 00000000000..9db3e22ee63 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/libtc05t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "tc05t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/tc05t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/tc05t001.c deleted file mode 100644 index faa42a2d592..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/tc05t001.c +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -static const jlong EXPECTED_TIMEOUT = 1; -/* - * The expected timeout accuracy was already increased from 100000 to 300000. - * Please, do not increase it anymore if the test still fails with the message: - * "(waitedTime - waitTime) >= (EXPECTED_TIMEOUT * 1000000) - EXPECTED_TIMEOUT_ACCURACY_NS" - */ -static const jlong EXPECTED_TIMEOUT_ACCURACY_NS = 300000; - -static const jlong EXPECTED_ACCURACY = 10; - -/* scaffold objects */ -static jlong timeout = 0; - -/* test objects */ -static jthread thread = NULL; -static jobject object_M = NULL; -static volatile int waitEventsCount = 0; -static volatile int waitedEventsCount = 0; -static jlong waitTime = 0; -static jlong waitThreadCpuTime = 0; -static jlong waitedTime = 0; -static jlong waitedThreadCpuTime = 0; - -/* ========================================================================== */ - -void JNICALL -MonitorWait(jvmtiEnv *jvmti, JNIEnv* jni, - jthread thr, jobject obj, jlong tout) { - char buffer[32]; - - if (!NSK_VERIFY(thr != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_VERIFY(obj != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* check if event is for tested thread and object */ - if (NSK_CPP_STUB3(IsSameObject, jni, thread, thr) && - NSK_CPP_STUB3(IsSameObject, jni, object_M, obj)) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3( - GetThreadCpuTime, jvmti, thr, &waitThreadCpuTime))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(GetTime, jvmti, &waitTime))) { - nsk_jvmti_setFailStatus(); - } - waitEventsCount++; - NSK_DISPLAY0("MonitorWait event:\n"); - NSK_DISPLAY3("\tthread: %p, object: %p, timeout: %s\n", - thr, obj, jlong_to_string(tout, buffer)); - NSK_DISPLAY1("\ttime: %s\n", - jlong_to_string(waitTime, buffer)); - NSK_DISPLAY1("\tthread CPU time: %s\n", - jlong_to_string(waitThreadCpuTime, buffer)); - - if (!NSK_VERIFY(tout == EXPECTED_TIMEOUT)) { - nsk_jvmti_setFailStatus(); - } - } -} - -void JNICALL -MonitorWaited(jvmtiEnv *jvmti, JNIEnv* jni, - jthread thr, jobject obj, jboolean timed_out) { - char buffer[32]; - - if (!NSK_VERIFY(thr != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_VERIFY(obj != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* check if event is for tested thread and object */ - if (NSK_CPP_STUB3(IsSameObject, jni, thread, thr) && - NSK_CPP_STUB3(IsSameObject, jni, object_M, obj)) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3( - GetThreadCpuTime, jvmti, thr, &waitedThreadCpuTime))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(GetTime, jvmti, &waitedTime))) { - nsk_jvmti_setFailStatus(); - } - waitedEventsCount++; - NSK_DISPLAY0("MonitorWaited event:\n"); - NSK_DISPLAY3("\tthread: %p, object: %p, timed_out: %s\n", - thr, obj, (timed_out==JNI_TRUE) ? "true" : "false"); - NSK_DISPLAY1("\tGetTime: %s\n", - jlong_to_string(waitedTime, buffer)); - NSK_DISPLAY1("\tthread CPU time: %s\n", - jlong_to_string(waitedThreadCpuTime, buffer)); - } -} - -/* ========================================================================== */ - -static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { - const char* THREAD_NAME = "Debuggee Thread"; - const char* FIELD_SIG = "Ljava/lang/Object;"; - jvmtiThreadInfo info; - jthread *threads = NULL; - jint threads_count = 0; - jfieldID field = NULL; - jclass klass = NULL; - int i; - - NSK_DISPLAY0("Prepare: find tested thread\n"); - - /* get all live threads */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetAllThreads, jvmti, &threads_count, &threads))) - return NSK_FALSE; - - if (!NSK_VERIFY(threads_count > 0 && threads != NULL)) - return NSK_FALSE; - - /* find tested thread */ - for (i = 0; i < threads_count; i++) { - if (!NSK_VERIFY(threads[i] != NULL)) - return NSK_FALSE; - - /* get thread information */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetThreadInfo, jvmti, threads[i], &info))) - return NSK_FALSE; - - NSK_DISPLAY3(" thread #%d (%s): %p\n", i, info.name, threads[i]); - - /* find by name */ - if (info.name != NULL && (strcmp(info.name, THREAD_NAME) == 0)) { - thread = threads[i]; - } - - if (info.name != NULL) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2( - Deallocate, jvmti, (unsigned char*)info.name))) - return NSK_FALSE; - } - } - - /* deallocate threads list */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)threads))) - return NSK_FALSE; - - if (thread == NULL) { - NSK_COMPLAIN0("Debuggee thread not found"); - return NSK_FALSE; - } - - /* make thread accessable for a long time */ - if (!NSK_JNI_VERIFY(jni, (thread = - NSK_CPP_STUB2(NewGlobalRef, jni, thread)) != NULL)) - return NSK_FALSE; - - /* get tested thread class */ - if (!NSK_JNI_VERIFY(jni, (klass = - NSK_CPP_STUB2(GetObjectClass, jni, thread)) != NULL)) - return NSK_FALSE; - - /* get tested thread field 'M' */ - if (!NSK_JNI_VERIFY(jni, (field = - NSK_CPP_STUB4(GetFieldID, jni, klass, "M", FIELD_SIG)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (object_M = - NSK_CPP_STUB3(GetObjectField, jni, thread, field)) != NULL)) - return NSK_FALSE; - - /* make object accessable for a long time */ - if (!NSK_JNI_VERIFY(jni, (object_M = - NSK_CPP_STUB2(NewGlobalRef, jni, object_M)) != NULL)) - return NSK_FALSE; - - /* enable MonitorWait event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, - JVMTI_EVENT_MONITOR_WAIT, NULL))) - return NSK_FALSE; - - /* enable MonitorWaited event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, - JVMTI_EVENT_MONITOR_WAITED, NULL))) - return NSK_FALSE; - - return NSK_TRUE; -} - -static int clean(jvmtiEnv* jvmti, JNIEnv* jni) { - - /* disable MonitorWait event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, - JVMTI_EVENT_MONITOR_WAIT, NULL))) - nsk_jvmti_setFailStatus(); - - /* disable MonitorWaited event */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, - JVMTI_EVENT_MONITOR_WAITED, NULL))) - nsk_jvmti_setFailStatus(); - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/* agent algorithm */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - char buffer[32]; - - /* wait for initial sync */ - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!prepare(jvmti, jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* resume debugee to catch MonitorContendedEntered events */ - if (!(NSK_VERIFY(nsk_jvmti_resumeSync()) && - NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))) - return; - - NSK_DISPLAY1("Number of MonitorWait events: %d\n", waitEventsCount); - if (!(NSK_VERIFY(waitEventsCount == 1))) { - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY1("Number of MonitorWaited events: %d\n", waitedEventsCount); - if (!(NSK_VERIFY(waitedEventsCount == 1))) { - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY1("Time frame between the events: %s ns\n", - jlong_to_string(waitedTime - waitTime, buffer)); - if (!(NSK_VERIFY((waitedTime - waitTime) >= (EXPECTED_TIMEOUT * 1000000) - EXPECTED_TIMEOUT_ACCURACY_NS))) { -#if (defined(WIN32) || defined(_WIN32)) - /* Do not fail on Windows as spurious wakeups are expected. The JDK-6313903 was closed as "Won't Fix". */ -#else - nsk_jvmti_setFailStatus(); -#endif - printf("waitedTime: %"LL"d, waitTime: %"LL"d, waitedTime - waitTime: %"LL"d\n", - waitedTime, waitTime, waitedTime - waitTime); - } - - NSK_DISPLAY1("Thread CPU time between the events: %s ns\n", - jlong_to_string(waitedThreadCpuTime - waitThreadCpuTime, buffer)); - if (!(NSK_VERIFY((waitedThreadCpuTime - waitThreadCpuTime) - < (EXPECTED_ACCURACY * 1000000)))) { - nsk_jvmti_setFailStatus(); - printf("waitedThreadCpuTime: %"LL"d, waitThreadCpuTime: %"LL"d, waitedThreadCpuTime - waitThreadCpuTime: %"LL"d\n", - waitedThreadCpuTime, waitThreadCpuTime, waitedThreadCpuTime - waitThreadCpuTime); - } - - if (!clean(jvmti, jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* resume debugee after last sync */ - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/* agent library initialization */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_tc05t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_tc05t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_tc05t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiCapabilities caps; - jvmtiEventCallbacks callbacks; - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60000; - NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout); - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* add capabilities */ - memset(&caps, 0, sizeof(caps)); - caps.can_generate_monitor_events = 1; - caps.can_get_thread_cpu_time = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.MonitorWait = &MonitorWait; - callbacks.MonitorWaited = &MonitorWaited; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/tc05t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/tc05t001.cpp new file mode 100644 index 00000000000..582b421407e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/contention/TC05/tc05t001/tc05t001.cpp @@ -0,0 +1,369 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +static const jlong EXPECTED_TIMEOUT = 1; +/* + * The expected timeout accuracy was already increased from 100000 to 300000. + * Please, do not increase it anymore if the test still fails with the message: + * "(waitedTime - waitTime) >= (EXPECTED_TIMEOUT * 1000000) - EXPECTED_TIMEOUT_ACCURACY_NS" + */ +static const jlong EXPECTED_TIMEOUT_ACCURACY_NS = 300000; + +static const jlong EXPECTED_ACCURACY = 10; + +/* scaffold objects */ +static jlong timeout = 0; + +/* test objects */ +static jthread thread = NULL; +static jobject object_M = NULL; +static volatile int waitEventsCount = 0; +static volatile int waitedEventsCount = 0; +static jlong waitTime = 0; +static jlong waitThreadCpuTime = 0; +static jlong waitedTime = 0; +static jlong waitedThreadCpuTime = 0; + +/* ========================================================================== */ + +void JNICALL +MonitorWait(jvmtiEnv *jvmti, JNIEnv* jni, + jthread thr, jobject obj, jlong tout) { + char buffer[32]; + + if (!NSK_VERIFY(thr != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_VERIFY(obj != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* check if event is for tested thread and object */ + if (NSK_CPP_STUB3(IsSameObject, jni, thread, thr) && + NSK_CPP_STUB3(IsSameObject, jni, object_M, obj)) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3( + GetThreadCpuTime, jvmti, thr, &waitThreadCpuTime))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(GetTime, jvmti, &waitTime))) { + nsk_jvmti_setFailStatus(); + } + waitEventsCount++; + NSK_DISPLAY0("MonitorWait event:\n"); + NSK_DISPLAY3("\tthread: %p, object: %p, timeout: %s\n", + thr, obj, jlong_to_string(tout, buffer)); + NSK_DISPLAY1("\ttime: %s\n", + jlong_to_string(waitTime, buffer)); + NSK_DISPLAY1("\tthread CPU time: %s\n", + jlong_to_string(waitThreadCpuTime, buffer)); + + if (!NSK_VERIFY(tout == EXPECTED_TIMEOUT)) { + nsk_jvmti_setFailStatus(); + } + } +} + +void JNICALL +MonitorWaited(jvmtiEnv *jvmti, JNIEnv* jni, + jthread thr, jobject obj, jboolean timed_out) { + char buffer[32]; + + if (!NSK_VERIFY(thr != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_VERIFY(obj != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* check if event is for tested thread and object */ + if (NSK_CPP_STUB3(IsSameObject, jni, thread, thr) && + NSK_CPP_STUB3(IsSameObject, jni, object_M, obj)) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3( + GetThreadCpuTime, jvmti, thr, &waitedThreadCpuTime))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(GetTime, jvmti, &waitedTime))) { + nsk_jvmti_setFailStatus(); + } + waitedEventsCount++; + NSK_DISPLAY0("MonitorWaited event:\n"); + NSK_DISPLAY3("\tthread: %p, object: %p, timed_out: %s\n", + thr, obj, (timed_out==JNI_TRUE) ? "true" : "false"); + NSK_DISPLAY1("\tGetTime: %s\n", + jlong_to_string(waitedTime, buffer)); + NSK_DISPLAY1("\tthread CPU time: %s\n", + jlong_to_string(waitedThreadCpuTime, buffer)); + } +} + +/* ========================================================================== */ + +static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { + const char* THREAD_NAME = "Debuggee Thread"; + const char* FIELD_SIG = "Ljava/lang/Object;"; + jvmtiThreadInfo info; + jthread *threads = NULL; + jint threads_count = 0; + jfieldID field = NULL; + jclass klass = NULL; + int i; + + NSK_DISPLAY0("Prepare: find tested thread\n"); + + /* get all live threads */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetAllThreads, jvmti, &threads_count, &threads))) + return NSK_FALSE; + + if (!NSK_VERIFY(threads_count > 0 && threads != NULL)) + return NSK_FALSE; + + /* find tested thread */ + for (i = 0; i < threads_count; i++) { + if (!NSK_VERIFY(threads[i] != NULL)) + return NSK_FALSE; + + /* get thread information */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetThreadInfo, jvmti, threads[i], &info))) + return NSK_FALSE; + + NSK_DISPLAY3(" thread #%d (%s): %p\n", i, info.name, threads[i]); + + /* find by name */ + if (info.name != NULL && (strcmp(info.name, THREAD_NAME) == 0)) { + thread = threads[i]; + } + + if (info.name != NULL) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2( + Deallocate, jvmti, (unsigned char*)info.name))) + return NSK_FALSE; + } + } + + /* deallocate threads list */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)threads))) + return NSK_FALSE; + + if (thread == NULL) { + NSK_COMPLAIN0("Debuggee thread not found"); + return NSK_FALSE; + } + + /* make thread accessable for a long time */ + if (!NSK_JNI_VERIFY(jni, (thread = + NSK_CPP_STUB2(NewGlobalRef, jni, thread)) != NULL)) + return NSK_FALSE; + + /* get tested thread class */ + if (!NSK_JNI_VERIFY(jni, (klass = + NSK_CPP_STUB2(GetObjectClass, jni, thread)) != NULL)) + return NSK_FALSE; + + /* get tested thread field 'M' */ + if (!NSK_JNI_VERIFY(jni, (field = + NSK_CPP_STUB4(GetFieldID, jni, klass, "M", FIELD_SIG)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (object_M = + NSK_CPP_STUB3(GetObjectField, jni, thread, field)) != NULL)) + return NSK_FALSE; + + /* make object accessable for a long time */ + if (!NSK_JNI_VERIFY(jni, (object_M = + NSK_CPP_STUB2(NewGlobalRef, jni, object_M)) != NULL)) + return NSK_FALSE; + + /* enable MonitorWait event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, + JVMTI_EVENT_MONITOR_WAIT, NULL))) + return NSK_FALSE; + + /* enable MonitorWaited event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, + JVMTI_EVENT_MONITOR_WAITED, NULL))) + return NSK_FALSE; + + return NSK_TRUE; +} + +static int clean(jvmtiEnv* jvmti, JNIEnv* jni) { + + /* disable MonitorWait event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, + JVMTI_EVENT_MONITOR_WAIT, NULL))) + nsk_jvmti_setFailStatus(); + + /* disable MonitorWaited event */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, + JVMTI_EVENT_MONITOR_WAITED, NULL))) + nsk_jvmti_setFailStatus(); + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/* agent algorithm */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + char buffer[32]; + + /* wait for initial sync */ + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!prepare(jvmti, jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* resume debugee to catch MonitorContendedEntered events */ + if (!(NSK_VERIFY(nsk_jvmti_resumeSync()) && + NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))) + return; + + NSK_DISPLAY1("Number of MonitorWait events: %d\n", waitEventsCount); + if (!(NSK_VERIFY(waitEventsCount == 1))) { + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY1("Number of MonitorWaited events: %d\n", waitedEventsCount); + if (!(NSK_VERIFY(waitedEventsCount == 1))) { + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY1("Time frame between the events: %s ns\n", + jlong_to_string(waitedTime - waitTime, buffer)); + if (!(NSK_VERIFY((waitedTime - waitTime) >= (EXPECTED_TIMEOUT * 1000000) - EXPECTED_TIMEOUT_ACCURACY_NS))) { +#if (defined(WIN32) || defined(_WIN32)) + /* Do not fail on Windows as spurious wakeups are expected. The JDK-6313903 was closed as "Won't Fix". */ +#else + nsk_jvmti_setFailStatus(); +#endif + printf("waitedTime: %" LL "d, waitTime: %" LL "d, waitedTime - waitTime: %" LL "d\n", + waitedTime, waitTime, waitedTime - waitTime); + } + + NSK_DISPLAY1("Thread CPU time between the events: %s ns\n", + jlong_to_string(waitedThreadCpuTime - waitThreadCpuTime, buffer)); + if (!(NSK_VERIFY((waitedThreadCpuTime - waitThreadCpuTime) + < (EXPECTED_ACCURACY * 1000000)))) { + nsk_jvmti_setFailStatus(); + printf("waitedThreadCpuTime: %" LL "d, waitThreadCpuTime: %" LL "d, waitedThreadCpuTime - waitThreadCpuTime: %" LL "d\n", + waitedThreadCpuTime, waitThreadCpuTime, waitedThreadCpuTime - waitThreadCpuTime); + } + + if (!clean(jvmti, jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* resume debugee after last sync */ + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/* agent library initialization */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_tc05t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_tc05t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_tc05t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiCapabilities caps; + jvmtiEventCallbacks callbacks; + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60000; + NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout); + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* add capabilities */ + memset(&caps, 0, sizeof(caps)); + caps.can_generate_monitor_events = 1; + caps.can_get_thread_cpu_time = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.MonitorWait = &MonitorWait; + callbacks.MonitorWaited = &MonitorWaited; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/em01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/em01t001.c deleted file mode 100644 index 75840f01713..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/em01t001.c +++ /dev/null @@ -1,484 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static JNIEnv* jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) -#define EXPECTED_CLASS_NAME "Lnsk/jvmti/scenarios/events/EM01/em01t001a;" -#define CLASS_LOADER_COUNT_PARAM "classLoaderCount" - -static int eventCount[JVMTI_EVENT_COUNT]; - -static int classLoaderCount = 0; - -static jvmtiPhase currentPhase; - -/* ============================================================================= */ - -static void -changeCount(jvmtiEvent event) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -static void -showEventStatistics() { - int i; - const char* str; - - NSK_DISPLAY0("Event statistics\n"); - NSK_DISPLAY0("----------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (eventCount[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, eventCount[i]); - } - } -} - -/* ========================================================================== */ - -/* callbacks */ -void -classEventsHandler(jvmtiEvent event, jvmtiEnv* jvmti_env, JNIEnv* jni_env, - jclass klass) { - - char *className; - char *generic; - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, - &className, &generic))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (strcmp(className, EXPECTED_CLASS_NAME) == 0) { - changeCount(event); - NSK_DISPLAY3("%25s(%4d)>>\tclass: %s\n", - TranslateEvent(event), - eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL], - className); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if (phase != currentPhase) { - NSK_DISPLAY2("Unexpected phase %s, but supposed %s", - TranslatePhase(phase), TranslatePhase(currentPhase)); - } - - if ((phase != JVMTI_PHASE_LIVE) && (phase != JVMTI_PHASE_START)) { - NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n", - TranslateEvent(event), - TranslatePhase(phase), - phase, - className); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)className))) { - nsk_jvmti_setFailStatus(); - } - if (generic != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)generic))) { - nsk_jvmti_setFailStatus(); - } -} - -void -threadEventHandler(jvmtiEvent event, jvmtiEnv* jvmti_env, JNIEnv* jni_env, - jthread thread) { - jclass classObject; - char *className; - char *generic; - jvmtiPhase phase; - - - if (!NSK_JNI_VERIFY(jni_env, (classObject = - NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, classObject, - &className, &generic))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (strcmp(className, EXPECTED_CLASS_NAME) == 0) { - changeCount(event); - NSK_DISPLAY3("%25s(%4d)>>\tclass: %s\n", - TranslateEvent(event), - eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL], - className); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if (phase != currentPhase) { - NSK_DISPLAY2("Unexpected phase %s, but supposed %s", - TranslatePhase(phase), TranslatePhase(currentPhase)); - } - - if ((phase != JVMTI_PHASE_START) && (phase != JVMTI_PHASE_LIVE)) { - NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n", - TranslateEvent(event), - TranslatePhase(phase), - phase, - className); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)className))) { - nsk_jvmti_setFailStatus(); - } - if (generic != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)generic))) { - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -cbVMStart(jvmtiEnv* jvmti_env, JNIEnv* jni_env) { - - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if ((phase != JVMTI_PHASE_START) && (phase != JVMTI_PHASE_LIVE)) { - NSK_COMPLAIN3("%25s was sent during %s(%d)\n", - TranslateEvent(JVMTI_EVENT_VM_START), - TranslatePhase(phase), - phase); - nsk_jvmti_setFailStatus(); - } - - changeCount(JVMTI_EVENT_VM_START); - currentPhase = JVMTI_PHASE_START; -} - -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) { - - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if (phase != JVMTI_PHASE_LIVE) { - NSK_COMPLAIN3("%25s was sent during %s(%d)\n", - TranslateEvent(JVMTI_EVENT_VM_INIT), - TranslatePhase(phase), - phase); - nsk_jvmti_setFailStatus(); - } - - changeCount(JVMTI_EVENT_VM_INIT); - currentPhase = JVMTI_PHASE_LIVE; -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti_env, JNIEnv* jni_env) { - - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if (phase != JVMTI_PHASE_LIVE) { - NSK_COMPLAIN3("%25s was sent during %s(%d)\n", - TranslateEvent(JVMTI_EVENT_VM_INIT), - TranslatePhase(phase), - phase); - nsk_jvmti_setFailStatus(); - } - - currentPhase = JVMTI_PHASE_DEAD; - changeCount(JVMTI_EVENT_VM_DEATH); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -JNIEXPORT void JNICALL -cbClassLoad(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread, - jclass klass) { - - classEventsHandler(JVMTI_EVENT_CLASS_LOAD, jvmti_env, jni_env, klass); -} - -JNIEXPORT void JNICALL -cbClassPrepare(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread, - jclass klass) { - - classEventsHandler(JVMTI_EVENT_CLASS_PREPARE, jvmti_env, jni_env, klass); -} - -JNIEXPORT void JNICALL -cbThreadStart(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) { - - threadEventHandler(JVMTI_EVENT_THREAD_START, jvmti_env, jni_env, thread); -} - -JNIEXPORT void JNICALL -cbThreadEnd(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) { - - threadEventHandler(JVMTI_EVENT_THREAD_END, jvmti_env, jni_env, thread); -} - -/* ============================================================================= */ - -static int -enableEvent(jvmtiEventMode enable, jvmtiEvent event) { - NSK_DISPLAY1("enabling %s\n", TranslateEvent(event)); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, enable, - event, NULL))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** - * Testcase: check tested events. - * - check if expected events received for each method - * - * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. - */ -int checkEvents(int step) { - - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int mustBeChecked; - - showEventStatistics(); - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - switch (step) { - case 1: - mustBeChecked = ((curr == JVMTI_EVENT_CLASS_LOAD) - || (curr == JVMTI_EVENT_CLASS_PREPARE)); - break; - - case 2: - mustBeChecked = ((curr == JVMTI_EVENT_CLASS_LOAD) - || (curr == JVMTI_EVENT_CLASS_PREPARE) - || (curr == JVMTI_EVENT_THREAD_START) - || (curr == JVMTI_EVENT_THREAD_END)); - break; - default: - mustBeChecked = NSK_TRUE; - } - - if (mustBeChecked && eventCount[i] != classLoaderCount) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN3("Unexpected number of %s events %7d\n\texpected value %d\n", - TranslateEvent(curr), - eventCount[i], - classLoaderCount); - nsk_jvmti_setFailStatus(); - result = NSK_FALSE; - } - } - - return result; -} - -/* ============================================================================= */ - -static int -setCallBacks() { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - eventCallbacks.VMStart = cbVMStart; - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.VMDeath = cbVMDeath; - eventCallbacks.ClassLoad = cbClassLoad; - eventCallbacks.ClassPrepare = cbClassPrepare; - eventCallbacks.ThreadStart = cbThreadStart; - eventCallbacks.ThreadEnd = cbThreadEnd; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - NSK_DISPLAY0("Wait for debuggee to become ready\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("Let debuggee to load class\n"); - if (!nsk_jvmti_resumeSync()) - return; - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - /* check only CLASS_LOAD and CLASS_PREPARE events */ - if (!checkEvents(1)) { - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY0("Let debuggee to start threads\n"); - if (!nsk_jvmti_resumeSync()) - return; - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("check event 2\n"); - if (!checkEvents(2)) { - nsk_jvmti_setFailStatus(); - NSK_DISPLAY0("fail\n"); - } - - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em01t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em01t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em01t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - currentPhase = JVMTI_PHASE_ONLOAD; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - classLoaderCount = nsk_jvmti_findOptionIntValue(CLASS_LOADER_COUNT_PARAM, 10); - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - if (!setCallBacks()) { - return JNI_ERR; - } - - if (!enableEvent(JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_THREAD_END) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_VM_START) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_VM_INIT) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH) - ) { - NSK_COMPLAIN0("Events could not be enabled"); - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - currentPhase = JVMTI_PHASE_PRIMORDIAL; - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/em01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/em01t001.cpp new file mode 100644 index 00000000000..41b693312f0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/em01t001.cpp @@ -0,0 +1,484 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static JNIEnv* jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) +#define EXPECTED_CLASS_NAME "Lnsk/jvmti/scenarios/events/EM01/em01t001a;" +#define CLASS_LOADER_COUNT_PARAM "classLoaderCount" + +static int eventCount[JVMTI_EVENT_COUNT]; + +static int classLoaderCount = 0; + +static jvmtiPhase currentPhase; + +/* ============================================================================= */ + +static void +changeCount(jvmtiEvent event) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +static void +showEventStatistics() { + int i; + const char* str; + + NSK_DISPLAY0("Event statistics\n"); + NSK_DISPLAY0("----------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (eventCount[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, eventCount[i]); + } + } +} + +/* ========================================================================== */ + +/* callbacks */ +void +classEventsHandler(jvmtiEvent event, jvmtiEnv* jvmti_env, JNIEnv* jni_env, + jclass klass) { + + char *className; + char *generic; + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, + &className, &generic))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (strcmp(className, EXPECTED_CLASS_NAME) == 0) { + changeCount(event); + NSK_DISPLAY3("%25s(%4d)>>\tclass: %s\n", + TranslateEvent(event), + eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL], + className); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if (phase != currentPhase) { + NSK_DISPLAY2("Unexpected phase %s, but supposed %s", + TranslatePhase(phase), TranslatePhase(currentPhase)); + } + + if ((phase != JVMTI_PHASE_LIVE) && (phase != JVMTI_PHASE_START)) { + NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n", + TranslateEvent(event), + TranslatePhase(phase), + phase, + className); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)className))) { + nsk_jvmti_setFailStatus(); + } + if (generic != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)generic))) { + nsk_jvmti_setFailStatus(); + } +} + +void +threadEventHandler(jvmtiEvent event, jvmtiEnv* jvmti_env, JNIEnv* jni_env, + jthread thread) { + jclass classObject; + char *className; + char *generic; + jvmtiPhase phase; + + + if (!NSK_JNI_VERIFY(jni_env, (classObject = + NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, classObject, + &className, &generic))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (strcmp(className, EXPECTED_CLASS_NAME) == 0) { + changeCount(event); + NSK_DISPLAY3("%25s(%4d)>>\tclass: %s\n", + TranslateEvent(event), + eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL], + className); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if (phase != currentPhase) { + NSK_DISPLAY2("Unexpected phase %s, but supposed %s", + TranslatePhase(phase), TranslatePhase(currentPhase)); + } + + if ((phase != JVMTI_PHASE_START) && (phase != JVMTI_PHASE_LIVE)) { + NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n", + TranslateEvent(event), + TranslatePhase(phase), + phase, + className); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)className))) { + nsk_jvmti_setFailStatus(); + } + if (generic != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)generic))) { + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +cbVMStart(jvmtiEnv* jvmti_env, JNIEnv* jni_env) { + + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if ((phase != JVMTI_PHASE_START) && (phase != JVMTI_PHASE_LIVE)) { + NSK_COMPLAIN3("%25s was sent during %s(%d)\n", + TranslateEvent(JVMTI_EVENT_VM_START), + TranslatePhase(phase), + phase); + nsk_jvmti_setFailStatus(); + } + + changeCount(JVMTI_EVENT_VM_START); + currentPhase = JVMTI_PHASE_START; +} + +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) { + + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if (phase != JVMTI_PHASE_LIVE) { + NSK_COMPLAIN3("%25s was sent during %s(%d)\n", + TranslateEvent(JVMTI_EVENT_VM_INIT), + TranslatePhase(phase), + phase); + nsk_jvmti_setFailStatus(); + } + + changeCount(JVMTI_EVENT_VM_INIT); + currentPhase = JVMTI_PHASE_LIVE; +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti_env, JNIEnv* jni_env) { + + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if (phase != JVMTI_PHASE_LIVE) { + NSK_COMPLAIN3("%25s was sent during %s(%d)\n", + TranslateEvent(JVMTI_EVENT_VM_INIT), + TranslatePhase(phase), + phase); + nsk_jvmti_setFailStatus(); + } + + currentPhase = JVMTI_PHASE_DEAD; + changeCount(JVMTI_EVENT_VM_DEATH); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +JNIEXPORT void JNICALL +cbClassLoad(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread, + jclass klass) { + + classEventsHandler(JVMTI_EVENT_CLASS_LOAD, jvmti_env, jni_env, klass); +} + +JNIEXPORT void JNICALL +cbClassPrepare(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread, + jclass klass) { + + classEventsHandler(JVMTI_EVENT_CLASS_PREPARE, jvmti_env, jni_env, klass); +} + +JNIEXPORT void JNICALL +cbThreadStart(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) { + + threadEventHandler(JVMTI_EVENT_THREAD_START, jvmti_env, jni_env, thread); +} + +JNIEXPORT void JNICALL +cbThreadEnd(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) { + + threadEventHandler(JVMTI_EVENT_THREAD_END, jvmti_env, jni_env, thread); +} + +/* ============================================================================= */ + +static int +enableEvent(jvmtiEventMode enable, jvmtiEvent event) { + NSK_DISPLAY1("enabling %s\n", TranslateEvent(event)); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, enable, + event, NULL))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** + * Testcase: check tested events. + * - check if expected events received for each method + * + * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. + */ +int checkEvents(int step) { + + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int mustBeChecked; + + showEventStatistics(); + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + switch (step) { + case 1: + mustBeChecked = ((curr == JVMTI_EVENT_CLASS_LOAD) + || (curr == JVMTI_EVENT_CLASS_PREPARE)); + break; + + case 2: + mustBeChecked = ((curr == JVMTI_EVENT_CLASS_LOAD) + || (curr == JVMTI_EVENT_CLASS_PREPARE) + || (curr == JVMTI_EVENT_THREAD_START) + || (curr == JVMTI_EVENT_THREAD_END)); + break; + default: + mustBeChecked = NSK_TRUE; + } + + if (mustBeChecked && eventCount[i] != classLoaderCount) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN3("Unexpected number of %s events %7d\n\texpected value %d\n", + TranslateEvent(curr), + eventCount[i], + classLoaderCount); + nsk_jvmti_setFailStatus(); + result = NSK_FALSE; + } + } + + return result; +} + +/* ============================================================================= */ + +static int +setCallBacks() { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + eventCallbacks.VMStart = cbVMStart; + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.VMDeath = cbVMDeath; + eventCallbacks.ClassLoad = cbClassLoad; + eventCallbacks.ClassPrepare = cbClassPrepare; + eventCallbacks.ThreadStart = cbThreadStart; + eventCallbacks.ThreadEnd = cbThreadEnd; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + NSK_DISPLAY0("Wait for debuggee to become ready\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("Let debuggee to load class\n"); + if (!nsk_jvmti_resumeSync()) + return; + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + /* check only CLASS_LOAD and CLASS_PREPARE events */ + if (!checkEvents(1)) { + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY0("Let debuggee to start threads\n"); + if (!nsk_jvmti_resumeSync()) + return; + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("check event 2\n"); + if (!checkEvents(2)) { + nsk_jvmti_setFailStatus(); + NSK_DISPLAY0("fail\n"); + } + + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em01t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em01t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em01t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + currentPhase = JVMTI_PHASE_ONLOAD; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + classLoaderCount = nsk_jvmti_findOptionIntValue(CLASS_LOADER_COUNT_PARAM, 10); + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + if (!setCallBacks()) { + return JNI_ERR; + } + + if (!enableEvent(JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_THREAD_END) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_VM_START) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_VM_INIT) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH) + ) { + NSK_COMPLAIN0("Events could not be enabled"); + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + currentPhase = JVMTI_PHASE_PRIMORDIAL; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/libem01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/libem01t001.c deleted file mode 100644 index 295eb9efc1c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/libem01t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em01t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/libem01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/libem01t001.cpp new file mode 100644 index 00000000000..0f80d717298 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/libem01t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em01t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/em01t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/em01t002.c deleted file mode 100644 index ac97cc42c17..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/em01t002.c +++ /dev/null @@ -1,582 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static JNIEnv* jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) -#define EXPECTED_CLASS_NAME "Lnsk/jvmti/scenarios/events/EM01/em01t002a;" -#define CLASS_LOADER_COUNT_PARAM "classLoaderCount" - -static int eventCount[JVMTI_EVENT_COUNT]; - -static int classLoaderCount = 0; - -static jvmtiPhase currentPhase; - -/* ============================================================================= */ -/* ============================================================================= */ - - -/* - * Class: nsk_jvmti_scenarios_events_EM01_em01t002 - * Method: loadClass - * Signature: (Lnsk/share/ClassLoader;Ljava/lang/String;)Ljava/lang/Class; - */ -JNIEXPORT jclass JNICALL -Java_nsk_jvmti_scenarios_events_EM01_em01t002_loadClass(JNIEnv *jni_env, - jobject this, jobject loader, jstring className) { - jclass klass; - jmethodID methodID; - jclass loadedClass; - - if (!NSK_JNI_VERIFY(jni_env, (klass = - NSK_CPP_STUB2(GetObjectClass, jni_env, loader)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - if (!NSK_JNI_VERIFY(jni_env, (methodID = - NSK_CPP_STUB4(GetMethodID, jni_env, klass, "loadClass", - "(Ljava/lang/String;)Ljava/lang/Class;")) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - if (!NSK_JNI_VERIFY(jni_env, (loadedClass = - NSK_CPP_STUB4(CallObjectMethod, jni_env, loader, methodID, - className)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - return loadedClass; -} - -/* - * Class: nsk_jvmti_scenarios_events_EM01_em01t002 - * Method: prepareClass - * Signature: (Ljava/lang/Class;)Z - */ -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_events_EM01_em01t002_prepareClass(JNIEnv *jni_env, - jobject this, jclass klass) { - jfieldID fieldID; - - if (!NSK_JNI_VERIFY(jni_env, (fieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni_env, klass, - "toProvokePreparation", "I")) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* - * Class: nsk_jvmti_scenarios_events_EM01_em01t002 - * Method: startThread - * Signature: (Ljava/lang/Thread;)Z - */ -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_events_EM01_em01t002_startThread(JNIEnv *jni_env, - jobject this, jobject thread) { - jclass klass; - jmethodID methodID; - - if (!NSK_JNI_VERIFY(jni_env, (klass = - NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - if (!NSK_JNI_VERIFY(jni_env, (methodID = - NSK_CPP_STUB4(GetMethodID, jni_env, klass, "start", "()V")) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - if (!NSK_JNI_VERIFY_VOID(jni_env, - NSK_CPP_STUB3(CallVoidMethod, jni_env, thread, methodID)) ) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ -/* ============================================================================= */ - -static void -changeCount(jvmtiEvent event) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -static void -showEventStatistics() { - int i; - const char* str; - - NSK_DISPLAY0("Event statistics\n"); - NSK_DISPLAY0("----------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (eventCount[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, eventCount[i]); - } - } -} - -/* ========================================================================== */ - -/* callbacks */ -void -classEventsHandler(jvmtiEvent event, jvmtiEnv* jvmti_env, JNIEnv* jni_env, - jclass klass) { - - char *className; - char *generic; - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, - &className, &generic))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (strcmp(className, EXPECTED_CLASS_NAME) == 0) { - changeCount(event); - NSK_DISPLAY3("%25s(%4d)>>\tclass: %s\n", - TranslateEvent(event), - eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL], - className); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if (phase != currentPhase) { - NSK_DISPLAY2("Unexpected phase %s, but supposed %s", - TranslatePhase(phase), TranslatePhase(currentPhase)); - } - - if ((phase != JVMTI_PHASE_LIVE) && (phase != JVMTI_PHASE_START)) { - NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n", - TranslateEvent(event), - TranslatePhase(phase), - phase, - className); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)className))) { - nsk_jvmti_setFailStatus(); - } - if (generic != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)generic))) { - nsk_jvmti_setFailStatus(); - } -} - -void -threadEventHandler(jvmtiEvent event, jvmtiEnv* jvmti_env, JNIEnv* jni_env, - jthread thread) { - jclass classObject; - char *className; - char *generic; - jvmtiPhase phase; - - - if (!NSK_JNI_VERIFY(jni_env, (classObject = - NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, classObject, - &className, &generic))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (strcmp(className, EXPECTED_CLASS_NAME) == 0) { - changeCount(event); - NSK_DISPLAY3("%25s(%4d)>>\tclass: %s\n", - TranslateEvent(event), - eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL], - className); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if (phase != currentPhase) { - NSK_DISPLAY2("Unexpected phase %s, but supposed %s", - TranslatePhase(phase), TranslatePhase(currentPhase)); - } - - if ((phase != JVMTI_PHASE_START) && (phase != JVMTI_PHASE_LIVE)) { - NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n", - TranslateEvent(event), - TranslatePhase(phase), - phase, - className); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)className))) { - nsk_jvmti_setFailStatus(); - } - if (generic != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)generic))) { - nsk_jvmti_setFailStatus(); - } -} - -JNIEXPORT void JNICALL -cbVMStart(jvmtiEnv* jvmti_env, JNIEnv* jni_env) { - - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if ((phase != JVMTI_PHASE_START) && (phase != JVMTI_PHASE_LIVE)) { - NSK_COMPLAIN3("%25s was sent during %s(%d)\n", - TranslateEvent(JVMTI_EVENT_VM_START), - TranslatePhase(phase), - phase); - nsk_jvmti_setFailStatus(); - } - - changeCount(JVMTI_EVENT_VM_START); - currentPhase = JVMTI_PHASE_START; -} - -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) { - - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if (phase != JVMTI_PHASE_LIVE) { - NSK_COMPLAIN3("%25s was sent during %s(%d)\n", - TranslateEvent(JVMTI_EVENT_VM_INIT), - TranslatePhase(phase), - phase); - nsk_jvmti_setFailStatus(); - } - - changeCount(JVMTI_EVENT_VM_INIT); - currentPhase = JVMTI_PHASE_LIVE; -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti_env, JNIEnv* jni_env) { - - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if (phase != JVMTI_PHASE_LIVE) { - NSK_COMPLAIN3("%25s was sent during %s(%d)\n", - TranslateEvent(JVMTI_EVENT_VM_INIT), - TranslatePhase(phase), - phase); - nsk_jvmti_setFailStatus(); - } - - currentPhase = JVMTI_PHASE_DEAD; - changeCount(JVMTI_EVENT_VM_DEATH); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -JNIEXPORT void JNICALL -cbClassLoad(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread, - jclass klass) { - - classEventsHandler(JVMTI_EVENT_CLASS_LOAD, jvmti_env, jni_env, klass); -} - -JNIEXPORT void JNICALL -cbClassPrepare(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread, - jclass klass) { - - classEventsHandler(JVMTI_EVENT_CLASS_PREPARE, jvmti_env, jni_env, klass); -} - -JNIEXPORT void JNICALL -cbThreadStart(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) { - - threadEventHandler(JVMTI_EVENT_THREAD_START, jvmti_env, jni_env, thread); -} - -JNIEXPORT void JNICALL -cbThreadEnd(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) { - - threadEventHandler(JVMTI_EVENT_THREAD_END, jvmti_env, jni_env, thread); -} - -/* ============================================================================= */ - -static int -enableEvent(jvmtiEventMode enable, jvmtiEvent event) { - - if (enable == JVMTI_ENABLE) { - NSK_DISPLAY1("enabling %s\n", TranslateEvent(event)); - } else { - NSK_DISPLAY1("disabling %s\n", TranslateEvent(event)); - } - - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, enable, - event, NULL))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** - * Testcase: check tested events. - * - check if expected events received for each method - * - * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. - */ -int checkEvents(int step) { - - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int mustBeChecked; - - showEventStatistics(); - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - switch (step) { - case 1: - mustBeChecked = ((curr == JVMTI_EVENT_CLASS_LOAD) - || (curr == JVMTI_EVENT_CLASS_PREPARE)); - break; - - case 2: - mustBeChecked = ((curr == JVMTI_EVENT_CLASS_LOAD) - || (curr == JVMTI_EVENT_CLASS_PREPARE) - || (curr == JVMTI_EVENT_THREAD_START) - || (curr == JVMTI_EVENT_THREAD_END)); - break; - default: - mustBeChecked = NSK_TRUE; - } - - if (mustBeChecked && eventCount[i] != classLoaderCount) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN3("Unexpected number of %s events %7d\n\texpected value %d\n", - TranslateEvent(curr), - eventCount[i], - classLoaderCount); - nsk_jvmti_setFailStatus(); - result = NSK_FALSE; - } - } - - return result; -} - -/* ============================================================================= */ - -static int -setCallBacks() { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - eventCallbacks.VMStart = cbVMStart; - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.VMDeath = cbVMDeath; - eventCallbacks.ClassLoad = cbClassLoad; - eventCallbacks.ClassPrepare = cbClassPrepare; - eventCallbacks.ThreadStart = cbThreadStart; - eventCallbacks.ThreadEnd = cbThreadEnd; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - NSK_DISPLAY0("Wait for debuggee to become ready\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("Let debuggee to load class\n"); - if (!nsk_jvmti_resumeSync()) - return; - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - /* check only CLASS_LOAD and CLASS_PREPARE events */ - if (!checkEvents(1)) { - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY0("Let debuggee to start threads\n"); - if (!nsk_jvmti_resumeSync()) - return; - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("check event 2\n"); - if (!checkEvents(2)) { - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em01t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em01t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em01t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - currentPhase = JVMTI_PHASE_ONLOAD; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - classLoaderCount = nsk_jvmti_findOptionIntValue(CLASS_LOADER_COUNT_PARAM, 10); - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - if (!setCallBacks()) { - return JNI_ERR; - } - - if (!enableEvent(JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_THREAD_END) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_VM_START) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_VM_INIT) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH) - ) { - NSK_COMPLAIN0("Events could not be enabled"); - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - currentPhase = JVMTI_PHASE_PRIMORDIAL; - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/em01t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/em01t002.cpp new file mode 100644 index 00000000000..fbca690a542 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/em01t002.cpp @@ -0,0 +1,582 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static JNIEnv* jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) +#define EXPECTED_CLASS_NAME "Lnsk/jvmti/scenarios/events/EM01/em01t002a;" +#define CLASS_LOADER_COUNT_PARAM "classLoaderCount" + +static int eventCount[JVMTI_EVENT_COUNT]; + +static int classLoaderCount = 0; + +static jvmtiPhase currentPhase; + +/* ============================================================================= */ +/* ============================================================================= */ + + +/* + * Class: nsk_jvmti_scenarios_events_EM01_em01t002 + * Method: loadClass + * Signature: (Lnsk/share/ClassLoader;Ljava/lang/String;)Ljava/lang/Class; + */ +JNIEXPORT jclass JNICALL +Java_nsk_jvmti_scenarios_events_EM01_em01t002_loadClass(JNIEnv *jni_env, + jobject o, jobject loader, jstring className) { + jclass klass; + jmethodID methodID; + jclass loadedClass; + + if (!NSK_JNI_VERIFY(jni_env, (klass = + NSK_CPP_STUB2(GetObjectClass, jni_env, loader)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + if (!NSK_JNI_VERIFY(jni_env, (methodID = + NSK_CPP_STUB4(GetMethodID, jni_env, klass, "loadClass", + "(Ljava/lang/String;)Ljava/lang/Class;")) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + if (!NSK_JNI_VERIFY(jni_env, (loadedClass = (jclass) + NSK_CPP_STUB4(CallObjectMethod, jni_env, loader, methodID, + className)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + return loadedClass; +} + +/* + * Class: nsk_jvmti_scenarios_events_EM01_em01t002 + * Method: prepareClass + * Signature: (Ljava/lang/Class;)Z + */ +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_events_EM01_em01t002_prepareClass(JNIEnv *jni_env, + jobject o, jclass klass) { + jfieldID fieldID; + + if (!NSK_JNI_VERIFY(jni_env, (fieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni_env, klass, + "toProvokePreparation", "I")) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* + * Class: nsk_jvmti_scenarios_events_EM01_em01t002 + * Method: startThread + * Signature: (Ljava/lang/Thread;)Z + */ +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_events_EM01_em01t002_startThread(JNIEnv *jni_env, + jobject o, jobject thread) { + jclass klass; + jmethodID methodID; + + if (!NSK_JNI_VERIFY(jni_env, (klass = + NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + if (!NSK_JNI_VERIFY(jni_env, (methodID = + NSK_CPP_STUB4(GetMethodID, jni_env, klass, "start", "()V")) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + if (!NSK_JNI_VERIFY_VOID(jni_env, + NSK_CPP_STUB3(CallVoidMethod, jni_env, thread, methodID)) ) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ +/* ============================================================================= */ + +static void +changeCount(jvmtiEvent event) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +static void +showEventStatistics() { + int i; + const char* str; + + NSK_DISPLAY0("Event statistics\n"); + NSK_DISPLAY0("----------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (eventCount[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, eventCount[i]); + } + } +} + +/* ========================================================================== */ + +/* callbacks */ +void +classEventsHandler(jvmtiEvent event, jvmtiEnv* jvmti_env, JNIEnv* jni_env, + jclass klass) { + + char *className; + char *generic; + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, + &className, &generic))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (strcmp(className, EXPECTED_CLASS_NAME) == 0) { + changeCount(event); + NSK_DISPLAY3("%25s(%4d)>>\tclass: %s\n", + TranslateEvent(event), + eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL], + className); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if (phase != currentPhase) { + NSK_DISPLAY2("Unexpected phase %s, but supposed %s", + TranslatePhase(phase), TranslatePhase(currentPhase)); + } + + if ((phase != JVMTI_PHASE_LIVE) && (phase != JVMTI_PHASE_START)) { + NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n", + TranslateEvent(event), + TranslatePhase(phase), + phase, + className); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)className))) { + nsk_jvmti_setFailStatus(); + } + if (generic != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)generic))) { + nsk_jvmti_setFailStatus(); + } +} + +void +threadEventHandler(jvmtiEvent event, jvmtiEnv* jvmti_env, JNIEnv* jni_env, + jthread thread) { + jclass classObject; + char *className; + char *generic; + jvmtiPhase phase; + + + if (!NSK_JNI_VERIFY(jni_env, (classObject = + NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, classObject, + &className, &generic))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (strcmp(className, EXPECTED_CLASS_NAME) == 0) { + changeCount(event); + NSK_DISPLAY3("%25s(%4d)>>\tclass: %s\n", + TranslateEvent(event), + eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL], + className); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if (phase != currentPhase) { + NSK_DISPLAY2("Unexpected phase %s, but supposed %s", + TranslatePhase(phase), TranslatePhase(currentPhase)); + } + + if ((phase != JVMTI_PHASE_START) && (phase != JVMTI_PHASE_LIVE)) { + NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n", + TranslateEvent(event), + TranslatePhase(phase), + phase, + className); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)className))) { + nsk_jvmti_setFailStatus(); + } + if (generic != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)generic))) { + nsk_jvmti_setFailStatus(); + } +} + +JNIEXPORT void JNICALL +cbVMStart(jvmtiEnv* jvmti_env, JNIEnv* jni_env) { + + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if ((phase != JVMTI_PHASE_START) && (phase != JVMTI_PHASE_LIVE)) { + NSK_COMPLAIN3("%25s was sent during %s(%d)\n", + TranslateEvent(JVMTI_EVENT_VM_START), + TranslatePhase(phase), + phase); + nsk_jvmti_setFailStatus(); + } + + changeCount(JVMTI_EVENT_VM_START); + currentPhase = JVMTI_PHASE_START; +} + +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) { + + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if (phase != JVMTI_PHASE_LIVE) { + NSK_COMPLAIN3("%25s was sent during %s(%d)\n", + TranslateEvent(JVMTI_EVENT_VM_INIT), + TranslatePhase(phase), + phase); + nsk_jvmti_setFailStatus(); + } + + changeCount(JVMTI_EVENT_VM_INIT); + currentPhase = JVMTI_PHASE_LIVE; +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti_env, JNIEnv* jni_env) { + + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if (phase != JVMTI_PHASE_LIVE) { + NSK_COMPLAIN3("%25s was sent during %s(%d)\n", + TranslateEvent(JVMTI_EVENT_VM_INIT), + TranslatePhase(phase), + phase); + nsk_jvmti_setFailStatus(); + } + + currentPhase = JVMTI_PHASE_DEAD; + changeCount(JVMTI_EVENT_VM_DEATH); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +JNIEXPORT void JNICALL +cbClassLoad(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread, + jclass klass) { + + classEventsHandler(JVMTI_EVENT_CLASS_LOAD, jvmti_env, jni_env, klass); +} + +JNIEXPORT void JNICALL +cbClassPrepare(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread, + jclass klass) { + + classEventsHandler(JVMTI_EVENT_CLASS_PREPARE, jvmti_env, jni_env, klass); +} + +JNIEXPORT void JNICALL +cbThreadStart(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) { + + threadEventHandler(JVMTI_EVENT_THREAD_START, jvmti_env, jni_env, thread); +} + +JNIEXPORT void JNICALL +cbThreadEnd(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) { + + threadEventHandler(JVMTI_EVENT_THREAD_END, jvmti_env, jni_env, thread); +} + +/* ============================================================================= */ + +static int +enableEvent(jvmtiEventMode enable, jvmtiEvent event) { + + if (enable == JVMTI_ENABLE) { + NSK_DISPLAY1("enabling %s\n", TranslateEvent(event)); + } else { + NSK_DISPLAY1("disabling %s\n", TranslateEvent(event)); + } + + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, enable, + event, NULL))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** + * Testcase: check tested events. + * - check if expected events received for each method + * + * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. + */ +int checkEvents(int step) { + + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int mustBeChecked; + + showEventStatistics(); + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + switch (step) { + case 1: + mustBeChecked = ((curr == JVMTI_EVENT_CLASS_LOAD) + || (curr == JVMTI_EVENT_CLASS_PREPARE)); + break; + + case 2: + mustBeChecked = ((curr == JVMTI_EVENT_CLASS_LOAD) + || (curr == JVMTI_EVENT_CLASS_PREPARE) + || (curr == JVMTI_EVENT_THREAD_START) + || (curr == JVMTI_EVENT_THREAD_END)); + break; + default: + mustBeChecked = NSK_TRUE; + } + + if (mustBeChecked && eventCount[i] != classLoaderCount) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN3("Unexpected number of %s events %7d\n\texpected value %d\n", + TranslateEvent(curr), + eventCount[i], + classLoaderCount); + nsk_jvmti_setFailStatus(); + result = NSK_FALSE; + } + } + + return result; +} + +/* ============================================================================= */ + +static int +setCallBacks() { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + eventCallbacks.VMStart = cbVMStart; + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.VMDeath = cbVMDeath; + eventCallbacks.ClassLoad = cbClassLoad; + eventCallbacks.ClassPrepare = cbClassPrepare; + eventCallbacks.ThreadStart = cbThreadStart; + eventCallbacks.ThreadEnd = cbThreadEnd; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + NSK_DISPLAY0("Wait for debuggee to become ready\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("Let debuggee to load class\n"); + if (!nsk_jvmti_resumeSync()) + return; + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + /* check only CLASS_LOAD and CLASS_PREPARE events */ + if (!checkEvents(1)) { + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY0("Let debuggee to start threads\n"); + if (!nsk_jvmti_resumeSync()) + return; + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("check event 2\n"); + if (!checkEvents(2)) { + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em01t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em01t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em01t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + currentPhase = JVMTI_PHASE_ONLOAD; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + classLoaderCount = nsk_jvmti_findOptionIntValue(CLASS_LOADER_COUNT_PARAM, 10); + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + if (!setCallBacks()) { + return JNI_ERR; + } + + if (!enableEvent(JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_THREAD_END) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_VM_START) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_VM_INIT) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH) + ) { + NSK_COMPLAIN0("Events could not be enabled"); + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + currentPhase = JVMTI_PHASE_PRIMORDIAL; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/libem01t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/libem01t002.c deleted file mode 100644 index ce9713bc64d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/libem01t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em01t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/libem01t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/libem01t002.cpp new file mode 100644 index 00000000000..ed754f67adc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/libem01t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em01t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/em02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/em02t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/em02t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/em02t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/libem02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/libem02t001.c deleted file mode 100644 index 79b1ced2dc6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/libem02t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em02t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/libem02t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/libem02t001.cpp new file mode 100644 index 00000000000..7c00d5bd2c2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/libem02t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em02t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/em02t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/em02t002.c deleted file mode 100644 index b65e733801c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/em02t002.c +++ /dev/null @@ -1,560 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define STEP_AMOUNT 3 -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) - -static int eventCount[JVMTI_EVENT_COUNT]; -static int newEventCount[JVMTI_EVENT_COUNT]; - -/* ============================================================================= */ - -static void -showEventStatistics(int step /*int *currentCounts*/) { - int i; - const char* str; - int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("Event statistics for %d step:\n", step); - NSK_DISPLAY0("-----------------------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (currentCounts[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); - } - } -} - -/* ========================================================================== */ - -/** - * Testcase: check tested events. - * - check if expected events received for each method - * - * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. - */ -int checkEvents(int step) { - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int *currentCounts; - int isExpected = 0; - - int ind_start = JVMTI_EVENT_GARBAGE_COLLECTION_START - JVMTI_MIN_EVENT_TYPE_VAL; - int ind_fnsh = JVMTI_EVENT_GARBAGE_COLLECTION_FINISH - JVMTI_MIN_EVENT_TYPE_VAL; - - switch (step) { - case 1: - currentCounts = &eventCount[0]; - break; - - case 2: - case 3: - currentCounts = &newEventCount[0]; - break; - - default: - NSK_COMPLAIN1("Unexpected step no: %d\n", step); - return NSK_FALSE; - } - - if (currentCounts[ind_start] != currentCounts[ind_fnsh]) { - - NSK_COMPLAIN0("Amounts of events are not equal\n"); - NSK_COMPLAIN1("\tGARBAGE_COLLECTION_START:\t%6d\n", - currentCounts[ind_start]); - NSK_COMPLAIN1("\tGARBAGE_COLLECTION_FINISH:\t%6d\n", - currentCounts[ind_fnsh]); - return NSK_FALSE; - } - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - - switch (step) { - case 1: - isExpected = ((curr == JVMTI_EVENT_GARBAGE_COLLECTION_START) - || (curr == JVMTI_EVENT_GARBAGE_COLLECTION_FINISH) - || (curr == JVMTI_EVENT_VM_INIT)); - break; - - case 2: - isExpected = ((curr == JVMTI_EVENT_GARBAGE_COLLECTION_START) - || (curr == JVMTI_EVENT_GARBAGE_COLLECTION_FINISH)); - break; - - case 3: - isExpected = (curr == JVMTI_EVENT_VM_DEATH); - break; - } - - if (isExpected) { - if (currentCounts[i] < 1) { - NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", - currentCounts[i], - TranslateEvent(curr)); - result = NSK_FALSE; - } - } else { - if (currentCounts[i] > 0) { - NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", - TranslateEvent(curr), - currentCounts[i]); - result = NSK_FALSE; - } - } - } - - return result; -} - -static void -changeCount(jvmtiEvent event, int *currentCounts) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/* callbacks */ -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { - changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); - NSK_DISPLAY0("--->VMINit is received\n"); -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { - - changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); - showEventStatistics(STEP_AMOUNT); - if (!checkEvents(STEP_AMOUNT)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -void JNICALL -cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); -} - -void JNICALL -cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); -} - -void JNICALL -cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); -} - -void JNICALL -cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); -} - -void JNICALL -cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); -} - -void JNICALL -cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); -} - -void JNICALL -cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); -} - -void JNICALL -cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); -} - -void JNICALL -cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); -} - -void JNICALL -cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); -} - -void JNICALL -cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jlong tout) { - - changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); -} - -void JNICALL -cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jboolean timed_out) { - - changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); -} - -void JNICALL -cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); -} - -void -handlerMC1(jvmtiEvent event) { - - changeCount(event, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { - - handlerMC1(JVMTI_EVENT_GARBAGE_COLLECTION_START); -} - -void JNICALL -cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - - handlerMC1(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH); -} - -void JNICALL -cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); -} - -void JNICALL -cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); -} - -void -handlerMC2(jvmtiEvent event) { - - changeCount(event, &newEventCount[0]); -} - -void JNICALL -cbNewGarbageCollectionStart(jvmtiEnv *jvmti_env) { - - handlerMC2(JVMTI_EVENT_GARBAGE_COLLECTION_START); -} - -void JNICALL -cbNewGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - - handlerMC2(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH); -} - -/* ============================================================================= */ - -static int enableEvent(jvmtiEvent event) { - - if (nsk_jvmti_isOptionalEvent(event) - && (event != JVMTI_EVENT_GARBAGE_COLLECTION_START) - && (event != JVMTI_EVENT_GARBAGE_COLLECTION_FINISH)) { - if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } else { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } - - return NSK_TRUE; -} - -static int enableEventList() { - int i; - int result = NSK_TRUE; - - NSK_DISPLAY0("Enable events\n"); - - result = enableEvent(JVMTI_EVENT_VM_INIT); - - result = result && enableEvent(JVMTI_EVENT_VM_DEATH); - - /* enabling optional events */ - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); - - if (nsk_jvmti_isOptionalEvent(event)) - result = result && enableEvent(event); - } - - if (result == NSK_FALSE) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -static int -setCallBacks(int step) { - - int i; - - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("===============step %d===============\n", step); - NSK_DISPLAY0("\n"); - switch (step) { - case 1: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - eventCount[i] = 0; - } - - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.Exception = cbException; - eventCallbacks.ExceptionCatch = cbExceptionCatch; - eventCallbacks.SingleStep = cbSingleStep; - eventCallbacks.FramePop = cbFramePop; - eventCallbacks.Breakpoint = cbBreakpoint; - eventCallbacks.FieldAccess = cbFieldAccess; - eventCallbacks.FieldModification = cbFieldModification; - eventCallbacks.MethodEntry = cbMethodEntry; - eventCallbacks.MethodExit = cbMethodExit; - eventCallbacks.NativeMethodBind = cbNativeMethodBind; - eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; - eventCallbacks.MonitorWait = cbMonitorWait; - eventCallbacks.MonitorWaited = cbMonitorWaited; - eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; - eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; - eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; - eventCallbacks.ObjectFree = cbObjectFree; - eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; - break; - - case 2: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.GarbageCollectionStart = cbNewGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbNewGarbageCollectionFinish; - break; - - case 3: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.VMDeath = cbVMDeath; - break; - - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - int i; - - for (i = 1; i <= STEP_AMOUNT; i++) { - if (i > 1) { - NSK_DISPLAY0("Check received events\n"); - - showEventStatistics(i-1); - if (!checkEvents(i-1)) - nsk_jvmti_setFailStatus(); - - if (!setCallBacks(i)) { - return; - } - - if (!nsk_jvmti_resumeSync()) - return; - } - - NSK_DISPLAY0("Wait for debuggee to become ready\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - } - - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em02t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em02t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em02t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_generate_garbage_collection_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - if (!setCallBacks(1)) { - return JNI_ERR; - } - - nsk_jvmti_showPossessedCapabilities(jvmti); - - if (!enableEventList()) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/em02t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/em02t002.cpp new file mode 100644 index 00000000000..02cdcf8a395 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/em02t002.cpp @@ -0,0 +1,560 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define STEP_AMOUNT 3 +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) + +static int eventCount[JVMTI_EVENT_COUNT]; +static int newEventCount[JVMTI_EVENT_COUNT]; + +/* ============================================================================= */ + +static void +showEventStatistics(int step /*int *currentCounts*/) { + int i; + const char* str; + int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("Event statistics for %d step:\n", step); + NSK_DISPLAY0("-----------------------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (currentCounts[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); + } + } +} + +/* ========================================================================== */ + +/** + * Testcase: check tested events. + * - check if expected events received for each method + * + * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. + */ +int checkEvents(int step) { + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int *currentCounts; + int isExpected = 0; + + int ind_start = JVMTI_EVENT_GARBAGE_COLLECTION_START - JVMTI_MIN_EVENT_TYPE_VAL; + int ind_fnsh = JVMTI_EVENT_GARBAGE_COLLECTION_FINISH - JVMTI_MIN_EVENT_TYPE_VAL; + + switch (step) { + case 1: + currentCounts = &eventCount[0]; + break; + + case 2: + case 3: + currentCounts = &newEventCount[0]; + break; + + default: + NSK_COMPLAIN1("Unexpected step no: %d\n", step); + return NSK_FALSE; + } + + if (currentCounts[ind_start] != currentCounts[ind_fnsh]) { + + NSK_COMPLAIN0("Amounts of events are not equal\n"); + NSK_COMPLAIN1("\tGARBAGE_COLLECTION_START:\t%6d\n", + currentCounts[ind_start]); + NSK_COMPLAIN1("\tGARBAGE_COLLECTION_FINISH:\t%6d\n", + currentCounts[ind_fnsh]); + return NSK_FALSE; + } + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + + switch (step) { + case 1: + isExpected = ((curr == JVMTI_EVENT_GARBAGE_COLLECTION_START) + || (curr == JVMTI_EVENT_GARBAGE_COLLECTION_FINISH) + || (curr == JVMTI_EVENT_VM_INIT)); + break; + + case 2: + isExpected = ((curr == JVMTI_EVENT_GARBAGE_COLLECTION_START) + || (curr == JVMTI_EVENT_GARBAGE_COLLECTION_FINISH)); + break; + + case 3: + isExpected = (curr == JVMTI_EVENT_VM_DEATH); + break; + } + + if (isExpected) { + if (currentCounts[i] < 1) { + NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", + currentCounts[i], + TranslateEvent(curr)); + result = NSK_FALSE; + } + } else { + if (currentCounts[i] > 0) { + NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", + TranslateEvent(curr), + currentCounts[i]); + result = NSK_FALSE; + } + } + } + + return result; +} + +static void +changeCount(jvmtiEvent event, int *currentCounts) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/* callbacks */ +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { + changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); + NSK_DISPLAY0("--->VMINit is received\n"); +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { + + changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); + showEventStatistics(STEP_AMOUNT); + if (!checkEvents(STEP_AMOUNT)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +void JNICALL +cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); +} + +void JNICALL +cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); +} + +void JNICALL +cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); +} + +void JNICALL +cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); +} + +void JNICALL +cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); +} + +void JNICALL +cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); +} + +void JNICALL +cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); +} + +void JNICALL +cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); +} + +void JNICALL +cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); +} + +void JNICALL +cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); +} + +void JNICALL +cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jlong tout) { + + changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); +} + +void JNICALL +cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jboolean timed_out) { + + changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); +} + +void JNICALL +cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); +} + +void +handlerMC1(jvmtiEvent event) { + + changeCount(event, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { + + handlerMC1(JVMTI_EVENT_GARBAGE_COLLECTION_START); +} + +void JNICALL +cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + + handlerMC1(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH); +} + +void JNICALL +cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); +} + +void JNICALL +cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); +} + +void +handlerMC2(jvmtiEvent event) { + + changeCount(event, &newEventCount[0]); +} + +void JNICALL +cbNewGarbageCollectionStart(jvmtiEnv *jvmti_env) { + + handlerMC2(JVMTI_EVENT_GARBAGE_COLLECTION_START); +} + +void JNICALL +cbNewGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + + handlerMC2(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH); +} + +/* ============================================================================= */ + +static int enableEvent(jvmtiEvent event) { + + if (nsk_jvmti_isOptionalEvent(event) + && (event != JVMTI_EVENT_GARBAGE_COLLECTION_START) + && (event != JVMTI_EVENT_GARBAGE_COLLECTION_FINISH)) { + if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } else { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } + + return NSK_TRUE; +} + +static int enableEventList() { + int i; + int result = NSK_TRUE; + + NSK_DISPLAY0("Enable events\n"); + + result = enableEvent(JVMTI_EVENT_VM_INIT); + + result = result && enableEvent(JVMTI_EVENT_VM_DEATH); + + /* enabling optional events */ + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); + + if (nsk_jvmti_isOptionalEvent(event)) + result = result && enableEvent(event); + } + + if (result == NSK_FALSE) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +static int +setCallBacks(int step) { + + int i; + + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("===============step %d===============\n", step); + NSK_DISPLAY0("\n"); + switch (step) { + case 1: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + eventCount[i] = 0; + } + + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.Exception = cbException; + eventCallbacks.ExceptionCatch = cbExceptionCatch; + eventCallbacks.SingleStep = cbSingleStep; + eventCallbacks.FramePop = cbFramePop; + eventCallbacks.Breakpoint = cbBreakpoint; + eventCallbacks.FieldAccess = cbFieldAccess; + eventCallbacks.FieldModification = cbFieldModification; + eventCallbacks.MethodEntry = cbMethodEntry; + eventCallbacks.MethodExit = cbMethodExit; + eventCallbacks.NativeMethodBind = cbNativeMethodBind; + eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; + eventCallbacks.MonitorWait = cbMonitorWait; + eventCallbacks.MonitorWaited = cbMonitorWaited; + eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; + eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; + eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; + eventCallbacks.ObjectFree = cbObjectFree; + eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; + break; + + case 2: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.GarbageCollectionStart = cbNewGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbNewGarbageCollectionFinish; + break; + + case 3: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.VMDeath = cbVMDeath; + break; + + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + int i; + + for (i = 1; i <= STEP_AMOUNT; i++) { + if (i > 1) { + NSK_DISPLAY0("Check received events\n"); + + showEventStatistics(i-1); + if (!checkEvents(i-1)) + nsk_jvmti_setFailStatus(); + + if (!setCallBacks(i)) { + return; + } + + if (!nsk_jvmti_resumeSync()) + return; + } + + NSK_DISPLAY0("Wait for debuggee to become ready\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + } + + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em02t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em02t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em02t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_generate_garbage_collection_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + if (!setCallBacks(1)) { + return JNI_ERR; + } + + nsk_jvmti_showPossessedCapabilities(jvmti); + + if (!enableEventList()) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/libem02t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/libem02t002.c deleted file mode 100644 index f9e6c10b11b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/libem02t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em02t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/libem02t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/libem02t002.cpp new file mode 100644 index 00000000000..a704c1f2805 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t002/libem02t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em02t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/em02t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/em02t003.c deleted file mode 100644 index 87a6b628532..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/em02t003.c +++ /dev/null @@ -1,609 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define STEP_AMOUNT 3 -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) - -static int eventCount[JVMTI_EVENT_COUNT]; -static int newEventCount[JVMTI_EVENT_COUNT]; -static int loadEvents = 0; -static int unloadEvents = 0; - -/* ============================================================================= */ - -static void -showEventStatistics(int step) { - int i; - const char* str; - int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("Event statistics for %d step:\n", step); - NSK_DISPLAY0("-----------------------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (currentCounts[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); - } - } -} - -/* ========================================================================== */ - -int checkEvents(int step) { - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int *currentCounts; - int isExpected = 0; - - switch (step) { - case 1: - currentCounts = &eventCount[0]; - break; - - case 2: - case 3: - currentCounts = &newEventCount[0]; - break; - - default: - NSK_COMPLAIN1("Unexpected step no: %d\n", step); - return NSK_FALSE; - } - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - - switch (step) { - case 1: - isExpected = ((curr == JVMTI_EVENT_COMPILED_METHOD_LOAD) - || (curr == JVMTI_EVENT_VM_INIT)); - break; - - case 2: - isExpected = (curr == JVMTI_EVENT_COMPILED_METHOD_LOAD); - break; - - case 3: - isExpected = (curr == JVMTI_EVENT_VM_DEATH); - break; - } - - if (isExpected) { - if (currentCounts[i] < 0) { - NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", - currentCounts[i], - TranslateEvent(curr)); - result = NSK_FALSE; - } - } else { - - if (curr != JVMTI_EVENT_COMPILED_METHOD_UNLOAD) { - if (currentCounts[i] > 0) { - NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", - TranslateEvent(curr), - currentCounts[i]); - result = NSK_FALSE; - } - } - } - } - - return result; -} - -static void -changeCount(jvmtiEvent event, int *currentCounts) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/* callbacks */ -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { - changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { - changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); - showEventStatistics(STEP_AMOUNT); - if (!checkEvents(STEP_AMOUNT)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -void JNICALL -cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); -} - -void JNICALL -cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); -} - -void JNICALL -cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); -} - -void JNICALL -cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); -} - -void JNICALL -cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); -} - -void JNICALL -cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); -} - -void JNICALL -cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); -} - -void JNICALL -cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); -} - -void JNICALL -cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); -} - -void JNICALL -cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); -} - -void JNICALL -cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jlong tout) { - - changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); -} - -void JNICALL -cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jboolean timed_out) { - - changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); -} - -void JNICALL -cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); -} - -void -handlerMC1(jvmtiEvent event, jvmtiEnv* jvmti, jmethodID method) { - - char *name; - char *sign; - char *genc; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5( - GetMethodName, jvmti, method, &name, &sign, &genc))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!strncmp(name,"javaMethod", 8)) { - NSK_DISPLAY2("\tMethod: %s, signature: %s\n", name, sign); - changeCount(event, &eventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti, (unsigned char*)name))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti, (unsigned char*)sign))) { - nsk_jvmti_setFailStatus(); - } - if (genc != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti, (unsigned char*)genc))) { - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - - loadEvents++; - handlerMC1(JVMTI_EVENT_COMPILED_METHOD_LOAD, jvmti_env, method); -} - -void JNICALL -cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - unloadEvents++; - NSK_DISPLAY0(">>>JVMTI_EVENT_COMPILED_METHOD_UNLOAD received for\n"); - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); -} - -void JNICALL -cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); -} - -void JNICALL -cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); -} - -void -handlerMC2(jvmtiEvent event, jvmtiEnv* jvmti, jmethodID method) { - - char *name; - char *sign; - char *genc; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5( - GetMethodName, jvmti, method, &name, &sign, &genc))) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY2("\tMethod: %s, signature: %s\n", name, sign); - changeCount(event, &newEventCount[0]); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti, (unsigned char*)name))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti, (unsigned char*)sign))) { - nsk_jvmti_setFailStatus(); - } - if (genc != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti, (unsigned char*)genc))) { - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbNewCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - - loadEvents++; - handlerMC2(JVMTI_EVENT_COMPILED_METHOD_LOAD, jvmti_env, method); -} - -void JNICALL -cbNewCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - - unloadEvents++; - NSK_DISPLAY0(">>>JVMTI_EVENT_COMPILED_METHOD_UNLOAD received for\n"); - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &newEventCount[0]); -} - -/* ============================================================================= */ - -static int enableEvent(jvmtiEvent event) { - - if (nsk_jvmti_isOptionalEvent(event) - && (event != JVMTI_EVENT_COMPILED_METHOD_LOAD) - && (event != JVMTI_EVENT_COMPILED_METHOD_UNLOAD)) { - if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } else { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } - - return NSK_TRUE; -} - -/** - * Enable or disable tested events. - */ -static int enableEventList() { - int i; - int result = NSK_TRUE; - - NSK_DISPLAY0("Enable events\n"); - - result = enableEvent(JVMTI_EVENT_VM_INIT); - - result = result && enableEvent(JVMTI_EVENT_VM_DEATH); - - /* enabling optional events */ - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); - - if (nsk_jvmti_isOptionalEvent(event)) - result = result && enableEvent(event); - } - - if (result == NSK_FALSE) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -static int -setCallBacks(int step) { - - int i; - - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("===============step %d===============\n", step); - NSK_DISPLAY0("\n"); - switch (step) { - case 1: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - eventCount[i] = 0; - } - - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.Exception = cbException; - eventCallbacks.ExceptionCatch = cbExceptionCatch; - eventCallbacks.SingleStep = cbSingleStep; - eventCallbacks.FramePop = cbFramePop; - eventCallbacks.Breakpoint = cbBreakpoint; - eventCallbacks.FieldAccess = cbFieldAccess; - eventCallbacks.FieldModification = cbFieldModification; - eventCallbacks.MethodEntry = cbMethodEntry; - eventCallbacks.MethodExit = cbMethodExit; - eventCallbacks.NativeMethodBind = cbNativeMethodBind; - eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; - eventCallbacks.MonitorWait = cbMonitorWait; - eventCallbacks.MonitorWaited = cbMonitorWaited; - eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; - eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; - eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; - eventCallbacks.ObjectFree = cbObjectFree; - eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; - break; - - case 2: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.CompiledMethodLoad = cbNewCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = cbNewCompiledMethodUnload; - break; - - case 3: - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.VMDeath = cbVMDeath; - break; - - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - int i; - - for (i = 1; i <= STEP_AMOUNT; i++) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("Check received events\n"); - - if (i < STEP_AMOUNT) { - showEventStatistics(i); - if (!checkEvents(i)) - nsk_jvmti_setFailStatus(); - - if (!setCallBacks(i + 1)) { - return; - } - } - - if (!nsk_jvmti_resumeSync()) - return; - } - - /* checking amounts of COMPILED_METHOD_LOAD and COMPILED_METHOD_UNLOAD events */ - if (loadEvents < unloadEvents) { - NSK_COMPLAIN2("Number of JVMTI_EVENT_COMPILED_METHOD_LOAD events %d is less than number of JVMTI_EVENT_COMPILED_METHOD_UNLOAD %d", - loadEvents, - unloadEvents); - } -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em02t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em02t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em02t003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_generate_compiled_method_load_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - if (!setCallBacks(1)) { - return JNI_ERR; - } - - nsk_jvmti_showPossessedCapabilities(jvmti); - - if (!enableEventList()) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/em02t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/em02t003.cpp new file mode 100644 index 00000000000..977dba3a1f4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/em02t003.cpp @@ -0,0 +1,609 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define STEP_AMOUNT 3 +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) + +static int eventCount[JVMTI_EVENT_COUNT]; +static int newEventCount[JVMTI_EVENT_COUNT]; +static int loadEvents = 0; +static int unloadEvents = 0; + +/* ============================================================================= */ + +static void +showEventStatistics(int step) { + int i; + const char* str; + int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("Event statistics for %d step:\n", step); + NSK_DISPLAY0("-----------------------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (currentCounts[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); + } + } +} + +/* ========================================================================== */ + +int checkEvents(int step) { + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int *currentCounts; + int isExpected = 0; + + switch (step) { + case 1: + currentCounts = &eventCount[0]; + break; + + case 2: + case 3: + currentCounts = &newEventCount[0]; + break; + + default: + NSK_COMPLAIN1("Unexpected step no: %d\n", step); + return NSK_FALSE; + } + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + + switch (step) { + case 1: + isExpected = ((curr == JVMTI_EVENT_COMPILED_METHOD_LOAD) + || (curr == JVMTI_EVENT_VM_INIT)); + break; + + case 2: + isExpected = (curr == JVMTI_EVENT_COMPILED_METHOD_LOAD); + break; + + case 3: + isExpected = (curr == JVMTI_EVENT_VM_DEATH); + break; + } + + if (isExpected) { + if (currentCounts[i] < 0) { + NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", + currentCounts[i], + TranslateEvent(curr)); + result = NSK_FALSE; + } + } else { + + if (curr != JVMTI_EVENT_COMPILED_METHOD_UNLOAD) { + if (currentCounts[i] > 0) { + NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", + TranslateEvent(curr), + currentCounts[i]); + result = NSK_FALSE; + } + } + } + } + + return result; +} + +static void +changeCount(jvmtiEvent event, int *currentCounts) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/* callbacks */ +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { + changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { + changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); + showEventStatistics(STEP_AMOUNT); + if (!checkEvents(STEP_AMOUNT)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +void JNICALL +cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); +} + +void JNICALL +cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); +} + +void JNICALL +cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); +} + +void JNICALL +cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); +} + +void JNICALL +cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); +} + +void JNICALL +cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); +} + +void JNICALL +cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); +} + +void JNICALL +cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); +} + +void JNICALL +cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); +} + +void JNICALL +cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); +} + +void JNICALL +cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jlong tout) { + + changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); +} + +void JNICALL +cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jboolean timed_out) { + + changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); +} + +void JNICALL +cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); +} + +void +handlerMC1(jvmtiEvent event, jvmtiEnv* jvmti, jmethodID method) { + + char *name; + char *sign; + char *genc; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5( + GetMethodName, jvmti, method, &name, &sign, &genc))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!strncmp(name,"javaMethod", 8)) { + NSK_DISPLAY2("\tMethod: %s, signature: %s\n", name, sign); + changeCount(event, &eventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti, (unsigned char*)name))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti, (unsigned char*)sign))) { + nsk_jvmti_setFailStatus(); + } + if (genc != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti, (unsigned char*)genc))) { + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + + loadEvents++; + handlerMC1(JVMTI_EVENT_COMPILED_METHOD_LOAD, jvmti_env, method); +} + +void JNICALL +cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + unloadEvents++; + NSK_DISPLAY0(">>>JVMTI_EVENT_COMPILED_METHOD_UNLOAD received for\n"); + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); +} + +void JNICALL +cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); +} + +void JNICALL +cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); +} + +void +handlerMC2(jvmtiEvent event, jvmtiEnv* jvmti, jmethodID method) { + + char *name; + char *sign; + char *genc; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5( + GetMethodName, jvmti, method, &name, &sign, &genc))) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY2("\tMethod: %s, signature: %s\n", name, sign); + changeCount(event, &newEventCount[0]); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti, (unsigned char*)name))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti, (unsigned char*)sign))) { + nsk_jvmti_setFailStatus(); + } + if (genc != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti, (unsigned char*)genc))) { + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbNewCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + + loadEvents++; + handlerMC2(JVMTI_EVENT_COMPILED_METHOD_LOAD, jvmti_env, method); +} + +void JNICALL +cbNewCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + + unloadEvents++; + NSK_DISPLAY0(">>>JVMTI_EVENT_COMPILED_METHOD_UNLOAD received for\n"); + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &newEventCount[0]); +} + +/* ============================================================================= */ + +static int enableEvent(jvmtiEvent event) { + + if (nsk_jvmti_isOptionalEvent(event) + && (event != JVMTI_EVENT_COMPILED_METHOD_LOAD) + && (event != JVMTI_EVENT_COMPILED_METHOD_UNLOAD)) { + if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } else { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } + + return NSK_TRUE; +} + +/** + * Enable or disable tested events. + */ +static int enableEventList() { + int i; + int result = NSK_TRUE; + + NSK_DISPLAY0("Enable events\n"); + + result = enableEvent(JVMTI_EVENT_VM_INIT); + + result = result && enableEvent(JVMTI_EVENT_VM_DEATH); + + /* enabling optional events */ + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); + + if (nsk_jvmti_isOptionalEvent(event)) + result = result && enableEvent(event); + } + + if (result == NSK_FALSE) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +static int +setCallBacks(int step) { + + int i; + + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("===============step %d===============\n", step); + NSK_DISPLAY0("\n"); + switch (step) { + case 1: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + eventCount[i] = 0; + } + + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.Exception = cbException; + eventCallbacks.ExceptionCatch = cbExceptionCatch; + eventCallbacks.SingleStep = cbSingleStep; + eventCallbacks.FramePop = cbFramePop; + eventCallbacks.Breakpoint = cbBreakpoint; + eventCallbacks.FieldAccess = cbFieldAccess; + eventCallbacks.FieldModification = cbFieldModification; + eventCallbacks.MethodEntry = cbMethodEntry; + eventCallbacks.MethodExit = cbMethodExit; + eventCallbacks.NativeMethodBind = cbNativeMethodBind; + eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; + eventCallbacks.MonitorWait = cbMonitorWait; + eventCallbacks.MonitorWaited = cbMonitorWaited; + eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; + eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; + eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; + eventCallbacks.ObjectFree = cbObjectFree; + eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; + break; + + case 2: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.CompiledMethodLoad = cbNewCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = cbNewCompiledMethodUnload; + break; + + case 3: + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.VMDeath = cbVMDeath; + break; + + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + int i; + + for (i = 1; i <= STEP_AMOUNT; i++) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("Check received events\n"); + + if (i < STEP_AMOUNT) { + showEventStatistics(i); + if (!checkEvents(i)) + nsk_jvmti_setFailStatus(); + + if (!setCallBacks(i + 1)) { + return; + } + } + + if (!nsk_jvmti_resumeSync()) + return; + } + + /* checking amounts of COMPILED_METHOD_LOAD and COMPILED_METHOD_UNLOAD events */ + if (loadEvents < unloadEvents) { + NSK_COMPLAIN2("Number of JVMTI_EVENT_COMPILED_METHOD_LOAD events %d is less than number of JVMTI_EVENT_COMPILED_METHOD_UNLOAD %d", + loadEvents, + unloadEvents); + } +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em02t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em02t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em02t003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_generate_compiled_method_load_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + if (!setCallBacks(1)) { + return JNI_ERR; + } + + nsk_jvmti_showPossessedCapabilities(jvmti); + + if (!enableEventList()) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/libem02t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/libem02t003.c deleted file mode 100644 index b41d0f7a30e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/libem02t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em02t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/libem02t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/libem02t003.cpp new file mode 100644 index 00000000000..677ff22d6f3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/libem02t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em02t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/em02t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/em02t004.c deleted file mode 100644 index 8b50c85310d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/em02t004.c +++ /dev/null @@ -1,615 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define STEP_AMOUNT 3 -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) - -static int eventCount[JVMTI_EVENT_COUNT]; -static int newEventCount[JVMTI_EVENT_COUNT]; - -/* ============================================================================= */ -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_events_EM02_em02t004_nativeMethod1(JNIEnv *jni_env, - jobject this) { - NSK_DISPLAY0("called nativeMethod1\n"); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_events_EM02_em02t004_nativeMethod2(JNIEnv *jni_env, - jobject this) { - NSK_DISPLAY0("called nativeMethod2\n"); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_events_EM02_em02t004_nativeMethod3(JNIEnv *jni_env, - jobject this) { - NSK_DISPLAY0("called nativeMethod3\n"); -} - -static void -showEventStatistics(int step) { - int i; - const char* str; - int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("Event statistics for %d step:\n", step); - NSK_DISPLAY0("-----------------------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (currentCounts[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); - } - } -} - -/* ========================================================================== */ - -int checkEvents(int step) { - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int *currentCounts; - int isExpected = 0; - - switch (step) { - case 1: - currentCounts = &eventCount[0]; - break; - - case 2: - case 3: - currentCounts = &newEventCount[0]; - break; - - default: - NSK_COMPLAIN1("Unexpected step no: %d\n", step); - return NSK_FALSE; - } - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - - switch (step) { - case 1: - isExpected = ((curr == JVMTI_EVENT_NATIVE_METHOD_BIND) - || (curr == JVMTI_EVENT_VM_INIT)); - break; - - case 2: - isExpected = ((curr == JVMTI_EVENT_NATIVE_METHOD_BIND)); - break; - - case 3: - isExpected = (curr == JVMTI_EVENT_VM_DEATH); - break; - } - - if (isExpected) { - if (currentCounts[i] < 1) { - NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", - currentCounts[i], - TranslateEvent(curr)); - result = NSK_FALSE; - } - } else { - if (currentCounts[i] > 0) { - NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", - TranslateEvent(curr), - currentCounts[i]); - result = NSK_FALSE; - } - } - } - - return result; -} - -static void -changeCount(jvmtiEvent event, int *currentCounts) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/* callbacks */ -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { - changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { - changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); - showEventStatistics(STEP_AMOUNT); - if (!checkEvents(STEP_AMOUNT)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -void JNICALL -cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); -} - -void JNICALL -cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); -} - -void JNICALL -cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); -} - -void JNICALL -cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); -} - -void JNICALL -cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); -} - -void JNICALL -cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); -} - -void JNICALL -cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); -} - -void JNICALL -cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); -} - -void JNICALL -cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); -} - -void JNICALL -cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jlong tout) { - - changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); -} - -void JNICALL -cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jboolean timed_out) { - - changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); -} - -void JNICALL -cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { - - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); -} - -void JNICALL -cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); -} - -void JNICALL -cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); -} - -void JNICALL -cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - - char *name; - char *sign; - char *genc; - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE) { - return; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5( - GetMethodName, jvmti_env, method, &name, &sign, &genc))) { - return; - } - - if (!strcmp(name,"nativeMethod1")) { - NSK_DISPLAY0("NATIVE_METHOD_BIND recieved for\n"); - NSK_DISPLAY4("\tmethod: %s, signature: %s address: %p new_address: %p\n", - name, sign, address, new_address_ptr); - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)name))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)sign))) { - nsk_jvmti_setFailStatus(); - } - if (genc != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)genc))) { - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbNewNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - char *name; - char *sign; - char *genc; - - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE) { - return; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5( - GetMethodName, jvmti_env, method, &name, &sign, &genc))) { - return; - } - - if (!strcmp(name,"nativeMethod2")) { - NSK_DISPLAY0("NATIVE_METHOD_BIND recieved for\n"); - NSK_DISPLAY4("\tmethod: %s, signature: %s address: %p new_address: %p\n", - name, sign, address, new_address_ptr); - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &newEventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)name))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)sign))) { - nsk_jvmti_setFailStatus(); - } - if (genc != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)genc))) { - nsk_jvmti_setFailStatus(); - } -} - -/* ============================================================================= */ - -static int enableEvent(jvmtiEvent event) { - - if (nsk_jvmti_isOptionalEvent(event) - && (event != JVMTI_EVENT_NATIVE_METHOD_BIND)) { - if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } else { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } - - return NSK_TRUE; -} - -/** - * Enable or disable tested events. - */ -static int enableEventList() { - int i; - int result = NSK_TRUE; - - NSK_DISPLAY0("Enable events\n"); - - result = enableEvent(JVMTI_EVENT_VM_INIT); - - result = result && enableEvent(JVMTI_EVENT_VM_DEATH); - - /* enabling optional events */ - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); - - if (nsk_jvmti_isOptionalEvent(event)) - result = result && enableEvent(event); - } - - if (result == NSK_FALSE) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -static int -setCallBacks(int step) { - - int i; - - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("===============step %d===============\n", step); - NSK_DISPLAY0("\n"); - switch (step) { - case 1: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - eventCount[i] = 0; - } - - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.Exception = cbException; - eventCallbacks.ExceptionCatch = cbExceptionCatch; - eventCallbacks.SingleStep = cbSingleStep; - eventCallbacks.FramePop = cbFramePop; - eventCallbacks.Breakpoint = cbBreakpoint; - eventCallbacks.FieldAccess = cbFieldAccess; - eventCallbacks.FieldModification = cbFieldModification; - eventCallbacks.MethodEntry = cbMethodEntry; - eventCallbacks.MethodExit = cbMethodExit; - eventCallbacks.NativeMethodBind = cbNativeMethodBind; - eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; - eventCallbacks.MonitorWait = cbMonitorWait; - eventCallbacks.MonitorWaited = cbMonitorWaited; - eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; - eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; - eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; - eventCallbacks.ObjectFree = cbObjectFree; - eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; - break; - - case 2: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.NativeMethodBind = cbNewNativeMethodBind; - break; - - case 3: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.VMDeath = cbVMDeath; - break; - - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - int i; - - for (i = 1; i <= STEP_AMOUNT; i++) { - if (i > 1) { - NSK_DISPLAY0("Check received events\n"); - - showEventStatistics(i-1); - if (!checkEvents(i-1)) - nsk_jvmti_setFailStatus(); - - if (!setCallBacks(i)) { - return; - } - - if (!nsk_jvmti_resumeSync()) - return; - } - - NSK_DISPLAY0("Wait for debuggee to become ready\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - } - - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em02t004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em02t004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em02t004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_generate_native_method_bind_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - if (!setCallBacks(1)) { - return JNI_ERR; - } - - nsk_jvmti_showPossessedCapabilities(jvmti); - - if (!enableEventList()) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/em02t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/em02t004.cpp new file mode 100644 index 00000000000..9e2c64e2ba2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/em02t004.cpp @@ -0,0 +1,615 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define STEP_AMOUNT 3 +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) + +static int eventCount[JVMTI_EVENT_COUNT]; +static int newEventCount[JVMTI_EVENT_COUNT]; + +/* ============================================================================= */ +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_events_EM02_em02t004_nativeMethod1(JNIEnv *jni_env, + jobject o) { + NSK_DISPLAY0("called nativeMethod1\n"); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_events_EM02_em02t004_nativeMethod2(JNIEnv *jni_env, + jobject o) { + NSK_DISPLAY0("called nativeMethod2\n"); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_events_EM02_em02t004_nativeMethod3(JNIEnv *jni_env, + jobject o) { + NSK_DISPLAY0("called nativeMethod3\n"); +} + +static void +showEventStatistics(int step) { + int i; + const char* str; + int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("Event statistics for %d step:\n", step); + NSK_DISPLAY0("-----------------------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (currentCounts[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); + } + } +} + +/* ========================================================================== */ + +int checkEvents(int step) { + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int *currentCounts; + int isExpected = 0; + + switch (step) { + case 1: + currentCounts = &eventCount[0]; + break; + + case 2: + case 3: + currentCounts = &newEventCount[0]; + break; + + default: + NSK_COMPLAIN1("Unexpected step no: %d\n", step); + return NSK_FALSE; + } + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + + switch (step) { + case 1: + isExpected = ((curr == JVMTI_EVENT_NATIVE_METHOD_BIND) + || (curr == JVMTI_EVENT_VM_INIT)); + break; + + case 2: + isExpected = ((curr == JVMTI_EVENT_NATIVE_METHOD_BIND)); + break; + + case 3: + isExpected = (curr == JVMTI_EVENT_VM_DEATH); + break; + } + + if (isExpected) { + if (currentCounts[i] < 1) { + NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", + currentCounts[i], + TranslateEvent(curr)); + result = NSK_FALSE; + } + } else { + if (currentCounts[i] > 0) { + NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", + TranslateEvent(curr), + currentCounts[i]); + result = NSK_FALSE; + } + } + } + + return result; +} + +static void +changeCount(jvmtiEvent event, int *currentCounts) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/* callbacks */ +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { + changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { + changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); + showEventStatistics(STEP_AMOUNT); + if (!checkEvents(STEP_AMOUNT)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +void JNICALL +cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); +} + +void JNICALL +cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); +} + +void JNICALL +cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); +} + +void JNICALL +cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); +} + +void JNICALL +cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); +} + +void JNICALL +cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); +} + +void JNICALL +cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); +} + +void JNICALL +cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); +} + +void JNICALL +cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); +} + +void JNICALL +cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jlong tout) { + + changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); +} + +void JNICALL +cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jboolean timed_out) { + + changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); +} + +void JNICALL +cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { + + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); +} + +void JNICALL +cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); +} + +void JNICALL +cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); +} + +void JNICALL +cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + + char *name; + char *sign; + char *genc; + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE) { + return; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5( + GetMethodName, jvmti_env, method, &name, &sign, &genc))) { + return; + } + + if (!strcmp(name,"nativeMethod1")) { + NSK_DISPLAY0("NATIVE_METHOD_BIND recieved for\n"); + NSK_DISPLAY4("\tmethod: %s, signature: %s address: %p new_address: %p\n", + name, sign, address, new_address_ptr); + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)name))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)sign))) { + nsk_jvmti_setFailStatus(); + } + if (genc != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)genc))) { + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbNewNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + char *name; + char *sign; + char *genc; + + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE) { + return; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5( + GetMethodName, jvmti_env, method, &name, &sign, &genc))) { + return; + } + + if (!strcmp(name,"nativeMethod2")) { + NSK_DISPLAY0("NATIVE_METHOD_BIND recieved for\n"); + NSK_DISPLAY4("\tmethod: %s, signature: %s address: %p new_address: %p\n", + name, sign, address, new_address_ptr); + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &newEventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)name))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)sign))) { + nsk_jvmti_setFailStatus(); + } + if (genc != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)genc))) { + nsk_jvmti_setFailStatus(); + } +} + +/* ============================================================================= */ + +static int enableEvent(jvmtiEvent event) { + + if (nsk_jvmti_isOptionalEvent(event) + && (event != JVMTI_EVENT_NATIVE_METHOD_BIND)) { + if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } else { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } + + return NSK_TRUE; +} + +/** + * Enable or disable tested events. + */ +static int enableEventList() { + int i; + int result = NSK_TRUE; + + NSK_DISPLAY0("Enable events\n"); + + result = enableEvent(JVMTI_EVENT_VM_INIT); + + result = result && enableEvent(JVMTI_EVENT_VM_DEATH); + + /* enabling optional events */ + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); + + if (nsk_jvmti_isOptionalEvent(event)) + result = result && enableEvent(event); + } + + if (result == NSK_FALSE) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +static int +setCallBacks(int step) { + + int i; + + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("===============step %d===============\n", step); + NSK_DISPLAY0("\n"); + switch (step) { + case 1: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + eventCount[i] = 0; + } + + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.Exception = cbException; + eventCallbacks.ExceptionCatch = cbExceptionCatch; + eventCallbacks.SingleStep = cbSingleStep; + eventCallbacks.FramePop = cbFramePop; + eventCallbacks.Breakpoint = cbBreakpoint; + eventCallbacks.FieldAccess = cbFieldAccess; + eventCallbacks.FieldModification = cbFieldModification; + eventCallbacks.MethodEntry = cbMethodEntry; + eventCallbacks.MethodExit = cbMethodExit; + eventCallbacks.NativeMethodBind = cbNativeMethodBind; + eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; + eventCallbacks.MonitorWait = cbMonitorWait; + eventCallbacks.MonitorWaited = cbMonitorWaited; + eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; + eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; + eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; + eventCallbacks.ObjectFree = cbObjectFree; + eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; + break; + + case 2: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.NativeMethodBind = cbNewNativeMethodBind; + break; + + case 3: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.VMDeath = cbVMDeath; + break; + + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + int i; + + for (i = 1; i <= STEP_AMOUNT; i++) { + if (i > 1) { + NSK_DISPLAY0("Check received events\n"); + + showEventStatistics(i-1); + if (!checkEvents(i-1)) + nsk_jvmti_setFailStatus(); + + if (!setCallBacks(i)) { + return; + } + + if (!nsk_jvmti_resumeSync()) + return; + } + + NSK_DISPLAY0("Wait for debuggee to become ready\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + } + + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em02t004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em02t004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em02t004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_generate_native_method_bind_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + if (!setCallBacks(1)) { + return JNI_ERR; + } + + nsk_jvmti_showPossessedCapabilities(jvmti); + + if (!enableEventList()) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/libem02t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/libem02t004.c deleted file mode 100644 index 12c7c87c16d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/libem02t004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em02t004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/libem02t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/libem02t004.cpp new file mode 100644 index 00000000000..a09d51ae22c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t004/libem02t004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em02t004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/em02t005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/em02t005.c deleted file mode 100644 index 2f7e87ea8fe..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/em02t005.c +++ /dev/null @@ -1,592 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define STEP_NUMBER 3 -#define EXPECTED_CLASS_NAME "Lnsk/jvmti/scenarios/events/EM02/em02t005a;" -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) -#define NUMBER_OF_INVOCATIONS 1000 - -static int eventCount[JVMTI_EVENT_COUNT]; -static int newEventCount[JVMTI_EVENT_COUNT]; - -/* ============================================================================= */ - -static void -showEventStatistics(int step) { - int i; - const char* str; - int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("Event statistics for %d step:\n", step); - NSK_DISPLAY0("-----------------------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (currentCounts[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); - } - } -} - -/* ========================================================================== */ - -int checkEvents(int step) { - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int *currentCounts; - int isExpected = 0; - - switch (step) { - case 1: - currentCounts = &eventCount[0]; - break; - - case 2: - case 3: - currentCounts = &newEventCount[0]; - break; - - default: - NSK_COMPLAIN1("Unexpected step no: %d\n", step); - return NSK_FALSE; - } - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - - switch (step) { - case 1: - isExpected = ((curr == JVMTI_EVENT_VM_INIT) - || (curr == JVMTI_EVENT_VM_OBJECT_ALLOC)); - break; - - case 2: - isExpected = (curr == JVMTI_EVENT_VM_OBJECT_ALLOC); - break; - - case 3: - isExpected = (curr == JVMTI_EVENT_VM_DEATH); - break; - } - - if (isExpected) { - if (currentCounts[i] < 0) { - NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be non-negative\n", - currentCounts[i], - TranslateEvent(curr)); - result = NSK_FALSE; - } - - } else { - - if (currentCounts[i] > 0) { - NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", - TranslateEvent(curr), - currentCounts[i]); - result = NSK_FALSE; - } - } - } - - return result; -} - -static void -changeCount(jvmtiEvent event, int *currentCounts) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/* callbacks */ -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { - changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { - changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); - showEventStatistics(STEP_NUMBER); - if (!checkEvents(STEP_NUMBER)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -void JNICALL -cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - - changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); -} - -void JNICALL -cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - - changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); -} - -void JNICALL -cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); -} - -void JNICALL -cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); -} - -void JNICALL -cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); -} - -void JNICALL -cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - - changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); -} - -void JNICALL -cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - - changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); -} - -void JNICALL -cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - - changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); -} - -void JNICALL -cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - - changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); -} - -void JNICALL -cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); -} - -void JNICALL -cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jlong tout) { - - changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); -} - -void JNICALL -cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jboolean timed_out) { - - changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); -} - -void JNICALL -cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); -} - -void JNICALL -cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - - changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); -} - -void JNICALL -cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - char *sign_ptr; - char *gen_ptr; - - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, object_klass, - &sign_ptr, &gen_ptr))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (strcmp(sign_ptr, EXPECTED_CLASS_NAME) == 0) { - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if (phase != JVMTI_PHASE_LIVE) { - NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n", - TranslateEvent(JVMTI_EVENT_VM_OBJECT_ALLOC), - TranslatePhase(phase), - phase, - sign_ptr); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)sign_ptr))) { - nsk_jvmti_setFailStatus(); - } - if (gen_ptr != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)gen_ptr))) { - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbNewVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - char *sign_ptr; - char *gen_ptr; - - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, object_klass, - &sign_ptr, &gen_ptr))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (strcmp(sign_ptr, EXPECTED_CLASS_NAME) == 0) { - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &newEventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - } - - if (phase != JVMTI_PHASE_LIVE) { - NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n", - TranslateEvent(JVMTI_EVENT_VM_OBJECT_ALLOC), - TranslatePhase(phase), - phase, - sign_ptr); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)sign_ptr))) { - nsk_jvmti_setFailStatus(); - } - if (gen_ptr != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)gen_ptr))) { - nsk_jvmti_setFailStatus(); - } -} - -/* ============================================================================= */ - -static int enableEvent(jvmtiEvent event) { - - if (nsk_jvmti_isOptionalEvent(event) - && (event != JVMTI_EVENT_VM_OBJECT_ALLOC)) { - if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } else { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } - - return NSK_TRUE; -} - -/** - * Enable or disable tested events. - */ -static int enableEventList() { - - int i, result; - - result = enableEvent(JVMTI_EVENT_VM_INIT); - - result = result && enableEvent(JVMTI_EVENT_VM_DEATH); - - /* enabling optional events */ - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); - - if (nsk_jvmti_isOptionalEvent(event)) - result = result && enableEvent(event); - } - - if (result == NSK_FALSE) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -static int -setCallBacks(int step) { - - int i; - - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - switch (step) { - case 1: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - eventCount[i] = 0; - } - - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.Exception = cbException; - eventCallbacks.ExceptionCatch = cbExceptionCatch; - eventCallbacks.SingleStep = cbSingleStep; - eventCallbacks.FramePop = cbFramePop; - eventCallbacks.Breakpoint = cbBreakpoint; - eventCallbacks.FieldAccess = cbFieldAccess; - eventCallbacks.FieldModification = cbFieldModification; - eventCallbacks.MethodEntry = cbMethodEntry; - eventCallbacks.MethodExit = cbMethodExit; - eventCallbacks.NativeMethodBind = cbNativeMethodBind; - eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; - eventCallbacks.MonitorWait = cbMonitorWait; - eventCallbacks.MonitorWaited = cbMonitorWaited; - eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; - eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; - eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; - eventCallbacks.ObjectFree = cbObjectFree; - eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; - break; - - case 2: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.VMObjectAlloc = cbNewVMObjectAlloc; - break; - - case 3: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.VMDeath = cbVMDeath; - break; - - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - int i; - - for (i = 1; i <= STEP_NUMBER; i++) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (i < STEP_NUMBER) { - showEventStatistics(i); - if (!checkEvents(i)) - nsk_jvmti_setFailStatus(); - - if (!setCallBacks(i + 1)) { - return; - } - } - - if (!nsk_jvmti_resumeSync()) - return; - } - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em02t005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em02t005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em02t005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_generate_vm_object_alloc_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - if (!setCallBacks(1)) { - return JNI_ERR; - } - - if (!enableEventList()) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/em02t005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/em02t005.cpp new file mode 100644 index 00000000000..8acb13c444f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/em02t005.cpp @@ -0,0 +1,592 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define STEP_NUMBER 3 +#define EXPECTED_CLASS_NAME "Lnsk/jvmti/scenarios/events/EM02/em02t005a;" +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) +#define NUMBER_OF_INVOCATIONS 1000 + +static int eventCount[JVMTI_EVENT_COUNT]; +static int newEventCount[JVMTI_EVENT_COUNT]; + +/* ============================================================================= */ + +static void +showEventStatistics(int step) { + int i; + const char* str; + int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("Event statistics for %d step:\n", step); + NSK_DISPLAY0("-----------------------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (currentCounts[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); + } + } +} + +/* ========================================================================== */ + +int checkEvents(int step) { + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int *currentCounts; + int isExpected = 0; + + switch (step) { + case 1: + currentCounts = &eventCount[0]; + break; + + case 2: + case 3: + currentCounts = &newEventCount[0]; + break; + + default: + NSK_COMPLAIN1("Unexpected step no: %d\n", step); + return NSK_FALSE; + } + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + + switch (step) { + case 1: + isExpected = ((curr == JVMTI_EVENT_VM_INIT) + || (curr == JVMTI_EVENT_VM_OBJECT_ALLOC)); + break; + + case 2: + isExpected = (curr == JVMTI_EVENT_VM_OBJECT_ALLOC); + break; + + case 3: + isExpected = (curr == JVMTI_EVENT_VM_DEATH); + break; + } + + if (isExpected) { + if (currentCounts[i] < 0) { + NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be non-negative\n", + currentCounts[i], + TranslateEvent(curr)); + result = NSK_FALSE; + } + + } else { + + if (currentCounts[i] > 0) { + NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", + TranslateEvent(curr), + currentCounts[i]); + result = NSK_FALSE; + } + } + } + + return result; +} + +static void +changeCount(jvmtiEvent event, int *currentCounts) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/* callbacks */ +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { + changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { + changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); + showEventStatistics(STEP_NUMBER); + if (!checkEvents(STEP_NUMBER)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +void JNICALL +cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + + changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); +} + +void JNICALL +cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + + changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); +} + +void JNICALL +cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); +} + +void JNICALL +cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); +} + +void JNICALL +cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); +} + +void JNICALL +cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + + changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); +} + +void JNICALL +cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + + changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); +} + +void JNICALL +cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + + changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); +} + +void JNICALL +cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + + changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); +} + +void JNICALL +cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); +} + +void JNICALL +cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jlong tout) { + + changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); +} + +void JNICALL +cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jboolean timed_out) { + + changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); +} + +void JNICALL +cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); +} + +void JNICALL +cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + + changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); +} + +void JNICALL +cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + char *sign_ptr; + char *gen_ptr; + + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, object_klass, + &sign_ptr, &gen_ptr))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (strcmp(sign_ptr, EXPECTED_CLASS_NAME) == 0) { + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if (phase != JVMTI_PHASE_LIVE) { + NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n", + TranslateEvent(JVMTI_EVENT_VM_OBJECT_ALLOC), + TranslatePhase(phase), + phase, + sign_ptr); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)sign_ptr))) { + nsk_jvmti_setFailStatus(); + } + if (gen_ptr != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)gen_ptr))) { + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbNewVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + char *sign_ptr; + char *gen_ptr; + + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, object_klass, + &sign_ptr, &gen_ptr))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (strcmp(sign_ptr, EXPECTED_CLASS_NAME) == 0) { + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &newEventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + } + + if (phase != JVMTI_PHASE_LIVE) { + NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n", + TranslateEvent(JVMTI_EVENT_VM_OBJECT_ALLOC), + TranslatePhase(phase), + phase, + sign_ptr); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)sign_ptr))) { + nsk_jvmti_setFailStatus(); + } + if (gen_ptr != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)gen_ptr))) { + nsk_jvmti_setFailStatus(); + } +} + +/* ============================================================================= */ + +static int enableEvent(jvmtiEvent event) { + + if (nsk_jvmti_isOptionalEvent(event) + && (event != JVMTI_EVENT_VM_OBJECT_ALLOC)) { + if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } else { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } + + return NSK_TRUE; +} + +/** + * Enable or disable tested events. + */ +static int enableEventList() { + + int i, result; + + result = enableEvent(JVMTI_EVENT_VM_INIT); + + result = result && enableEvent(JVMTI_EVENT_VM_DEATH); + + /* enabling optional events */ + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); + + if (nsk_jvmti_isOptionalEvent(event)) + result = result && enableEvent(event); + } + + if (result == NSK_FALSE) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +static int +setCallBacks(int step) { + + int i; + + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + switch (step) { + case 1: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + eventCount[i] = 0; + } + + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.Exception = cbException; + eventCallbacks.ExceptionCatch = cbExceptionCatch; + eventCallbacks.SingleStep = cbSingleStep; + eventCallbacks.FramePop = cbFramePop; + eventCallbacks.Breakpoint = cbBreakpoint; + eventCallbacks.FieldAccess = cbFieldAccess; + eventCallbacks.FieldModification = cbFieldModification; + eventCallbacks.MethodEntry = cbMethodEntry; + eventCallbacks.MethodExit = cbMethodExit; + eventCallbacks.NativeMethodBind = cbNativeMethodBind; + eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; + eventCallbacks.MonitorWait = cbMonitorWait; + eventCallbacks.MonitorWaited = cbMonitorWaited; + eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; + eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; + eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; + eventCallbacks.ObjectFree = cbObjectFree; + eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; + break; + + case 2: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.VMObjectAlloc = cbNewVMObjectAlloc; + break; + + case 3: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.VMDeath = cbVMDeath; + break; + + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + int i; + + for (i = 1; i <= STEP_NUMBER; i++) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (i < STEP_NUMBER) { + showEventStatistics(i); + if (!checkEvents(i)) + nsk_jvmti_setFailStatus(); + + if (!setCallBacks(i + 1)) { + return; + } + } + + if (!nsk_jvmti_resumeSync()) + return; + } + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em02t005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em02t005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em02t005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_generate_vm_object_alloc_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + if (!setCallBacks(1)) { + return JNI_ERR; + } + + if (!enableEventList()) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/libem02t005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/libem02t005.c deleted file mode 100644 index 457b1655622..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/libem02t005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em02t005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/libem02t005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/libem02t005.cpp new file mode 100644 index 00000000000..0ab6f22c801 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t005/libem02t005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em02t005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/em02t006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/em02t006.c deleted file mode 100644 index 04ac629f523..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/em02t006.c +++ /dev/null @@ -1,535 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define STEP_NUMBER 3 -#define OBJECT_NUMBER 100 -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) - -static int eventCount[JVMTI_EVENT_COUNT]; -static int newEventCount[JVMTI_EVENT_COUNT]; - -/* ============================================================================= */ - - -/* - * Class: nsk_jvmti_scenarios_events_EM02_em02t006 - * Method: setTag - * Signature: (Ljava/lang/Object;J)Z - */ -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_events_EM02_em02t006_setTag(JNIEnv *env, - jobject this, jobject object, jlong tag) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, object, tag))) { - NSK_COMPLAIN0("TEST FAILED: unable to set tag for a tested object\n"); - return NSK_FALSE; - } - return NSK_TRUE; -} - -static void -showEventStatistics(int step) { - int i; - const char* str; - int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("Event statistics for %d step:\n", step); - NSK_DISPLAY0("-----------------------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (currentCounts[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); - } - } -} - -/* ========================================================================== */ - -int checkEvents(int step) { - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int *currentCounts; - int isExpected = 0; - - switch (step) { - case 1: - currentCounts = &eventCount[0]; - break; - - case 2: - case 3: - currentCounts = &newEventCount[0]; - break; - - default: - NSK_COMPLAIN1("Unexpected step no: %d\n", step); - return NSK_FALSE; - } - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - - switch (step) { - case 1: - isExpected = ((curr == JVMTI_EVENT_OBJECT_FREE) - || (curr == JVMTI_EVENT_VM_INIT)); - break; - - case 2: - isExpected = (curr == JVMTI_EVENT_OBJECT_FREE); - break; - - case 3: - isExpected = (curr == JVMTI_EVENT_VM_DEATH); - break; - } - - if (isExpected) { - if (currentCounts[i] < 0 || currentCounts[i] > OBJECT_NUMBER) { - NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", - currentCounts[i], - TranslateEvent(curr)); - result = NSK_FALSE; - } - } else { - - if (currentCounts[i] > 0) { - NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", - TranslateEvent(curr), - currentCounts[i]); - result = NSK_FALSE; - } - } - } - - return result; -} - -static void -changeCount(jvmtiEvent event, int *currentCounts) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/* callbacks */ -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { - changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { - changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); - showEventStatistics(STEP_NUMBER); - if (!checkEvents(STEP_NUMBER)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -void JNICALL -cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); -} - -void JNICALL -cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); -} - -void JNICALL -cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); -} - -void JNICALL -cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); -} - -void JNICALL -cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); -} - -void JNICALL -cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); -} - -void JNICALL -cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); -} - -void JNICALL -cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); -} - -void JNICALL -cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); -} - -void JNICALL -cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); -} - -void JNICALL -cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jlong tout) { - - changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); -} - -void JNICALL -cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jboolean timed_out) { - - changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); -} - -void JNICALL -cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); -} - -void JNICALL -cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - - changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); - if (tag < 1 || tag > OBJECT_NUMBER) { - NSK_COMPLAIN1("Unexpected tag value %lld\n", tag); - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbNewObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - - changeCount(JVMTI_EVENT_OBJECT_FREE, &newEventCount[0]); - if (tag < 1 || tag > OBJECT_NUMBER) { - NSK_COMPLAIN1("Unexpected tag value %lld\n", tag); - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); -} - -/* ============================================================================= */ - -static int enableEvent(jvmtiEvent event) { - - if (nsk_jvmti_isOptionalEvent(event) - && (event != JVMTI_EVENT_OBJECT_FREE)) { - if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } else { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } - - return NSK_TRUE; -} - -/** - * Enable or disable tested events. - */ -static int enableEventList() { - - int i, result; - - result = enableEvent(JVMTI_EVENT_VM_INIT); - - result = result && enableEvent(JVMTI_EVENT_VM_DEATH); - - /* enabling optional events */ - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); - - if (nsk_jvmti_isOptionalEvent(event)) - result = result && enableEvent(event); - } - - if (result == NSK_FALSE) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -static int -setCallBacks(int step) { - - int i; - - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - switch (step) { - case 1: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - eventCount[i] = 0; - } - - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.Exception = cbException; - eventCallbacks.ExceptionCatch = cbExceptionCatch; - eventCallbacks.SingleStep = cbSingleStep; - eventCallbacks.FramePop = cbFramePop; - eventCallbacks.Breakpoint = cbBreakpoint; - eventCallbacks.FieldAccess = cbFieldAccess; - eventCallbacks.FieldModification = cbFieldModification; - eventCallbacks.MethodEntry = cbMethodEntry; - eventCallbacks.MethodExit = cbMethodExit; - eventCallbacks.NativeMethodBind = cbNativeMethodBind; - eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; - eventCallbacks.MonitorWait = cbMonitorWait; - eventCallbacks.MonitorWaited = cbMonitorWaited; - eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; - eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; - eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; - eventCallbacks.ObjectFree = cbObjectFree; - eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; - break; - - case 2: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.ObjectFree = cbNewObjectFree; - break; - - case 3: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.VMDeath = cbVMDeath; - break; - - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - int i; - - for (i = 1; i <= STEP_NUMBER; i++) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("Check received events\n"); - - if (i < STEP_NUMBER) { - showEventStatistics(i); - if (!checkEvents(i)) - nsk_jvmti_setFailStatus(); - - if (!setCallBacks(i + 1)) { - return; - } - } - - if (!nsk_jvmti_resumeSync()) - return; - } - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em02t006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em02t006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em02t006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_tag_objects = 1; - caps.can_generate_object_free_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - if (!setCallBacks(1)) { - return JNI_ERR; - } - - if (!enableEventList()) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/em02t006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/em02t006.cpp new file mode 100644 index 00000000000..f8d053600e5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/em02t006.cpp @@ -0,0 +1,535 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define STEP_NUMBER 3 +#define OBJECT_NUMBER 100 +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) + +static int eventCount[JVMTI_EVENT_COUNT]; +static int newEventCount[JVMTI_EVENT_COUNT]; + +/* ============================================================================= */ + + +/* + * Class: nsk_jvmti_scenarios_events_EM02_em02t006 + * Method: setTag + * Signature: (Ljava/lang/Object;J)Z + */ +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_events_EM02_em02t006_setTag(JNIEnv *env, + jobject o, jobject object, jlong tag) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, object, tag))) { + NSK_COMPLAIN0("TEST FAILED: unable to set tag for a tested object\n"); + return NSK_FALSE; + } + return NSK_TRUE; +} + +static void +showEventStatistics(int step) { + int i; + const char* str; + int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("Event statistics for %d step:\n", step); + NSK_DISPLAY0("-----------------------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (currentCounts[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); + } + } +} + +/* ========================================================================== */ + +int checkEvents(int step) { + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int *currentCounts; + int isExpected = 0; + + switch (step) { + case 1: + currentCounts = &eventCount[0]; + break; + + case 2: + case 3: + currentCounts = &newEventCount[0]; + break; + + default: + NSK_COMPLAIN1("Unexpected step no: %d\n", step); + return NSK_FALSE; + } + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + + switch (step) { + case 1: + isExpected = ((curr == JVMTI_EVENT_OBJECT_FREE) + || (curr == JVMTI_EVENT_VM_INIT)); + break; + + case 2: + isExpected = (curr == JVMTI_EVENT_OBJECT_FREE); + break; + + case 3: + isExpected = (curr == JVMTI_EVENT_VM_DEATH); + break; + } + + if (isExpected) { + if (currentCounts[i] < 0 || currentCounts[i] > OBJECT_NUMBER) { + NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", + currentCounts[i], + TranslateEvent(curr)); + result = NSK_FALSE; + } + } else { + + if (currentCounts[i] > 0) { + NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", + TranslateEvent(curr), + currentCounts[i]); + result = NSK_FALSE; + } + } + } + + return result; +} + +static void +changeCount(jvmtiEvent event, int *currentCounts) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/* callbacks */ +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { + changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { + changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); + showEventStatistics(STEP_NUMBER); + if (!checkEvents(STEP_NUMBER)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +void JNICALL +cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); +} + +void JNICALL +cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); +} + +void JNICALL +cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); +} + +void JNICALL +cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); +} + +void JNICALL +cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); +} + +void JNICALL +cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); +} + +void JNICALL +cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); +} + +void JNICALL +cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); +} + +void JNICALL +cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); +} + +void JNICALL +cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); +} + +void JNICALL +cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jlong tout) { + + changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); +} + +void JNICALL +cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jboolean timed_out) { + + changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); +} + +void JNICALL +cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); +} + +void JNICALL +cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + + changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); + if (tag < 1 || tag > OBJECT_NUMBER) { + NSK_COMPLAIN1("Unexpected tag value %lld\n", tag); + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbNewObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + + changeCount(JVMTI_EVENT_OBJECT_FREE, &newEventCount[0]); + if (tag < 1 || tag > OBJECT_NUMBER) { + NSK_COMPLAIN1("Unexpected tag value %lld\n", tag); + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); +} + +/* ============================================================================= */ + +static int enableEvent(jvmtiEvent event) { + + if (nsk_jvmti_isOptionalEvent(event) + && (event != JVMTI_EVENT_OBJECT_FREE)) { + if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } else { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } + + return NSK_TRUE; +} + +/** + * Enable or disable tested events. + */ +static int enableEventList() { + + int i, result; + + result = enableEvent(JVMTI_EVENT_VM_INIT); + + result = result && enableEvent(JVMTI_EVENT_VM_DEATH); + + /* enabling optional events */ + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); + + if (nsk_jvmti_isOptionalEvent(event)) + result = result && enableEvent(event); + } + + if (result == NSK_FALSE) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +static int +setCallBacks(int step) { + + int i; + + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + switch (step) { + case 1: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + eventCount[i] = 0; + } + + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.Exception = cbException; + eventCallbacks.ExceptionCatch = cbExceptionCatch; + eventCallbacks.SingleStep = cbSingleStep; + eventCallbacks.FramePop = cbFramePop; + eventCallbacks.Breakpoint = cbBreakpoint; + eventCallbacks.FieldAccess = cbFieldAccess; + eventCallbacks.FieldModification = cbFieldModification; + eventCallbacks.MethodEntry = cbMethodEntry; + eventCallbacks.MethodExit = cbMethodExit; + eventCallbacks.NativeMethodBind = cbNativeMethodBind; + eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; + eventCallbacks.MonitorWait = cbMonitorWait; + eventCallbacks.MonitorWaited = cbMonitorWaited; + eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; + eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; + eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; + eventCallbacks.ObjectFree = cbObjectFree; + eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; + break; + + case 2: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.ObjectFree = cbNewObjectFree; + break; + + case 3: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.VMDeath = cbVMDeath; + break; + + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + int i; + + for (i = 1; i <= STEP_NUMBER; i++) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("Check received events\n"); + + if (i < STEP_NUMBER) { + showEventStatistics(i); + if (!checkEvents(i)) + nsk_jvmti_setFailStatus(); + + if (!setCallBacks(i + 1)) { + return; + } + } + + if (!nsk_jvmti_resumeSync()) + return; + } + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em02t006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em02t006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em02t006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_tag_objects = 1; + caps.can_generate_object_free_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + if (!setCallBacks(1)) { + return JNI_ERR; + } + + if (!enableEventList()) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/libem02t006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/libem02t006.c deleted file mode 100644 index 3403e379d0c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/libem02t006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em02t006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/libem02t006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/libem02t006.cpp new file mode 100644 index 00000000000..388187170ce --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t006/libem02t006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em02t006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/em02t007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/em02t007.c deleted file mode 100644 index 146303bbcaf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/em02t007.c +++ /dev/null @@ -1,580 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define STEP_NUMBER 3 -#define OBJECT_NUMBER 100 -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) - -static int eventCount[JVMTI_EVENT_COUNT]; -static int newEventCount[JVMTI_EVENT_COUNT]; -static int singleStepIdx = JVMTI_EVENT_SINGLE_STEP - JVMTI_MIN_EVENT_TYPE_VAL; - -/* ============================================================================= */ - - -static void -showEventStatistics(int step) { - int i; - const char* str; - int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("Event statistics for %d step:\n", step); - NSK_DISPLAY0("-----------------------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (currentCounts[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); - } - } -} - -/* ========================================================================== */ - -int checkEvents(int step) { - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int *currentCounts; - int isExpected = 0; - - switch (step) { - case 1: - currentCounts = &eventCount[0]; - break; - - case 2: - case 3: - currentCounts = &newEventCount[0]; - break; - - default: - NSK_COMPLAIN1("Unexpected step no: %d\n", step); - return NSK_FALSE; - } - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - - switch (step) { - case 1: - isExpected = ((curr == JVMTI_EVENT_VM_INIT) - || (curr == JVMTI_EVENT_SINGLE_STEP)); - break; - - case 2: - isExpected = (curr == JVMTI_EVENT_SINGLE_STEP); - break; - - case 3: - isExpected = (curr == JVMTI_EVENT_VM_DEATH); - break; - } - - if (isExpected) { - if (currentCounts[i] < 0) { - NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", - currentCounts[i], - TranslateEvent(curr)); - result = NSK_FALSE; - } - } else { - - if (currentCounts[i] > 0) { - NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", - TranslateEvent(curr), - currentCounts[i]); - result = NSK_FALSE; - } - } - } - - return result; -} - -static void -changeCount(jvmtiEvent event, int *currentCounts) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/* callbacks */ -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { - changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { - changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); - showEventStatistics(STEP_NUMBER); - if (!checkEvents(STEP_NUMBER)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -void JNICALL -cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); -} - -void JNICALL -cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); -} - -void JNICALL -cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - char *name; - char *sign; - char *genc; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5( - GetMethodName, jvmti_env, method, &name, &sign, &genc))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!strncmp(name,"javaMethod", 8)) { - NSK_DISPLAY2("\tMethod: %s, location: %lld\n", - name, location); - changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)name))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)sign))) { - nsk_jvmti_setFailStatus(); - } - if (genc != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)genc))) { - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbNewSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - char *name; - char *sign; - char *genc; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5( - GetMethodName, jvmti_env, method, &name, &sign, &genc))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!strncmp(name,"javaMethod", 8)) { - NSK_DISPLAY2("\tMethod: %s, location: %lld\n", - name, location); - changeCount(JVMTI_EVENT_SINGLE_STEP, &newEventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)name))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)sign))) { - nsk_jvmti_setFailStatus(); - } - if (genc != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)genc))) { - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); -} - -void JNICALL -cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); -} - -void JNICALL -cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); -} - -void JNICALL -cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); -} - -void JNICALL -cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); -} - -void JNICALL -cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); -} - -void JNICALL -cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); -} - -void JNICALL -cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jlong tout) { - - changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); -} - -void JNICALL -cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jboolean timed_out) { - - changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); -} - -void JNICALL -cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); -} - -void JNICALL -cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - - changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); - if (tag < 1 || tag > OBJECT_NUMBER) { - NSK_COMPLAIN1("Unexpected tag value %lld\n", tag); - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); -} - -/* ============================================================================= */ - -static int enableEvent(jvmtiEvent event) { - - if (nsk_jvmti_isOptionalEvent(event) - && (event != JVMTI_EVENT_SINGLE_STEP)) { - if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } else { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } - - return NSK_TRUE; -} - -/** - * Enable or disable tested events. - */ -static int enableEventList() { - - int i, result; - - result = enableEvent(JVMTI_EVENT_VM_INIT); - - result = result && enableEvent(JVMTI_EVENT_VM_DEATH); - - /* enabling optional events */ - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); - - if (nsk_jvmti_isOptionalEvent(event)) - result = result && enableEvent(event); - } - - if (result == NSK_FALSE) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -static int -setCallBacks(int step) { - - int i; - - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - switch (step) { - case 1: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - eventCount[i] = 0; - } - - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.Exception = cbException; - eventCallbacks.ExceptionCatch = cbExceptionCatch; - eventCallbacks.SingleStep = cbSingleStep; - eventCallbacks.FramePop = cbFramePop; - eventCallbacks.Breakpoint = cbBreakpoint; - eventCallbacks.FieldAccess = cbFieldAccess; - eventCallbacks.FieldModification = cbFieldModification; - eventCallbacks.MethodEntry = cbMethodEntry; - eventCallbacks.MethodExit = cbMethodExit; - eventCallbacks.NativeMethodBind = cbNativeMethodBind; - eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; - eventCallbacks.MonitorWait = cbMonitorWait; - eventCallbacks.MonitorWaited = cbMonitorWaited; - eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; - eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; - eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; - eventCallbacks.ObjectFree = cbObjectFree; - eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; - break; - - case 2: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.SingleStep = cbNewSingleStep; - break; - - case 3: - /* comparing number of JVMTI_EVENT_SINGLE_STEP events for steps*/ - if (eventCount[singleStepIdx] != newEventCount[singleStepIdx]) { - NSK_COMPLAIN2("Number of JVMTI_EVENT_SINGLE_STEP events must be the same\n\t1-st callback=%d; 2-nd callback=%d\n", - eventCount[singleStepIdx], - newEventCount[singleStepIdx]); - } - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.VMDeath = cbVMDeath; - break; - - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - int i; - - for (i = 1; i <= STEP_NUMBER; i++) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("Check received events\n"); - - if (i < STEP_NUMBER) { - showEventStatistics(i); - if (!checkEvents(i)) - nsk_jvmti_setFailStatus(); - - if (!setCallBacks(i + 1)) { - return; - } - } - - if (!nsk_jvmti_resumeSync()) - return; - } - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em02t007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em02t007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em02t007(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_generate_single_step_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - if (!setCallBacks(1)) { - return JNI_ERR; - } - - if (!enableEventList()) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/em02t007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/em02t007.cpp new file mode 100644 index 00000000000..7a2fe4cd071 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/em02t007.cpp @@ -0,0 +1,580 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define STEP_NUMBER 3 +#define OBJECT_NUMBER 100 +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) + +static int eventCount[JVMTI_EVENT_COUNT]; +static int newEventCount[JVMTI_EVENT_COUNT]; +static int singleStepIdx = JVMTI_EVENT_SINGLE_STEP - JVMTI_MIN_EVENT_TYPE_VAL; + +/* ============================================================================= */ + + +static void +showEventStatistics(int step) { + int i; + const char* str; + int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("Event statistics for %d step:\n", step); + NSK_DISPLAY0("-----------------------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (currentCounts[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); + } + } +} + +/* ========================================================================== */ + +int checkEvents(int step) { + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int *currentCounts; + int isExpected = 0; + + switch (step) { + case 1: + currentCounts = &eventCount[0]; + break; + + case 2: + case 3: + currentCounts = &newEventCount[0]; + break; + + default: + NSK_COMPLAIN1("Unexpected step no: %d\n", step); + return NSK_FALSE; + } + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + + switch (step) { + case 1: + isExpected = ((curr == JVMTI_EVENT_VM_INIT) + || (curr == JVMTI_EVENT_SINGLE_STEP)); + break; + + case 2: + isExpected = (curr == JVMTI_EVENT_SINGLE_STEP); + break; + + case 3: + isExpected = (curr == JVMTI_EVENT_VM_DEATH); + break; + } + + if (isExpected) { + if (currentCounts[i] < 0) { + NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", + currentCounts[i], + TranslateEvent(curr)); + result = NSK_FALSE; + } + } else { + + if (currentCounts[i] > 0) { + NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", + TranslateEvent(curr), + currentCounts[i]); + result = NSK_FALSE; + } + } + } + + return result; +} + +static void +changeCount(jvmtiEvent event, int *currentCounts) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/* callbacks */ +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { + changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { + changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); + showEventStatistics(STEP_NUMBER); + if (!checkEvents(STEP_NUMBER)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +void JNICALL +cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); +} + +void JNICALL +cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); +} + +void JNICALL +cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + char *name; + char *sign; + char *genc; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5( + GetMethodName, jvmti_env, method, &name, &sign, &genc))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!strncmp(name,"javaMethod", 8)) { + NSK_DISPLAY2("\tMethod: %s, location: %lld\n", + name, location); + changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)name))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)sign))) { + nsk_jvmti_setFailStatus(); + } + if (genc != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)genc))) { + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbNewSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + char *name; + char *sign; + char *genc; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5( + GetMethodName, jvmti_env, method, &name, &sign, &genc))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!strncmp(name,"javaMethod", 8)) { + NSK_DISPLAY2("\tMethod: %s, location: %lld\n", + name, location); + changeCount(JVMTI_EVENT_SINGLE_STEP, &newEventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)name))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)sign))) { + nsk_jvmti_setFailStatus(); + } + if (genc != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)genc))) { + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); +} + +void JNICALL +cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); +} + +void JNICALL +cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); +} + +void JNICALL +cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); +} + +void JNICALL +cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); +} + +void JNICALL +cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); +} + +void JNICALL +cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); +} + +void JNICALL +cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jlong tout) { + + changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); +} + +void JNICALL +cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jboolean timed_out) { + + changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); +} + +void JNICALL +cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); +} + +void JNICALL +cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + + changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); + if (tag < 1 || tag > OBJECT_NUMBER) { + NSK_COMPLAIN1("Unexpected tag value %lld\n", tag); + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); +} + +/* ============================================================================= */ + +static int enableEvent(jvmtiEvent event) { + + if (nsk_jvmti_isOptionalEvent(event) + && (event != JVMTI_EVENT_SINGLE_STEP)) { + if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } else { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } + + return NSK_TRUE; +} + +/** + * Enable or disable tested events. + */ +static int enableEventList() { + + int i, result; + + result = enableEvent(JVMTI_EVENT_VM_INIT); + + result = result && enableEvent(JVMTI_EVENT_VM_DEATH); + + /* enabling optional events */ + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); + + if (nsk_jvmti_isOptionalEvent(event)) + result = result && enableEvent(event); + } + + if (result == NSK_FALSE) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +static int +setCallBacks(int step) { + + int i; + + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + switch (step) { + case 1: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + eventCount[i] = 0; + } + + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.Exception = cbException; + eventCallbacks.ExceptionCatch = cbExceptionCatch; + eventCallbacks.SingleStep = cbSingleStep; + eventCallbacks.FramePop = cbFramePop; + eventCallbacks.Breakpoint = cbBreakpoint; + eventCallbacks.FieldAccess = cbFieldAccess; + eventCallbacks.FieldModification = cbFieldModification; + eventCallbacks.MethodEntry = cbMethodEntry; + eventCallbacks.MethodExit = cbMethodExit; + eventCallbacks.NativeMethodBind = cbNativeMethodBind; + eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; + eventCallbacks.MonitorWait = cbMonitorWait; + eventCallbacks.MonitorWaited = cbMonitorWaited; + eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; + eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; + eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; + eventCallbacks.ObjectFree = cbObjectFree; + eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; + break; + + case 2: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.SingleStep = cbNewSingleStep; + break; + + case 3: + /* comparing number of JVMTI_EVENT_SINGLE_STEP events for steps*/ + if (eventCount[singleStepIdx] != newEventCount[singleStepIdx]) { + NSK_COMPLAIN2("Number of JVMTI_EVENT_SINGLE_STEP events must be the same\n\t1-st callback=%d; 2-nd callback=%d\n", + eventCount[singleStepIdx], + newEventCount[singleStepIdx]); + } + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.VMDeath = cbVMDeath; + break; + + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + int i; + + for (i = 1; i <= STEP_NUMBER; i++) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("Check received events\n"); + + if (i < STEP_NUMBER) { + showEventStatistics(i); + if (!checkEvents(i)) + nsk_jvmti_setFailStatus(); + + if (!setCallBacks(i + 1)) { + return; + } + } + + if (!nsk_jvmti_resumeSync()) + return; + } + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em02t007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em02t007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em02t007(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_generate_single_step_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + if (!setCallBacks(1)) { + return JNI_ERR; + } + + if (!enableEventList()) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/libem02t007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/libem02t007.c deleted file mode 100644 index 29351430c24..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/libem02t007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em02t007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/libem02t007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/libem02t007.cpp new file mode 100644 index 00000000000..97b697865db --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t007/libem02t007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em02t007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/em02t008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/em02t008.c deleted file mode 100644 index 5270b0a4839..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/em02t008.c +++ /dev/null @@ -1,594 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define STEP_NUMBER 3 -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) - -static int eventCount[JVMTI_EVENT_COUNT]; -static int newEventCount[JVMTI_EVENT_COUNT]; - -/* ============================================================================= */ - -static void -showEventStatistics(int step) { - int i; - const char* str; - int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("Event statistics for %d step:\n", step); - NSK_DISPLAY0("-----------------------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (currentCounts[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); - } - } -} - -/* ========================================================================== */ - -int checkEvents(int step) { - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int *currentCounts; - int isExpected = 0; - - switch (step) { - case 1: - currentCounts = &eventCount[0]; - break; - - case 2: - case 3: - currentCounts = &newEventCount[0]; - break; - - default: - NSK_COMPLAIN1("Unexpected step no: %d\n", step); - return NSK_FALSE; - } - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - - switch (step) { - case 1: - isExpected = ((curr == JVMTI_EVENT_VM_INIT) - || (curr == JVMTI_EVENT_EXCEPTION) - || (curr == JVMTI_EVENT_EXCEPTION_CATCH)); - break; - - case 2: - isExpected = ((curr == JVMTI_EVENT_EXCEPTION) - || (curr == JVMTI_EVENT_EXCEPTION_CATCH)); - break; - - case 3: - isExpected = (curr == JVMTI_EVENT_VM_DEATH); - break; - } - - if (isExpected) { - if (currentCounts[i] < 1) { - NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", - currentCounts[i], - TranslateEvent(curr)); - result = NSK_FALSE; - } - } else { - - if (currentCounts[i] > 0) { - NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", - TranslateEvent(curr), - currentCounts[i]); - result = NSK_FALSE; - } - } - } - - return result; -} - -static void -changeCount(jvmtiEvent event, int *currentCounts) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/* callbacks */ -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { - changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { - changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); - showEventStatistics(STEP_NUMBER); - if (!checkEvents(STEP_NUMBER)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -void JNICALL -cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - - jvmtiThreadInfo info_ptr; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - GetThreadInfo, jvmti_env, thread, &info_ptr))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!strncmp(info_ptr.name,"em02t008", 8)) { - NSK_DISPLAY1("\tThread: %s\n", info_ptr.name); - - changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)info_ptr.name))) { - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbNewException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - - jvmtiThreadInfo info_ptr; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - GetThreadInfo, jvmti_env, thread, &info_ptr))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!strncmp(info_ptr.name,"em02t008", 8)) { - NSK_DISPLAY1("\tThread: %s\n", info_ptr.name); - - changeCount(JVMTI_EVENT_EXCEPTION, &newEventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)info_ptr.name))) { - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - - jvmtiThreadInfo info_ptr; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - GetThreadInfo, jvmti_env, thread, &info_ptr))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!strncmp(info_ptr.name,"em02t008", 8)) { - NSK_DISPLAY1("\tThread: %s\n", info_ptr.name); - - changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)info_ptr.name))) { - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbNewExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - - jvmtiThreadInfo info_ptr; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - GetThreadInfo, jvmti_env, thread, &info_ptr))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!strncmp(info_ptr.name,"em02t008", 8)) { - NSK_DISPLAY1("\tThread: %s\n", info_ptr.name); - - changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &newEventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)info_ptr.name))) { - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); -} - -void JNICALL -cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); -} - -void JNICALL -cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); -} - -void JNICALL -cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); -} - -void JNICALL -cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); -} - -void JNICALL -cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); -} - -void JNICALL -cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); -} - -void JNICALL -cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); -} - -void JNICALL -cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jlong tout) { - - changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); -} - -void JNICALL -cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jboolean timed_out) { - - changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); -} - -void JNICALL -cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); -} - -void JNICALL -cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - - changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); -} - -void JNICALL -cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); -} - -/* ============================================================================= */ - -static int enableEvent(jvmtiEvent event) { - - if (nsk_jvmti_isOptionalEvent(event) - && (event != JVMTI_EVENT_EXCEPTION) - && (event != JVMTI_EVENT_EXCEPTION_CATCH)) { - if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } else { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } - - return NSK_TRUE; -} - -/** - * Enable or disable tested events. - */ -static int enableEventList() { - - int i, result; - - result = enableEvent(JVMTI_EVENT_VM_INIT); - - result = result && enableEvent(JVMTI_EVENT_VM_DEATH); - - /* enabling optional events */ - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); - - if (nsk_jvmti_isOptionalEvent(event)) - result = result && enableEvent(event); - } - - if (result == NSK_FALSE) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -static int -setCallBacks(int step) { - - int i; - - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - switch (step) { - case 1: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - eventCount[i] = 0; - } - - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.Exception = cbException; - eventCallbacks.ExceptionCatch = cbExceptionCatch; - eventCallbacks.SingleStep = cbSingleStep; - eventCallbacks.FramePop = cbFramePop; - eventCallbacks.Breakpoint = cbBreakpoint; - eventCallbacks.FieldAccess = cbFieldAccess; - eventCallbacks.FieldModification = cbFieldModification; - eventCallbacks.MethodEntry = cbMethodEntry; - eventCallbacks.MethodExit = cbMethodExit; - eventCallbacks.NativeMethodBind = cbNativeMethodBind; - eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; - eventCallbacks.MonitorWait = cbMonitorWait; - eventCallbacks.MonitorWaited = cbMonitorWaited; - eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; - eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; - eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; - eventCallbacks.ObjectFree = cbObjectFree; - eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; - break; - - case 2: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.Exception = cbNewException; - eventCallbacks.ExceptionCatch = cbNewExceptionCatch; - break; - - case 3: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.VMDeath = cbVMDeath; - break; - - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - int i; - - for (i = 1; i <= STEP_NUMBER; i++) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (i < STEP_NUMBER) { - showEventStatistics(i); - if (!checkEvents(i)) - nsk_jvmti_setFailStatus(); - - if (!setCallBacks(i + 1)) { - return; - } - } - - if (!nsk_jvmti_resumeSync()) - return; - } - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em02t008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em02t008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em02t008(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_generate_exception_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - if (!setCallBacks(1)) { - return JNI_ERR; - } - - if (!enableEventList()) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/em02t008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/em02t008.cpp new file mode 100644 index 00000000000..a799a7dff06 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/em02t008.cpp @@ -0,0 +1,594 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define STEP_NUMBER 3 +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) + +static int eventCount[JVMTI_EVENT_COUNT]; +static int newEventCount[JVMTI_EVENT_COUNT]; + +/* ============================================================================= */ + +static void +showEventStatistics(int step) { + int i; + const char* str; + int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("Event statistics for %d step:\n", step); + NSK_DISPLAY0("-----------------------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (currentCounts[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); + } + } +} + +/* ========================================================================== */ + +int checkEvents(int step) { + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int *currentCounts; + int isExpected = 0; + + switch (step) { + case 1: + currentCounts = &eventCount[0]; + break; + + case 2: + case 3: + currentCounts = &newEventCount[0]; + break; + + default: + NSK_COMPLAIN1("Unexpected step no: %d\n", step); + return NSK_FALSE; + } + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + + switch (step) { + case 1: + isExpected = ((curr == JVMTI_EVENT_VM_INIT) + || (curr == JVMTI_EVENT_EXCEPTION) + || (curr == JVMTI_EVENT_EXCEPTION_CATCH)); + break; + + case 2: + isExpected = ((curr == JVMTI_EVENT_EXCEPTION) + || (curr == JVMTI_EVENT_EXCEPTION_CATCH)); + break; + + case 3: + isExpected = (curr == JVMTI_EVENT_VM_DEATH); + break; + } + + if (isExpected) { + if (currentCounts[i] < 1) { + NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", + currentCounts[i], + TranslateEvent(curr)); + result = NSK_FALSE; + } + } else { + + if (currentCounts[i] > 0) { + NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", + TranslateEvent(curr), + currentCounts[i]); + result = NSK_FALSE; + } + } + } + + return result; +} + +static void +changeCount(jvmtiEvent event, int *currentCounts) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/* callbacks */ +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { + changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { + changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); + showEventStatistics(STEP_NUMBER); + if (!checkEvents(STEP_NUMBER)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +void JNICALL +cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + + jvmtiThreadInfo info_ptr; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + GetThreadInfo, jvmti_env, thread, &info_ptr))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!strncmp(info_ptr.name,"em02t008", 8)) { + NSK_DISPLAY1("\tThread: %s\n", info_ptr.name); + + changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)info_ptr.name))) { + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbNewException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + + jvmtiThreadInfo info_ptr; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + GetThreadInfo, jvmti_env, thread, &info_ptr))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!strncmp(info_ptr.name,"em02t008", 8)) { + NSK_DISPLAY1("\tThread: %s\n", info_ptr.name); + + changeCount(JVMTI_EVENT_EXCEPTION, &newEventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)info_ptr.name))) { + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + + jvmtiThreadInfo info_ptr; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + GetThreadInfo, jvmti_env, thread, &info_ptr))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!strncmp(info_ptr.name,"em02t008", 8)) { + NSK_DISPLAY1("\tThread: %s\n", info_ptr.name); + + changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)info_ptr.name))) { + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbNewExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + + jvmtiThreadInfo info_ptr; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + GetThreadInfo, jvmti_env, thread, &info_ptr))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!strncmp(info_ptr.name,"em02t008", 8)) { + NSK_DISPLAY1("\tThread: %s\n", info_ptr.name); + + changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &newEventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)info_ptr.name))) { + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); +} + +void JNICALL +cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); +} + +void JNICALL +cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); +} + +void JNICALL +cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); +} + +void JNICALL +cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); +} + +void JNICALL +cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); +} + +void JNICALL +cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); +} + +void JNICALL +cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); +} + +void JNICALL +cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jlong tout) { + + changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); +} + +void JNICALL +cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jboolean timed_out) { + + changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); +} + +void JNICALL +cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); +} + +void JNICALL +cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + + changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); +} + +void JNICALL +cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); +} + +/* ============================================================================= */ + +static int enableEvent(jvmtiEvent event) { + + if (nsk_jvmti_isOptionalEvent(event) + && (event != JVMTI_EVENT_EXCEPTION) + && (event != JVMTI_EVENT_EXCEPTION_CATCH)) { + if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } else { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } + + return NSK_TRUE; +} + +/** + * Enable or disable tested events. + */ +static int enableEventList() { + + int i, result; + + result = enableEvent(JVMTI_EVENT_VM_INIT); + + result = result && enableEvent(JVMTI_EVENT_VM_DEATH); + + /* enabling optional events */ + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); + + if (nsk_jvmti_isOptionalEvent(event)) + result = result && enableEvent(event); + } + + if (result == NSK_FALSE) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +static int +setCallBacks(int step) { + + int i; + + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + switch (step) { + case 1: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + eventCount[i] = 0; + } + + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.Exception = cbException; + eventCallbacks.ExceptionCatch = cbExceptionCatch; + eventCallbacks.SingleStep = cbSingleStep; + eventCallbacks.FramePop = cbFramePop; + eventCallbacks.Breakpoint = cbBreakpoint; + eventCallbacks.FieldAccess = cbFieldAccess; + eventCallbacks.FieldModification = cbFieldModification; + eventCallbacks.MethodEntry = cbMethodEntry; + eventCallbacks.MethodExit = cbMethodExit; + eventCallbacks.NativeMethodBind = cbNativeMethodBind; + eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; + eventCallbacks.MonitorWait = cbMonitorWait; + eventCallbacks.MonitorWaited = cbMonitorWaited; + eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; + eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; + eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; + eventCallbacks.ObjectFree = cbObjectFree; + eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; + break; + + case 2: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.Exception = cbNewException; + eventCallbacks.ExceptionCatch = cbNewExceptionCatch; + break; + + case 3: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.VMDeath = cbVMDeath; + break; + + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + int i; + + for (i = 1; i <= STEP_NUMBER; i++) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (i < STEP_NUMBER) { + showEventStatistics(i); + if (!checkEvents(i)) + nsk_jvmti_setFailStatus(); + + if (!setCallBacks(i + 1)) { + return; + } + } + + if (!nsk_jvmti_resumeSync()) + return; + } + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em02t008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em02t008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em02t008(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_generate_exception_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + if (!setCallBacks(1)) { + return JNI_ERR; + } + + if (!enableEventList()) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/libem02t008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/libem02t008.c deleted file mode 100644 index d4b6d53ddac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/libem02t008.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em02t008.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/libem02t008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/libem02t008.cpp new file mode 100644 index 00000000000..a045a93e42f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t008/libem02t008.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em02t008.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/em02t009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/em02t009.c deleted file mode 100644 index 808a75a193e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/em02t009.c +++ /dev/null @@ -1,600 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define STEP_NUMBER 3 -#define NUMBER_OF_INVOCATIONS 1000 -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) - -static int eventCount[JVMTI_EVENT_COUNT]; -static int newEventCount[JVMTI_EVENT_COUNT]; - -/* ============================================================================= */ - -static void -showEventStatistics(int step) { - int i; - const char* str; - int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("Event statistics for %d step:\n", step); - NSK_DISPLAY0("-----------------------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (currentCounts[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); - } - } -} - -/* ========================================================================== */ - -int checkEvents(int step) { - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int *currentCounts; - int isExpected = 0; - - switch (step) { - case 1: - currentCounts = &eventCount[0]; - break; - - case 2: - case 3: - currentCounts = &newEventCount[0]; - break; - - default: - NSK_COMPLAIN1("Unexpected step no: %d\n", step); - return NSK_FALSE; - } - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - - switch (step) { - case 1: - isExpected = ((curr == JVMTI_EVENT_VM_INIT) - || (curr == JVMTI_EVENT_METHOD_ENTRY) - || (curr == JVMTI_EVENT_METHOD_EXIT)); - break; - - case 2: - isExpected = ((curr == JVMTI_EVENT_METHOD_ENTRY) - || (curr == JVMTI_EVENT_METHOD_EXIT)); - break; - - case 3: - isExpected = (curr == JVMTI_EVENT_VM_DEATH); - break; - } - - if (isExpected) { - if (curr == JVMTI_EVENT_VM_INIT || curr == JVMTI_EVENT_VM_DEATH) { - if (currentCounts[i] < 1) { - NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", - currentCounts[i], - TranslateEvent(curr)); - result = NSK_FALSE; - } - } else { - if (currentCounts[i] != NUMBER_OF_INVOCATIONS) { - NSK_COMPLAIN3("Unexpected number of %s events %d, expected value is %d\n", - TranslateEvent(curr), - currentCounts[i], - NUMBER_OF_INVOCATIONS); - result = NSK_FALSE; - } - } - } else { - - if (currentCounts[i] > 0) { - NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", - TranslateEvent(curr), - currentCounts[i]); - result = NSK_FALSE; - } - } - } - - return result; -} - -static void -changeCount(jvmtiEvent event, int *currentCounts) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/* callbacks */ -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { - changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { - changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); - showEventStatistics(STEP_NUMBER); - if (!checkEvents(STEP_NUMBER)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -void JNICALL -cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - - changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); -} - -void JNICALL -cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - - changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); -} - -void JNICALL -cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); -} - -void JNICALL -cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); -} - -void JNICALL -cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); -} - -void JNICALL -cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); -} - -void JNICALL -cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); -} - -void handler1(jvmtiEnv *jvmti_env, jvmtiEvent event, jmethodID method) { - - char *name; - char *sign; - char *genc; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5( - GetMethodName, jvmti_env, method, &name, &sign, &genc))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!strncmp(name,"javaMethod", 8)) { - changeCount(event, &eventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)name))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)sign))) { - nsk_jvmti_setFailStatus(); - } - if (genc != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)genc))) { - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - - handler1(jvmti_env, JVMTI_EVENT_METHOD_ENTRY, method); -} - -void JNICALL -cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - - handler1(jvmti_env, JVMTI_EVENT_METHOD_EXIT, method); -} - -void handler2(jvmtiEnv *jvmti_env, jvmtiEvent event, jmethodID method) { - - char *name; - char *sign; - char *genc; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5( - GetMethodName, jvmti_env, method, &name, &sign, &genc))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!strncmp(name,"javaMethod", 8)) { - changeCount(event, &newEventCount[0]); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)name))) { - nsk_jvmti_setFailStatus(); - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)sign))) { - nsk_jvmti_setFailStatus(); - } - if (genc != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)genc))) { - nsk_jvmti_setFailStatus(); - } -} - -void JNICALL -cbNewMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - - handler2(jvmti_env, JVMTI_EVENT_METHOD_ENTRY, method); -} - -void JNICALL -cbNewMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - - handler2(jvmti_env, JVMTI_EVENT_METHOD_EXIT, method); -} - -void JNICALL -cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); -} - -void JNICALL -cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jlong tout) { - - changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); -} - -void JNICALL -cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jboolean timed_out) { - - changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); -} - -void JNICALL -cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); -} - -void JNICALL -cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - - changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); -} - -void JNICALL -cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); -} - -/* ============================================================================= */ - -static int enableEvent(jvmtiEvent event) { - - if (nsk_jvmti_isOptionalEvent(event) - && (event != JVMTI_EVENT_METHOD_ENTRY) - && (event != JVMTI_EVENT_METHOD_EXIT)) { - if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } else { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } - - return NSK_TRUE; -} - -/** - * Enable or disable tested events. - */ -static int enableEventList() { - - int i, result; - - result = enableEvent(JVMTI_EVENT_VM_INIT); - - result = result && enableEvent(JVMTI_EVENT_VM_DEATH); - - /* enabling optional events */ - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); - - if (nsk_jvmti_isOptionalEvent(event)) - result = result && enableEvent(event); - } - - if (result == NSK_FALSE) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -static int -setCallBacks(int step) { - - int i; - - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - switch (step) { - case 1: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - eventCount[i] = 0; - } - - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.Exception = cbException; - eventCallbacks.ExceptionCatch = cbExceptionCatch; - eventCallbacks.SingleStep = cbSingleStep; - eventCallbacks.FramePop = cbFramePop; - eventCallbacks.Breakpoint = cbBreakpoint; - eventCallbacks.FieldAccess = cbFieldAccess; - eventCallbacks.FieldModification = cbFieldModification; - eventCallbacks.MethodEntry = cbMethodEntry; - eventCallbacks.MethodExit = cbMethodExit; - eventCallbacks.NativeMethodBind = cbNativeMethodBind; - eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; - eventCallbacks.MonitorWait = cbMonitorWait; - eventCallbacks.MonitorWaited = cbMonitorWaited; - eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; - eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; - eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; - eventCallbacks.ObjectFree = cbObjectFree; - eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; - break; - - case 2: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.MethodEntry = cbNewMethodEntry; - eventCallbacks.MethodExit = cbNewMethodExit; - break; - - case 3: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.VMDeath = cbVMDeath; - break; - - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - int i; - - for (i = 1; i <= STEP_NUMBER; i++) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (i < STEP_NUMBER) { - showEventStatistics(i); - if (!checkEvents(i)) - nsk_jvmti_setFailStatus(); - - if (!setCallBacks(i + 1)) { - return; - } - } - - if (!nsk_jvmti_resumeSync()) - return; - } - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em02t009(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em02t009(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em02t009(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_generate_method_entry_events = 1; - caps.can_generate_method_exit_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - if (!setCallBacks(1)) { - return JNI_ERR; - } - - if (!enableEventList()) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/em02t009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/em02t009.cpp new file mode 100644 index 00000000000..8aeb82f3a65 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/em02t009.cpp @@ -0,0 +1,600 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define STEP_NUMBER 3 +#define NUMBER_OF_INVOCATIONS 1000 +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) + +static int eventCount[JVMTI_EVENT_COUNT]; +static int newEventCount[JVMTI_EVENT_COUNT]; + +/* ============================================================================= */ + +static void +showEventStatistics(int step) { + int i; + const char* str; + int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("Event statistics for %d step:\n", step); + NSK_DISPLAY0("-----------------------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (currentCounts[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); + } + } +} + +/* ========================================================================== */ + +int checkEvents(int step) { + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int *currentCounts; + int isExpected = 0; + + switch (step) { + case 1: + currentCounts = &eventCount[0]; + break; + + case 2: + case 3: + currentCounts = &newEventCount[0]; + break; + + default: + NSK_COMPLAIN1("Unexpected step no: %d\n", step); + return NSK_FALSE; + } + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + + switch (step) { + case 1: + isExpected = ((curr == JVMTI_EVENT_VM_INIT) + || (curr == JVMTI_EVENT_METHOD_ENTRY) + || (curr == JVMTI_EVENT_METHOD_EXIT)); + break; + + case 2: + isExpected = ((curr == JVMTI_EVENT_METHOD_ENTRY) + || (curr == JVMTI_EVENT_METHOD_EXIT)); + break; + + case 3: + isExpected = (curr == JVMTI_EVENT_VM_DEATH); + break; + } + + if (isExpected) { + if (curr == JVMTI_EVENT_VM_INIT || curr == JVMTI_EVENT_VM_DEATH) { + if (currentCounts[i] < 1) { + NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", + currentCounts[i], + TranslateEvent(curr)); + result = NSK_FALSE; + } + } else { + if (currentCounts[i] != NUMBER_OF_INVOCATIONS) { + NSK_COMPLAIN3("Unexpected number of %s events %d, expected value is %d\n", + TranslateEvent(curr), + currentCounts[i], + NUMBER_OF_INVOCATIONS); + result = NSK_FALSE; + } + } + } else { + + if (currentCounts[i] > 0) { + NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", + TranslateEvent(curr), + currentCounts[i]); + result = NSK_FALSE; + } + } + } + + return result; +} + +static void +changeCount(jvmtiEvent event, int *currentCounts) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/* callbacks */ +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { + changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { + changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); + showEventStatistics(STEP_NUMBER); + if (!checkEvents(STEP_NUMBER)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +void JNICALL +cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + + changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); +} + +void JNICALL +cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + + changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); +} + +void JNICALL +cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); +} + +void JNICALL +cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); +} + +void JNICALL +cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); +} + +void JNICALL +cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); +} + +void JNICALL +cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); +} + +void handler1(jvmtiEnv *jvmti_env, jvmtiEvent event, jmethodID method) { + + char *name; + char *sign; + char *genc; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5( + GetMethodName, jvmti_env, method, &name, &sign, &genc))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!strncmp(name,"javaMethod", 8)) { + changeCount(event, &eventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)name))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)sign))) { + nsk_jvmti_setFailStatus(); + } + if (genc != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)genc))) { + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + + handler1(jvmti_env, JVMTI_EVENT_METHOD_ENTRY, method); +} + +void JNICALL +cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + + handler1(jvmti_env, JVMTI_EVENT_METHOD_EXIT, method); +} + +void handler2(jvmtiEnv *jvmti_env, jvmtiEvent event, jmethodID method) { + + char *name; + char *sign; + char *genc; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5( + GetMethodName, jvmti_env, method, &name, &sign, &genc))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!strncmp(name,"javaMethod", 8)) { + changeCount(event, &newEventCount[0]); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)name))) { + nsk_jvmti_setFailStatus(); + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)sign))) { + nsk_jvmti_setFailStatus(); + } + if (genc != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)genc))) { + nsk_jvmti_setFailStatus(); + } +} + +void JNICALL +cbNewMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + + handler2(jvmti_env, JVMTI_EVENT_METHOD_ENTRY, method); +} + +void JNICALL +cbNewMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + + handler2(jvmti_env, JVMTI_EVENT_METHOD_EXIT, method); +} + +void JNICALL +cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); +} + +void JNICALL +cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jlong tout) { + + changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); +} + +void JNICALL +cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jboolean timed_out) { + + changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); +} + +void JNICALL +cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); +} + +void JNICALL +cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + + changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); +} + +void JNICALL +cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); +} + +/* ============================================================================= */ + +static int enableEvent(jvmtiEvent event) { + + if (nsk_jvmti_isOptionalEvent(event) + && (event != JVMTI_EVENT_METHOD_ENTRY) + && (event != JVMTI_EVENT_METHOD_EXIT)) { + if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } else { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } + + return NSK_TRUE; +} + +/** + * Enable or disable tested events. + */ +static int enableEventList() { + + int i, result; + + result = enableEvent(JVMTI_EVENT_VM_INIT); + + result = result && enableEvent(JVMTI_EVENT_VM_DEATH); + + /* enabling optional events */ + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); + + if (nsk_jvmti_isOptionalEvent(event)) + result = result && enableEvent(event); + } + + if (result == NSK_FALSE) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +static int +setCallBacks(int step) { + + int i; + + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + switch (step) { + case 1: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + eventCount[i] = 0; + } + + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.Exception = cbException; + eventCallbacks.ExceptionCatch = cbExceptionCatch; + eventCallbacks.SingleStep = cbSingleStep; + eventCallbacks.FramePop = cbFramePop; + eventCallbacks.Breakpoint = cbBreakpoint; + eventCallbacks.FieldAccess = cbFieldAccess; + eventCallbacks.FieldModification = cbFieldModification; + eventCallbacks.MethodEntry = cbMethodEntry; + eventCallbacks.MethodExit = cbMethodExit; + eventCallbacks.NativeMethodBind = cbNativeMethodBind; + eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; + eventCallbacks.MonitorWait = cbMonitorWait; + eventCallbacks.MonitorWaited = cbMonitorWaited; + eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; + eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; + eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; + eventCallbacks.ObjectFree = cbObjectFree; + eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; + break; + + case 2: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.MethodEntry = cbNewMethodEntry; + eventCallbacks.MethodExit = cbNewMethodExit; + break; + + case 3: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.VMDeath = cbVMDeath; + break; + + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + int i; + + for (i = 1; i <= STEP_NUMBER; i++) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (i < STEP_NUMBER) { + showEventStatistics(i); + if (!checkEvents(i)) + nsk_jvmti_setFailStatus(); + + if (!setCallBacks(i + 1)) { + return; + } + } + + if (!nsk_jvmti_resumeSync()) + return; + } + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em02t009(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em02t009(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em02t009(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_generate_method_entry_events = 1; + caps.can_generate_method_exit_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + if (!setCallBacks(1)) { + return JNI_ERR; + } + + if (!enableEventList()) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/libem02t009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/libem02t009.c deleted file mode 100644 index 4abfc693c08..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/libem02t009.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em02t009.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/libem02t009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/libem02t009.cpp new file mode 100644 index 00000000000..02b9e6d72bc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t009/libem02t009.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em02t009.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/em02t010.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/em02t010.c deleted file mode 100644 index 10b400ca0fc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/em02t010.c +++ /dev/null @@ -1,576 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define STEP_NUMBER 3 -#define CLASS_NAME "nsk/jvmti/scenarios/events/EM02/em02t010" -#define FIELD_ACC_NAME "testedField_acc" -#define FIELD_MOD_NAME "testedField_mod" -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) -#define NUMBER_OF_INVOCATIONS 1000 - -static int eventCount[JVMTI_EVENT_COUNT]; -static int newEventCount[JVMTI_EVENT_COUNT]; - -/* ============================================================================= */ - -static void -showEventStatistics(int step) { - int i; - const char* str; - int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("Event statistics for %d step:\n", step); - NSK_DISPLAY0("-----------------------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (currentCounts[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); - } - } -} - -/* ========================================================================== */ - -int checkEvents(int step) { - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int *currentCounts; - int isExpected = 0; - - switch (step) { - case 1: - currentCounts = &eventCount[0]; - break; - - case 2: - case 3: - currentCounts = &newEventCount[0]; - break; - - default: - NSK_COMPLAIN1("Unexpected step no: %d\n", step); - return NSK_FALSE; - } - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - - switch (step) { - case 1: - isExpected = ((curr == JVMTI_EVENT_VM_INIT) - || (curr == JVMTI_EVENT_FIELD_MODIFICATION) - || (curr == JVMTI_EVENT_FIELD_ACCESS)); - break; - - case 2: - isExpected = ((curr == JVMTI_EVENT_FIELD_MODIFICATION) - || (curr == JVMTI_EVENT_FIELD_ACCESS)); - break; - - case 3: - isExpected = (curr == JVMTI_EVENT_VM_DEATH); - break; - } - - if (isExpected) { - if (curr == JVMTI_EVENT_FIELD_MODIFICATION || - curr == JVMTI_EVENT_FIELD_ACCESS) { - if (currentCounts[i] != NUMBER_OF_INVOCATIONS) { - NSK_COMPLAIN3("Unexpected number of %s events %d, expected value is %d\n", - TranslateEvent(curr), - currentCounts[i], - NUMBER_OF_INVOCATIONS); - result = NSK_FALSE; - } - } else { - if (currentCounts[i] < 1) { - NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", - currentCounts[i], - TranslateEvent(curr)); - result = NSK_FALSE; - } - } - - } else { - - if (currentCounts[i] > 0) { - NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", - TranslateEvent(curr), - currentCounts[i]); - result = NSK_FALSE; - } - } - } - - return result; -} - -static void -changeCount(jvmtiEvent event, int *currentCounts) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/* callbacks */ -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { - changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { - changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); - showEventStatistics(STEP_NUMBER); - if (!checkEvents(STEP_NUMBER)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -void JNICALL -cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - - changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); -} - -void JNICALL -cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - - changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); -} - -void JNICALL -cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); -} - -void JNICALL -cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); -} - -void JNICALL -cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); -} - -void JNICALL -cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - - changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); -} - -void JNICALL -cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - - changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); -} - -void JNICALL -cbNewFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - - changeCount(JVMTI_EVENT_FIELD_ACCESS, &newEventCount[0]); -} - -void JNICALL -cbNewFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - - changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &newEventCount[0]); -} - -void JNICALL -cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - - changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); -} - -void JNICALL -cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - - changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); -} - -void JNICALL -cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); -} - -void JNICALL -cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jlong tout) { - - changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); -} - -void JNICALL -cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jboolean timed_out) { - - changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); -} - -void JNICALL -cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); -} - -void JNICALL -cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - - changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); -} - -void JNICALL -cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); -} - -/* ============================================================================= */ - -static int enableEvent(jvmtiEvent event) { - - if (nsk_jvmti_isOptionalEvent(event) - && (event != JVMTI_EVENT_FIELD_MODIFICATION) - && (event != JVMTI_EVENT_FIELD_ACCESS)) { - if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } else { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } - - return NSK_TRUE; -} - -/** - * Enable or disable tested events. - */ -static int enableEventList() { - - int i, result; - - result = enableEvent(JVMTI_EVENT_VM_INIT); - - result = result && enableEvent(JVMTI_EVENT_VM_DEATH); - - /* enabling optional events */ - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); - - if (nsk_jvmti_isOptionalEvent(event)) - result = result && enableEvent(event); - } - - if (result == NSK_FALSE) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -static int -setCallBacks(int step) { - - int i; - - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - switch (step) { - case 1: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - eventCount[i] = 0; - } - - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.Exception = cbException; - eventCallbacks.ExceptionCatch = cbExceptionCatch; - eventCallbacks.SingleStep = cbSingleStep; - eventCallbacks.FramePop = cbFramePop; - eventCallbacks.Breakpoint = cbBreakpoint; - eventCallbacks.FieldAccess = cbFieldAccess; - eventCallbacks.FieldModification = cbFieldModification; - eventCallbacks.MethodEntry = cbMethodEntry; - eventCallbacks.MethodExit = cbMethodExit; - eventCallbacks.NativeMethodBind = cbNativeMethodBind; - eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; - eventCallbacks.MonitorWait = cbMonitorWait; - eventCallbacks.MonitorWaited = cbMonitorWaited; - eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; - eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; - eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; - eventCallbacks.ObjectFree = cbObjectFree; - eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; - break; - - case 2: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.FieldAccess = cbNewFieldAccess; - eventCallbacks.FieldModification = cbNewFieldModification; - break; - - case 3: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.VMDeath = cbVMDeath; - break; - - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - int i; - jfieldID field_accID, field_modID; - jclass cls; - - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!NSK_JNI_VERIFY(agentJNI, (cls = - NSK_CPP_STUB2(FindClass, agentJNI, CLASS_NAME)) != NULL)) - return; - - if (!NSK_JNI_VERIFY(agentJNI, (field_accID = - NSK_CPP_STUB4(GetStaticFieldID, agentJNI, cls, FIELD_ACC_NAME, - "I")) != NULL)) - return; - - if (!NSK_JNI_VERIFY(agentJNI, (field_modID = - NSK_CPP_STUB4(GetStaticFieldID, agentJNI, cls, FIELD_MOD_NAME, - "I")) != NULL)) - return; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetFieldModificationWatch, jvmti, cls, field_modID))) - return; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetFieldAccessWatch, jvmti, cls, field_accID))) - return; - - if (!nsk_jvmti_resumeSync()) - return; - - for (i = 1; i <= STEP_NUMBER; i++) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (i < STEP_NUMBER) { - showEventStatistics(i); - if (!checkEvents(i)) - nsk_jvmti_setFailStatus(); - - if (!setCallBacks(i + 1)) { - return; - } - } - - if (!nsk_jvmti_resumeSync()) - return; - } - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em02t010(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em02t010(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em02t010(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_generate_field_modification_events = 1; - caps.can_generate_field_access_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - if (!setCallBacks(1)) { - return JNI_ERR; - } - - if (!enableEventList()) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/em02t010.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/em02t010.cpp new file mode 100644 index 00000000000..53f50845991 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/em02t010.cpp @@ -0,0 +1,576 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define STEP_NUMBER 3 +#define CLASS_NAME "nsk/jvmti/scenarios/events/EM02/em02t010" +#define FIELD_ACC_NAME "testedField_acc" +#define FIELD_MOD_NAME "testedField_mod" +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) +#define NUMBER_OF_INVOCATIONS 1000 + +static int eventCount[JVMTI_EVENT_COUNT]; +static int newEventCount[JVMTI_EVENT_COUNT]; + +/* ============================================================================= */ + +static void +showEventStatistics(int step) { + int i; + const char* str; + int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("Event statistics for %d step:\n", step); + NSK_DISPLAY0("-----------------------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (currentCounts[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); + } + } +} + +/* ========================================================================== */ + +int checkEvents(int step) { + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int *currentCounts; + int isExpected = 0; + + switch (step) { + case 1: + currentCounts = &eventCount[0]; + break; + + case 2: + case 3: + currentCounts = &newEventCount[0]; + break; + + default: + NSK_COMPLAIN1("Unexpected step no: %d\n", step); + return NSK_FALSE; + } + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + + switch (step) { + case 1: + isExpected = ((curr == JVMTI_EVENT_VM_INIT) + || (curr == JVMTI_EVENT_FIELD_MODIFICATION) + || (curr == JVMTI_EVENT_FIELD_ACCESS)); + break; + + case 2: + isExpected = ((curr == JVMTI_EVENT_FIELD_MODIFICATION) + || (curr == JVMTI_EVENT_FIELD_ACCESS)); + break; + + case 3: + isExpected = (curr == JVMTI_EVENT_VM_DEATH); + break; + } + + if (isExpected) { + if (curr == JVMTI_EVENT_FIELD_MODIFICATION || + curr == JVMTI_EVENT_FIELD_ACCESS) { + if (currentCounts[i] != NUMBER_OF_INVOCATIONS) { + NSK_COMPLAIN3("Unexpected number of %s events %d, expected value is %d\n", + TranslateEvent(curr), + currentCounts[i], + NUMBER_OF_INVOCATIONS); + result = NSK_FALSE; + } + } else { + if (currentCounts[i] < 1) { + NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", + currentCounts[i], + TranslateEvent(curr)); + result = NSK_FALSE; + } + } + + } else { + + if (currentCounts[i] > 0) { + NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", + TranslateEvent(curr), + currentCounts[i]); + result = NSK_FALSE; + } + } + } + + return result; +} + +static void +changeCount(jvmtiEvent event, int *currentCounts) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/* callbacks */ +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { + changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { + changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); + showEventStatistics(STEP_NUMBER); + if (!checkEvents(STEP_NUMBER)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +void JNICALL +cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + + changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); +} + +void JNICALL +cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + + changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); +} + +void JNICALL +cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); +} + +void JNICALL +cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); +} + +void JNICALL +cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); +} + +void JNICALL +cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + + changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); +} + +void JNICALL +cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + + changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); +} + +void JNICALL +cbNewFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + + changeCount(JVMTI_EVENT_FIELD_ACCESS, &newEventCount[0]); +} + +void JNICALL +cbNewFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + + changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &newEventCount[0]); +} + +void JNICALL +cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + + changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); +} + +void JNICALL +cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + + changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); +} + +void JNICALL +cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); +} + +void JNICALL +cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jlong tout) { + + changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); +} + +void JNICALL +cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jboolean timed_out) { + + changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); +} + +void JNICALL +cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); +} + +void JNICALL +cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + + changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); +} + +void JNICALL +cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); +} + +/* ============================================================================= */ + +static int enableEvent(jvmtiEvent event) { + + if (nsk_jvmti_isOptionalEvent(event) + && (event != JVMTI_EVENT_FIELD_MODIFICATION) + && (event != JVMTI_EVENT_FIELD_ACCESS)) { + if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } else { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } + + return NSK_TRUE; +} + +/** + * Enable or disable tested events. + */ +static int enableEventList() { + + int i, result; + + result = enableEvent(JVMTI_EVENT_VM_INIT); + + result = result && enableEvent(JVMTI_EVENT_VM_DEATH); + + /* enabling optional events */ + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); + + if (nsk_jvmti_isOptionalEvent(event)) + result = result && enableEvent(event); + } + + if (result == NSK_FALSE) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +static int +setCallBacks(int step) { + + int i; + + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + switch (step) { + case 1: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + eventCount[i] = 0; + } + + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.Exception = cbException; + eventCallbacks.ExceptionCatch = cbExceptionCatch; + eventCallbacks.SingleStep = cbSingleStep; + eventCallbacks.FramePop = cbFramePop; + eventCallbacks.Breakpoint = cbBreakpoint; + eventCallbacks.FieldAccess = cbFieldAccess; + eventCallbacks.FieldModification = cbFieldModification; + eventCallbacks.MethodEntry = cbMethodEntry; + eventCallbacks.MethodExit = cbMethodExit; + eventCallbacks.NativeMethodBind = cbNativeMethodBind; + eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; + eventCallbacks.MonitorWait = cbMonitorWait; + eventCallbacks.MonitorWaited = cbMonitorWaited; + eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; + eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; + eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; + eventCallbacks.ObjectFree = cbObjectFree; + eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; + break; + + case 2: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.FieldAccess = cbNewFieldAccess; + eventCallbacks.FieldModification = cbNewFieldModification; + break; + + case 3: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.VMDeath = cbVMDeath; + break; + + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + int i; + jfieldID field_accID, field_modID; + jclass cls; + + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!NSK_JNI_VERIFY(agentJNI, (cls = + NSK_CPP_STUB2(FindClass, agentJNI, CLASS_NAME)) != NULL)) + return; + + if (!NSK_JNI_VERIFY(agentJNI, (field_accID = + NSK_CPP_STUB4(GetStaticFieldID, agentJNI, cls, FIELD_ACC_NAME, + "I")) != NULL)) + return; + + if (!NSK_JNI_VERIFY(agentJNI, (field_modID = + NSK_CPP_STUB4(GetStaticFieldID, agentJNI, cls, FIELD_MOD_NAME, + "I")) != NULL)) + return; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetFieldModificationWatch, jvmti, cls, field_modID))) + return; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetFieldAccessWatch, jvmti, cls, field_accID))) + return; + + if (!nsk_jvmti_resumeSync()) + return; + + for (i = 1; i <= STEP_NUMBER; i++) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (i < STEP_NUMBER) { + showEventStatistics(i); + if (!checkEvents(i)) + nsk_jvmti_setFailStatus(); + + if (!setCallBacks(i + 1)) { + return; + } + } + + if (!nsk_jvmti_resumeSync()) + return; + } + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em02t010(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em02t010(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em02t010(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_generate_field_modification_events = 1; + caps.can_generate_field_access_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + if (!setCallBacks(1)) { + return JNI_ERR; + } + + if (!enableEventList()) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/libem02t010.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/libem02t010.c deleted file mode 100644 index ba4ed1b62a4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/libem02t010.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em02t010.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/libem02t010.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/libem02t010.cpp new file mode 100644 index 00000000000..65a2ff49c81 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t010/libem02t010.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em02t010.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/em02t011.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/em02t011.c deleted file mode 100644 index c9471577c4e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/em02t011.c +++ /dev/null @@ -1,551 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define STEP_NUMBER 3 -#define CLASS_NAME "nsk/jvmti/scenarios/events/EM02/em02t011" -#define METHOD_NAME "javaMethod" -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) -#define NUMBER_OF_INVOCATIONS 1000 - -static int eventCount[JVMTI_EVENT_COUNT]; -static int newEventCount[JVMTI_EVENT_COUNT]; - -/* ============================================================================= */ - -static void -showEventStatistics(int step) { - int i; - const char* str; - int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("Event statistics for %d step:\n", step); - NSK_DISPLAY0("-----------------------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (currentCounts[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); - } - } -} - -/* ========================================================================== */ - -int checkEvents(int step) { - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int *currentCounts; - int isExpected = 0; - - switch (step) { - case 1: - currentCounts = &eventCount[0]; - break; - - case 2: - case 3: - currentCounts = &newEventCount[0]; - break; - - default: - NSK_COMPLAIN1("Unexpected step no: %d\n", step); - return NSK_FALSE; - } - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - - switch (step) { - case 1: - isExpected = ((curr == JVMTI_EVENT_VM_INIT) - || (curr == JVMTI_EVENT_BREAKPOINT)); - break; - - case 2: - isExpected = (curr == JVMTI_EVENT_BREAKPOINT); - break; - - case 3: - isExpected = (curr == JVMTI_EVENT_VM_DEATH); - break; - } - - if (isExpected) { - if (curr != JVMTI_EVENT_BREAKPOINT) { - if (currentCounts[i] < 1) { - NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", - currentCounts[i], - TranslateEvent(curr)); - result = NSK_FALSE; - } - } else { - if (currentCounts[i] != NUMBER_OF_INVOCATIONS) { - NSK_COMPLAIN3("Unexpected number of %s events %d, expected value is %d\n", - TranslateEvent(curr), - currentCounts[i], - NUMBER_OF_INVOCATIONS); - result = NSK_FALSE; - } - } - - } else { - - if (currentCounts[i] > 0) { - NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", - TranslateEvent(curr), - currentCounts[i]); - result = NSK_FALSE; - } - } - } - - return result; -} - -static void -changeCount(jvmtiEvent event, int *currentCounts) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/* callbacks */ -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { - changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { - changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); - showEventStatistics(STEP_NUMBER); - if (!checkEvents(STEP_NUMBER)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -void JNICALL -cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - - changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); -} - -void JNICALL -cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - - changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); -} - -void JNICALL -cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); -} - -void JNICALL -cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); -} - -void JNICALL -cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); -} - -void JNICALL -cbNewBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - changeCount(JVMTI_EVENT_BREAKPOINT, &newEventCount[0]); -} - -void JNICALL -cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - - changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); -} - -void JNICALL -cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - - changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); -} - -void JNICALL -cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - - changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); -} - -void JNICALL -cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - - changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); -} - -void JNICALL -cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); -} - -void JNICALL -cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jlong tout) { - - changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); -} - -void JNICALL -cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jboolean timed_out) { - - changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); -} - -void JNICALL -cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); -} - -void JNICALL -cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - - changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); -} - -void JNICALL -cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); -} - -/* ============================================================================= */ - -static int enableEvent(jvmtiEvent event) { - - if (nsk_jvmti_isOptionalEvent(event) - && (event != JVMTI_EVENT_BREAKPOINT)) { - if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } else { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } - - return NSK_TRUE; -} - -/** - * Enable or disable tested events. - */ -static int enableEventList() { - - int i, result; - - result = enableEvent(JVMTI_EVENT_VM_INIT); - - result = result && enableEvent(JVMTI_EVENT_VM_DEATH); - - /* enabling optional events */ - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); - - if (nsk_jvmti_isOptionalEvent(event)) - result = result && enableEvent(event); - } - - if (result == NSK_FALSE) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -static int -setCallBacks(int step) { - - int i; - - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - switch (step) { - case 1: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - eventCount[i] = 0; - } - - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.Exception = cbException; - eventCallbacks.ExceptionCatch = cbExceptionCatch; - eventCallbacks.SingleStep = cbSingleStep; - eventCallbacks.FramePop = cbFramePop; - eventCallbacks.Breakpoint = cbBreakpoint; - eventCallbacks.FieldAccess = cbFieldAccess; - eventCallbacks.FieldModification = cbFieldModification; - eventCallbacks.MethodEntry = cbMethodEntry; - eventCallbacks.MethodExit = cbMethodExit; - eventCallbacks.NativeMethodBind = cbNativeMethodBind; - eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; - eventCallbacks.MonitorWait = cbMonitorWait; - eventCallbacks.MonitorWaited = cbMonitorWaited; - eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; - eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; - eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; - eventCallbacks.ObjectFree = cbObjectFree; - eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; - break; - - case 2: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.Breakpoint = cbNewBreakpoint; - break; - - case 3: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.VMDeath = cbVMDeath; - break; - - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - int i; - jmethodID methodID; - jclass cls; - - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!NSK_JNI_VERIFY(agentJNI, (cls = - NSK_CPP_STUB2(FindClass, agentJNI, CLASS_NAME)) != NULL)) - return; - - if (!NSK_JNI_VERIFY(agentJNI, (methodID = - NSK_CPP_STUB4(GetStaticMethodID, agentJNI, cls, METHOD_NAME, - "()I")) != NULL)) - return; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetBreakpoint, jvmti, methodID, 0))) - return; - - if (!nsk_jvmti_resumeSync()) - return; - - for (i = 1; i <= STEP_NUMBER; i++) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (i < STEP_NUMBER) { - showEventStatistics(i); - if (!checkEvents(i)) - nsk_jvmti_setFailStatus(); - - if (!setCallBacks(i + 1)) { - return; - } - } - - if (!nsk_jvmti_resumeSync()) - return; - } - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em02t011(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em02t011(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em02t011(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_generate_breakpoint_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - if (!setCallBacks(1)) { - return JNI_ERR; - } - - if (!enableEventList()) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/em02t011.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/em02t011.cpp new file mode 100644 index 00000000000..5fa1f64623a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/em02t011.cpp @@ -0,0 +1,551 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define STEP_NUMBER 3 +#define CLASS_NAME "nsk/jvmti/scenarios/events/EM02/em02t011" +#define METHOD_NAME "javaMethod" +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) +#define NUMBER_OF_INVOCATIONS 1000 + +static int eventCount[JVMTI_EVENT_COUNT]; +static int newEventCount[JVMTI_EVENT_COUNT]; + +/* ============================================================================= */ + +static void +showEventStatistics(int step) { + int i; + const char* str; + int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("Event statistics for %d step:\n", step); + NSK_DISPLAY0("-----------------------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (currentCounts[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); + } + } +} + +/* ========================================================================== */ + +int checkEvents(int step) { + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int *currentCounts; + int isExpected = 0; + + switch (step) { + case 1: + currentCounts = &eventCount[0]; + break; + + case 2: + case 3: + currentCounts = &newEventCount[0]; + break; + + default: + NSK_COMPLAIN1("Unexpected step no: %d\n", step); + return NSK_FALSE; + } + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + + switch (step) { + case 1: + isExpected = ((curr == JVMTI_EVENT_VM_INIT) + || (curr == JVMTI_EVENT_BREAKPOINT)); + break; + + case 2: + isExpected = (curr == JVMTI_EVENT_BREAKPOINT); + break; + + case 3: + isExpected = (curr == JVMTI_EVENT_VM_DEATH); + break; + } + + if (isExpected) { + if (curr != JVMTI_EVENT_BREAKPOINT) { + if (currentCounts[i] < 1) { + NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", + currentCounts[i], + TranslateEvent(curr)); + result = NSK_FALSE; + } + } else { + if (currentCounts[i] != NUMBER_OF_INVOCATIONS) { + NSK_COMPLAIN3("Unexpected number of %s events %d, expected value is %d\n", + TranslateEvent(curr), + currentCounts[i], + NUMBER_OF_INVOCATIONS); + result = NSK_FALSE; + } + } + + } else { + + if (currentCounts[i] > 0) { + NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", + TranslateEvent(curr), + currentCounts[i]); + result = NSK_FALSE; + } + } + } + + return result; +} + +static void +changeCount(jvmtiEvent event, int *currentCounts) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/* callbacks */ +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { + changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { + changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); + showEventStatistics(STEP_NUMBER); + if (!checkEvents(STEP_NUMBER)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +void JNICALL +cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + + changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); +} + +void JNICALL +cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + + changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); +} + +void JNICALL +cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); +} + +void JNICALL +cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); +} + +void JNICALL +cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); +} + +void JNICALL +cbNewBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + changeCount(JVMTI_EVENT_BREAKPOINT, &newEventCount[0]); +} + +void JNICALL +cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + + changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); +} + +void JNICALL +cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + + changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); +} + +void JNICALL +cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + + changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); +} + +void JNICALL +cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + + changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); +} + +void JNICALL +cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); +} + +void JNICALL +cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jlong tout) { + + changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); +} + +void JNICALL +cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jboolean timed_out) { + + changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); +} + +void JNICALL +cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); +} + +void JNICALL +cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + + changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); +} + +void JNICALL +cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); +} + +/* ============================================================================= */ + +static int enableEvent(jvmtiEvent event) { + + if (nsk_jvmti_isOptionalEvent(event) + && (event != JVMTI_EVENT_BREAKPOINT)) { + if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } else { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } + + return NSK_TRUE; +} + +/** + * Enable or disable tested events. + */ +static int enableEventList() { + + int i, result; + + result = enableEvent(JVMTI_EVENT_VM_INIT); + + result = result && enableEvent(JVMTI_EVENT_VM_DEATH); + + /* enabling optional events */ + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); + + if (nsk_jvmti_isOptionalEvent(event)) + result = result && enableEvent(event); + } + + if (result == NSK_FALSE) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +static int +setCallBacks(int step) { + + int i; + + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + switch (step) { + case 1: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + eventCount[i] = 0; + } + + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.Exception = cbException; + eventCallbacks.ExceptionCatch = cbExceptionCatch; + eventCallbacks.SingleStep = cbSingleStep; + eventCallbacks.FramePop = cbFramePop; + eventCallbacks.Breakpoint = cbBreakpoint; + eventCallbacks.FieldAccess = cbFieldAccess; + eventCallbacks.FieldModification = cbFieldModification; + eventCallbacks.MethodEntry = cbMethodEntry; + eventCallbacks.MethodExit = cbMethodExit; + eventCallbacks.NativeMethodBind = cbNativeMethodBind; + eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; + eventCallbacks.MonitorWait = cbMonitorWait; + eventCallbacks.MonitorWaited = cbMonitorWaited; + eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; + eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; + eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; + eventCallbacks.ObjectFree = cbObjectFree; + eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; + break; + + case 2: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.Breakpoint = cbNewBreakpoint; + break; + + case 3: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.VMDeath = cbVMDeath; + break; + + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + int i; + jmethodID methodID; + jclass cls; + + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!NSK_JNI_VERIFY(agentJNI, (cls = + NSK_CPP_STUB2(FindClass, agentJNI, CLASS_NAME)) != NULL)) + return; + + if (!NSK_JNI_VERIFY(agentJNI, (methodID = + NSK_CPP_STUB4(GetStaticMethodID, agentJNI, cls, METHOD_NAME, + "()I")) != NULL)) + return; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetBreakpoint, jvmti, methodID, 0))) + return; + + if (!nsk_jvmti_resumeSync()) + return; + + for (i = 1; i <= STEP_NUMBER; i++) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (i < STEP_NUMBER) { + showEventStatistics(i); + if (!checkEvents(i)) + nsk_jvmti_setFailStatus(); + + if (!setCallBacks(i + 1)) { + return; + } + } + + if (!nsk_jvmti_resumeSync()) + return; + } + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em02t011(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em02t011(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em02t011(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_generate_breakpoint_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + if (!setCallBacks(1)) { + return JNI_ERR; + } + + if (!enableEventList()) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/libem02t011.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/libem02t011.c deleted file mode 100644 index 7c984888169..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/libem02t011.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em02t011.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/libem02t011.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/libem02t011.cpp new file mode 100644 index 00000000000..7f3d0d58f2c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/libem02t011.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em02t011.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/em02t012.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/em02t012.c deleted file mode 100644 index 0c2da546a93..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/em02t012.c +++ /dev/null @@ -1,555 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jvmtiEnv *jvmti = NULL; -static jthread testedThread; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define STEP_NUMBER 3 -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) -#define NUMBER_OF_INVOCATIONS 1000 - -static int eventCount[JVMTI_EVENT_COUNT]; -static int newEventCount[JVMTI_EVENT_COUNT]; - -/* ============================================================================= */ -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_events_EM02_em02t012_setThread(JNIEnv *jni_env, - jobject this, jthread thrd) { - - /* make thread accessable for a long time */ - NSK_JNI_VERIFY(jni_env, (testedThread = - NSK_CPP_STUB2(NewGlobalRef, jni_env, thrd)) != NULL); -} - -static void -showEventStatistics(int step) { - int i; - const char* str; - int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; - - NSK_DISPLAY0("\n"); - NSK_DISPLAY1("Event statistics for %d step:\n", step); - NSK_DISPLAY0("-----------------------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (currentCounts[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); - } - } -} - -/* ========================================================================== */ - -int checkEvents(int step) { - int i; - jvmtiEvent curr; - int result = NSK_TRUE; - int *currentCounts; - int isExpected = 0; - - switch (step) { - case 1: - currentCounts = &eventCount[0]; - break; - - case 2: - case 3: - currentCounts = &newEventCount[0]; - break; - - default: - NSK_COMPLAIN1("Unexpected step no: %d\n", step); - return NSK_FALSE; - } - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - curr = i + JVMTI_MIN_EVENT_TYPE_VAL; - - switch (step) { - case 1: - isExpected = ((curr == JVMTI_EVENT_VM_INIT) - || (curr == JVMTI_EVENT_FRAME_POP)); - break; - - case 2: - isExpected = (curr == JVMTI_EVENT_FRAME_POP); - break; - - case 3: - isExpected = (curr == JVMTI_EVENT_VM_DEATH); - break; - } - - if (isExpected) { - if (curr == JVMTI_EVENT_FRAME_POP) { - if (currentCounts[i] != NUMBER_OF_INVOCATIONS) { - NSK_COMPLAIN3("Unexpected number of %s events %d, expected value is %d\n", - TranslateEvent(curr), - currentCounts[i], - NUMBER_OF_INVOCATIONS); - result = NSK_FALSE; - } - } else { - if (currentCounts[i] < 1) { - NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", - currentCounts[i], - TranslateEvent(curr)); - result = NSK_FALSE; - } - } - - } else { - - if (currentCounts[i] > 0) { - NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", - TranslateEvent(curr), - currentCounts[i]); - result = NSK_FALSE; - } - } - } - - return result; -} - -static void -changeCount(jvmtiEvent event, int *currentCounts) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/* callbacks */ -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { - changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { - changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); - showEventStatistics(STEP_NUMBER); - if (!checkEvents(STEP_NUMBER)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -void JNICALL -cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - - changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); -} - -void JNICALL -cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - - changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); -} - -void JNICALL -cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); -} - -void JNICALL -cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); -} - -void JNICALL -cbNewFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP, &newEventCount[0]); -} - -void JNICALL -cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); -} - -void JNICALL -cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - - changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); -} - -void JNICALL -cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - - changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); -} - -void JNICALL -cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - - changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); -} - -void JNICALL -cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - - changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); -} - -void JNICALL -cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); -} - -void JNICALL -cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jlong tout) { - - changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); -} - -void JNICALL -cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jboolean timed_out) { - - changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); -} - -JNIEXPORT void JNICALL -cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); -} - -void JNICALL -cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); -} - -void JNICALL -cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); -} - -void JNICALL -cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); -} - -void JNICALL -cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - - changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); -} - -void JNICALL -cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); -} - -/* ============================================================================= */ - -static int enableEvent(jvmtiEvent event) { - - if (nsk_jvmti_isOptionalEvent(event) - && (event != JVMTI_EVENT_FRAME_POP)) { - if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } else { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - return NSK_FALSE; - } - } - - return NSK_TRUE; -} - -/** - * Enable or disable tested events. - */ -static int enableEventList() { - - int i, result; - - result = enableEvent(JVMTI_EVENT_VM_INIT); - - result = result && enableEvent(JVMTI_EVENT_VM_DEATH); - - /* enabling optional events */ - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); - - if (nsk_jvmti_isOptionalEvent(event)) - result = result && enableEvent(event); - } - - if (result == NSK_FALSE) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -static int -setCallBacks(int step) { - - int i; - - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - switch (step) { - case 1: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - eventCount[i] = 0; - } - - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.Exception = cbException; - eventCallbacks.ExceptionCatch = cbExceptionCatch; - eventCallbacks.SingleStep = cbSingleStep; - eventCallbacks.FramePop = cbFramePop; - eventCallbacks.Breakpoint = cbBreakpoint; - eventCallbacks.FieldAccess = cbFieldAccess; - eventCallbacks.FieldModification = cbFieldModification; - eventCallbacks.MethodEntry = cbMethodEntry; - eventCallbacks.MethodExit = cbMethodExit; - eventCallbacks.NativeMethodBind = cbNativeMethodBind; - eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; - eventCallbacks.MonitorWait = cbMonitorWait; - eventCallbacks.MonitorWaited = cbMonitorWaited; - eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; - eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; - eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; - eventCallbacks.ObjectFree = cbObjectFree; - eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; - break; - - case 2: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.FramePop = cbNewFramePop; - break; - - case 3: - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - newEventCount[i] = 0; - } - - eventCallbacks.VMDeath = cbVMDeath; - break; - - } - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - int i, j; - - for (i = 1; i <= STEP_NUMBER; i++) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(SuspendThread, jvmti, testedThread))) - return; - - for (j = 2; j < 1002; j++) { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(NotifyFramePop, jvmti, testedThread, j))) - return; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(ResumeThread, jvmti, testedThread))) - return; - - if (!nsk_jvmti_resumeSync()) - return; - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (i < STEP_NUMBER) { - showEventStatistics(i); - if (!checkEvents(i)) - nsk_jvmti_setFailStatus(); - - if (!setCallBacks(i + 1)) { - return; - } - } - - if (!nsk_jvmti_resumeSync()) - return; - } - - NSK_CPP_STUB2(DeleteGlobalRef, agentJNI, testedThread); -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em02t012(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em02t012(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em02t012(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_suspend = 1; - caps.can_generate_frame_pop_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - if (!setCallBacks(1)) { - return JNI_ERR; - } - - if (!enableEventList()) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/em02t012.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/em02t012.cpp new file mode 100644 index 00000000000..de40d7070d2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/em02t012.cpp @@ -0,0 +1,555 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jvmtiEnv *jvmti = NULL; +static jthread testedThread; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define STEP_NUMBER 3 +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) +#define NUMBER_OF_INVOCATIONS 1000 + +static int eventCount[JVMTI_EVENT_COUNT]; +static int newEventCount[JVMTI_EVENT_COUNT]; + +/* ============================================================================= */ +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_events_EM02_em02t012_setThread(JNIEnv *jni_env, + jobject o, jthread thrd) { + + /* make thread accessable for a long time */ + NSK_JNI_VERIFY(jni_env, (testedThread = + NSK_CPP_STUB2(NewGlobalRef, jni_env, thrd)) != NULL); +} + +static void +showEventStatistics(int step) { + int i; + const char* str; + int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; + + NSK_DISPLAY0("\n"); + NSK_DISPLAY1("Event statistics for %d step:\n", step); + NSK_DISPLAY0("-----------------------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (currentCounts[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); + } + } +} + +/* ========================================================================== */ + +int checkEvents(int step) { + int i; + jvmtiEvent curr; + int result = NSK_TRUE; + int *currentCounts; + int isExpected = 0; + + switch (step) { + case 1: + currentCounts = &eventCount[0]; + break; + + case 2: + case 3: + currentCounts = &newEventCount[0]; + break; + + default: + NSK_COMPLAIN1("Unexpected step no: %d\n", step); + return NSK_FALSE; + } + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + + switch (step) { + case 1: + isExpected = ((curr == JVMTI_EVENT_VM_INIT) + || (curr == JVMTI_EVENT_FRAME_POP)); + break; + + case 2: + isExpected = (curr == JVMTI_EVENT_FRAME_POP); + break; + + case 3: + isExpected = (curr == JVMTI_EVENT_VM_DEATH); + break; + } + + if (isExpected) { + if (curr == JVMTI_EVENT_FRAME_POP) { + if (currentCounts[i] != NUMBER_OF_INVOCATIONS) { + NSK_COMPLAIN3("Unexpected number of %s events %d, expected value is %d\n", + TranslateEvent(curr), + currentCounts[i], + NUMBER_OF_INVOCATIONS); + result = NSK_FALSE; + } + } else { + if (currentCounts[i] < 1) { + NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", + currentCounts[i], + TranslateEvent(curr)); + result = NSK_FALSE; + } + } + + } else { + + if (currentCounts[i] > 0) { + NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", + TranslateEvent(curr), + currentCounts[i]); + result = NSK_FALSE; + } + } + } + + return result; +} + +static void +changeCount(jvmtiEvent event, int *currentCounts) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/* callbacks */ +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { + changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { + changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); + showEventStatistics(STEP_NUMBER); + if (!checkEvents(STEP_NUMBER)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +void JNICALL +cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + + changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); +} + +void JNICALL +cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + + changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); +} + +void JNICALL +cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); +} + +void JNICALL +cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); +} + +void JNICALL +cbNewFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP, &newEventCount[0]); +} + +void JNICALL +cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); +} + +void JNICALL +cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + + changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); +} + +void JNICALL +cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + + changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); +} + +void JNICALL +cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + + changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); +} + +void JNICALL +cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + + changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); +} + +void JNICALL +cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); +} + +void JNICALL +cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jlong tout) { + + changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); +} + +void JNICALL +cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jboolean timed_out) { + + changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); +} + +JNIEXPORT void JNICALL +cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); +} + +void JNICALL +cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]); +} + +void JNICALL +cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); +} + +void JNICALL +cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); +} + +void JNICALL +cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + + changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); +} + +void JNICALL +cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); +} + +/* ============================================================================= */ + +static int enableEvent(jvmtiEvent event) { + + if (nsk_jvmti_isOptionalEvent(event) + && (event != JVMTI_EVENT_FRAME_POP)) { + if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } else { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + return NSK_FALSE; + } + } + + return NSK_TRUE; +} + +/** + * Enable or disable tested events. + */ +static int enableEventList() { + + int i, result; + + result = enableEvent(JVMTI_EVENT_VM_INIT); + + result = result && enableEvent(JVMTI_EVENT_VM_DEATH); + + /* enabling optional events */ + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); + + if (nsk_jvmti_isOptionalEvent(event)) + result = result && enableEvent(event); + } + + if (result == NSK_FALSE) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +static int +setCallBacks(int step) { + + int i; + + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + switch (step) { + case 1: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + eventCount[i] = 0; + } + + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.Exception = cbException; + eventCallbacks.ExceptionCatch = cbExceptionCatch; + eventCallbacks.SingleStep = cbSingleStep; + eventCallbacks.FramePop = cbFramePop; + eventCallbacks.Breakpoint = cbBreakpoint; + eventCallbacks.FieldAccess = cbFieldAccess; + eventCallbacks.FieldModification = cbFieldModification; + eventCallbacks.MethodEntry = cbMethodEntry; + eventCallbacks.MethodExit = cbMethodExit; + eventCallbacks.NativeMethodBind = cbNativeMethodBind; + eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; + eventCallbacks.MonitorWait = cbMonitorWait; + eventCallbacks.MonitorWaited = cbMonitorWaited; + eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; + eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; + eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; + eventCallbacks.ObjectFree = cbObjectFree; + eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; + break; + + case 2: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.FramePop = cbNewFramePop; + break; + + case 3: + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + newEventCount[i] = 0; + } + + eventCallbacks.VMDeath = cbVMDeath; + break; + + } + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + int i, j; + + for (i = 1; i <= STEP_NUMBER; i++) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(SuspendThread, jvmti, testedThread))) + return; + + for (j = 2; j < 1002; j++) { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(NotifyFramePop, jvmti, testedThread, j))) + return; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(ResumeThread, jvmti, testedThread))) + return; + + if (!nsk_jvmti_resumeSync()) + return; + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (i < STEP_NUMBER) { + showEventStatistics(i); + if (!checkEvents(i)) + nsk_jvmti_setFailStatus(); + + if (!setCallBacks(i + 1)) { + return; + } + } + + if (!nsk_jvmti_resumeSync()) + return; + } + + NSK_CPP_STUB2(DeleteGlobalRef, agentJNI, testedThread); +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em02t012(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em02t012(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em02t012(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_suspend = 1; + caps.can_generate_frame_pop_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + if (!setCallBacks(1)) { + return JNI_ERR; + } + + if (!enableEventList()) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/libem02t012.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/libem02t012.c deleted file mode 100644 index 69a95d37c17..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/libem02t012.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em02t012.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/libem02t012.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/libem02t012.cpp new file mode 100644 index 00000000000..02246e132cf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/libem02t012.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em02t012.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/em04t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/em04t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/em04t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/em04t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/libem04t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/libem04t001.c deleted file mode 100644 index 86e796670ff..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/libem04t001.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_list.c" -#include "nsk_mutex.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em04t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/libem04t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/libem04t001.cpp new file mode 100644 index 00000000000..1974ec9fe6c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/libem04t001.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_list.cpp" +#include "nsk_mutex.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em04t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/em05t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/em05t001.c deleted file mode 100644 index ba54d4c0a19..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/em05t001.c +++ /dev/null @@ -1,358 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static JNIEnv* jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/scenarios/events/EM05/em05t001" -#define THREAD_CLASS_NAME "nsk/jvmti/scenarios/events/EM05/em05t001Thread" -#define THREAD_FIELD_NAME "thread" -#define THREAD_FIELD_SIG "L"THREAD_CLASS_NAME";" - -/* constants */ -#define MAX_NAME_LENGTH 64 -#define EVENTS_COUNT 2 -#define METHODS_COUNT 2 - -/* tested events */ -static jvmtiEvent eventsList[EVENTS_COUNT] = { - JVMTI_EVENT_COMPILED_METHOD_LOAD, - JVMTI_EVENT_COMPILED_METHOD_UNLOAD -}; - -/* method description structure */ -typedef struct { - char methodName[MAX_NAME_LENGTH]; - char methodSig[MAX_NAME_LENGTH]; - jmethodID method; - int compiled; - int loadEvents; - int unloadEvents; -} MethodDesc; - -/* descriptions of tested methods */ -static MethodDesc methodsDesc[METHODS_COUNT] = { - {"javaMethod", "(I)I", NULL, 0, 0, 0}, - {"nativeMethod", "(I)I", NULL, 0, 0, 0} -}; - -/* ============================================================================= */ - -/* testcase(s) */ -static int prepare(); -static int checkEvents(); -static int clean(); - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - jni = agentJNI; - - NSK_DISPLAY0("Wait for debuggee to become ready\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - { - NSK_DISPLAY0("Prepare data\n"); - if (!prepare()) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Provoke methods compilation\n"); - if (!nsk_jvmti_resumeSync()) - return; - - NSK_DISPLAY0("Wait for threads to complete\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY0("Check if events received\n"); - if (!checkEvents()) - return; - - NSK_DISPLAY0("Clean data\n"); - if (!clean()) { - nsk_jvmti_setFailStatus(); - return; - } - } - - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ============================================================================= */ - -/** - * Enable or disable tested events. - */ -static int enableEvents(jvmtiEventMode enable) { - int i; - - for (i = 0; i < EVENTS_COUNT; i++) { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, enable, - eventsList[i], NULL))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - return NSK_TRUE; -} - -/** - * Prepare data. - * - find tested thread - * - get tested methodIDs - * - enable events - */ -static int prepare() { - jclass debugeeClass = NULL; - jclass threadClass = NULL; - jfieldID threadFieldID = NULL; - jthread thread = NULL; - int i; - - for (i = 0; i < METHODS_COUNT; i++) { - methodsDesc[i].method = (jmethodID)NULL; - methodsDesc[i].loadEvents = 0; - methodsDesc[i].unloadEvents = 0; - } - - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (threadFieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - THREAD_FIELD_NAME, THREAD_FIELD_SIG)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (thread = (jthread) - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, threadFieldID)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (threadClass = - NSK_CPP_STUB2(GetObjectClass, jni, thread)) != NULL)) - return NSK_FALSE; - - NSK_DISPLAY0("Find tested methods:\n"); - for (i = 0; i < METHODS_COUNT; i++) { - if (!NSK_JNI_VERIFY(jni, (methodsDesc[i].method = - NSK_CPP_STUB4(GetMethodID, jni, threadClass, - methodsDesc[i].methodName, methodsDesc[i].methodSig)) != NULL)) - return NSK_FALSE; - NSK_DISPLAY3(" method #%d (%s): 0x%p\n", - i, methodsDesc[i].methodName, (void*)methodsDesc[i].method); - } - - NSK_DISPLAY0("Enable events\n"); - if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, eventsList, NULL)) - return NSK_FALSE; - - return NSK_TRUE; -} - -/** - * Testcase: check tested events. - * - check if expected events received for each method - * - * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. - */ -static int checkEvents() { - int i; - - for (i = 0; i < METHODS_COUNT; i++) { - NSK_DISPLAY2(" method #%d (%s):\n", - i, methodsDesc[i].methodName); - NSK_DISPLAY2(" COMPILED_METHOD_LOAD: %d, COMPILED_METHOD_UNLOAD: %d\n", - methodsDesc[i].loadEvents, methodsDesc[i].unloadEvents); - - if (methodsDesc[i].loadEvents <= 0) { - NSK_DISPLAY1("# WARNING: No COMPILED_METHOD_LOAD events for method: %s\n", - methodsDesc[i].methodName); - } - - if (methodsDesc[i].unloadEvents > methodsDesc[i].loadEvents) { - NSK_DISPLAY1("# WARNING: Too many COMPILED_METHOD_UNLOAD events for method: %s\n", - methodsDesc[i].methodName); - NSK_DISPLAY2("# COMPILED_METHOD_LOAD: %d, COMPILED_METHOD_UNLOAD: %d\n", - methodsDesc[i].loadEvents, methodsDesc[i].unloadEvents); - } - } - return NSK_TRUE; -} - -/** - * Clean data: - * - disable events - */ -static int clean() { - NSK_DISPLAY0("Disable events\n"); - if (!nsk_jvmti_enableEvents(JVMTI_DISABLE, EVENTS_COUNT, eventsList, NULL)) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** - * COMPILED_METHOD_LOAD callback. - * - turn on flag if method is compiled - */ -JNIEXPORT void JNICALL -callbackCompiledMethodLoad(jvmtiEnv* jvmti, jmethodID method, - jint code_size, const void* code_addr, - jint map_length, const jvmtiAddrLocationMap* map, - const void* compile_info) { - int i; - - for (i = 0; i < METHODS_COUNT; i++) { - if (methodsDesc[i].method == method) { - methodsDesc[i].loadEvents++; - NSK_DISPLAY3(" COMPILED_METHOD_LOAD for method #%d (%s): %d times\n", - i, methodsDesc[i].methodName, methodsDesc[i].loadEvents); - NSK_DISPLAY1(" methodID: 0x%p\n", - (void*)methodsDesc[i].method); - NSK_DISPLAY1(" code_size: %d\n", - (int)code_size); - NSK_DISPLAY1(" map_length: %d\n", - (int)map_length); - break; - } - } -} - -/** - * COMPILED_METHOD_UNLOAD callback. - * - turn off flag that method is compiled - */ -JNIEXPORT void JNICALL -callbackCompiledMethodUnload(jvmtiEnv* jvmti, jmethodID method, - const void* code_addr) { - int i; - - for (i = 0; i < METHODS_COUNT; i++) { - if (methodsDesc[i].method == method) { - methodsDesc[i].unloadEvents++; - NSK_DISPLAY3(" COMPILED_METHOD_UNLOAD for method #%d (%s): %d times\n", - i, methodsDesc[i].methodName, methodsDesc[i].loadEvents); - NSK_DISPLAY1(" methodID: 0x%p\n", - (void*)methodsDesc[i].method); - break; - } - } -} - -/* ============================================================================= */ - -/** Native running method in tested thread. */ -JNIEXPORT jint JNICALL -Java_nsk_jvmti_scenarios_events_EM05_em05t001Thread_nativeMethod(JNIEnv* jni, - jobject obj, - jint i) { - jint k = 0; - jint j; - - for (j = 0; j < i; j++) { - k += (i - j); - } - return k; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em05t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em05t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em05t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - caps.can_generate_compiled_method_load_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.CompiledMethodLoad = callbackCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = callbackCompiledMethodUnload; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/em05t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/em05t001.cpp new file mode 100644 index 00000000000..2959b416439 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/em05t001.cpp @@ -0,0 +1,358 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static JNIEnv* jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/scenarios/events/EM05/em05t001" +#define THREAD_CLASS_NAME "nsk/jvmti/scenarios/events/EM05/em05t001Thread" +#define THREAD_FIELD_NAME "thread" +#define THREAD_FIELD_SIG "L" THREAD_CLASS_NAME ";" + +/* constants */ +#define MAX_NAME_LENGTH 64 +#define EVENTS_COUNT 2 +#define METHODS_COUNT 2 + +/* tested events */ +static jvmtiEvent eventsList[EVENTS_COUNT] = { + JVMTI_EVENT_COMPILED_METHOD_LOAD, + JVMTI_EVENT_COMPILED_METHOD_UNLOAD +}; + +/* method description structure */ +typedef struct { + char methodName[MAX_NAME_LENGTH]; + char methodSig[MAX_NAME_LENGTH]; + jmethodID method; + int compiled; + int loadEvents; + int unloadEvents; +} MethodDesc; + +/* descriptions of tested methods */ +static MethodDesc methodsDesc[METHODS_COUNT] = { + {"javaMethod", "(I)I", NULL, 0, 0, 0}, + {"nativeMethod", "(I)I", NULL, 0, 0, 0} +}; + +/* ============================================================================= */ + +/* testcase(s) */ +static int prepare(); +static int checkEvents(); +static int clean(); + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + jni = agentJNI; + + NSK_DISPLAY0("Wait for debuggee to become ready\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + { + NSK_DISPLAY0("Prepare data\n"); + if (!prepare()) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Provoke methods compilation\n"); + if (!nsk_jvmti_resumeSync()) + return; + + NSK_DISPLAY0("Wait for threads to complete\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY0("Check if events received\n"); + if (!checkEvents()) + return; + + NSK_DISPLAY0("Clean data\n"); + if (!clean()) { + nsk_jvmti_setFailStatus(); + return; + } + } + + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ============================================================================= */ + +/** + * Enable or disable tested events. + */ +static int enableEvents(jvmtiEventMode enable) { + int i; + + for (i = 0; i < EVENTS_COUNT; i++) { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, enable, + eventsList[i], NULL))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + return NSK_TRUE; +} + +/** + * Prepare data. + * - find tested thread + * - get tested methodIDs + * - enable events + */ +static int prepare() { + jclass debugeeClass = NULL; + jclass threadClass = NULL; + jfieldID threadFieldID = NULL; + jthread thread = NULL; + int i; + + for (i = 0; i < METHODS_COUNT; i++) { + methodsDesc[i].method = (jmethodID)NULL; + methodsDesc[i].loadEvents = 0; + methodsDesc[i].unloadEvents = 0; + } + + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (threadFieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + THREAD_FIELD_NAME, THREAD_FIELD_SIG)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (thread = (jthread) + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, threadFieldID)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (threadClass = + NSK_CPP_STUB2(GetObjectClass, jni, thread)) != NULL)) + return NSK_FALSE; + + NSK_DISPLAY0("Find tested methods:\n"); + for (i = 0; i < METHODS_COUNT; i++) { + if (!NSK_JNI_VERIFY(jni, (methodsDesc[i].method = + NSK_CPP_STUB4(GetMethodID, jni, threadClass, + methodsDesc[i].methodName, methodsDesc[i].methodSig)) != NULL)) + return NSK_FALSE; + NSK_DISPLAY3(" method #%d (%s): 0x%p\n", + i, methodsDesc[i].methodName, (void*)methodsDesc[i].method); + } + + NSK_DISPLAY0("Enable events\n"); + if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, eventsList, NULL)) + return NSK_FALSE; + + return NSK_TRUE; +} + +/** + * Testcase: check tested events. + * - check if expected events received for each method + * + * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. + */ +static int checkEvents() { + int i; + + for (i = 0; i < METHODS_COUNT; i++) { + NSK_DISPLAY2(" method #%d (%s):\n", + i, methodsDesc[i].methodName); + NSK_DISPLAY2(" COMPILED_METHOD_LOAD: %d, COMPILED_METHOD_UNLOAD: %d\n", + methodsDesc[i].loadEvents, methodsDesc[i].unloadEvents); + + if (methodsDesc[i].loadEvents <= 0) { + NSK_DISPLAY1("# WARNING: No COMPILED_METHOD_LOAD events for method: %s\n", + methodsDesc[i].methodName); + } + + if (methodsDesc[i].unloadEvents > methodsDesc[i].loadEvents) { + NSK_DISPLAY1("# WARNING: Too many COMPILED_METHOD_UNLOAD events for method: %s\n", + methodsDesc[i].methodName); + NSK_DISPLAY2("# COMPILED_METHOD_LOAD: %d, COMPILED_METHOD_UNLOAD: %d\n", + methodsDesc[i].loadEvents, methodsDesc[i].unloadEvents); + } + } + return NSK_TRUE; +} + +/** + * Clean data: + * - disable events + */ +static int clean() { + NSK_DISPLAY0("Disable events\n"); + if (!nsk_jvmti_enableEvents(JVMTI_DISABLE, EVENTS_COUNT, eventsList, NULL)) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** + * COMPILED_METHOD_LOAD callback. + * - turn on flag if method is compiled + */ +JNIEXPORT void JNICALL +callbackCompiledMethodLoad(jvmtiEnv* jvmti, jmethodID method, + jint code_size, const void* code_addr, + jint map_length, const jvmtiAddrLocationMap* map, + const void* compile_info) { + int i; + + for (i = 0; i < METHODS_COUNT; i++) { + if (methodsDesc[i].method == method) { + methodsDesc[i].loadEvents++; + NSK_DISPLAY3(" COMPILED_METHOD_LOAD for method #%d (%s): %d times\n", + i, methodsDesc[i].methodName, methodsDesc[i].loadEvents); + NSK_DISPLAY1(" methodID: 0x%p\n", + (void*)methodsDesc[i].method); + NSK_DISPLAY1(" code_size: %d\n", + (int)code_size); + NSK_DISPLAY1(" map_length: %d\n", + (int)map_length); + break; + } + } +} + +/** + * COMPILED_METHOD_UNLOAD callback. + * - turn off flag that method is compiled + */ +JNIEXPORT void JNICALL +callbackCompiledMethodUnload(jvmtiEnv* jvmti, jmethodID method, + const void* code_addr) { + int i; + + for (i = 0; i < METHODS_COUNT; i++) { + if (methodsDesc[i].method == method) { + methodsDesc[i].unloadEvents++; + NSK_DISPLAY3(" COMPILED_METHOD_UNLOAD for method #%d (%s): %d times\n", + i, methodsDesc[i].methodName, methodsDesc[i].loadEvents); + NSK_DISPLAY1(" methodID: 0x%p\n", + (void*)methodsDesc[i].method); + break; + } + } +} + +/* ============================================================================= */ + +/** Native running method in tested thread. */ +JNIEXPORT jint JNICALL +Java_nsk_jvmti_scenarios_events_EM05_em05t001Thread_nativeMethod(JNIEnv* jni, + jobject obj, + jint i) { + jint k = 0; + jint j; + + for (j = 0; j < i; j++) { + k += (i - j); + } + return k; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em05t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em05t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em05t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + caps.can_generate_compiled_method_load_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.CompiledMethodLoad = callbackCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = callbackCompiledMethodUnload; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/libem05t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/libem05t001.c deleted file mode 100644 index 4c8dcce20dd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/libem05t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em05t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/libem05t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/libem05t001.cpp new file mode 100644 index 00000000000..81d9046d2f8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t001/libem05t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em05t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/em05t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/em05t002.c deleted file mode 100644 index 7a9b6ad152f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/em05t002.c +++ /dev/null @@ -1,426 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static JNIEnv* jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/scenarios/events/EM05/em05t002" -#define THREAD_CLASS_NAME "nsk/jvmti/scenarios/events/EM05/em05t002Thread" -#define THREAD_FIELD_NAME "thread" -#define THREAD_FIELD_SIG "L"THREAD_CLASS_NAME";" - -/* constants */ -#define MAX_NAME_LENGTH 64 -#define EVENTS_COUNT 2 -#define METHODS_COUNT 2 -#define MOMENTS_COUNT 3 - -/* compilation moments */ -#define COMPILATION_MOMENT_BEFORE 0 -#define COMPILATION_MOMENT_RUNNING 1 -#define COMPILATION_MOMENT_AFTER 2 - -/* tested events */ -static jvmtiEvent eventsList[EVENTS_COUNT] = { - JVMTI_EVENT_COMPILED_METHOD_LOAD, - JVMTI_EVENT_COMPILED_METHOD_UNLOAD -}; - -/* method description structure */ -typedef struct { - char methodName[MAX_NAME_LENGTH]; - char methodSig[MAX_NAME_LENGTH]; - jmethodID method; - int compiled; - int loadEvents[MOMENTS_COUNT]; - int unloadEvents[MOMENTS_COUNT]; -} MethodDesc; - -/* descriptions of tested methods */ -static MethodDesc methodsDesc[METHODS_COUNT] = { - {"javaMethod", "(I)I", NULL, 0, {0}, {0}}, - {"nativeMethod", "(I)I", NULL, 0, {0}, {0}} -}; - -/* current compilation moment */ -static volatile int moment = COMPILATION_MOMENT_BEFORE; - -/* ============================================================================= */ - -/* testcase(s) */ -static int prepare(); -static int generateEvents(); -static int checkEvents(); -static int clean(); - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - jni = agentJNI; - - NSK_DISPLAY0("Wait for debuggee to become ready\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - { - NSK_DISPLAY0("Prepare data\n"); - if (!prepare()) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Testcase #1: generate events before running thread\n"); - moment = COMPILATION_MOMENT_BEFORE; - NSK_DISPLAY0("Call GenerateEvents() before running methods\n"); - if (!generateEvents()) - return; - NSK_DISPLAY0("Check if events received\n"); - if (!checkEvents()) - return; - - NSK_DISPLAY0("Testcase #2: run methods to provoke compilation\n"); - moment = COMPILATION_MOMENT_RUNNING; - NSK_DISPLAY0("Provoke methods compilation\n"); - if (!nsk_jvmti_resumeSync()) - return; - NSK_DISPLAY0("Wait for thread to completed\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - NSK_DISPLAY0("Check if events received\n"); - if (!checkEvents()) - return; - - NSK_DISPLAY0("Testcase #3: generate events before running thread\n"); - moment = COMPILATION_MOMENT_AFTER; - NSK_DISPLAY0("Call GenerateEvents() after running methods\n"); - if (!generateEvents()) - return; - NSK_DISPLAY0("Check if events received\n"); - if (!checkEvents()) - return; - - NSK_DISPLAY0("Clean data\n"); - if (!clean()) { - nsk_jvmti_setFailStatus(); - return; - } - } - - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ============================================================================= */ - -/** - * Generate tested events (COMPILED_METHOD_LOAD only). - */ -static int generateEvents() { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(GenerateEvents, jvmti, JVMTI_EVENT_COMPILED_METHOD_LOAD))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - return NSK_TRUE; -} - -/** - * Prepare data. - * - find tested thread - * - get tested methodIDs - * - enable events - */ -static int prepare() { - jclass debugeeClass = NULL; - jclass threadClass = NULL; - jfieldID threadFieldID = NULL; - jthread thread = NULL; - int i; - - for (i = 0; i < METHODS_COUNT; i++) { - int j; - methodsDesc[i].method = (jmethodID)NULL; - methodsDesc[i].compiled = NSK_FALSE; - for (j = 0; j < MOMENTS_COUNT; j++) { - methodsDesc[i].loadEvents[j] = 0; - methodsDesc[i].unloadEvents[j] = 0; - } - } - - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (threadFieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - THREAD_FIELD_NAME, THREAD_FIELD_SIG)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (thread = (jthread) - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, threadFieldID)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (threadClass = - NSK_CPP_STUB2(GetObjectClass, jni, thread)) != NULL)) - return NSK_FALSE; - - NSK_DISPLAY0("Find tested methods:\n"); - for (i = 0; i < METHODS_COUNT; i++) { - if (!NSK_JNI_VERIFY(jni, (methodsDesc[i].method = - NSK_CPP_STUB4(GetMethodID, jni, threadClass, - methodsDesc[i].methodName, methodsDesc[i].methodSig)) != NULL)) - return NSK_FALSE; - NSK_DISPLAY3(" method #%d (%s): 0x%p\n", - i, methodsDesc[i].methodName, (void*)methodsDesc[i].method); - } - - NSK_DISPLAY0("Enable events\n"); - if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, eventsList, NULL)) - return NSK_FALSE; - - return NSK_TRUE; -} - -/** - * Testcase: check tested events. - * - check if expected events received for each method - * - * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. - */ -static int checkEvents() { - int i; - - for (i = 0; i < METHODS_COUNT; i++) { - NSK_DISPLAY2(" method #%d (%s):\n", - i, methodsDesc[i].methodName); - NSK_DISPLAY2(" COMPILED_METHOD_LOAD: %d, COMPILED_METHOD_UNLOAD: %d\n", - methodsDesc[i].loadEvents[moment], - methodsDesc[i].unloadEvents[moment]); - - if (moment == COMPILATION_MOMENT_AFTER) { - int loadEventsTotal = methodsDesc[i].loadEvents[COMPILATION_MOMENT_BEFORE] - + methodsDesc[i].loadEvents[COMPILATION_MOMENT_RUNNING]; - int unloadEventsTotal = methodsDesc[i].unloadEvents[COMPILATION_MOMENT_BEFORE] - + methodsDesc[i].unloadEvents[COMPILATION_MOMENT_RUNNING]; - - /* complain if no COMPILED_METHOD_LOAD events finally generated for compiled events */ - if (methodsDesc[i].compiled) { - if (methodsDesc[i].loadEvents[COMPILATION_MOMENT_AFTER] > loadEventsTotal) { - NSK_COMPLAIN4("No COMPILED_METHOD_LOAD events finally generated for compiled method: %s\n" - "# total COMPILED_METHOD_LOAD: %d\n" - "# total COMPILED_METHOD_UNLOAD: %d\n" - "# final GenerateEvents(): %d\n", - methodsDesc[i].methodName, - loadEventsTotal, - unloadEventsTotal, - methodsDesc[i].loadEvents[COMPILATION_MOMENT_AFTER]); - nsk_jvmti_setFailStatus(); - } - } - - /* complain if too many COMPILED_METHOD_LOAD events finally generated */ - if (methodsDesc[i].loadEvents[COMPILATION_MOMENT_AFTER] > loadEventsTotal) { - NSK_COMPLAIN5("Too many COMPILED_METHOD_LOAD events finally generated for method: %s\n" - "# GenerateEvents() before execution: %d\n" - "# generated during execution: %d\n" - "# total: %d\n" - "# GenerateEvents() after execution: %d\n", - methodsDesc[i].methodName, - methodsDesc[i].loadEvents[COMPILATION_MOMENT_BEFORE], - methodsDesc[i].loadEvents[COMPILATION_MOMENT_RUNNING], - loadEventsTotal, - methodsDesc[i].loadEvents[COMPILATION_MOMENT_AFTER]); - nsk_jvmti_setFailStatus(); - } - - /* warn if too mamy COMPILED_METHOD_UNLOAD events received */ - if (unloadEventsTotal > loadEventsTotal) { - NSK_DISPLAY1("# WARNING: Too many COMPILED_METHOD_UNLOAD events for method: %s\n", - methodsDesc[i].methodName); - NSK_DISPLAY2("# COMPILED_METHOD_LOAD: %d, COMPILED_METHOD_UNLOAD: %d\n", - loadEventsTotal, unloadEventsTotal); - } - } - } - return NSK_TRUE; -} - -/** - * Clean data. - * - disable events - */ -static int clean() { - NSK_DISPLAY0("Disable events\n"); - if (!nsk_jvmti_enableEvents(JVMTI_DISABLE, EVENTS_COUNT, eventsList, NULL)) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** - * COMPILED_METHOD_LOAD callback. - * - turm on flag that method is compiled - */ -JNIEXPORT void JNICALL -callbackCompiledMethodLoad(jvmtiEnv* jvmti, jmethodID method, - jint code_size, const void* code_addr, - jint map_length, const jvmtiAddrLocationMap* map, - const void* compile_info) { - int i; - - /* check if event is for tested method and count it */ - for (i = 0; i < METHODS_COUNT; i++) { - if (methodsDesc[i].method == method) { - methodsDesc[i].loadEvents[moment]++; - methodsDesc[i].compiled = NSK_TRUE; - - NSK_DISPLAY3(" COMPILED_METHOD_LOAD for method #%d (%s): %d times\n", - i, methodsDesc[i].methodName, - methodsDesc[i].loadEvents[moment]); - NSK_DISPLAY1(" methodID: 0x%p\n", - (void*)methodsDesc[i].method); - NSK_DISPLAY1(" code_size: %d\n", - (int)code_size); - NSK_DISPLAY1(" map_length: %d\n", - (int)map_length); - break; - } - } -} - -/** - * COMPILED_METHOD_UNLOAD callback. - * - turn off flag that method is compiled - */ -JNIEXPORT void JNICALL -callbackCompiledMethodUnload(jvmtiEnv* jvmti, jmethodID method, - const void* code_addr) { - int i; - - /* check if event is for tested method and count it */ - for (i = 0; i < METHODS_COUNT; i++) { - if (methodsDesc[i].method == method) { - methodsDesc[i].unloadEvents[moment]++; - methodsDesc[i].compiled = NSK_FALSE; - - NSK_DISPLAY3(" COMPILED_METHOD_UNLOAD for method #%d (%s): %d times\n", - i, methodsDesc[i].methodName, - methodsDesc[i].loadEvents[moment]); - NSK_DISPLAY1(" methodID: 0x%p\n", - (void*)methodsDesc[i].method); - break; - } - } -} - -/* ============================================================================= */ - -/** Native running method in tested thread. */ -JNIEXPORT jint JNICALL -Java_nsk_jvmti_scenarios_events_EM05_em05t002Thread_nativeMethod(JNIEnv* jni, - jobject obj, jint i) { - jint k = 0; - jint j; - - for (j = 0; j < i; j++) { - k += (i - j); - } - return k; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em05t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em05t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em05t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - caps.can_generate_compiled_method_load_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.CompiledMethodLoad = callbackCompiledMethodLoad; - eventCallbacks.CompiledMethodUnload = callbackCompiledMethodUnload; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/em05t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/em05t002.cpp new file mode 100644 index 00000000000..df2a463db4b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/em05t002.cpp @@ -0,0 +1,426 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static JNIEnv* jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/scenarios/events/EM05/em05t002" +#define THREAD_CLASS_NAME "nsk/jvmti/scenarios/events/EM05/em05t002Thread" +#define THREAD_FIELD_NAME "thread" +#define THREAD_FIELD_SIG "L" THREAD_CLASS_NAME ";" + +/* constants */ +#define MAX_NAME_LENGTH 64 +#define EVENTS_COUNT 2 +#define METHODS_COUNT 2 +#define MOMENTS_COUNT 3 + +/* compilation moments */ +#define COMPILATION_MOMENT_BEFORE 0 +#define COMPILATION_MOMENT_RUNNING 1 +#define COMPILATION_MOMENT_AFTER 2 + +/* tested events */ +static jvmtiEvent eventsList[EVENTS_COUNT] = { + JVMTI_EVENT_COMPILED_METHOD_LOAD, + JVMTI_EVENT_COMPILED_METHOD_UNLOAD +}; + +/* method description structure */ +typedef struct { + char methodName[MAX_NAME_LENGTH]; + char methodSig[MAX_NAME_LENGTH]; + jmethodID method; + int compiled; + int loadEvents[MOMENTS_COUNT]; + int unloadEvents[MOMENTS_COUNT]; +} MethodDesc; + +/* descriptions of tested methods */ +static MethodDesc methodsDesc[METHODS_COUNT] = { + {"javaMethod", "(I)I", NULL, 0, {}, {} }, + {"nativeMethod", "(I)I", NULL, 0, {}, {} } +}; + +/* current compilation moment */ +static volatile int moment = COMPILATION_MOMENT_BEFORE; + +/* ============================================================================= */ + +/* testcase(s) */ +static int prepare(); +static int generateEvents(); +static int checkEvents(); +static int clean(); + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + jni = agentJNI; + + NSK_DISPLAY0("Wait for debuggee to become ready\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + { + NSK_DISPLAY0("Prepare data\n"); + if (!prepare()) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Testcase #1: generate events before running thread\n"); + moment = COMPILATION_MOMENT_BEFORE; + NSK_DISPLAY0("Call GenerateEvents() before running methods\n"); + if (!generateEvents()) + return; + NSK_DISPLAY0("Check if events received\n"); + if (!checkEvents()) + return; + + NSK_DISPLAY0("Testcase #2: run methods to provoke compilation\n"); + moment = COMPILATION_MOMENT_RUNNING; + NSK_DISPLAY0("Provoke methods compilation\n"); + if (!nsk_jvmti_resumeSync()) + return; + NSK_DISPLAY0("Wait for thread to completed\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + NSK_DISPLAY0("Check if events received\n"); + if (!checkEvents()) + return; + + NSK_DISPLAY0("Testcase #3: generate events before running thread\n"); + moment = COMPILATION_MOMENT_AFTER; + NSK_DISPLAY0("Call GenerateEvents() after running methods\n"); + if (!generateEvents()) + return; + NSK_DISPLAY0("Check if events received\n"); + if (!checkEvents()) + return; + + NSK_DISPLAY0("Clean data\n"); + if (!clean()) { + nsk_jvmti_setFailStatus(); + return; + } + } + + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ============================================================================= */ + +/** + * Generate tested events (COMPILED_METHOD_LOAD only). + */ +static int generateEvents() { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(GenerateEvents, jvmti, JVMTI_EVENT_COMPILED_METHOD_LOAD))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + return NSK_TRUE; +} + +/** + * Prepare data. + * - find tested thread + * - get tested methodIDs + * - enable events + */ +static int prepare() { + jclass debugeeClass = NULL; + jclass threadClass = NULL; + jfieldID threadFieldID = NULL; + jthread thread = NULL; + int i; + + for (i = 0; i < METHODS_COUNT; i++) { + int j; + methodsDesc[i].method = (jmethodID)NULL; + methodsDesc[i].compiled = NSK_FALSE; + for (j = 0; j < MOMENTS_COUNT; j++) { + methodsDesc[i].loadEvents[j] = 0; + methodsDesc[i].unloadEvents[j] = 0; + } + } + + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (threadFieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + THREAD_FIELD_NAME, THREAD_FIELD_SIG)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (thread = (jthread) + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, threadFieldID)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (threadClass = + NSK_CPP_STUB2(GetObjectClass, jni, thread)) != NULL)) + return NSK_FALSE; + + NSK_DISPLAY0("Find tested methods:\n"); + for (i = 0; i < METHODS_COUNT; i++) { + if (!NSK_JNI_VERIFY(jni, (methodsDesc[i].method = + NSK_CPP_STUB4(GetMethodID, jni, threadClass, + methodsDesc[i].methodName, methodsDesc[i].methodSig)) != NULL)) + return NSK_FALSE; + NSK_DISPLAY3(" method #%d (%s): 0x%p\n", + i, methodsDesc[i].methodName, (void*)methodsDesc[i].method); + } + + NSK_DISPLAY0("Enable events\n"); + if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, eventsList, NULL)) + return NSK_FALSE; + + return NSK_TRUE; +} + +/** + * Testcase: check tested events. + * - check if expected events received for each method + * + * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. + */ +static int checkEvents() { + int i; + + for (i = 0; i < METHODS_COUNT; i++) { + NSK_DISPLAY2(" method #%d (%s):\n", + i, methodsDesc[i].methodName); + NSK_DISPLAY2(" COMPILED_METHOD_LOAD: %d, COMPILED_METHOD_UNLOAD: %d\n", + methodsDesc[i].loadEvents[moment], + methodsDesc[i].unloadEvents[moment]); + + if (moment == COMPILATION_MOMENT_AFTER) { + int loadEventsTotal = methodsDesc[i].loadEvents[COMPILATION_MOMENT_BEFORE] + + methodsDesc[i].loadEvents[COMPILATION_MOMENT_RUNNING]; + int unloadEventsTotal = methodsDesc[i].unloadEvents[COMPILATION_MOMENT_BEFORE] + + methodsDesc[i].unloadEvents[COMPILATION_MOMENT_RUNNING]; + + /* complain if no COMPILED_METHOD_LOAD events finally generated for compiled events */ + if (methodsDesc[i].compiled) { + if (methodsDesc[i].loadEvents[COMPILATION_MOMENT_AFTER] > loadEventsTotal) { + NSK_COMPLAIN4("No COMPILED_METHOD_LOAD events finally generated for compiled method: %s\n" + "# total COMPILED_METHOD_LOAD: %d\n" + "# total COMPILED_METHOD_UNLOAD: %d\n" + "# final GenerateEvents(): %d\n", + methodsDesc[i].methodName, + loadEventsTotal, + unloadEventsTotal, + methodsDesc[i].loadEvents[COMPILATION_MOMENT_AFTER]); + nsk_jvmti_setFailStatus(); + } + } + + /* complain if too many COMPILED_METHOD_LOAD events finally generated */ + if (methodsDesc[i].loadEvents[COMPILATION_MOMENT_AFTER] > loadEventsTotal) { + NSK_COMPLAIN5("Too many COMPILED_METHOD_LOAD events finally generated for method: %s\n" + "# GenerateEvents() before execution: %d\n" + "# generated during execution: %d\n" + "# total: %d\n" + "# GenerateEvents() after execution: %d\n", + methodsDesc[i].methodName, + methodsDesc[i].loadEvents[COMPILATION_MOMENT_BEFORE], + methodsDesc[i].loadEvents[COMPILATION_MOMENT_RUNNING], + loadEventsTotal, + methodsDesc[i].loadEvents[COMPILATION_MOMENT_AFTER]); + nsk_jvmti_setFailStatus(); + } + + /* warn if too mamy COMPILED_METHOD_UNLOAD events received */ + if (unloadEventsTotal > loadEventsTotal) { + NSK_DISPLAY1("# WARNING: Too many COMPILED_METHOD_UNLOAD events for method: %s\n", + methodsDesc[i].methodName); + NSK_DISPLAY2("# COMPILED_METHOD_LOAD: %d, COMPILED_METHOD_UNLOAD: %d\n", + loadEventsTotal, unloadEventsTotal); + } + } + } + return NSK_TRUE; +} + +/** + * Clean data. + * - disable events + */ +static int clean() { + NSK_DISPLAY0("Disable events\n"); + if (!nsk_jvmti_enableEvents(JVMTI_DISABLE, EVENTS_COUNT, eventsList, NULL)) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** + * COMPILED_METHOD_LOAD callback. + * - turm on flag that method is compiled + */ +JNIEXPORT void JNICALL +callbackCompiledMethodLoad(jvmtiEnv* jvmti, jmethodID method, + jint code_size, const void* code_addr, + jint map_length, const jvmtiAddrLocationMap* map, + const void* compile_info) { + int i; + + /* check if event is for tested method and count it */ + for (i = 0; i < METHODS_COUNT; i++) { + if (methodsDesc[i].method == method) { + methodsDesc[i].loadEvents[moment]++; + methodsDesc[i].compiled = NSK_TRUE; + + NSK_DISPLAY3(" COMPILED_METHOD_LOAD for method #%d (%s): %d times\n", + i, methodsDesc[i].methodName, + methodsDesc[i].loadEvents[moment]); + NSK_DISPLAY1(" methodID: 0x%p\n", + (void*)methodsDesc[i].method); + NSK_DISPLAY1(" code_size: %d\n", + (int)code_size); + NSK_DISPLAY1(" map_length: %d\n", + (int)map_length); + break; + } + } +} + +/** + * COMPILED_METHOD_UNLOAD callback. + * - turn off flag that method is compiled + */ +JNIEXPORT void JNICALL +callbackCompiledMethodUnload(jvmtiEnv* jvmti, jmethodID method, + const void* code_addr) { + int i; + + /* check if event is for tested method and count it */ + for (i = 0; i < METHODS_COUNT; i++) { + if (methodsDesc[i].method == method) { + methodsDesc[i].unloadEvents[moment]++; + methodsDesc[i].compiled = NSK_FALSE; + + NSK_DISPLAY3(" COMPILED_METHOD_UNLOAD for method #%d (%s): %d times\n", + i, methodsDesc[i].methodName, + methodsDesc[i].loadEvents[moment]); + NSK_DISPLAY1(" methodID: 0x%p\n", + (void*)methodsDesc[i].method); + break; + } + } +} + +/* ============================================================================= */ + +/** Native running method in tested thread. */ +JNIEXPORT jint JNICALL +Java_nsk_jvmti_scenarios_events_EM05_em05t002Thread_nativeMethod(JNIEnv* jni, + jobject obj, jint i) { + jint k = 0; + jint j; + + for (j = 0; j < i; j++) { + k += (i - j); + } + return k; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em05t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em05t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em05t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + caps.can_generate_compiled_method_load_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.CompiledMethodLoad = callbackCompiledMethodLoad; + eventCallbacks.CompiledMethodUnload = callbackCompiledMethodUnload; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/libem05t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/libem05t002.c deleted file mode 100644 index baaca2050d5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/libem05t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em05t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/libem05t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/libem05t002.cpp new file mode 100644 index 00000000000..1549261917d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM05/em05t002/libem05t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em05t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/em06t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/em06t001.c deleted file mode 100644 index 981b70decf2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/em06t001.c +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static JNIEnv* jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) -#define EXPECTED_CLASS_NAME "nsk.jvmti.scenarios.events.EM06.em06t001a" -#define CLASS_LOADER_COUNT_PARAM "classLoaderCount" - -static int classLoaderCount = 0; -static int classloadEventCount = 0; -static int classprepareEventCount = 0; - -/* ============================================================================= */ - -/* callbacks */ - -void -handler(jvmtiEvent event, jvmtiEnv* jvmti, JNIEnv* jni_env, - jthread thread, jclass klass) { - - jmethodID methodID; - jclass classObject; - jstring jclassName; - const char *className; - - if (!NSK_JNI_VERIFY(jni_env, (classObject = - NSK_CPP_STUB2(GetObjectClass, jni_env, klass)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_JNI_VERIFY(jni_env, (methodID = - NSK_CPP_STUB4(GetMethodID, jni_env, classObject, - "getName", "()Ljava/lang/String;")) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - jclassName = NSK_CPP_STUB3(CallObjectMethod, jni_env, klass, - methodID); - - className = NSK_CPP_STUB3(GetStringUTFChars, jni_env, jclassName, 0); - - if ( className != NULL && (strcmp(className, EXPECTED_CLASS_NAME)==0) ) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - switch (event) { - case JVMTI_EVENT_CLASS_LOAD: - classloadEventCount++; break; - case JVMTI_EVENT_CLASS_PREPARE: - classprepareEventCount++; break; - default: - NSK_COMPLAIN1("Unexpected event %s", TranslateEvent(event)); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - } - - NSK_CPP_STUB3(ReleaseStringUTFChars, jni_env, jclassName, className); -} - -JNIEXPORT void JNICALL -cbClassLoad(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, jclass klass) { - - handler(JVMTI_EVENT_CLASS_LOAD, jvmti, jni_env, thread, klass); -} - -JNIEXPORT void JNICALL -cbClassPrepare(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, jclass klass) { - - handler(JVMTI_EVENT_CLASS_PREPARE, jvmti, jni_env, thread, klass); -} - -/* ============================================================================= */ - -static int -enableEvent(jvmtiEventMode enable, jvmtiEvent event) { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, enable, - event, NULL))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** - * Testcase: check tested events. - * - check if expected events received for each method - * - * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. - */ -int checkEvents() { - - int result = NSK_TRUE; - - if (classloadEventCount == classLoaderCount) { - NSK_DISPLAY1("Expected number of JVMTI_EVENT_CLASS_LOAD events %d\n", - classloadEventCount); - } else { - NSK_COMPLAIN2("Unexpected number of JVMTI_EVENT_CLASS_LOAD events %d\n\texpected value %d\n", - classloadEventCount, - classLoaderCount); - result = NSK_FALSE; - } - - if (classprepareEventCount == classLoaderCount) { - NSK_DISPLAY1("Expected number of JVMTI_EVENT_CLASS_PREPARE events %d\n", - classloadEventCount); - } else { - NSK_COMPLAIN2("Unexpected number of JVMTI_EVENT_CLASS_PREPARE events %d\n\texpected value %d\n", - classprepareEventCount, - classLoaderCount); - result = NSK_FALSE; - } - - return result; -} - -/* ============================================================================= */ - -static int -setCallBacks() { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - eventCallbacks.ClassLoad = cbClassLoad; - eventCallbacks.ClassPrepare = cbClassPrepare; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return; - } - - jni = agentJNI; - - NSK_DISPLAY0("Wait for debuggee to become ready\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!setCallBacks()) { - return; - } - - if (!enableEvent(JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD) - || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE)) { - NSK_COMPLAIN0("Events could not be enabled"); - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Let debuggee to load class\n"); - if (!nsk_jvmti_resumeSync()) - return; - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!checkEvents()) { - nsk_jvmti_setFailStatus(); - } - - if (!enableEvent(JVMTI_DISABLE, JVMTI_EVENT_CLASS_LOAD) - || !enableEvent(JVMTI_DISABLE, JVMTI_EVENT_CLASS_PREPARE)) { - NSK_COMPLAIN0("Events could not be disabled"); - nsk_jvmti_setFailStatus(); - } - - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em06t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em06t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em06t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - classLoaderCount = nsk_jvmti_findOptionIntValue(CLASS_LOADER_COUNT_PARAM, 100); - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/em06t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/em06t001.cpp new file mode 100644 index 00000000000..7d88beab0af --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/em06t001.cpp @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static JNIEnv* jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) +#define EXPECTED_CLASS_NAME "nsk.jvmti.scenarios.events.EM06.em06t001a" +#define CLASS_LOADER_COUNT_PARAM "classLoaderCount" + +static int classLoaderCount = 0; +static int classloadEventCount = 0; +static int classprepareEventCount = 0; + +/* ============================================================================= */ + +/* callbacks */ + +void +handler(jvmtiEvent event, jvmtiEnv* jvmti, JNIEnv* jni_env, + jthread thread, jclass klass) { + + jmethodID methodID; + jclass classObject; + jstring jclassName; + const char *className; + + if (!NSK_JNI_VERIFY(jni_env, (classObject = + NSK_CPP_STUB2(GetObjectClass, jni_env, klass)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_JNI_VERIFY(jni_env, (methodID = + NSK_CPP_STUB4(GetMethodID, jni_env, classObject, + "getName", "()Ljava/lang/String;")) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + jclassName = (jstring) (jstring) (jstring) (jstring) (jstring) (jstring) (jstring) (jstring) (jstring) NSK_CPP_STUB3(CallObjectMethod, jni_env, klass, + methodID); + + className = NSK_CPP_STUB3(GetStringUTFChars, jni_env, jclassName, 0); + + if ( className != NULL && (strcmp(className, EXPECTED_CLASS_NAME)==0) ) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + switch (event) { + case JVMTI_EVENT_CLASS_LOAD: + classloadEventCount++; break; + case JVMTI_EVENT_CLASS_PREPARE: + classprepareEventCount++; break; + default: + NSK_COMPLAIN1("Unexpected event %s", TranslateEvent(event)); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + } + + NSK_CPP_STUB3(ReleaseStringUTFChars, jni_env, jclassName, className); +} + +JNIEXPORT void JNICALL +cbClassLoad(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, jclass klass) { + + handler(JVMTI_EVENT_CLASS_LOAD, jvmti, jni_env, thread, klass); +} + +JNIEXPORT void JNICALL +cbClassPrepare(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, jclass klass) { + + handler(JVMTI_EVENT_CLASS_PREPARE, jvmti, jni_env, thread, klass); +} + +/* ============================================================================= */ + +static int +enableEvent(jvmtiEventMode enable, jvmtiEvent event) { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, enable, + event, NULL))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** + * Testcase: check tested events. + * - check if expected events received for each method + * + * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. + */ +int checkEvents() { + + int result = NSK_TRUE; + + if (classloadEventCount == classLoaderCount) { + NSK_DISPLAY1("Expected number of JVMTI_EVENT_CLASS_LOAD events %d\n", + classloadEventCount); + } else { + NSK_COMPLAIN2("Unexpected number of JVMTI_EVENT_CLASS_LOAD events %d\n\texpected value %d\n", + classloadEventCount, + classLoaderCount); + result = NSK_FALSE; + } + + if (classprepareEventCount == classLoaderCount) { + NSK_DISPLAY1("Expected number of JVMTI_EVENT_CLASS_PREPARE events %d\n", + classloadEventCount); + } else { + NSK_COMPLAIN2("Unexpected number of JVMTI_EVENT_CLASS_PREPARE events %d\n\texpected value %d\n", + classprepareEventCount, + classLoaderCount); + result = NSK_FALSE; + } + + return result; +} + +/* ============================================================================= */ + +static int +setCallBacks() { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + eventCallbacks.ClassLoad = cbClassLoad; + eventCallbacks.ClassPrepare = cbClassPrepare; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return; + } + + jni = agentJNI; + + NSK_DISPLAY0("Wait for debuggee to become ready\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!setCallBacks()) { + return; + } + + if (!enableEvent(JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD) + || !enableEvent(JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE)) { + NSK_COMPLAIN0("Events could not be enabled"); + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Let debuggee to load class\n"); + if (!nsk_jvmti_resumeSync()) + return; + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!checkEvents()) { + nsk_jvmti_setFailStatus(); + } + + if (!enableEvent(JVMTI_DISABLE, JVMTI_EVENT_CLASS_LOAD) + || !enableEvent(JVMTI_DISABLE, JVMTI_EVENT_CLASS_PREPARE)) { + NSK_COMPLAIN0("Events could not be disabled"); + nsk_jvmti_setFailStatus(); + } + + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em06t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em06t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em06t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + classLoaderCount = nsk_jvmti_findOptionIntValue(CLASS_LOADER_COUNT_PARAM, 100); + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/libem06t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/libem06t001.c deleted file mode 100644 index 7eaa5c0b0d0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/libem06t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em06t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/libem06t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/libem06t001.cpp new file mode 100644 index 00000000000..370fae7d5e2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM06/em06t001/libem06t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em06t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/em07t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/em07t001.c deleted file mode 100644 index b69da1568a0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/em07t001.c +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static jlong timeout = 0; -static jvmtiEnv *jvmti = NULL; -static jrawMonitorID syncLock = NULL; - -/* constant names */ -#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) -#define EXPECTED_COUNT 0 - -static int eventCount[JVMTI_EVENT_COUNT]; - -/* ============================================================================= */ - -void showEventStatistics() { - int i; - const char* str; - - NSK_DISPLAY0("\n"); - NSK_DISPLAY0("Event statistics\n"); - NSK_DISPLAY0("----------------\n"); - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - if (eventCount[i] > 0) { - str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); - NSK_DISPLAY2("%-40s %7d\n", str, eventCount[i]); - } - } -} - -/* ========================================================================== */ - -void changeCount(jvmtiEvent event) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - - eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL]++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -/* callbacks */ -JNIEXPORT void JNICALL -cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { - changeCount(JVMTI_EVENT_VM_INIT); - NSK_DISPLAY0("--->VMINit is received\n"); -} - -JNIEXPORT void JNICALL -cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { - changeCount(JVMTI_EVENT_VM_DEATH); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) - nsk_jvmti_setFailStatus(); - -} - -void JNICALL -cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - changeCount(JVMTI_EVENT_EXCEPTION); -} - -void JNICALL -cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception) { - changeCount(JVMTI_EVENT_EXCEPTION_CATCH); -} - -void JNICALL -cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_SINGLE_STEP); -} - -void JNICALL -cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception) { - changeCount(JVMTI_EVENT_FRAME_POP); -} - -void JNICALL -cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - changeCount(JVMTI_EVENT_BREAKPOINT); -} - -void JNICALL -cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field) { - changeCount(JVMTI_EVENT_FIELD_ACCESS); -} - -void JNICALL -cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jclass field_klass, - jobject object, jfieldID field, char signature_type, - jvalue new_value) { - changeCount(JVMTI_EVENT_FIELD_MODIFICATION); -} - -void JNICALL -cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method) { - changeCount(JVMTI_EVENT_METHOD_ENTRY); -} - -void JNICALL -cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, - jvalue return_value) { - changeCount(JVMTI_EVENT_METHOD_EXIT); -} - -void JNICALL -cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, - jmethodID method, void* address, void** new_address_ptr) { - changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND); -} - -void JNICALL -cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD); -} - -void JNICALL -cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD); -} - -void JNICALL -cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jlong tout) { - - changeCount(JVMTI_EVENT_MONITOR_WAIT); -} - -void JNICALL -cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jboolean timed_out) { - - changeCount(JVMTI_EVENT_MONITOR_WAITED); -} - -JNIEXPORT void JNICALL -cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER); -} - -void JNICALL -cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object) { - - changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED); -} - -void JNICALL -cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START); -} - -void JNICALL -cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { - changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH); -} - -void JNICALL -cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - changeCount(JVMTI_EVENT_OBJECT_FREE); -} - -void JNICALL -cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC); -} - -/* ============================================================================= */ - -int enableOptionalEvents(jvmtiEnv *jvmti) { - int i; - int result = NSK_TRUE; - - NSK_DISPLAY0("Enable events\n"); - - /* enabling optional events */ - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - jvmtiEvent event = (jvmtiEvent)(i + JVMTI_MIN_EVENT_TYPE_VAL); - if (nsk_jvmti_isOptionalEvent(event)) - if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_ENABLE, event, NULL))) { - NSK_COMPLAIN1("Unexpected error enabling %s\n", - TranslateEvent(event)); - result = NSK_FALSE; - } - } - - return result; -} - -/* ============================================================================= */ - -/** - * Testcase: check tested events. - * - check if expected events received for each method - * - * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. - */ -int checkEvents() { - int i; - jvmtiEvent event; - int result = NSK_TRUE; - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - - event = i + JVMTI_MIN_EVENT_TYPE_VAL; - - if (nsk_jvmti_isOptionalEvent(event) && eventCount[i] > EXPECTED_COUNT) { - nsk_jvmti_setFailStatus(); - NSK_COMPLAIN3("Unexpected number of %s events:\n\treceived: %7d\n\texpected: %7d\n", - TranslateEvent(event), - eventCount[i], - EXPECTED_COUNT); - result = NSK_FALSE; - } - } - - return result; -} - -/* ============================================================================= */ - -static int setCallBacks(jvmtiEnv *jvmti) { - int i; - - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - - for (i = 0; i < JVMTI_EVENT_COUNT; i++) { - eventCount[i] = 0; - } - - eventCallbacks.VMInit = cbVMInit; - eventCallbacks.VMDeath = cbVMDeath; - eventCallbacks.Exception = cbException; - eventCallbacks.ExceptionCatch = cbExceptionCatch; - eventCallbacks.SingleStep = cbSingleStep; - eventCallbacks.FramePop = cbFramePop; - eventCallbacks.Breakpoint = cbBreakpoint; - eventCallbacks.FieldAccess = cbFieldAccess; - eventCallbacks.FieldModification = cbFieldModification; - eventCallbacks.MethodEntry = cbMethodEntry; - eventCallbacks.MethodExit = cbMethodExit; - eventCallbacks.NativeMethodBind = cbNativeMethodBind; - eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; - eventCallbacks.MonitorWait = cbMonitorWait; - eventCallbacks.MonitorWaited = cbMonitorWaited; - eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; - eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; - eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; - eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; - eventCallbacks.ObjectFree = cbObjectFree; - eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, - sizeof(eventCallbacks)))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - NSK_DISPLAY0("Wait for debuggee to become ready\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!checkEvents()) { - nsk_jvmti_setFailStatus(); - } - showEventStatistics(); - - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; - -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_em07t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_em07t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_em07t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { - nsk_jvmti_setFailStatus(); - return JNI_ERR; - } - - if (!setCallBacks(jvmti)) { - return JNI_ERR; - } - - nsk_jvmti_showPossessedCapabilities(jvmti); - - if (!enableOptionalEvents(jvmti)) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/em07t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/em07t001.cpp new file mode 100644 index 00000000000..a19b9e559e9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/em07t001.cpp @@ -0,0 +1,395 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static jlong timeout = 0; +static jvmtiEnv *jvmti = NULL; +static jrawMonitorID syncLock = NULL; + +/* constant names */ +#define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) +#define EXPECTED_COUNT 0 + +static int eventCount[JVMTI_EVENT_COUNT]; + +/* ============================================================================= */ + +void showEventStatistics() { + int i; + const char* str; + + NSK_DISPLAY0("\n"); + NSK_DISPLAY0("Event statistics\n"); + NSK_DISPLAY0("----------------\n"); + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + if (eventCount[i] > 0) { + str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); + NSK_DISPLAY2("%-40s %7d\n", str, eventCount[i]); + } + } +} + +/* ========================================================================== */ + +void changeCount(jvmtiEvent event) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + + eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL]++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +/* callbacks */ +JNIEXPORT void JNICALL +cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { + changeCount(JVMTI_EVENT_VM_INIT); + NSK_DISPLAY0("--->VMINit is received\n"); +} + +JNIEXPORT void JNICALL +cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { + changeCount(JVMTI_EVENT_VM_DEATH); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) + nsk_jvmti_setFailStatus(); + +} + +void JNICALL +cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + changeCount(JVMTI_EVENT_EXCEPTION); +} + +void JNICALL +cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception) { + changeCount(JVMTI_EVENT_EXCEPTION_CATCH); +} + +void JNICALL +cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_SINGLE_STEP); +} + +void JNICALL +cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception) { + changeCount(JVMTI_EVENT_FRAME_POP); +} + +void JNICALL +cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + changeCount(JVMTI_EVENT_BREAKPOINT); +} + +void JNICALL +cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field) { + changeCount(JVMTI_EVENT_FIELD_ACCESS); +} + +void JNICALL +cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jclass field_klass, + jobject object, jfieldID field, char signature_type, + jvalue new_value) { + changeCount(JVMTI_EVENT_FIELD_MODIFICATION); +} + +void JNICALL +cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method) { + changeCount(JVMTI_EVENT_METHOD_ENTRY); +} + +void JNICALL +cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, + jvalue return_value) { + changeCount(JVMTI_EVENT_METHOD_EXIT); +} + +void JNICALL +cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, + jmethodID method, void* address, void** new_address_ptr) { + changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND); +} + +void JNICALL +cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD); +} + +void JNICALL +cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD); +} + +void JNICALL +cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jlong tout) { + + changeCount(JVMTI_EVENT_MONITOR_WAIT); +} + +void JNICALL +cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jboolean timed_out) { + + changeCount(JVMTI_EVENT_MONITOR_WAITED); +} + +JNIEXPORT void JNICALL +cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER); +} + +void JNICALL +cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object) { + + changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED); +} + +void JNICALL +cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START); +} + +void JNICALL +cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { + changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH); +} + +void JNICALL +cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + changeCount(JVMTI_EVENT_OBJECT_FREE); +} + +void JNICALL +cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC); +} + +/* ============================================================================= */ + +int enableOptionalEvents(jvmtiEnv *jvmti) { + int i; + int result = NSK_TRUE; + + NSK_DISPLAY0("Enable events\n"); + + /* enabling optional events */ + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + jvmtiEvent event = (jvmtiEvent)(i + JVMTI_MIN_EVENT_TYPE_VAL); + if (nsk_jvmti_isOptionalEvent(event)) + if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_ENABLE, event, NULL))) { + NSK_COMPLAIN1("Unexpected error enabling %s\n", + TranslateEvent(event)); + result = NSK_FALSE; + } + } + + return result; +} + +/* ============================================================================= */ + +/** + * Testcase: check tested events. + * - check if expected events received for each method + * + * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. + */ +int checkEvents() { + int i; + jvmtiEvent event; + int result = NSK_TRUE; + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + + event = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL); + + if (nsk_jvmti_isOptionalEvent(event) && eventCount[i] > EXPECTED_COUNT) { + nsk_jvmti_setFailStatus(); + NSK_COMPLAIN3("Unexpected number of %s events:\n\treceived: %7d\n\texpected: %7d\n", + TranslateEvent(event), + eventCount[i], + EXPECTED_COUNT); + result = NSK_FALSE; + } + } + + return result; +} + +/* ============================================================================= */ + +static int setCallBacks(jvmtiEnv *jvmti) { + int i; + + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + + for (i = 0; i < JVMTI_EVENT_COUNT; i++) { + eventCount[i] = 0; + } + + eventCallbacks.VMInit = cbVMInit; + eventCallbacks.VMDeath = cbVMDeath; + eventCallbacks.Exception = cbException; + eventCallbacks.ExceptionCatch = cbExceptionCatch; + eventCallbacks.SingleStep = cbSingleStep; + eventCallbacks.FramePop = cbFramePop; + eventCallbacks.Breakpoint = cbBreakpoint; + eventCallbacks.FieldAccess = cbFieldAccess; + eventCallbacks.FieldModification = cbFieldModification; + eventCallbacks.MethodEntry = cbMethodEntry; + eventCallbacks.MethodExit = cbMethodExit; + eventCallbacks.NativeMethodBind = cbNativeMethodBind; + eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; + eventCallbacks.MonitorWait = cbMonitorWait; + eventCallbacks.MonitorWaited = cbMonitorWaited; + eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; + eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; + eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; + eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; + eventCallbacks.ObjectFree = cbObjectFree; + eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, + sizeof(eventCallbacks)))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + NSK_DISPLAY0("Wait for debuggee to become ready\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!checkEvents()) { + nsk_jvmti_setFailStatus(); + } + showEventStatistics(); + + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; + +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_em07t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_em07t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_em07t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { + nsk_jvmti_setFailStatus(); + return JNI_ERR; + } + + if (!setCallBacks(jvmti)) { + return JNI_ERR; + } + + nsk_jvmti_showPossessedCapabilities(jvmti); + + if (!enableOptionalEvents(jvmti)) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/libem07t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/libem07t001.c deleted file mode 100644 index 7bea2322b44..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/libem07t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em07t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/libem07t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/libem07t001.cpp new file mode 100644 index 00000000000..95137ab11e6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t001/libem07t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em07t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/em07t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/em07t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/em07t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/em07t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/libem07t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/libem07t002.c deleted file mode 100644 index 4705930d1bb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/libem07t002.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_list.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "em07t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/libem07t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/libem07t002.cpp new file mode 100644 index 00000000000..618e158ae33 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/libem07t002.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_list.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "em07t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/ex03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/ex03t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/ex03t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/ex03t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/libex03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/libex03t001.c deleted file mode 100644 index 7525ec5d1db..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/libex03t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ex03t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/libex03t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/libex03t001.cpp new file mode 100644 index 00000000000..d2b27e61d94 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/libex03t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ex03t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/gf01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/gf01t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/gf01t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/gf01t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/libgf01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/libgf01t001.c deleted file mode 100644 index ad68386ec91..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/libgf01t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "gf01t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/libgf01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/libgf01t001.cpp new file mode 100644 index 00000000000..41d32a1b497 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF01/gf01t001/libgf01t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "gf01t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/gf04t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/gf04t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/gf04t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/gf04t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/libgf04t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/libgf04t001.c deleted file mode 100644 index 414e2d71571..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/libgf04t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "gf04t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/libgf04t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/libgf04t001.cpp new file mode 100644 index 00000000000..63e49a10aae --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF04/gf04t001/libgf04t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "gf04t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/gf06t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/gf06t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/gf06t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/gf06t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/libgf06t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/libgf06t001.c deleted file mode 100644 index b74ba2c1254..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/libgf06t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "gf06t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/libgf06t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/libgf06t001.cpp new file mode 100644 index 00000000000..b0bdd5f4334 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF06/gf06t001/libgf06t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "gf06t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/gf08t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/gf08t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/gf08t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/gf08t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/libgf08t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/libgf08t001.c deleted file mode 100644 index 7494c49ca3b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/libgf08t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "gf08t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/libgf08t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/libgf08t001.cpp new file mode 100644 index 00000000000..aaf3a73445b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/libgf08t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "gf08t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/gf08t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/gf08t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/gf08t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/gf08t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/libgf08t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/libgf08t002.c deleted file mode 100644 index cc3e61ab3d7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/libgf08t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "gf08t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/libgf08t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/libgf08t002.cpp new file mode 100644 index 00000000000..f5908088c47 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t002/libgf08t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "gf08t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/gf08t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/gf08t003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/gf08t003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/gf08t003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/libgf08t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/libgf08t003.c deleted file mode 100644 index b2fecf60816..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/libgf08t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "gf08t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/libgf08t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/libgf08t003.cpp new file mode 100644 index 00000000000..e1ec9edd633 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t003/libgf08t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "gf08t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/hs103t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/hs103t002.c deleted file mode 100644 index 883b40f198d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/hs103t002.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/* - Periodically hotswap class(es) with a changed version in - asynchronous manner from specified number of JVMTI agents. The VM - works in default mode. -*/ -#include -#include -#include "agent_common.h" -#include -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS103/hs103t002/MyThread" -#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS103/hs103t002/MyThread" -#define MAIN_CLASS "nsk/jvmti/scenarios/hotswap/HS103/hs103t002/hs103t002" - -static jvmtiEnv * jvmti; -static jthread testAgentThread; - -JNIEXPORT void JNICALL doRedefineInNativeThread(jvmtiEnv * jvmti, - JNIEnv * jni, void * arg) { - jclass cla; - int i = 0; - int redefineNumber = 0; - char fileName[512]; - - jclass testClass; - - jmethodID setRedefinitionDone; - jmethodID setRedefinitionFailed; - - testClass = (*jni)->FindClass(jni, MAIN_CLASS); - - if (!NSK_JNI_VERIFY(jni, ( - setRedefinitionFailed = NSK_CPP_STUB4(GetStaticMethodID, jni, - testClass, "setRedefinitionFailed", "()V")) != NULL)) - { - NSK_CPP_STUB2(FatalError, jni, - "TEST FAILED: while getting setRedefinitionFailed()\n"); - } - - if (!NSK_JNI_VERIFY(jni, ( - setRedefinitionDone = NSK_CPP_STUB4(GetStaticMethodID, jni, - testClass, "setRedefinitionDone", "()V")) != NULL)) - { - NSK_CPP_STUB2(FatalError, jni, - "TEST FAILED: while getting setRedefinitionDone()\n"); - } - - nsk_printf("doRedefineInNativeThread\n"); - cla = (*jni)->FindClass(jni, SEARCH_NAME); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); - for(i = 0; i < 30; i++) { - nsk_printf(" Inside the redefine method..\n"); - if ( nsk_jvmti_redefineClass(jvmti, cla,fileName) == NSK_TRUE) { - nsk_printf("\nMyClass :: Successfully redefined..\n"); - } else { - nsk_printf("\nMyClass :: Failed to redefine ..\n"); - - if (!NSK_JNI_VERIFY_VOID(jni, NSK_CPP_STUB3(CallStaticVoidMethod, jni, - testClass, setRedefinitionFailed))) - { - NSK_CPP_STUB2(FatalError, jni, - "TEST FAILED: while calling setRedefinitionFailed()\n"); - } - } - } - - if (!NSK_JNI_VERIFY_VOID(jni, NSK_CPP_STUB3(CallStaticVoidMethod, jni, - testClass, setRedefinitionDone))) - { - NSK_CPP_STUB2(FatalError, jni, - "TEST FAILED: while calling setRedefinitionDone()\n"); - } - - nsk_printf(" All 30 redefinitions are done..\n"); -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs103t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs103t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs103t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif - -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc; - - nsk_printf("Agent:: VM.. Started..\n"); - - rc = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if (rc != JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - (*jvmti)->AddCapabilities(jvmti, &caps); - } - return JNI_OK; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS103_hs103t002_hs103t002_startAgentThread(JNIEnv * jni, jclass cls) { - jvmtiError err ; - jthread thread; - jclass clas; - jmethodID method; - const char * threadName = "Agent Thread"; - jobject name; - - nsk_printf("hs103t002_startAgentThread\n"); - - name = (*jni)->NewStringUTF(jni, threadName); - clas = (*jni)->FindClass(jni, "java/lang/Thread"); - - if (!NSK_JNI_VERIFY(jni, (method = NSK_CPP_STUB4(GetMethodID, - jni, clas, "","(Ljava/lang/String;)V")) != NULL)) { - NSK_CPP_STUB2(FatalError, jni, - "failed to get ID for the java method\n"); - } - - thread = (jthread) (*jni)->NewObject(jni, clas,method,name); - testAgentThread = (*jni)->NewGlobalRef(jni, thread); - err = JVMTI_ERROR_NONE; - err = (*jvmti)->RunAgentThread(jvmti, testAgentThread, &doRedefineInNativeThread, NULL, - JVMTI_THREAD_NORM_PRIORITY); - if (err == JVMTI_ERROR_INVALID_PRIORITY) { - nsk_printf(" JVMTI_ERROR_INVALID_PRIORITY ..\n"); - return JNI_ERR; - } else if ( err == JVMTI_ERROR_INVALID_THREAD) { - nsk_printf(" JVMTI_ERROR_INVALID_THREAD ..\n"); - return JNI_ERR; - } else if (err == JVMTI_ERROR_NULL_POINTER) { - nsk_printf(" JVMTI_ERROR_NULL_POINTER ..\n"); - return JNI_ERR; - } else { - nsk_printf(" Agent Thread Created.. \n"); - } - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/hs103t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/hs103t002.cpp new file mode 100644 index 00000000000..d3b46cafd19 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/hs103t002.cpp @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* + Periodically hotswap class(es) with a changed version in + asynchronous manner from specified number of JVMTI agents. The VM + works in default mode. +*/ +#include +#include +#include "agent_common.h" +#include +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS103/hs103t002/MyThread" +#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS103/hs103t002/MyThread" +#define MAIN_CLASS "nsk/jvmti/scenarios/hotswap/HS103/hs103t002/hs103t002" + +static jvmtiEnv * jvmti; +static jthread testAgentThread; + +JNIEXPORT void JNICALL doRedefineInNativeThread(jvmtiEnv * jvmti, + JNIEnv * jni, void * arg) { + jclass cla; + int i = 0; + int redefineNumber = 0; + char fileName[512]; + + jclass testClass; + + jmethodID setRedefinitionDone; + jmethodID setRedefinitionFailed; + + testClass = jni->FindClass(MAIN_CLASS); + + if (!NSK_JNI_VERIFY(jni, ( + setRedefinitionFailed = NSK_CPP_STUB4(GetStaticMethodID, jni, + testClass, "setRedefinitionFailed", "()V")) != NULL)) + { + NSK_CPP_STUB2(FatalError, jni, + "TEST FAILED: while getting setRedefinitionFailed()\n"); + } + + if (!NSK_JNI_VERIFY(jni, ( + setRedefinitionDone = NSK_CPP_STUB4(GetStaticMethodID, jni, + testClass, "setRedefinitionDone", "()V")) != NULL)) + { + NSK_CPP_STUB2(FatalError, jni, + "TEST FAILED: while getting setRedefinitionDone()\n"); + } + + nsk_printf("doRedefineInNativeThread\n"); + cla = jni->FindClass(SEARCH_NAME); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); + for(i = 0; i < 30; i++) { + nsk_printf(" Inside the redefine method..\n"); + if ( nsk_jvmti_redefineClass(jvmti, cla,fileName) == NSK_TRUE) { + nsk_printf("\nMyClass :: Successfully redefined..\n"); + } else { + nsk_printf("\nMyClass :: Failed to redefine ..\n"); + + if (!NSK_JNI_VERIFY_VOID(jni, NSK_CPP_STUB3(CallStaticVoidMethod, jni, + testClass, setRedefinitionFailed))) + { + NSK_CPP_STUB2(FatalError, jni, + "TEST FAILED: while calling setRedefinitionFailed()\n"); + } + } + } + + if (!NSK_JNI_VERIFY_VOID(jni, NSK_CPP_STUB3(CallStaticVoidMethod, jni, + testClass, setRedefinitionDone))) + { + NSK_CPP_STUB2(FatalError, jni, + "TEST FAILED: while calling setRedefinitionDone()\n"); + } + + nsk_printf(" All 30 redefinitions are done..\n"); +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs103t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs103t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs103t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif + +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc; + + nsk_printf("Agent:: VM.. Started..\n"); + + rc = vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if (rc != JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + jvmti->AddCapabilities(&caps); + } + return JNI_OK; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS103_hs103t002_hs103t002_startAgentThread(JNIEnv * jni, jclass cls) { + jvmtiError err ; + jthread thread; + jclass clas; + jmethodID method; + const char * threadName = "Agent Thread"; + jobject name; + + nsk_printf("hs103t002_startAgentThread\n"); + + name = jni->NewStringUTF(threadName); + clas = jni->FindClass("java/lang/Thread"); + + if (!NSK_JNI_VERIFY(jni, (method = NSK_CPP_STUB4(GetMethodID, + jni, clas, "","(Ljava/lang/String;)V")) != NULL)) { + NSK_CPP_STUB2(FatalError, jni, + "failed to get ID for the java method\n"); + } + + thread = (jthread) jni->NewObject(clas,method,name); + testAgentThread = jni->NewGlobalRef(thread); + err = JVMTI_ERROR_NONE; + err = jvmti->RunAgentThread(testAgentThread, &doRedefineInNativeThread, NULL, + JVMTI_THREAD_NORM_PRIORITY); + if (err == JVMTI_ERROR_INVALID_PRIORITY) { + nsk_printf(" JVMTI_ERROR_INVALID_PRIORITY ..\n"); + return JNI_ERR; + } else if ( err == JVMTI_ERROR_INVALID_THREAD) { + nsk_printf(" JVMTI_ERROR_INVALID_THREAD ..\n"); + return JNI_ERR; + } else if (err == JVMTI_ERROR_NULL_POINTER) { + nsk_printf(" JVMTI_ERROR_NULL_POINTER ..\n"); + return JNI_ERR; + } else { + nsk_printf(" Agent Thread Created.. \n"); + } + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/libhs103t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/libhs103t002.c deleted file mode 100644 index 42de19b8464..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/libhs103t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs103t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/libhs103t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/libhs103t002.cpp new file mode 100644 index 00000000000..8078e16ebf5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS103/hs103t002/libhs103t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs103t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/hs104t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/hs104t001.c deleted file mode 100644 index 3abfc39806e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/hs104t001.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" -#include "JVMTITools.h" - - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS104/hs104t001/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS104/hs104t001/MyClass;" - -JNIEXPORT void JNICALL - callbackClassPrepare(jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread, - jclass klass) { - - char * className; - char * generic; - (*jvmti)->GetClassSignature(jvmti, klass, &className, &generic); - if (strcmp(className, CLASS_NAME) == 0) { - char fileName[512]; - nsk_jvmti_getFileName(0, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti, klass, fileName ) == NSK_TRUE ) { - nsk_printf("Agent:: Successfully redefined.."); - if ( nsk_jvmti_disableNotification(jvmti,JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Agent :: NOTIFICATIONS ARE DISABLED \n"); - } else { - nsk_printf(" Agent :: Failed to disabled \n"); - } - } else { - nsk_printf("Agent:: Failed to redefine.."); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs104t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs104t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs104t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events = 1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare =callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, - JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf("Agent :: NOTIFICATIONS ARE ENABLED \n"); - } else { - nsk_printf(" Error in Eanableing Notifications.."); - } - } - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/hs104t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/hs104t001.cpp new file mode 100644 index 00000000000..683177df3de --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/hs104t001.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" +#include "JVMTITools.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS104/hs104t001/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS104/hs104t001/MyClass;" + +JNIEXPORT void JNICALL + callbackClassPrepare(jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread, + jclass klass) { + + char * className; + char * generic; + jvmti->GetClassSignature(klass, &className, &generic); + if (strcmp(className, CLASS_NAME) == 0) { + char fileName[512]; + nsk_jvmti_getFileName(0, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti, klass, fileName ) == NSK_TRUE ) { + nsk_printf("Agent:: Successfully redefined.."); + if ( nsk_jvmti_disableNotification(jvmti,JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Agent :: NOTIFICATIONS ARE DISABLED \n"); + } else { + nsk_printf(" Agent :: Failed to disabled \n"); + } + } else { + nsk_printf("Agent:: Failed to redefine.."); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs104t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs104t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs104t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events = 1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare =callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, + JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf("Agent :: NOTIFICATIONS ARE ENABLED \n"); + } else { + nsk_printf(" Error in Eanableing Notifications.."); + } + } + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/libhs104t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/libhs104t001.c deleted file mode 100644 index 45992af556a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/libhs104t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs104t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/libhs104t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/libhs104t001.cpp new file mode 100644 index 00000000000..7969e456112 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t001/libhs104t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs104t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/hs104t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/hs104t002.c deleted file mode 100644 index 2b5e7832a70..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/hs104t002.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" -#include "JVMTITools.h" -#include "jni_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define DIR_NAME "newclass" -#define PATH_FORMAT "%s%02d/%s" -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS104/hs104t002/MyThread" -#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS104/hs104t002/MyThread" - -static jvmtiEnv * jvmti; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs104t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs104t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs104t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved){ - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(GetEnv, vm, - (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { - nsk_printf("#error Agent :: Could not load JVMTI interface.\n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - if (! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, jvmti, - &caps) )) { - nsk_printf("#error Agent :: occured while adding capabilities.\n"); - return JNI_ERR; - } - } - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS104_hs104t002_hs104t002_redefineClasses( - JNIEnv *jni, jclass classObject) { - jclass cla; - char fileName[512]; - - if ( ! NSK_JNI_VERIFY(jni, ( cla = NSK_CPP_STUB2(FindClass, - jni, SEARCH_NAME) ) != NULL ) ) { - nsk_printf(" Agent :: Failed to get class.\n"); - nsk_jvmti_agentFailed(); - return; - } - nsk_jvmti_getFileName(0, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass( jvmti, cla, fileName) == NSK_TRUE ) { - nsk_printf(" Agent :: Redefine successfull.\n"); - } else { - nsk_printf("# error Agent :: Redefine failed.\n"); - nsk_jvmti_agentFailed(); - } -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/hs104t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/hs104t002.cpp new file mode 100644 index 00000000000..24e2f25267b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/hs104t002.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" +#include "JVMTITools.h" +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define DIR_NAME "newclass" +#define PATH_FORMAT "%s%02d/%s" +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS104/hs104t002/MyThread" +#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS104/hs104t002/MyThread" + +static jvmtiEnv * jvmti; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs104t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs104t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs104t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved){ + if ( ! NSK_VERIFY ( JNI_OK == NSK_CPP_STUB3(GetEnv, vm, + (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { + nsk_printf("#error Agent :: Could not load JVMTI interface.\n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + if (! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, jvmti, + &caps) )) { + nsk_printf("#error Agent :: occured while adding capabilities.\n"); + return JNI_ERR; + } + } + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS104_hs104t002_hs104t002_redefineClasses( + JNIEnv *jni, jclass classObject) { + jclass cla; + char fileName[512]; + + if ( ! NSK_JNI_VERIFY(jni, ( cla = NSK_CPP_STUB2(FindClass, + jni, SEARCH_NAME) ) != NULL ) ) { + nsk_printf(" Agent :: Failed to get class.\n"); + nsk_jvmti_agentFailed(); + return; + } + nsk_jvmti_getFileName(0, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass( jvmti, cla, fileName) == NSK_TRUE ) { + nsk_printf(" Agent :: Redefine successfull.\n"); + } else { + nsk_printf("# error Agent :: Redefine failed.\n"); + nsk_jvmti_agentFailed(); + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/libhs104t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/libhs104t002.c deleted file mode 100644 index 4bbba60e4c8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/libhs104t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs104t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/libhs104t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/libhs104t002.cpp new file mode 100644 index 00000000000..7a0379a4cc8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS104/hs104t002/libhs104t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs104t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/hs201t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/hs201t001.c deleted file mode 100644 index 776982bed4a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/hs201t001.c +++ /dev/null @@ -1,737 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static JNIEnv* jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; - -/* constant names */ -#define EXPECTED_CLASS_NAME "nsk/jvmti/scenarios/hotswap/HS201/hs201t001a" -#define EXPECTED_CLASS_SIGN "Lnsk/jvmti/scenarios/hotswap/HS201/hs201t001a;" -#define METHOD_NAME "doInit" -#define METHOD_SIG "()V" -#define LOCAL_VARIABLE_NAME "localVariable" -#define PATH_TO_NEW_BYTECODE "pathToNewByteCode" - -static jint testStep; -static int redefineNumber; -static jint newClassSize; -static unsigned char* newClassBytes; -static jthread testedThread; -static jclass testClass; -char chbuffer[255]; - -const char* getThreadName(JNIEnv* jni_env, jthread thread); -const char* getClassName(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jobject object); -int readNewBytecode(jvmtiEnv* jvmti, int testcase); -int getLocalVariableValue(jvmtiEnv *jvmti_env, jthread thread, jmethodID method); - -/* ============================================================================= */ - -void setCurrentStep(JNIEnv* jni_env, int value) { - - jfieldID fld; - - if (!NSK_JNI_VERIFY(jni_env, (fld = - NSK_CPP_STUB4(GetStaticFieldID, jni_env, testClass, "currentStep", "I")) != NULL)) { - NSK_CPP_STUB2(FatalError, jni_env, - "TEST FAILED: while getting currentStep fieldID\n"); - } - - if (!NSK_JNI_VERIFY_VOID(jni_env, - NSK_CPP_STUB4(SetStaticIntField, jni_env, testClass, fld, value))) { - NSK_CPP_STUB2(FatalError, jni_env, - "TEST FAILED: while setting value of currentStep fieldID\n"); - } - -} - -/* ============================================================================= */ - -void enableEvent(jvmtiEnv *jvmti_env, jvmtiEvent event, jthread thread) { - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_ENABLE, - event, thread))) { - NSK_COMPLAIN1("TEST FAILED: enabling %s\n", TranslateEvent(event)); - nsk_jvmti_setFailStatus(); - } -} - -/* ============================================================================= */ - -void disableEvent(jvmtiEnv *jvmti_env, jvmtiEvent event, jthread thread) { - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_DISABLE, - event, thread))) { - NSK_COMPLAIN1("TEST FAILED: disabling %s\n", TranslateEvent(event)); - nsk_jvmti_setFailStatus(); - } -} - -/* ============================================================================= */ - -void redefineClass(jvmtiEnv *jvmti_env, jclass klass) { - - jvmtiClassDefinition classDef; - - char *className; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, - &className, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_VERIFY(readNewBytecode(jvmti_env, redefineNumber++))) { - NSK_COMPLAIN0("TEST FAILED: new bytecode could not be read\n"); - nsk_jvmti_setFailStatus(); - return; - } - - classDef.klass = klass; - classDef.class_byte_count = newClassSize; - classDef.class_bytes = newClassBytes; - - NSK_DISPLAY1("\tredefining class %s\n", className); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RedefineClasses, jvmti_env, 1, &classDef))) { - NSK_COMPLAIN1("TEST FAILED: while redefining class %s\n", className); - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)className))) { - nsk_jvmti_setFailStatus(); - } - -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - redefineNumber = 1; - jni = agentJNI; - - NSK_DISPLAY0("Waiting for debuggee to become ready\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - testStep = 1; - NSK_DISPLAY0("\n\n>>>> Debugge started, waiting for class loading \n"); - if (!nsk_jvmti_resumeSync()) - return; - - NSK_DISPLAY0("Waiting for debuggee's threads to finish\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testClass)); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedThread)); - - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ============================================================================= */ - -void setBreakPoint(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jclass klass) { - jmethodID mid; - - if (!NSK_JNI_VERIFY(jni_env, (mid = NSK_CPP_STUB4(GetMethodID, - jni_env, klass, METHOD_NAME, METHOD_SIG)) != NULL)) - NSK_CPP_STUB2(FatalError, jni_env, - "[agent] failed to get ID for the java method\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetBreakpoint, - jvmti_env, mid, 1))) - NSK_CPP_STUB2(FatalError, jni_env, - "[agent] failed to set breakpoint\n"); -} - -/* ============================================================================= */ - -/** - * CLASS_LOAD callback. - * - - */ -JNIEXPORT void JNICALL -callbackClassLoad(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jclass klass) { - - char *className; - char *generic; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, - &className, &generic))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (strcmp(className, EXPECTED_CLASS_SIGN) - == 0) { - - NSK_DISPLAY1("\n\n>>>> Class loaded: %s", className); - NSK_DISPLAY0(", activating breakpoint\n"); - setBreakPoint(jvmti_env, jni_env, klass); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)className))) { - nsk_jvmti_setFailStatus(); - } - - if (generic != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)generic))) { - nsk_jvmti_setFailStatus(); - } -} - -/* ============================================================================= */ - -/** - * BREAKPOINT callback. - * - - */ -JNIEXPORT void JNICALL -callbackBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - NSK_DISPLAY0("\n\n>>>>Breakpoint fired, enabling SINGLE_STEP\n"); - enableEvent(jvmti_env, JVMTI_EVENT_SINGLE_STEP, thread); -} - -/* ============================================================================= */ - -/** - * BREAKPOINT callback. - * - - */ -JNIEXPORT void JNICALL -callbackSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - char *methodName; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &methodName, NULL, NULL))) { - NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); - } - - if (strcmp(methodName, METHOD_NAME) == 0) { - char *declaringClassName; - jclass declaringClass; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, method, &declaringClass))) { - NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, - jvmti_env, declaringClass, &declaringClassName, NULL))) { - NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); - } - - if (strcmp(declaringClassName, EXPECTED_CLASS_SIGN) == 0) { - int value; - jboolean is_obsolete; - - /* getting local variable table*/ - value = getLocalVariableValue(jvmti_env, thread, method); - - switch (testStep) { - case 1: - - if (value == 1) { - redefineClass(jvmti_env, declaringClass); - testStep++; - } - break; - - case 2: - - NSK_DISPLAY1("\n\n>>>> Checking if redefined method is obsolete\n", testStep); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(IsMethodObsolete, jvmti, method, &is_obsolete))) { - NSK_COMPLAIN0("TEST FAILED: unable to check method to be obsolete\n"); - nsk_jvmti_setFailStatus(); - return; - } - - if (!is_obsolete) { - NSK_COMPLAIN0("TEST FAILED: method must be obsolete\n"); - nsk_jvmti_setFailStatus(); - } - testStep++; - break; - - case 3: - - NSK_DISPLAY1("\n\n>>>> Popping the currently executing frame\n", testStep); - testStep++; - setCurrentStep(jni_env, testStep); - - break; - - case 5: - - if (value > 10 && value < 1000) { - NSK_DISPLAY1("\n\n>>>> Disabling single step\n", testStep); - disableEvent(jvmti_env, JVMTI_EVENT_SINGLE_STEP, thread); - setCurrentStep(jni_env, testStep); - } - - } /* case */ - - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*) declaringClassName))) { - NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); - } - - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*) methodName))) { - NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); - } - -} - -/* ============================================================================= */ - -/** - * EXCEPTION callback. - * - - */ -JNIEXPORT void JNICALL -callbackException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - - const char *className; - - className = getClassName(jvmti_env, jni_env, exception); - - if (strcmp(EXPECTED_CLASS_SIGN, className) == 0) { - jclass klass; - - NSK_DISPLAY2("\n\n>>>> Exception %s in thread - %s\n", - className, getThreadName(jni_env, thread)); - - testStep++; - if (!NSK_JNI_VERIFY(jni_env, (klass = - NSK_CPP_STUB2(GetObjectClass, jni_env, exception)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - redefineClass(jvmti_env, klass); - } -} - -/* ============================================================================= */ - -/** - * EXCEPTION_CATCH callback. - * - - */ -JNIEXPORT void JNICALL -callbackExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, - jobject exception) { - - const char *className; - - className = getClassName(jvmti_env, jni_env, exception); - - if (strcmp(EXPECTED_CLASS_SIGN, className) == 0) { - jclass klass; - - NSK_DISPLAY2("\n\n>>>> Caught exception %s in thread - %s\n", - className, getThreadName(jni_env, thread)); - - testStep++; - if (!NSK_JNI_VERIFY(jni_env, (klass = - NSK_CPP_STUB2(GetObjectClass, jni_env, exception)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - redefineClass(jvmti_env, klass); - } -} - -/* ============================================================================= */ - -int readNewBytecode(jvmtiEnv* jvmti, int testcase) { - - char filename[256]; - FILE *bytecode; - const char *pathToByteCode = nsk_jvmti_findOptionValue(PATH_TO_NEW_BYTECODE); - jint read_bytes; - - - if (!pathToByteCode) { - NSK_COMPLAIN0("TEST FAILED: error opening file\n"); - return NSK_FALSE; - } - - sprintf(filename,"%s/%s%02d/%s.class", - pathToByteCode, "newclass", testcase, EXPECTED_CLASS_NAME); - - NSK_DISPLAY1("\treading new bytecode for the tested class\n\tfile name: %s\n", - filename); - - bytecode = fopen(filename, "rb"); - if (bytecode == NULL) { - NSK_COMPLAIN0("TEST FAILED: error opening file\n"); - return NSK_FALSE; - } - - fseek(bytecode, 0, SEEK_END); - newClassSize = ftell(bytecode); - rewind(bytecode); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, - newClassSize, &newClassBytes))) { - NSK_COMPLAIN0("buffer couldn't be allocated\n"); - return NSK_FALSE; - } - read_bytes = (jint) fread(newClassBytes, 1, newClassSize, bytecode); - fclose(bytecode); - if (read_bytes != newClassSize) { - NSK_COMPLAIN0("TEST FAILED: error reading file\n"); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -const char* getThreadName(JNIEnv* jni_env, jthread thread) { - jmethodID methodID; - jclass klass; - jstring jthreadName; - const char *threadName; - - strcpy(chbuffer, ""); - - if (!NSK_JNI_VERIFY(jni_env, (klass = - NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) { - nsk_jvmti_setFailStatus(); - return chbuffer; - } - - if (!NSK_JNI_VERIFY(jni_env, (methodID = - NSK_CPP_STUB4(GetMethodID, jni_env, klass, - "getName", "()Ljava/lang/String;")) != NULL)) { - nsk_jvmti_setFailStatus(); - return chbuffer; - } - - jthreadName = NSK_CPP_STUB3(CallObjectMethod, jni_env, thread, - methodID); - - threadName = NSK_CPP_STUB3(GetStringUTFChars, jni_env, jthreadName, 0); - - strcpy(chbuffer, threadName); - - NSK_CPP_STUB3(ReleaseStringUTFChars, jni_env, jthreadName, threadName); - - return chbuffer; -} - -/* ============================================================================= */ - -const char* getClassName(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jobject object) { - - char *className; - char *generic; - jclass klass; - - strcpy(chbuffer, ""); - - if (!NSK_JNI_VERIFY(jni_env, (klass = - NSK_CPP_STUB2(GetObjectClass, jni_env, object)) != NULL)) { - nsk_jvmti_setFailStatus(); - return chbuffer; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, - &className, &generic))) { - nsk_jvmti_setFailStatus(); - return chbuffer; - } - - strcpy(chbuffer, className); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)className))) { - nsk_jvmti_setFailStatus(); - } - - if (generic != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)generic))) { - nsk_jvmti_setFailStatus(); - } - - return chbuffer; -} - -/* ============================================================================= */ - -int getLocalVariableValue(jvmtiEnv *jvmti_env, jthread thread, - jmethodID method) { - - jvmtiLocalVariableEntry *table = NULL; - jint entryCount = 0; - int i; - int value = -1; - - /* getting local variable table*/ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetLocalVariableTable, - jvmti_env, method, &entryCount, &table))) { - NSK_COMPLAIN0("TEST FAILED: unable to get local variable table\n\n"); - } - - if (table != NULL) { - jvmtiError error; - - for (i = 0; i < entryCount; i++) { - if (strcmp(table[i].name, LOCAL_VARIABLE_NAME) == 0) { - error = NSK_CPP_STUB5(GetLocalInt, jvmti_env, thread, 0, - table[i].slot, &value); - if (!NSK_VERIFY(error == JVMTI_ERROR_NONE - || error == JVMTI_ERROR_INVALID_SLOT)) - NSK_COMPLAIN0("TEST FAILED: unable to get local variable table\n\n"); - } - } - - for (i = 0; i < entryCount; i++) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)table[i].name))) { - NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)table[i].signature))) { - NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method signature\n\n"); - } - - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)table))) { - NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to local variable table\n\n"); - } - - } - - return value; -} - -/* ============================================================================= */ - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t001_setThread(JNIEnv *env, - jclass cls, jthread thread) { - - if (!NSK_JNI_VERIFY(env, (testClass = - NSK_CPP_STUB2(NewGlobalRef, env, cls)) != NULL)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JNI_VERIFY(env, (testedThread = - NSK_CPP_STUB2(NewGlobalRef, env, thread)) != NULL)) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t001_resumeThread(JNIEnv *env, - jclass cls, jthread thread) { - - NSK_DISPLAY0("\tresuming thread...\n"); - disableEvent(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(ResumeThread, jvmti, thread))) { - NSK_COMPLAIN0("TEST FAILED: unable to resume the thread\n"); - nsk_jvmti_setFailStatus(); - return JNI_FALSE; - } - - return JNI_TRUE; -} - -/* ============================================================================= */ - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t001_suspendThread(JNIEnv *env, - jclass cls, jthread thread) { - - NSK_DISPLAY0("\tsuspending thread...\n"); - disableEvent(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(SuspendThread, jvmti, thread))) { - NSK_COMPLAIN0("TEST FAILED: unable to suspend the thread\n"); - nsk_jvmti_setFailStatus(); - return JNI_FALSE; - } - - return JNI_TRUE; -} - -/* ============================================================================= */ - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t001_popFrame(JNIEnv *env, - jclass cls, jthread thread) { - - NSK_DISPLAY0("\tpopping frame...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(PopFrame, jvmti, thread))) { - NSK_COMPLAIN0("TEST FAILED: unable to pop the currently executed frame\n"); - nsk_jvmti_setFailStatus(); - return JNI_FALSE; - } - - NSK_DISPLAY0("\tresuming thread...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(ResumeThread, jvmti, thread))) { - NSK_COMPLAIN0("TEST FAILED: unable to resume the thread\n"); - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - testStep++; - enableEvent(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); - - return JNI_TRUE; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs201t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs201t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs201t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_generate_exception_events = 1; - caps.can_generate_breakpoint_events = 1; - caps.can_generate_single_step_events = 1; - caps.can_access_local_variables = 1; - caps.can_redefine_classes = 1; - caps.can_pop_frame = 1; - caps.can_suspend = 1; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassLoad = callbackClassLoad; - eventCallbacks.Exception = callbackException; - eventCallbacks.ExceptionCatch = callbackExceptionCatch; - eventCallbacks.Breakpoint = callbackBreakpoint; - eventCallbacks.SingleStep = callbackSingleStep; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) - return JNI_ERR; - } - - NSK_DISPLAY0("Enable events\n"); - - enableEvent(jvmti, JVMTI_EVENT_CLASS_LOAD, testedThread); - enableEvent(jvmti, JVMTI_EVENT_BREAKPOINT, testedThread); - enableEvent(jvmti, JVMTI_EVENT_EXCEPTION, testedThread); - enableEvent(jvmti, JVMTI_EVENT_EXCEPTION_CATCH, testedThread); - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/hs201t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/hs201t001.cpp new file mode 100644 index 00000000000..6cd3da41767 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/hs201t001.cpp @@ -0,0 +1,737 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static JNIEnv* jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; + +/* constant names */ +#define EXPECTED_CLASS_NAME "nsk/jvmti/scenarios/hotswap/HS201/hs201t001a" +#define EXPECTED_CLASS_SIGN "Lnsk/jvmti/scenarios/hotswap/HS201/hs201t001a;" +#define METHOD_NAME "doInit" +#define METHOD_SIG "()V" +#define LOCAL_VARIABLE_NAME "localVariable" +#define PATH_TO_NEW_BYTECODE "pathToNewByteCode" + +static jint testStep; +static int redefineNumber; +static jint newClassSize; +static unsigned char* newClassBytes; +static jthread testedThread; +static jclass testClass; +char chbuffer[255]; + +const char* getThreadName(JNIEnv* jni_env, jthread thread); +const char* getClassName(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jobject object); +int readNewBytecode(jvmtiEnv* jvmti, int testcase); +int getLocalVariableValue(jvmtiEnv *jvmti_env, jthread thread, jmethodID method); + +/* ============================================================================= */ + +void setCurrentStep(JNIEnv* jni_env, int value) { + + jfieldID fld; + + if (!NSK_JNI_VERIFY(jni_env, (fld = + NSK_CPP_STUB4(GetStaticFieldID, jni_env, testClass, "currentStep", "I")) != NULL)) { + NSK_CPP_STUB2(FatalError, jni_env, + "TEST FAILED: while getting currentStep fieldID\n"); + } + + if (!NSK_JNI_VERIFY_VOID(jni_env, + NSK_CPP_STUB4(SetStaticIntField, jni_env, testClass, fld, value))) { + NSK_CPP_STUB2(FatalError, jni_env, + "TEST FAILED: while setting value of currentStep fieldID\n"); + } + +} + +/* ============================================================================= */ + +void enableEvent(jvmtiEnv *jvmti_env, jvmtiEvent event, jthread thread) { + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_ENABLE, + event, thread))) { + NSK_COMPLAIN1("TEST FAILED: enabling %s\n", TranslateEvent(event)); + nsk_jvmti_setFailStatus(); + } +} + +/* ============================================================================= */ + +void disableEvent(jvmtiEnv *jvmti_env, jvmtiEvent event, jthread thread) { + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_DISABLE, + event, thread))) { + NSK_COMPLAIN1("TEST FAILED: disabling %s\n", TranslateEvent(event)); + nsk_jvmti_setFailStatus(); + } +} + +/* ============================================================================= */ + +void redefineClass(jvmtiEnv *jvmti_env, jclass klass) { + + jvmtiClassDefinition classDef; + + char *className; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, + &className, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_VERIFY(readNewBytecode(jvmti_env, redefineNumber++))) { + NSK_COMPLAIN0("TEST FAILED: new bytecode could not be read\n"); + nsk_jvmti_setFailStatus(); + return; + } + + classDef.klass = klass; + classDef.class_byte_count = newClassSize; + classDef.class_bytes = newClassBytes; + + NSK_DISPLAY1("\tredefining class %s\n", className); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RedefineClasses, jvmti_env, 1, &classDef))) { + NSK_COMPLAIN1("TEST FAILED: while redefining class %s\n", className); + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)className))) { + nsk_jvmti_setFailStatus(); + } + +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + redefineNumber = 1; + jni = agentJNI; + + NSK_DISPLAY0("Waiting for debuggee to become ready\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + testStep = 1; + NSK_DISPLAY0("\n\n>>>> Debugge started, waiting for class loading \n"); + if (!nsk_jvmti_resumeSync()) + return; + + NSK_DISPLAY0("Waiting for debuggee's threads to finish\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testClass)); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedThread)); + + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ============================================================================= */ + +void setBreakPoint(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jclass klass) { + jmethodID mid; + + if (!NSK_JNI_VERIFY(jni_env, (mid = NSK_CPP_STUB4(GetMethodID, + jni_env, klass, METHOD_NAME, METHOD_SIG)) != NULL)) + NSK_CPP_STUB2(FatalError, jni_env, + "[agent] failed to get ID for the java method\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetBreakpoint, + jvmti_env, mid, 1))) + NSK_CPP_STUB2(FatalError, jni_env, + "[agent] failed to set breakpoint\n"); +} + +/* ============================================================================= */ + +/** + * CLASS_LOAD callback. + * - + */ +JNIEXPORT void JNICALL +callbackClassLoad(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jclass klass) { + + char *className; + char *generic; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, + &className, &generic))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (strcmp(className, EXPECTED_CLASS_SIGN) + == 0) { + + NSK_DISPLAY1("\n\n>>>> Class loaded: %s", className); + NSK_DISPLAY0(", activating breakpoint\n"); + setBreakPoint(jvmti_env, jni_env, klass); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)className))) { + nsk_jvmti_setFailStatus(); + } + + if (generic != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)generic))) { + nsk_jvmti_setFailStatus(); + } +} + +/* ============================================================================= */ + +/** + * BREAKPOINT callback. + * - + */ +JNIEXPORT void JNICALL +callbackBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + NSK_DISPLAY0("\n\n>>>>Breakpoint fired, enabling SINGLE_STEP\n"); + enableEvent(jvmti_env, JVMTI_EVENT_SINGLE_STEP, thread); +} + +/* ============================================================================= */ + +/** + * BREAKPOINT callback. + * - + */ +JNIEXPORT void JNICALL +callbackSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + char *methodName; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &methodName, NULL, NULL))) { + NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); + } + + if (strcmp(methodName, METHOD_NAME) == 0) { + char *declaringClassName; + jclass declaringClass; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, method, &declaringClass))) { + NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, + jvmti_env, declaringClass, &declaringClassName, NULL))) { + NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); + } + + if (strcmp(declaringClassName, EXPECTED_CLASS_SIGN) == 0) { + int value; + jboolean is_obsolete; + + /* getting local variable table*/ + value = getLocalVariableValue(jvmti_env, thread, method); + + switch (testStep) { + case 1: + + if (value == 1) { + redefineClass(jvmti_env, declaringClass); + testStep++; + } + break; + + case 2: + + NSK_DISPLAY1("\n\n>>>> Checking if redefined method is obsolete\n", testStep); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(IsMethodObsolete, jvmti, method, &is_obsolete))) { + NSK_COMPLAIN0("TEST FAILED: unable to check method to be obsolete\n"); + nsk_jvmti_setFailStatus(); + return; + } + + if (!is_obsolete) { + NSK_COMPLAIN0("TEST FAILED: method must be obsolete\n"); + nsk_jvmti_setFailStatus(); + } + testStep++; + break; + + case 3: + + NSK_DISPLAY1("\n\n>>>> Popping the currently executing frame\n", testStep); + testStep++; + setCurrentStep(jni_env, testStep); + + break; + + case 5: + + if (value > 10 && value < 1000) { + NSK_DISPLAY1("\n\n>>>> Disabling single step\n", testStep); + disableEvent(jvmti_env, JVMTI_EVENT_SINGLE_STEP, thread); + setCurrentStep(jni_env, testStep); + } + + } /* case */ + + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*) declaringClassName))) { + NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); + } + + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*) methodName))) { + NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); + } + +} + +/* ============================================================================= */ + +/** + * EXCEPTION callback. + * - + */ +JNIEXPORT void JNICALL +callbackException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + + const char *className; + + className = getClassName(jvmti_env, jni_env, exception); + + if (strcmp(EXPECTED_CLASS_SIGN, className) == 0) { + jclass klass; + + NSK_DISPLAY2("\n\n>>>> Exception %s in thread - %s\n", + className, getThreadName(jni_env, thread)); + + testStep++; + if (!NSK_JNI_VERIFY(jni_env, (klass = + NSK_CPP_STUB2(GetObjectClass, jni_env, exception)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + redefineClass(jvmti_env, klass); + } +} + +/* ============================================================================= */ + +/** + * EXCEPTION_CATCH callback. + * - + */ +JNIEXPORT void JNICALL +callbackExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, + jobject exception) { + + const char *className; + + className = getClassName(jvmti_env, jni_env, exception); + + if (strcmp(EXPECTED_CLASS_SIGN, className) == 0) { + jclass klass; + + NSK_DISPLAY2("\n\n>>>> Caught exception %s in thread - %s\n", + className, getThreadName(jni_env, thread)); + + testStep++; + if (!NSK_JNI_VERIFY(jni_env, (klass = + NSK_CPP_STUB2(GetObjectClass, jni_env, exception)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + redefineClass(jvmti_env, klass); + } +} + +/* ============================================================================= */ + +int readNewBytecode(jvmtiEnv* jvmti, int testcase) { + + char filename[256]; + FILE *bytecode; + const char *pathToByteCode = nsk_jvmti_findOptionValue(PATH_TO_NEW_BYTECODE); + jint read_bytes; + + + if (!pathToByteCode) { + NSK_COMPLAIN0("TEST FAILED: error opening file\n"); + return NSK_FALSE; + } + + sprintf(filename,"%s/%s%02d/%s.class", + pathToByteCode, "newclass", testcase, EXPECTED_CLASS_NAME); + + NSK_DISPLAY1("\treading new bytecode for the tested class\n\tfile name: %s\n", + filename); + + bytecode = fopen(filename, "rb"); + if (bytecode == NULL) { + NSK_COMPLAIN0("TEST FAILED: error opening file\n"); + return NSK_FALSE; + } + + fseek(bytecode, 0, SEEK_END); + newClassSize = ftell(bytecode); + rewind(bytecode); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, + newClassSize, &newClassBytes))) { + NSK_COMPLAIN0("buffer couldn't be allocated\n"); + return NSK_FALSE; + } + read_bytes = (jint) fread(newClassBytes, 1, newClassSize, bytecode); + fclose(bytecode); + if (read_bytes != newClassSize) { + NSK_COMPLAIN0("TEST FAILED: error reading file\n"); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +const char* getThreadName(JNIEnv* jni_env, jthread thread) { + jmethodID methodID; + jclass klass; + jstring jthreadName; + const char *threadName; + + strcpy(chbuffer, ""); + + if (!NSK_JNI_VERIFY(jni_env, (klass = + NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) { + nsk_jvmti_setFailStatus(); + return chbuffer; + } + + if (!NSK_JNI_VERIFY(jni_env, (methodID = + NSK_CPP_STUB4(GetMethodID, jni_env, klass, + "getName", "()Ljava/lang/String;")) != NULL)) { + nsk_jvmti_setFailStatus(); + return chbuffer; + } + + jthreadName = (jstring) NSK_CPP_STUB3(CallObjectMethod, jni_env, thread, + methodID); + + threadName = NSK_CPP_STUB3(GetStringUTFChars, jni_env, jthreadName, 0); + + strcpy(chbuffer, threadName); + + NSK_CPP_STUB3(ReleaseStringUTFChars, jni_env, jthreadName, threadName); + + return chbuffer; +} + +/* ============================================================================= */ + +const char* getClassName(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jobject object) { + + char *className; + char *generic; + jclass klass; + + strcpy(chbuffer, ""); + + if (!NSK_JNI_VERIFY(jni_env, (klass = + NSK_CPP_STUB2(GetObjectClass, jni_env, object)) != NULL)) { + nsk_jvmti_setFailStatus(); + return chbuffer; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, + &className, &generic))) { + nsk_jvmti_setFailStatus(); + return chbuffer; + } + + strcpy(chbuffer, className); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)className))) { + nsk_jvmti_setFailStatus(); + } + + if (generic != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)generic))) { + nsk_jvmti_setFailStatus(); + } + + return chbuffer; +} + +/* ============================================================================= */ + +int getLocalVariableValue(jvmtiEnv *jvmti_env, jthread thread, + jmethodID method) { + + jvmtiLocalVariableEntry *table = NULL; + jint entryCount = 0; + int i; + jint value = -1; + + /* getting local variable table*/ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetLocalVariableTable, + jvmti_env, method, &entryCount, &table))) { + NSK_COMPLAIN0("TEST FAILED: unable to get local variable table\n\n"); + } + + if (table != NULL) { + jvmtiError error; + + for (i = 0; i < entryCount; i++) { + if (strcmp(table[i].name, LOCAL_VARIABLE_NAME) == 0) { + error = NSK_CPP_STUB5(GetLocalInt, jvmti_env, thread, 0, + table[i].slot, &value); + if (!NSK_VERIFY(error == JVMTI_ERROR_NONE + || error == JVMTI_ERROR_INVALID_SLOT)) + NSK_COMPLAIN0("TEST FAILED: unable to get local variable table\n\n"); + } + } + + for (i = 0; i < entryCount; i++) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)table[i].name))) { + NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)table[i].signature))) { + NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method signature\n\n"); + } + + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)table))) { + NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to local variable table\n\n"); + } + + } + + return value; +} + +/* ============================================================================= */ + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t001_setThread(JNIEnv *env, + jclass cls, jthread thread) { + + if (!NSK_JNI_VERIFY(env, (testClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, env, cls)) != NULL)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JNI_VERIFY(env, (testedThread = + NSK_CPP_STUB2(NewGlobalRef, env, thread)) != NULL)) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t001_resumeThread(JNIEnv *env, + jclass cls, jthread thread) { + + NSK_DISPLAY0("\tresuming thread...\n"); + disableEvent(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(ResumeThread, jvmti, thread))) { + NSK_COMPLAIN0("TEST FAILED: unable to resume the thread\n"); + nsk_jvmti_setFailStatus(); + return JNI_FALSE; + } + + return JNI_TRUE; +} + +/* ============================================================================= */ + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t001_suspendThread(JNIEnv *env, + jclass cls, jthread thread) { + + NSK_DISPLAY0("\tsuspending thread...\n"); + disableEvent(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(SuspendThread, jvmti, thread))) { + NSK_COMPLAIN0("TEST FAILED: unable to suspend the thread\n"); + nsk_jvmti_setFailStatus(); + return JNI_FALSE; + } + + return JNI_TRUE; +} + +/* ============================================================================= */ + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t001_popFrame(JNIEnv *env, + jclass cls, jthread thread) { + + NSK_DISPLAY0("\tpopping frame...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(PopFrame, jvmti, thread))) { + NSK_COMPLAIN0("TEST FAILED: unable to pop the currently executed frame\n"); + nsk_jvmti_setFailStatus(); + return JNI_FALSE; + } + + NSK_DISPLAY0("\tresuming thread...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(ResumeThread, jvmti, thread))) { + NSK_COMPLAIN0("TEST FAILED: unable to resume the thread\n"); + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + testStep++; + enableEvent(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); + + return JNI_TRUE; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs201t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs201t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs201t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_generate_exception_events = 1; + caps.can_generate_breakpoint_events = 1; + caps.can_generate_single_step_events = 1; + caps.can_access_local_variables = 1; + caps.can_redefine_classes = 1; + caps.can_pop_frame = 1; + caps.can_suspend = 1; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassLoad = callbackClassLoad; + eventCallbacks.Exception = callbackException; + eventCallbacks.ExceptionCatch = callbackExceptionCatch; + eventCallbacks.Breakpoint = callbackBreakpoint; + eventCallbacks.SingleStep = callbackSingleStep; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) + return JNI_ERR; + } + + NSK_DISPLAY0("Enable events\n"); + + enableEvent(jvmti, JVMTI_EVENT_CLASS_LOAD, testedThread); + enableEvent(jvmti, JVMTI_EVENT_BREAKPOINT, testedThread); + enableEvent(jvmti, JVMTI_EVENT_EXCEPTION, testedThread); + enableEvent(jvmti, JVMTI_EVENT_EXCEPTION_CATCH, testedThread); + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/libhs201t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/libhs201t001.c deleted file mode 100644 index 9bd14b9a5b9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/libhs201t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs201t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/libhs201t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/libhs201t001.cpp new file mode 100644 index 00000000000..4bf6da50df4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t001/libhs201t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs201t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/hs201t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/hs201t002.c deleted file mode 100644 index 8fb512e7698..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/hs201t002.c +++ /dev/null @@ -1,737 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* scaffold objects */ -static JNIEnv* jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; - -/* constant names */ -#define EXPECTED_CLASS_NAME "nsk/jvmti/scenarios/hotswap/HS201/hs201t002a" -#define EXPECTED_CLASS_SIGN "Lnsk/jvmti/scenarios/hotswap/HS201/hs201t002a;" -#define METHOD_NAME "doInit" -#define METHOD_SIG "()V" -#define LOCAL_VARIABLE_NAME "localVariable" -#define PATH_TO_NEW_BYTECODE "pathToNewByteCode" - -static jint testStep; -static int redefineNumber; -static jint newClassSize; -static unsigned char* newClassBytes; -static jthread testedThread; -static jclass testClass; -char chbuffer[255]; - -const char* getThreadName(JNIEnv* jni_env, jthread thread); -const char* getClassName(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jobject object); -int readNewBytecode(jvmtiEnv* jvmti); -int getLocalVariableValue(jvmtiEnv *jvmti_env, jthread thread, jmethodID method); - -/* ============================================================================= */ - -void setCurrentStep(JNIEnv* jni_env, int value) { - - jfieldID fld; - - if (!NSK_JNI_VERIFY(jni_env, (fld = - NSK_CPP_STUB4(GetStaticFieldID, jni_env, testClass, "currentStep", "I")) != NULL)) { - NSK_CPP_STUB2(FatalError, jni_env, - "TEST FAILED: while getting currentStep fieldID\n"); - } - - if (!NSK_JNI_VERIFY_VOID(jni_env, - NSK_CPP_STUB4(SetStaticIntField, jni_env, testClass, fld, value))) { - NSK_CPP_STUB2(FatalError, jni_env, - "TEST FAILED: while setting value of currentStep fieldID\n"); - } - -} - -/* ============================================================================= */ - -void enableEvent(jvmtiEnv *jvmti_env, jvmtiEvent event, jthread thread) { - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_ENABLE, - event, thread))) { - NSK_COMPLAIN1("TEST FAILED: enabling %s\n", TranslateEvent(event)); - nsk_jvmti_setFailStatus(); - } -} - -/* ============================================================================= */ - -void disableEvent(jvmtiEnv *jvmti_env, jvmtiEvent event, jthread thread) { - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_DISABLE, - event, thread))) { - NSK_COMPLAIN1("TEST FAILED: disabling %s\n", TranslateEvent(event)); - nsk_jvmti_setFailStatus(); - } -} - -/* ============================================================================= */ - -void redefineClass(jvmtiEnv *jvmti_env, jclass klass) { - - jvmtiClassDefinition classDef; - - char *className; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, - &className, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_VERIFY(readNewBytecode(jvmti_env))) { - NSK_COMPLAIN0("TEST FAILED: new bytecode could not be read\n"); - nsk_jvmti_setFailStatus(); - return; - } - - classDef.klass = klass; - classDef.class_byte_count = newClassSize; - classDef.class_bytes = newClassBytes; - - NSK_DISPLAY1("\tredefining class %s\n", className); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RedefineClasses, jvmti_env, 1, &classDef))) { - NSK_COMPLAIN1("TEST FAILED: while redefining class %s\n", className); - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)className))) { - nsk_jvmti_setFailStatus(); - } - -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - - redefineNumber = 1; - jni = agentJNI; - - NSK_DISPLAY0("Waiting for debuggee to become ready\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - testStep = 1; - NSK_DISPLAY0("\n\n>>>> Debugge started, waiting for class loading \n"); - if (!nsk_jvmti_resumeSync()) - return; - - NSK_DISPLAY0("Waiting for debuggee's threads to finish\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testClass)); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedThread)); - - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ============================================================================= */ - -void setBreakPoint(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jclass klass) { - jmethodID mid; - - if (!NSK_JNI_VERIFY(jni_env, (mid = NSK_CPP_STUB4(GetMethodID, - jni_env, klass, METHOD_NAME, METHOD_SIG)) != NULL)) - NSK_CPP_STUB2(FatalError, jni_env, - "[agent] failed to get ID for the java method\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetBreakpoint, - jvmti_env, mid, 1))) - NSK_CPP_STUB2(FatalError, jni_env, - "[agent] failed to set breakpoint\n"); -} - -/* ============================================================================= */ - -/** - * CLASS_LOAD callback. - * - - */ -JNIEXPORT void JNICALL -callbackClassLoad(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jclass klass) { - - char *className; - char *generic; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, - &className, &generic))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (strcmp(className, EXPECTED_CLASS_SIGN) - == 0) { - - NSK_DISPLAY1("\n\n>>>> Class loaded: %s", className); - NSK_DISPLAY0(", activating breakpoint\n"); - setBreakPoint(jvmti_env, jni_env, klass); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)className))) { - nsk_jvmti_setFailStatus(); - } - - if (generic != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)generic))) { - nsk_jvmti_setFailStatus(); - } -} - -/* ============================================================================= */ - -/** - * BREAKPOINT callback. - * - - */ -JNIEXPORT void JNICALL -callbackBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - NSK_DISPLAY0("\n\n>>>>Breakpoint fired, enabling SINGLE_STEP\n"); - enableEvent(jvmti_env, JVMTI_EVENT_SINGLE_STEP, thread); -} - -/* ============================================================================= */ - -/** - * BREAKPOINT callback. - * - - */ -JNIEXPORT void JNICALL -callbackSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - char *methodName; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &methodName, NULL, NULL))) { - NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); - } - - if (strcmp(methodName, METHOD_NAME) == 0) { - char *declaringClassName; - jclass declaringClass; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, method, &declaringClass))) { - NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, - jvmti_env, declaringClass, &declaringClassName, NULL))) { - NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); - } - - if (strcmp(declaringClassName, EXPECTED_CLASS_SIGN) == 0) { - int value; - jboolean is_obsolete; - - /* getting local variable table*/ - value = getLocalVariableValue(jvmti_env, thread, method); - - switch (testStep) { - case 1: - - if (value == 1) { - redefineClass(jvmti_env, declaringClass); - testStep++; - } - break; - - case 2: - - NSK_DISPLAY1("\n\n>>>> Checking if redefined method is not obsolete\n", testStep); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(IsMethodObsolete, jvmti, method, &is_obsolete))) { - NSK_COMPLAIN0("TEST FAILED: unable to check method to be obsolete\n"); - nsk_jvmti_setFailStatus(); - return; - } - - if (is_obsolete) { - NSK_COMPLAIN0("TEST FAILED: method must not be obsolete\n"); - nsk_jvmti_setFailStatus(); - } - testStep++; - break; - - case 3: - - NSK_DISPLAY1("\n\n>>>> Popping the currently executing frame\n", testStep); - testStep++; - setCurrentStep(jni_env, testStep); - - break; - - case 5: - - if (value < 10) { - NSK_DISPLAY1("\n\n>>>> Disabling single step\n", testStep); - disableEvent(jvmti_env, JVMTI_EVENT_SINGLE_STEP, thread); - setCurrentStep(jni_env, testStep); - } - - } /* case */ - - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*) declaringClassName))) { - NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); - } - - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*) methodName))) { - NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); - } - -} - -/* ============================================================================= */ - -/** - * EXCEPTION callback. - * - - */ -JNIEXPORT void JNICALL -callbackException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - - const char *className; - - className = getClassName(jvmti_env, jni_env, exception); - - if (strcmp(EXPECTED_CLASS_SIGN, className) == 0) { - jclass klass; - - NSK_DISPLAY2("\n\n>>>> Exception %s in thread - %s\n", - className, getThreadName(jni_env, thread)); - - testStep++; - if (!NSK_JNI_VERIFY(jni_env, (klass = - NSK_CPP_STUB2(GetObjectClass, jni_env, exception)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - redefineClass(jvmti_env, klass); - } -} - -/* ============================================================================= */ - -/** - * EXCEPTION_CATCH callback. - * - - */ -JNIEXPORT void JNICALL -callbackExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location, - jobject exception) { - - const char *className; - - className = getClassName(jvmti_env, jni_env, exception); - - if (strcmp(EXPECTED_CLASS_SIGN, className) == 0) { - jclass klass; - - NSK_DISPLAY2("\n\n>>>> Caught exception %s in thread - %s\n", - className, getThreadName(jni_env, thread)); - - testStep++; - if (!NSK_JNI_VERIFY(jni_env, (klass = - NSK_CPP_STUB2(GetObjectClass, jni_env, exception)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - redefineClass(jvmti_env, klass); - } -} - -/* ============================================================================= */ - -int readNewBytecode(jvmtiEnv* jvmti) { - - char filename[256]; - FILE *bytecode; - const char *pathToByteCode = nsk_jvmti_findOptionValue(PATH_TO_NEW_BYTECODE); - jint read_bytes; - - - if (!pathToByteCode) { - NSK_COMPLAIN0("TEST FAILED: error opening file\n"); - return NSK_FALSE; - } - - sprintf(filename,"%s/%s/%s.class", - pathToByteCode, "newclass", EXPECTED_CLASS_NAME); - - NSK_DISPLAY1("\treading new bytecode for the tested class\n\tfile name: %s\n", - filename); - - bytecode = fopen(filename, "rb"); - if (bytecode == NULL) { - NSK_COMPLAIN0("TEST FAILED: error opening file\n"); - return NSK_FALSE; - } - - fseek(bytecode, 0, SEEK_END); - newClassSize = ftell(bytecode); - rewind(bytecode); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, - newClassSize, &newClassBytes))) { - NSK_COMPLAIN0("buffer couldn't be allocated\n"); - return NSK_FALSE; - } - read_bytes = (jint) fread(newClassBytes, 1, newClassSize, bytecode); - fclose(bytecode); - if (read_bytes != newClassSize) { - NSK_COMPLAIN0("TEST FAILED: error reading file\n"); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -const char* getThreadName(JNIEnv* jni_env, jthread thread) { - jmethodID methodID; - jclass klass; - jstring jthreadName; - const char *threadName; - - strcpy(chbuffer, ""); - - if (!NSK_JNI_VERIFY(jni_env, (klass = - NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) { - nsk_jvmti_setFailStatus(); - return chbuffer; - } - - if (!NSK_JNI_VERIFY(jni_env, (methodID = - NSK_CPP_STUB4(GetMethodID, jni_env, klass, - "getName", "()Ljava/lang/String;")) != NULL)) { - nsk_jvmti_setFailStatus(); - return chbuffer; - } - - jthreadName = NSK_CPP_STUB3(CallObjectMethod, jni_env, thread, - methodID); - - threadName = NSK_CPP_STUB3(GetStringUTFChars, jni_env, jthreadName, 0); - - strcpy(chbuffer, threadName); - - NSK_CPP_STUB3(ReleaseStringUTFChars, jni_env, jthreadName, threadName); - - return chbuffer; -} - -/* ============================================================================= */ - -const char* getClassName(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jobject object) { - - char *className; - char *generic; - jclass klass; - - strcpy(chbuffer, ""); - - if (!NSK_JNI_VERIFY(jni_env, (klass = - NSK_CPP_STUB2(GetObjectClass, jni_env, object)) != NULL)) { - nsk_jvmti_setFailStatus(); - return chbuffer; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, - &className, &generic))) { - nsk_jvmti_setFailStatus(); - return chbuffer; - } - - strcpy(chbuffer, className); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)className))) { - nsk_jvmti_setFailStatus(); - } - - if (generic != NULL) - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)generic))) { - nsk_jvmti_setFailStatus(); - } - - return chbuffer; -} - -/* ============================================================================= */ - -int getLocalVariableValue(jvmtiEnv *jvmti_env, jthread thread, - jmethodID method) { - - jvmtiLocalVariableEntry *table = NULL; - jint entryCount = 0; - int i; - int value = -1; - - /* getting local variable table*/ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetLocalVariableTable, - jvmti_env, method, &entryCount, &table))) { - NSK_COMPLAIN0("TEST FAILED: unable to get local variable table\n\n"); - } - - if (table != NULL) { - jvmtiError error; - - for (i = 0; i < entryCount; i++) { - if (strcmp(table[i].name, LOCAL_VARIABLE_NAME) == 0) { - error = NSK_CPP_STUB5(GetLocalInt, jvmti_env, thread, 0, - table[i].slot, &value); - if (!NSK_VERIFY(error == JVMTI_ERROR_NONE - || error == JVMTI_ERROR_INVALID_SLOT)) - NSK_COMPLAIN0("TEST FAILED: unable to get local variable table\n\n"); - } - } - - for (i = 0; i < entryCount; i++) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)table[i].name))) { - NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)table[i].signature))) { - NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method signature\n\n"); - } - - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti_env, (unsigned char*)table))) { - NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to local variable table\n\n"); - } - - } - - return value; -} - -/* ============================================================================= */ - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t002_setThread(JNIEnv *env, - jclass cls, jthread thread) { - - if (!NSK_JNI_VERIFY(env, (testClass = - NSK_CPP_STUB2(NewGlobalRef, env, cls)) != NULL)) - nsk_jvmti_setFailStatus(); - - if (!NSK_JNI_VERIFY(env, (testedThread = - NSK_CPP_STUB2(NewGlobalRef, env, thread)) != NULL)) - nsk_jvmti_setFailStatus(); - -} - -/* ============================================================================= */ - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t002_resumeThread(JNIEnv *env, - jclass cls, jthread thread) { - - NSK_DISPLAY0("\tresuming thread...\n"); - disableEvent(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(ResumeThread, jvmti, thread))) { - NSK_COMPLAIN0("TEST FAILED: unable to resume the thread\n"); - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t002_suspendThread(JNIEnv *env, - jclass cls, jthread thread) { - - NSK_DISPLAY0("\tsuspending thread...\n"); - disableEvent(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(SuspendThread, jvmti, thread))) { - NSK_COMPLAIN0("TEST FAILED: unable to suspend the thread\n"); - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t002_popFrame(JNIEnv *env, - jclass cls, jthread thread) { - - NSK_DISPLAY0("\tpopping frame...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(PopFrame, jvmti, thread))) { - NSK_COMPLAIN0("TEST FAILED: unable to pop the currently executed frame\n"); - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - NSK_DISPLAY0("\tresuming thread...\n"); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(ResumeThread, jvmti, thread))) { - NSK_COMPLAIN0("TEST FAILED: unable to resume the thread\n"); - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - testStep++; - enableEvent(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs201t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs201t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs201t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - caps.can_generate_exception_events = 1; - caps.can_generate_breakpoint_events = 1; - caps.can_generate_single_step_events = 1; - caps.can_access_local_variables = 1; - caps.can_redefine_classes = 1; - caps.can_pop_frame = 1; - caps.can_suspend = 1; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - } - - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassLoad = callbackClassLoad; - eventCallbacks.Exception = callbackException; - eventCallbacks.ExceptionCatch = callbackExceptionCatch; - eventCallbacks.Breakpoint = callbackBreakpoint; - eventCallbacks.SingleStep = callbackSingleStep; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) - return JNI_ERR; - } - - NSK_DISPLAY0("Enable events\n"); - - enableEvent(jvmti, JVMTI_EVENT_CLASS_LOAD, testedThread); - enableEvent(jvmti, JVMTI_EVENT_BREAKPOINT, testedThread); - enableEvent(jvmti, JVMTI_EVENT_EXCEPTION, testedThread); - enableEvent(jvmti, JVMTI_EVENT_EXCEPTION_CATCH, testedThread); - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/hs201t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/hs201t002.cpp new file mode 100644 index 00000000000..0e5008f2c86 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/hs201t002.cpp @@ -0,0 +1,737 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* scaffold objects */ +static JNIEnv* jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; + +/* constant names */ +#define EXPECTED_CLASS_NAME "nsk/jvmti/scenarios/hotswap/HS201/hs201t002a" +#define EXPECTED_CLASS_SIGN "Lnsk/jvmti/scenarios/hotswap/HS201/hs201t002a;" +#define METHOD_NAME "doInit" +#define METHOD_SIG "()V" +#define LOCAL_VARIABLE_NAME "localVariable" +#define PATH_TO_NEW_BYTECODE "pathToNewByteCode" + +static jint testStep; +static int redefineNumber; +static jint newClassSize; +static unsigned char* newClassBytes; +static jthread testedThread; +static jclass testClass; +char chbuffer[255]; + +const char* getThreadName(JNIEnv* jni_env, jthread thread); +const char* getClassName(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jobject object); +int readNewBytecode(jvmtiEnv* jvmti); +int getLocalVariableValue(jvmtiEnv *jvmti_env, jthread thread, jmethodID method); + +/* ============================================================================= */ + +void setCurrentStep(JNIEnv* jni_env, int value) { + + jfieldID fld; + + if (!NSK_JNI_VERIFY(jni_env, (fld = + NSK_CPP_STUB4(GetStaticFieldID, jni_env, testClass, "currentStep", "I")) != NULL)) { + NSK_CPP_STUB2(FatalError, jni_env, + "TEST FAILED: while getting currentStep fieldID\n"); + } + + if (!NSK_JNI_VERIFY_VOID(jni_env, + NSK_CPP_STUB4(SetStaticIntField, jni_env, testClass, fld, value))) { + NSK_CPP_STUB2(FatalError, jni_env, + "TEST FAILED: while setting value of currentStep fieldID\n"); + } + +} + +/* ============================================================================= */ + +void enableEvent(jvmtiEnv *jvmti_env, jvmtiEvent event, jthread thread) { + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_ENABLE, + event, thread))) { + NSK_COMPLAIN1("TEST FAILED: enabling %s\n", TranslateEvent(event)); + nsk_jvmti_setFailStatus(); + } +} + +/* ============================================================================= */ + +void disableEvent(jvmtiEnv *jvmti_env, jvmtiEvent event, jthread thread) { + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_DISABLE, + event, thread))) { + NSK_COMPLAIN1("TEST FAILED: disabling %s\n", TranslateEvent(event)); + nsk_jvmti_setFailStatus(); + } +} + +/* ============================================================================= */ + +void redefineClass(jvmtiEnv *jvmti_env, jclass klass) { + + jvmtiClassDefinition classDef; + + char *className; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, + &className, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_VERIFY(readNewBytecode(jvmti_env))) { + NSK_COMPLAIN0("TEST FAILED: new bytecode could not be read\n"); + nsk_jvmti_setFailStatus(); + return; + } + + classDef.klass = klass; + classDef.class_byte_count = newClassSize; + classDef.class_bytes = newClassBytes; + + NSK_DISPLAY1("\tredefining class %s\n", className); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RedefineClasses, jvmti_env, 1, &classDef))) { + NSK_COMPLAIN1("TEST FAILED: while redefining class %s\n", className); + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)className))) { + nsk_jvmti_setFailStatus(); + } + +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + + redefineNumber = 1; + jni = agentJNI; + + NSK_DISPLAY0("Waiting for debuggee to become ready\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + testStep = 1; + NSK_DISPLAY0("\n\n>>>> Debugge started, waiting for class loading \n"); + if (!nsk_jvmti_resumeSync()) + return; + + NSK_DISPLAY0("Waiting for debuggee's threads to finish\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testClass)); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedThread)); + + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ============================================================================= */ + +void setBreakPoint(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jclass klass) { + jmethodID mid; + + if (!NSK_JNI_VERIFY(jni_env, (mid = NSK_CPP_STUB4(GetMethodID, + jni_env, klass, METHOD_NAME, METHOD_SIG)) != NULL)) + NSK_CPP_STUB2(FatalError, jni_env, + "[agent] failed to get ID for the java method\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetBreakpoint, + jvmti_env, mid, 1))) + NSK_CPP_STUB2(FatalError, jni_env, + "[agent] failed to set breakpoint\n"); +} + +/* ============================================================================= */ + +/** + * CLASS_LOAD callback. + * - + */ +JNIEXPORT void JNICALL +callbackClassLoad(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jclass klass) { + + char *className; + char *generic; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, + &className, &generic))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (strcmp(className, EXPECTED_CLASS_SIGN) + == 0) { + + NSK_DISPLAY1("\n\n>>>> Class loaded: %s", className); + NSK_DISPLAY0(", activating breakpoint\n"); + setBreakPoint(jvmti_env, jni_env, klass); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)className))) { + nsk_jvmti_setFailStatus(); + } + + if (generic != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)generic))) { + nsk_jvmti_setFailStatus(); + } +} + +/* ============================================================================= */ + +/** + * BREAKPOINT callback. + * - + */ +JNIEXPORT void JNICALL +callbackBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + NSK_DISPLAY0("\n\n>>>>Breakpoint fired, enabling SINGLE_STEP\n"); + enableEvent(jvmti_env, JVMTI_EVENT_SINGLE_STEP, thread); +} + +/* ============================================================================= */ + +/** + * BREAKPOINT callback. + * - + */ +JNIEXPORT void JNICALL +callbackSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + char *methodName; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &methodName, NULL, NULL))) { + NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); + } + + if (strcmp(methodName, METHOD_NAME) == 0) { + char *declaringClassName; + jclass declaringClass; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, method, &declaringClass))) { + NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, + jvmti_env, declaringClass, &declaringClassName, NULL))) { + NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n"); + } + + if (strcmp(declaringClassName, EXPECTED_CLASS_SIGN) == 0) { + int value; + jboolean is_obsolete; + + /* getting local variable table*/ + value = getLocalVariableValue(jvmti_env, thread, method); + + switch (testStep) { + case 1: + + if (value == 1) { + redefineClass(jvmti_env, declaringClass); + testStep++; + } + break; + + case 2: + + NSK_DISPLAY1("\n\n>>>> Checking if redefined method is not obsolete\n", testStep); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(IsMethodObsolete, jvmti, method, &is_obsolete))) { + NSK_COMPLAIN0("TEST FAILED: unable to check method to be obsolete\n"); + nsk_jvmti_setFailStatus(); + return; + } + + if (is_obsolete) { + NSK_COMPLAIN0("TEST FAILED: method must not be obsolete\n"); + nsk_jvmti_setFailStatus(); + } + testStep++; + break; + + case 3: + + NSK_DISPLAY1("\n\n>>>> Popping the currently executing frame\n", testStep); + testStep++; + setCurrentStep(jni_env, testStep); + + break; + + case 5: + + if (value < 10) { + NSK_DISPLAY1("\n\n>>>> Disabling single step\n", testStep); + disableEvent(jvmti_env, JVMTI_EVENT_SINGLE_STEP, thread); + setCurrentStep(jni_env, testStep); + } + + } /* case */ + + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*) declaringClassName))) { + NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); + } + + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*) methodName))) { + NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); + } + +} + +/* ============================================================================= */ + +/** + * EXCEPTION callback. + * - + */ +JNIEXPORT void JNICALL +callbackException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + + const char *className; + + className = getClassName(jvmti_env, jni_env, exception); + + if (strcmp(EXPECTED_CLASS_SIGN, className) == 0) { + jclass klass; + + NSK_DISPLAY2("\n\n>>>> Exception %s in thread - %s\n", + className, getThreadName(jni_env, thread)); + + testStep++; + if (!NSK_JNI_VERIFY(jni_env, (klass = + NSK_CPP_STUB2(GetObjectClass, jni_env, exception)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + redefineClass(jvmti_env, klass); + } +} + +/* ============================================================================= */ + +/** + * EXCEPTION_CATCH callback. + * - + */ +JNIEXPORT void JNICALL +callbackExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location, + jobject exception) { + + const char *className; + + className = getClassName(jvmti_env, jni_env, exception); + + if (strcmp(EXPECTED_CLASS_SIGN, className) == 0) { + jclass klass; + + NSK_DISPLAY2("\n\n>>>> Caught exception %s in thread - %s\n", + className, getThreadName(jni_env, thread)); + + testStep++; + if (!NSK_JNI_VERIFY(jni_env, (klass = + NSK_CPP_STUB2(GetObjectClass, jni_env, exception)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + redefineClass(jvmti_env, klass); + } +} + +/* ============================================================================= */ + +int readNewBytecode(jvmtiEnv* jvmti) { + + char filename[256]; + FILE *bytecode; + const char *pathToByteCode = nsk_jvmti_findOptionValue(PATH_TO_NEW_BYTECODE); + jint read_bytes; + + + if (!pathToByteCode) { + NSK_COMPLAIN0("TEST FAILED: error opening file\n"); + return NSK_FALSE; + } + + sprintf(filename,"%s/%s/%s.class", + pathToByteCode, "newclass", EXPECTED_CLASS_NAME); + + NSK_DISPLAY1("\treading new bytecode for the tested class\n\tfile name: %s\n", + filename); + + bytecode = fopen(filename, "rb"); + if (bytecode == NULL) { + NSK_COMPLAIN0("TEST FAILED: error opening file\n"); + return NSK_FALSE; + } + + fseek(bytecode, 0, SEEK_END); + newClassSize = ftell(bytecode); + rewind(bytecode); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, + newClassSize, &newClassBytes))) { + NSK_COMPLAIN0("buffer couldn't be allocated\n"); + return NSK_FALSE; + } + read_bytes = (jint) fread(newClassBytes, 1, newClassSize, bytecode); + fclose(bytecode); + if (read_bytes != newClassSize) { + NSK_COMPLAIN0("TEST FAILED: error reading file\n"); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +const char* getThreadName(JNIEnv* jni_env, jthread thread) { + jmethodID methodID; + jclass klass; + jstring jthreadName; + const char *threadName; + + strcpy(chbuffer, ""); + + if (!NSK_JNI_VERIFY(jni_env, (klass = + NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) { + nsk_jvmti_setFailStatus(); + return chbuffer; + } + + if (!NSK_JNI_VERIFY(jni_env, (methodID = + NSK_CPP_STUB4(GetMethodID, jni_env, klass, + "getName", "()Ljava/lang/String;")) != NULL)) { + nsk_jvmti_setFailStatus(); + return chbuffer; + } + + jthreadName = (jstring) NSK_CPP_STUB3(CallObjectMethod, jni_env, thread, + methodID); + + threadName = NSK_CPP_STUB3(GetStringUTFChars, jni_env, jthreadName, 0); + + strcpy(chbuffer, threadName); + + NSK_CPP_STUB3(ReleaseStringUTFChars, jni_env, jthreadName, threadName); + + return chbuffer; +} + +/* ============================================================================= */ + +const char* getClassName(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jobject object) { + + char *className; + char *generic; + jclass klass; + + strcpy(chbuffer, ""); + + if (!NSK_JNI_VERIFY(jni_env, (klass = + NSK_CPP_STUB2(GetObjectClass, jni_env, object)) != NULL)) { + nsk_jvmti_setFailStatus(); + return chbuffer; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass, + &className, &generic))) { + nsk_jvmti_setFailStatus(); + return chbuffer; + } + + strcpy(chbuffer, className); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)className))) { + nsk_jvmti_setFailStatus(); + } + + if (generic != NULL) + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)generic))) { + nsk_jvmti_setFailStatus(); + } + + return chbuffer; +} + +/* ============================================================================= */ + +int getLocalVariableValue(jvmtiEnv *jvmti_env, jthread thread, + jmethodID method) { + + jvmtiLocalVariableEntry *table = NULL; + jint entryCount = 0; + int i; + jint value = -1; + + /* getting local variable table*/ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetLocalVariableTable, + jvmti_env, method, &entryCount, &table))) { + NSK_COMPLAIN0("TEST FAILED: unable to get local variable table\n\n"); + } + + if (table != NULL) { + jvmtiError error; + + for (i = 0; i < entryCount; i++) { + if (strcmp(table[i].name, LOCAL_VARIABLE_NAME) == 0) { + error = NSK_CPP_STUB5(GetLocalInt, jvmti_env, thread, 0, + table[i].slot, &value); + if (!NSK_VERIFY(error == JVMTI_ERROR_NONE + || error == JVMTI_ERROR_INVALID_SLOT)) + NSK_COMPLAIN0("TEST FAILED: unable to get local variable table\n\n"); + } + } + + for (i = 0; i < entryCount; i++) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)table[i].name))) { + NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n"); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)table[i].signature))) { + NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method signature\n\n"); + } + + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti_env, (unsigned char*)table))) { + NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to local variable table\n\n"); + } + + } + + return value; +} + +/* ============================================================================= */ + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t002_setThread(JNIEnv *env, + jclass cls, jthread thread) { + + if (!NSK_JNI_VERIFY(env, (testClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, env, cls)) != NULL)) + nsk_jvmti_setFailStatus(); + + if (!NSK_JNI_VERIFY(env, (testedThread = + NSK_CPP_STUB2(NewGlobalRef, env, thread)) != NULL)) + nsk_jvmti_setFailStatus(); + +} + +/* ============================================================================= */ + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t002_resumeThread(JNIEnv *env, + jclass cls, jthread thread) { + + NSK_DISPLAY0("\tresuming thread...\n"); + disableEvent(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(ResumeThread, jvmti, thread))) { + NSK_COMPLAIN0("TEST FAILED: unable to resume the thread\n"); + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t002_suspendThread(JNIEnv *env, + jclass cls, jthread thread) { + + NSK_DISPLAY0("\tsuspending thread...\n"); + disableEvent(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(SuspendThread, jvmti, thread))) { + NSK_COMPLAIN0("TEST FAILED: unable to suspend the thread\n"); + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS201_hs201t002_popFrame(JNIEnv *env, + jclass cls, jthread thread) { + + NSK_DISPLAY0("\tpopping frame...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(PopFrame, jvmti, thread))) { + NSK_COMPLAIN0("TEST FAILED: unable to pop the currently executed frame\n"); + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + NSK_DISPLAY0("\tresuming thread...\n"); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(ResumeThread, jvmti, thread))) { + NSK_COMPLAIN0("TEST FAILED: unable to resume the thread\n"); + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + testStep++; + enableEvent(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs201t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs201t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs201t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + caps.can_generate_exception_events = 1; + caps.can_generate_breakpoint_events = 1; + caps.can_generate_single_step_events = 1; + caps.can_access_local_variables = 1; + caps.can_redefine_classes = 1; + caps.can_pop_frame = 1; + caps.can_suspend = 1; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + } + + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassLoad = callbackClassLoad; + eventCallbacks.Exception = callbackException; + eventCallbacks.ExceptionCatch = callbackExceptionCatch; + eventCallbacks.Breakpoint = callbackBreakpoint; + eventCallbacks.SingleStep = callbackSingleStep; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) + return JNI_ERR; + } + + NSK_DISPLAY0("Enable events\n"); + + enableEvent(jvmti, JVMTI_EVENT_CLASS_LOAD, testedThread); + enableEvent(jvmti, JVMTI_EVENT_BREAKPOINT, testedThread); + enableEvent(jvmti, JVMTI_EVENT_EXCEPTION, testedThread); + enableEvent(jvmti, JVMTI_EVENT_EXCEPTION_CATCH, testedThread); + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/libhs201t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/libhs201t002.c deleted file mode 100644 index f04ee9fa6d3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/libhs201t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs201t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/libhs201t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/libhs201t002.cpp new file mode 100644 index 00000000000..e940dfe9bfa --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t002/libhs201t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs201t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/hs201t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/hs201t003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/hs201t003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/hs201t003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/libhs201t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/libhs201t003.c deleted file mode 100644 index 62f0488a3a1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/libhs201t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs201t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/libhs201t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/libhs201t003.cpp new file mode 100644 index 00000000000..4a29003e410 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS201/hs201t003/libhs201t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs201t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/hs202t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/hs202t001.c deleted file mode 100644 index 4021f15b138..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/hs202t001.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" -#include "JVMTITools.h" -/* - hs202t001: - 1. Set breakpoints in several methods when Object.wait(), - Object.notify(), Object.notifyAll() are in use in these methods. - 2. Upon reaching a breakpoint, enable SingleStep. - 3. Redefine an java.lang.Object class within SingleStep callback - when one of its methods is called by the tested method. - 4. Pop a currently executed frame. - -*/ -#ifdef __cplusplus -extern "C" { -#endif -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS202/hs203t001/MyObject" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS202/hs203t001/MyObject;" -#define METHOD_NAME "leaveMonitor" -#define METHOD_SIGN "()V" -#define METHOD_NOTIFYALL "notifyAll" - -static jvmtiEnv * jvmti; - - -JNIEXPORT void JNICALL callbackClassPrepare(jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread, - jclass klass) { - char * className; - char * generic; - (*jvmti)->GetClassSignature(jvmti, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - jmethodID method; - method = (*jni)->GetMethodID(jni,klass, METHOD_NAME, METHOD_SIGN); - if (method == NULL) { - nsk_printf("Agent:: Method is null "); - } else { - jlocation start; - jlocation end; - jvmtiError err ; - err=(*jvmti)->GetMethodLocation(jvmti, method, &start, &end); - if ( err != JVMTI_ERROR_NONE ) { - nsk_printf(" ## Error occured %s \n",TranslateError(err)); - }else { - nsk_printf("\n Start = %d and end = %d ", start , end); - nsk_printf(" setting break points.."); - err= (*jvmti)->SetBreakpoint(jvmti,method, start); - if (err != JVMTI_ERROR_NONE) { - nsk_printf(" ## Error occured %s \n",TranslateError(err)); - } else { - nsk_printf(" NO ERRORS "); - if (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_BREAKPOINT, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled.. notification event ..\n"); - } - } - } - } - } -} - -/* - *This event call back will be called when a filed - *threadState is beeing upodated or beeing used in - *the program java flow. - *In this current example the code will be called - */ -void JNICALL callbackSingleStep(jvmtiEnv *jvmti_env, - JNIEnv* jni, - jthread thread, - jmethodID method, - jlocation location) { - jvmtiError err; - char * name; - char * signature; - char * generic ; - err = JVMTI_ERROR_NONE; - (*jvmti_env)->GetMethodName(jvmti_env, method, &name, &signature, &generic); - if (strcmp(name,METHOD_NAME) == 0) { /* same method */ - jclass cls; - jmethodID mem ; - (*jvmti_env)->GetMethodDeclaringClass(jvmti_env,method, &cls); - mem=(*jni)->GetMethodID(jni,cls,METHOD_NOTIFYALL,"()V"); - (*jni)->CallVoidMethod(jni,thread,mem); - } - -} - -void JNICALL callbackBreakpoint(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jlocation location) { - jvmtiError err; - err = JVMTI_ERROR_NONE; - if ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_SINGLE_STEP, NULL) - == NSK_TRUE ) { - nsk_printf(" Enabled.. notification event .."); - } - err= (*jvmti)->SetEventNotificationMode(jvmti,JVMTI_DISABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err == JVMTI_ERROR_NONE) { - nsk_printf(" Disabled notification.."); - } - -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs202t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs202t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs202t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - memset(&caps, 0, sizeof(caps)); - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - caps.can_redefine_classes = 1; - caps.can_suspend = 1; - caps.can_pop_frame = 1; - caps.can_generate_all_class_hook_events = 1; - caps.can_generate_compiled_method_load_events = 1; - caps.can_generate_breakpoint_events=1; - caps.can_generate_single_step_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare =callbackClassPrepare; - eventCallbacks.SingleStep =callbackSingleStep; - eventCallbacks.Breakpoint =callbackBreakpoint; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" ## Error occured %s \n",TranslateError(rc)); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf("Agent :: NOTIFICATIONS ARE ENABLED \n"); - } else { - nsk_printf(" Error in Eanableing Notifications.."); - } - } - return JNI_OK; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t001_hs202t001_popThreadFrame(JNIEnv * jni, - jclass clas, - jthread thread) { - jvmtiError err ; - jboolean retvalue; - jint state; - nsk_printf("Agent:: POPING THE FRAME....\n"); - retvalue = JNI_FALSE; - (*jvmti)->GetThreadState(jvmti, thread, &state); - if ( state & JVMTI_THREAD_STATE_SUSPENDED) { - err = (*jvmti)->PopFrame(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf("Agent:: NO Errors poped very well ..\n"); - retvalue=JNI_OK; - return retvalue; - } else if (err != JVMTI_ERROR_NONE) { - nsk_printf(" ## Error occured %s \n",TranslateError(err)); - } - nsk_printf("Agent:: some other error ..\n"); - } else { - nsk_printf("Agent:: Thread was not suspened.. check for capabilities, and java method signature "); - } - return retvalue; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t001_hs202t001_resumeThread(JNIEnv * jni, - jclass clas, - jthread thread) { - jvmtiError err ; - jboolean retvalue; - retvalue = JNI_FALSE; - err = (*jvmti)->ResumeThread(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Thread Resumed.. \n"); - retvalue=JNI_OK; - } else { - nsk_printf(" Agent:: Failed.. to Resume the thread.\n"); - } - return retvalue; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/hs202t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/hs202t001.cpp new file mode 100644 index 00000000000..4633aed6b23 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/hs202t001.cpp @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" +#include "JVMTITools.h" +/* + hs202t001: + 1. Set breakpoints in several methods when Object.wait(), + Object.notify(), Object.notifyAll() are in use in these methods. + 2. Upon reaching a breakpoint, enable SingleStep. + 3. Redefine an java.lang.Object class within SingleStep callback + when one of its methods is called by the tested method. + 4. Pop a currently executed frame. + +*/ +#ifdef __cplusplus +extern "C" { +#endif +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS202/hs203t001/MyObject" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS202/hs203t001/MyObject;" +#define METHOD_NAME "leaveMonitor" +#define METHOD_SIGN "()V" +#define METHOD_NOTIFYALL "notifyAll" + +static jvmtiEnv * jvmti; + + +JNIEXPORT void JNICALL callbackClassPrepare(jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread, + jclass klass) { + char * className; + char * generic; + jvmti->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + jmethodID method; + method = jni->GetMethodID(klass, METHOD_NAME, METHOD_SIGN); + if (method == NULL) { + nsk_printf("Agent:: Method is null "); + } else { + jlocation start; + jlocation end; + jvmtiError err ; + err=jvmti->GetMethodLocation(method, &start, &end); + if ( err != JVMTI_ERROR_NONE ) { + nsk_printf(" ## Error occured %s \n",TranslateError(err)); + }else { + nsk_printf("\n Start = %d and end = %d ", start , end); + nsk_printf(" setting break points.."); + err= jvmti->SetBreakpoint(method, start); + if (err != JVMTI_ERROR_NONE) { + nsk_printf(" ## Error occured %s \n",TranslateError(err)); + } else { + nsk_printf(" NO ERRORS "); + if (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_BREAKPOINT, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled.. notification event ..\n"); + } + } + } + } + } +} + +/* + *This event call back will be called when a filed + *threadState is beeing upodated or beeing used in + *the program java flow. + *In this current example the code will be called + */ +void JNICALL callbackSingleStep(jvmtiEnv *jvmti_env, + JNIEnv* jni, + jthread thread, + jmethodID method, + jlocation location) { + jvmtiError err; + char * name; + char * signature; + char * generic ; + err = JVMTI_ERROR_NONE; + jvmti_env->GetMethodName(method, &name, &signature, &generic); + if (strcmp(name,METHOD_NAME) == 0) { /* same method */ + jclass cls; + jmethodID mem ; + jvmti_env->GetMethodDeclaringClass(method, &cls); + mem=jni->GetMethodID(cls,METHOD_NOTIFYALL,"()V"); + jni->CallVoidMethod(thread,mem); + } + +} + +void JNICALL callbackBreakpoint(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jlocation location) { + jvmtiError err; + err = JVMTI_ERROR_NONE; + if ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_SINGLE_STEP, NULL) + == NSK_TRUE ) { + nsk_printf(" Enabled.. notification event .."); + } + err= jvmti->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err == JVMTI_ERROR_NONE) { + nsk_printf(" Disabled notification.."); + } + +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs202t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs202t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs202t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jvmtiError rc; + jint code; + nsk_printf("Agent:: VM.. Started..\n"); + code = vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( code != JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + memset(&caps, 0, sizeof(caps)); + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + caps.can_redefine_classes = 1; + caps.can_suspend = 1; + caps.can_pop_frame = 1; + caps.can_generate_all_class_hook_events = 1; + caps.can_generate_compiled_method_load_events = 1; + caps.can_generate_breakpoint_events=1; + caps.can_generate_single_step_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare =callbackClassPrepare; + eventCallbacks.SingleStep =callbackSingleStep; + eventCallbacks.Breakpoint =callbackBreakpoint; + rc = jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" ## Error occured %s \n",TranslateError(rc)); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf("Agent :: NOTIFICATIONS ARE ENABLED \n"); + } else { + nsk_printf(" Error in Eanableing Notifications.."); + } + } + return JNI_OK; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t001_hs202t001_popThreadFrame(JNIEnv * jni, + jclass clas, + jthread thread) { + jvmtiError err ; + jboolean retvalue; + jint state; + nsk_printf("Agent:: POPING THE FRAME....\n"); + retvalue = JNI_FALSE; + jvmti->GetThreadState(thread, &state); + if ( state & JVMTI_THREAD_STATE_SUSPENDED) { + err = jvmti->PopFrame(thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf("Agent:: NO Errors poped very well ..\n"); + retvalue=JNI_OK; + return retvalue; + } else if (err != JVMTI_ERROR_NONE) { + nsk_printf(" ## Error occured %s \n",TranslateError(err)); + } + nsk_printf("Agent:: some other error ..\n"); + } else { + nsk_printf("Agent:: Thread was not suspened.. check for capabilities, and java method signature "); + } + return retvalue; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t001_hs202t001_resumeThread(JNIEnv * jni, + jclass clas, + jthread thread) { + jvmtiError err ; + jboolean retvalue; + retvalue = JNI_FALSE; + err = jvmti->ResumeThread(thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Thread Resumed.. \n"); + retvalue=JNI_OK; + } else { + nsk_printf(" Agent:: Failed.. to Resume the thread.\n"); + } + return retvalue; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/libhs202t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/libhs202t001.c deleted file mode 100644 index fdfac2fd9c4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/libhs202t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs202t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/libhs202t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/libhs202t001.cpp new file mode 100644 index 00000000000..922729ae21f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t001/libhs202t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs202t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/hs202t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/hs202t002.c deleted file mode 100644 index c35a8ba0a4d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/hs202t002.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include -#include "jvmti_tools.h" -#include "JVMTITools.h" - -/* -hs202t002: -*/ -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS202/hs202t002/MyThread" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS202/hs202t002/MyThread;" - -#define PATH_FORMAT "%s%02d/%s" -#define DIR_NAME "newclass" -#define METHOD_NAME "display" - -static jint redefineNumber = 0; -static jvmtiEnv * jvmti = NULL; - -typedef enum { - suspend_error = -1, - not_suspended, - suspended -} thread_suspend_status_t; - -static volatile thread_suspend_status_t thread_suspend_status = not_suspended; - -void JNICALL callbackMethodExit(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jboolean was_popped_by_exception, - jvalue return_value) { - if ( was_popped_by_exception ) { - char * name; - char * signature; - char * generic ; - jvmtiError err; - err= JVMTI_ERROR_NONE; - (*jvmti_env)->GetMethodName(jvmti_env, method, &name, &signature, &generic); - if (strcmp(name,METHOD_NAME) == 0) { - jclass cls; - char fileName[512]; - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - (*jvmti_env)->GetMethodDeclaringClass(jvmti_env,method, &cls); - if ( nsk_jvmti_redefineClass(jvmti_env, cls,fileName) == NSK_TRUE ) { - nsk_printf(" Agent:: redefine class success ..\n"); - nsk_printf("Agent::SUSPENDING>> \n"); - err=(*jvmti_env)->SuspendThread(jvmti_env,thread); - if (err == JVMTI_ERROR_NONE) { - thread_suspend_status = suspended; - nsk_printf("Agent:: Thread successfully suspended..\n"); - } else if (err == JVMTI_ERROR_THREAD_SUSPENDED) { - thread_suspend_status = suspend_error; - nsk_printf(" ## Error occured %s \n",TranslateError(err)); - } - } - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs202t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs202t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs202t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - nsk_printf("Agent:: VM.. Started..\n"); - redefineNumber=0; - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - memset(&caps, 0, sizeof(caps)); - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - caps.can_redefine_classes = 1; - caps.can_suspend = 1; - caps.can_pop_frame = 1; - caps.can_generate_method_exit_events = 1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.MethodExit = callbackMethodExit; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event callbacks \n"); - return JNI_ERR; - } - if (NSK_TRUE == nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_METHOD_EXIT, NULL)) { - nsk_printf(" Agent :: NOTIFICATIONS ARE ENABLED \n"); - } else { - nsk_printf(" Agent :: Error Enabling Notifications.."); - } - } - return JNI_OK; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t002_hs202t002_popThreadFrame(JNIEnv * jni, - jclass clas, - jthread thread) { - jvmtiError err = JVMTI_ERROR_NONE; - jboolean retvalue = JNI_FALSE; - jint state; - nsk_printf("Agent:: POPPING THE FRAME..\n"); - (*jvmti)->GetThreadState(jvmti, thread, &state); - if ( state & JVMTI_THREAD_STATE_SUSPENDED) { - err = (*jvmti)->PopFrame(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf("Agent:: PopFrame succeeded..\n"); - return JNI_TRUE; - } else { - nsk_printf(" ## Error occured %s \n",TranslateError(err)); - } - } else { - nsk_printf("Agent:: Thread was not suspened.. check for capabilities, and java method signature "); - } - return retvalue; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t002_hs202t002_resumeThread(JNIEnv * jni, - jclass clas, - jthread thread) { - jvmtiError err = JVMTI_ERROR_NONE; - jboolean retvalue = JNI_FALSE; - - // disable notifications before resuming thread - // to avoid recursion on PopFrame issued reinvoke - if (NSK_TRUE == nsk_jvmti_disableNotification(jvmti,JVMTI_EVENT_METHOD_EXIT, NULL)) { - nsk_printf("Agent :: nsk_jvmti_disabled notifications..\n"); - } else { - nsk_printf("Agent :: Failed to disable notifications.."); - return JNI_FALSE; - } - - err = (*jvmti)->ResumeThread(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - thread_suspend_status = not_suspended; - retvalue = JNI_TRUE; - nsk_printf(" Agent:: Thread Resumed.. \n"); - } else { - nsk_printf(" Agent:: Failed.. to Resume the thread.\n"); - retvalue = JNI_FALSE; - } - return retvalue; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t002_hs202t002_isThreadSuspended(JNIEnv* jni, - jclass clas, - jthread thread) { - if (suspend_error == thread_suspend_status) { - jclass ex_class = (*jni)->FindClass(jni, "java/lang/IllegalThreadStateException"); - (*jni)->ThrowNew(jni, ex_class, "Thread has failed to self suspend"); - return JNI_FALSE; - } - - return suspended == thread_suspend_status; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/hs202t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/hs202t002.cpp new file mode 100644 index 00000000000..b880b4d3a7c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/hs202t002.cpp @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include +#include "jvmti_tools.h" +#include "JVMTITools.h" + +/* +hs202t002: +*/ +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS202/hs202t002/MyThread" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS202/hs202t002/MyThread;" + +#define PATH_FORMAT "%s%02d/%s" +#define DIR_NAME "newclass" +#define METHOD_NAME "display" + +static jint redefineNumber = 0; +static jvmtiEnv * jvmti = NULL; + +typedef enum { + suspend_error = -1, + not_suspended, + suspended +} thread_suspend_status_t; + +static volatile thread_suspend_status_t thread_suspend_status = not_suspended; + +void JNICALL callbackMethodExit(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jboolean was_popped_by_exception, + jvalue return_value) { + if ( was_popped_by_exception ) { + char * name; + char * signature; + char * generic ; + jvmtiError err; + err= JVMTI_ERROR_NONE; + jvmti_env->GetMethodName(method, &name, &signature, &generic); + if (strcmp(name,METHOD_NAME) == 0) { + jclass cls; + char fileName[512]; + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + jvmti_env->GetMethodDeclaringClass(method, &cls); + if ( nsk_jvmti_redefineClass(jvmti_env, cls,fileName) == NSK_TRUE ) { + nsk_printf(" Agent:: redefine class success ..\n"); + nsk_printf("Agent::SUSPENDING>> \n"); + err=jvmti_env->SuspendThread(thread); + if (err == JVMTI_ERROR_NONE) { + thread_suspend_status = suspended; + nsk_printf("Agent:: Thread successfully suspended..\n"); + } else if (err == JVMTI_ERROR_THREAD_SUSPENDED) { + thread_suspend_status = suspend_error; + nsk_printf(" ## Error occured %s \n",TranslateError(err)); + } + } + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs202t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs202t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs202t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + nsk_printf("Agent:: VM.. Started..\n"); + redefineNumber=0; + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + memset(&caps, 0, sizeof(caps)); + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + caps.can_redefine_classes = 1; + caps.can_suspend = 1; + caps.can_pop_frame = 1; + caps.can_generate_method_exit_events = 1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.MethodExit = callbackMethodExit; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event callbacks \n"); + return JNI_ERR; + } + if (NSK_TRUE == nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_METHOD_EXIT, NULL)) { + nsk_printf(" Agent :: NOTIFICATIONS ARE ENABLED \n"); + } else { + nsk_printf(" Agent :: Error Enabling Notifications.."); + } + } + return JNI_OK; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t002_hs202t002_popThreadFrame(JNIEnv * jni, + jclass clas, + jthread thread) { + jvmtiError err = JVMTI_ERROR_NONE; + jboolean retvalue = JNI_FALSE; + jint state; + nsk_printf("Agent:: POPPING THE FRAME..\n"); + jvmti->GetThreadState(thread, &state); + if ( state & JVMTI_THREAD_STATE_SUSPENDED) { + err = jvmti->PopFrame(thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf("Agent:: PopFrame succeeded..\n"); + return JNI_TRUE; + } else { + nsk_printf(" ## Error occured %s \n",TranslateError(err)); + } + } else { + nsk_printf("Agent:: Thread was not suspened.. check for capabilities, and java method signature "); + } + return retvalue; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t002_hs202t002_resumeThread(JNIEnv * jni, + jclass clas, + jthread thread) { + jvmtiError err = JVMTI_ERROR_NONE; + jboolean retvalue = JNI_FALSE; + + // disable notifications before resuming thread + // to avoid recursion on PopFrame issued reinvoke + if (NSK_TRUE == nsk_jvmti_disableNotification(jvmti,JVMTI_EVENT_METHOD_EXIT, NULL)) { + nsk_printf("Agent :: nsk_jvmti_disabled notifications..\n"); + } else { + nsk_printf("Agent :: Failed to disable notifications.."); + return JNI_FALSE; + } + + err = jvmti->ResumeThread(thread); + if (err == JVMTI_ERROR_NONE) { + thread_suspend_status = not_suspended; + retvalue = JNI_TRUE; + nsk_printf(" Agent:: Thread Resumed.. \n"); + } else { + nsk_printf(" Agent:: Failed.. to Resume the thread.\n"); + retvalue = JNI_FALSE; + } + return retvalue; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t002_hs202t002_isThreadSuspended(JNIEnv* jni, + jclass clas, + jthread thread) { + if (suspend_error == thread_suspend_status) { + jclass ex_class = jni->FindClass("java/lang/IllegalThreadStateException"); + jni->ThrowNew(ex_class, "Thread has failed to self suspend"); + return JNI_FALSE; + } + + return suspended == thread_suspend_status; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/libhs202t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/libhs202t002.c deleted file mode 100644 index 4dfaeff34e2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/libhs202t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs202t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/libhs202t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/libhs202t002.cpp new file mode 100644 index 00000000000..a187521180e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/libhs202t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs202t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/hs203t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/hs203t001.c deleted file mode 100644 index 16cb36e34b0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/hs203t001.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" -#include "JVMTITools.h" -/* - README - ****** - HS203: Hotswap + pop frame within events - T001: - 1. Set a breakpoint. - 2. Upon reaching the breakpoint, enable SingleStep. - 3. Redefine a class within SingleStep callback. Stepping should - be continued in obsolete method. - 4. Pop a currently executed frame. Stepping should be continued - on invoke instruction. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t001/MyThread" - -#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t001/MyThread" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS203/hs203t001/MyThread;" -#define METHOD_NAME "doThisFunction" -#define METHOD_SIGN "()V" - -static jint redefineNumber; -static jvmtiEnv * jvmti; - -JNIEXPORT void JNICALL - callbackClassLoad(jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread, - jclass klass) { - char * className; - char * generic; - redefineNumber=0; - (*jvmti)->GetClassSignature(jvmti, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - jmethodID method; - method = (*jni)->GetMethodID(jni,klass,METHOD_NAME,METHOD_SIGN); - if (method != NULL) { - jlocation start; - jlocation end; - jvmtiError err ; - err=(*jvmti)->GetMethodLocation(jvmti, method, &start, &end); - if (err == JVMTI_ERROR_NONE) { - nsk_printf("Agent:: NO ERRORS FOUND \n"); - err= (*jvmti)->SetBreakpoint(jvmti,method, start); - if ( err == JVMTI_ERROR_NONE) { - nsk_printf(" Class Name %s \n", className); - nsk_printf("Agent:: Breakpoint set \n"); - } else { - nsk_printf(" ## Error occured %s \n",TranslateError(err)); - } - } else { - nsk_printf("Agent:: ***ERROR OCCURED .. in METHOD LOCATION FINDER \n"); - } - } else { - nsk_printf("Agent:: ***ERROR OCCURED .. COUND NOT FIND THE METHOD AND SIGNATURE SPECIFIED \n"); - } - } - } - -void JNICALL callbackSingleStep(jvmtiEnv *jvmti, JNIEnv* jni, - jthread thread, - jmethodID method, - jlocation location) { - jclass threadClass; - jvmtiError err; - char fileName[512]; - threadClass = (*jni)->FindClass(jni,SEARCH_NAME); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - nsk_printf(" %d..",redefineNumber); - if ( nsk_jvmti_redefineClass(jvmti, threadClass, fileName) == NSK_TRUE) { - nsk_printf("\nMyClass :: Successfully redefined..\n"); - } else { - nsk_printf("\nMyClass :: Failed to redefine ..\n"); - } - nsk_printf(" End of REDEFINE CLASS LOADER \n"); - err=(*jvmti)->SuspendThread(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf("Agent:: Succeded in suspending..\n"); - } else { - nsk_printf(" ## Error occured %s \n",TranslateError(err)); - } -} - -void JNICALL -callbackBreakpoint(jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread, - jmethodID method, - jlocation location) { - nsk_printf("Agent::... BreakPoint Reached..\n"); - if ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_SINGLE_STEP,thread) == NSK_TRUE ) { - nsk_printf(" .... Enabled..\n"); - } - return; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs203t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs203t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs203t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_suspend=1; - caps.can_pop_frame=1; - caps.can_generate_breakpoint_events=1; - caps.can_generate_all_class_hook_events=1; - caps.can_generate_single_step_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassLoad =callbackClassLoad; - eventCallbacks.Breakpoint = callbackBreakpoint; - eventCallbacks.SingleStep =callbackSingleStep; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_LOAD, NULL) == NSK_TRUE ) && - (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_BREAKPOINT,NULL) == NSK_TRUE) ) { - nsk_printf("Agent :: NOTIFICATIONS ARE ENABLED \n"); - } else { - nsk_printf(" Error in Eanableing Notifications.."); - } - } - return JNI_OK; -} - - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t001_hs203t001_popThreadFrame(JNIEnv * jni, - jclass clas, - jthread thread) { - jvmtiError err ; - jboolean retvalue; - jint state; - nsk_printf("Agent:: POPING THE FRAME....\n"); - retvalue = JNI_FALSE; - nsk_printf(" Here "); - (*jvmti)->GetThreadState(jvmti, thread, &state); - nsk_printf(" Here "); - if ( state & JVMTI_THREAD_STATE_SUSPENDED) { - err = (*jvmti)->PopFrame(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf("Agent:: NO Errors poped very well ..\n"); - retvalue = JNI_TRUE; - } else { - nsk_printf(" Here -3"); - nsk_printf(" ## Error occured %s \n",TranslateError(err)); - } - } else { - nsk_printf("Agent:: Thread was not suspened.. check for capabilities, and java method signature "); - } - return retvalue; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t001_hs203t001_resumeThread(JNIEnv * jni, - jclass clas, - jthread thread) { - jvmtiError err ; - jboolean retvalue; - retvalue = JNI_FALSE; - err =(*jvmti)->SetEventNotificationMode(jvmti,JVMTI_DISABLE,JVMTI_EVENT_SINGLE_STEP,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: cleared Single Step event"); - } else { - nsk_printf(" Agent :: Failed to clear Single Step Event"); - } - err =(*jvmti)->SetEventNotificationMode(jvmti,JVMTI_DISABLE,JVMTI_EVENT_BREAKPOINT,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: cleared Break point event"); - } else { - nsk_printf(" Agent :: Failed to clear Single Step Event"); - } - err = (*jvmti)->ResumeThread(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Thread Resumed.."); - } else { - nsk_printf(" Failed.. to Resume the thread."); - } - return retvalue; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/hs203t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/hs203t001.cpp new file mode 100644 index 00000000000..10690ca49a7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/hs203t001.cpp @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" +#include "JVMTITools.h" +/* + README + ****** + HS203: Hotswap + pop frame within events + T001: + 1. Set a breakpoint. + 2. Upon reaching the breakpoint, enable SingleStep. + 3. Redefine a class within SingleStep callback. Stepping should + be continued in obsolete method. + 4. Pop a currently executed frame. Stepping should be continued + on invoke instruction. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t001/MyThread" + +#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t001/MyThread" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS203/hs203t001/MyThread;" +#define METHOD_NAME "doThisFunction" +#define METHOD_SIGN "()V" + +static jint redefineNumber; +static jvmtiEnv * jvmti; + +JNIEXPORT void JNICALL + callbackClassLoad(jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread, + jclass klass) { + char * className; + char * generic; + redefineNumber=0; + jvmti->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + jmethodID method; + method = jni->GetMethodID(klass,METHOD_NAME,METHOD_SIGN); + if (method != NULL) { + jlocation start; + jlocation end; + jvmtiError err ; + err=jvmti->GetMethodLocation(method, &start, &end); + if (err == JVMTI_ERROR_NONE) { + nsk_printf("Agent:: NO ERRORS FOUND \n"); + err= jvmti->SetBreakpoint(method, start); + if ( err == JVMTI_ERROR_NONE) { + nsk_printf(" Class Name %s \n", className); + nsk_printf("Agent:: Breakpoint set \n"); + } else { + nsk_printf(" ## Error occured %s \n",TranslateError(err)); + } + } else { + nsk_printf("Agent:: ***ERROR OCCURED .. in METHOD LOCATION FINDER \n"); + } + } else { + nsk_printf("Agent:: ***ERROR OCCURED .. COUND NOT FIND THE METHOD AND SIGNATURE SPECIFIED \n"); + } + } + } + +void JNICALL callbackSingleStep(jvmtiEnv *jvmti, JNIEnv* jni, + jthread thread, + jmethodID method, + jlocation location) { + jclass threadClass; + jvmtiError err; + char fileName[512]; + threadClass = jni->FindClass(SEARCH_NAME); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + nsk_printf(" %d..",redefineNumber); + if ( nsk_jvmti_redefineClass(jvmti, threadClass, fileName) == NSK_TRUE) { + nsk_printf("\nMyClass :: Successfully redefined..\n"); + } else { + nsk_printf("\nMyClass :: Failed to redefine ..\n"); + } + nsk_printf(" End of REDEFINE CLASS LOADER \n"); + err=jvmti->SuspendThread(thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf("Agent:: Succeded in suspending..\n"); + } else { + nsk_printf(" ## Error occured %s \n",TranslateError(err)); + } +} + +void JNICALL +callbackBreakpoint(jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread, + jmethodID method, + jlocation location) { + nsk_printf("Agent::... BreakPoint Reached..\n"); + if ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_SINGLE_STEP,thread) == NSK_TRUE ) { + nsk_printf(" .... Enabled..\n"); + } + return; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs203t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs203t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs203t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_suspend=1; + caps.can_pop_frame=1; + caps.can_generate_breakpoint_events=1; + caps.can_generate_all_class_hook_events=1; + caps.can_generate_single_step_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassLoad =callbackClassLoad; + eventCallbacks.Breakpoint = callbackBreakpoint; + eventCallbacks.SingleStep =callbackSingleStep; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_LOAD, NULL) == NSK_TRUE ) && + (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_BREAKPOINT,NULL) == NSK_TRUE) ) { + nsk_printf("Agent :: NOTIFICATIONS ARE ENABLED \n"); + } else { + nsk_printf(" Error in Eanableing Notifications.."); + } + } + return JNI_OK; +} + + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t001_hs203t001_popThreadFrame(JNIEnv * jni, + jclass clas, + jthread thread) { + jvmtiError err ; + jboolean retvalue; + jint state; + nsk_printf("Agent:: POPING THE FRAME....\n"); + retvalue = JNI_FALSE; + nsk_printf(" Here "); + jvmti->GetThreadState(thread, &state); + nsk_printf(" Here "); + if ( state & JVMTI_THREAD_STATE_SUSPENDED) { + err = jvmti->PopFrame(thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf("Agent:: NO Errors poped very well ..\n"); + retvalue = JNI_TRUE; + } else { + nsk_printf(" Here -3"); + nsk_printf(" ## Error occured %s \n",TranslateError(err)); + } + } else { + nsk_printf("Agent:: Thread was not suspened.. check for capabilities, and java method signature "); + } + return retvalue; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t001_hs203t001_resumeThread(JNIEnv * jni, + jclass clas, + jthread thread) { + jvmtiError err ; + jboolean retvalue; + retvalue = JNI_FALSE; + err =jvmti->SetEventNotificationMode(JVMTI_DISABLE,JVMTI_EVENT_SINGLE_STEP,thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: cleared Single Step event"); + } else { + nsk_printf(" Agent :: Failed to clear Single Step Event"); + } + err =jvmti->SetEventNotificationMode(JVMTI_DISABLE,JVMTI_EVENT_BREAKPOINT,thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: cleared Break point event"); + } else { + nsk_printf(" Agent :: Failed to clear Single Step Event"); + } + err = jvmti->ResumeThread(thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Thread Resumed.."); + } else { + nsk_printf(" Failed.. to Resume the thread."); + } + return retvalue; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/libhs203t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/libhs203t001.c deleted file mode 100644 index 6fbd6ac8385..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/libhs203t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs203t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/libhs203t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/libhs203t001.cpp new file mode 100644 index 00000000000..4b0bbbcf0cf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t001/libhs203t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs203t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/hs203t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/hs203t002.c deleted file mode 100644 index 6c1d1ff7e3d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/hs203t002.c +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include -#include "jvmti_tools.h" -#include "JVMTITools.h" - -/* - T002: - 1. Set a breakpoint in method b(). - 2. Call method a() which calls b(). - Upon reaching the breakpoint, enable SingleStep. - 3. Redefine class within SingleStep callback. New class version - contains the same method b() and the changed method a(). Stepping - should be continued in the method b(). - 4. Pop a currently executed frame. Stepping should be continued - on invoke instruction of the obsolete method a(). - 5. Pop a frame once more. Stepping should be continued - on invoke instruction of main method and then in the changed - method b(). -*/ - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t002/MyThread" -#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t002/MyThread" -#define METHOD_NAME "doTask2" -#define METHOD_SIGN "()V" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS203/hs203t002/MyThread;" -static jint redefineNumber; -static jvmtiEnv * jvmti; - -JNIEXPORT void JNICALL -callbackClassLoad(jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread, - jclass klass) { - char * className; - char * generic; - redefineNumber=0; - (*jvmti)->GetClassSignature(jvmti, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - jmethodID method; - method = (*jni)->GetMethodID(jni,klass,METHOD_NAME,METHOD_SIGN); - if (method != NULL) { - jlocation start; - jlocation end; - jvmtiError err ; - err=(*jvmti)->GetMethodLocation(jvmti, method, &start, &end); - if (err == JVMTI_ERROR_NONE) { - nsk_printf("Agent:: NO ERRORS FOUND \n"); - err= (*jvmti)->SetBreakpoint(jvmti,method, start); - if ( err == JVMTI_ERROR_NONE) { - nsk_printf("Agent:: Breakpoint set \n"); - } else { - nsk_printf("Agent:: ***ERROR OCCURED ... in SET BREAK POINT ERROR \n"); - } - } else { - nsk_printf("Agent:: ***ERROR OCCURED .. in METHOD LOCATION FINDER \n"); - } - } else { - nsk_printf("Agent:: ***ERROR OCCURED .. COUND NOT FIND THE METHOD AND SIGNATURE SPECIFIED \n"); - } - } -} - -void JNICALL callbackSingleStep(jvmtiEnv *jvmti, - JNIEnv* jni, jthread thread, - jmethodID method, jlocation location) { - jclass threadClass; - jvmtiError err; - char fileName[512]; - - threadClass = (*jni)->FindClass(jni,SEARCH_NAME); - nsk_printf(" %d..",redefineNumber); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); - - if( nsk_jvmti_redefineClass(jvmti, threadClass,fileName) == NSK_TRUE ) { - nsk_printf("Agent:: Redefined..\n"); - } else { - nsk_printf(" Failed to redefine..\n"); - return; - } - err=(*jvmti)->SuspendThread(jvmti,thread); - if ( err == JVMTI_ERROR_NONE ) { - nsk_printf("Agent:: Succeded in suspending..\n"); - } else { - nsk_printf(" ## Error occured %s \n",TranslateError(err)); - } -} - -void JNICALL callbackBreakpoint(jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread, - jmethodID method, - jlocation location) { - nsk_printf("Agent::... BreakPoint Reached..\n"); - if ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_SINGLE_STEP,thread) == JNI_OK ) { - nsk_printf(" .... Enabled..\n"); - } - return; -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs203t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs203t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs203t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_suspend=1; - caps.can_pop_frame=1; - caps.can_generate_breakpoint_events=1; - caps.can_generate_all_class_hook_events=1; - caps.can_generate_single_step_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassLoad =callbackClassLoad; - eventCallbacks.Breakpoint = callbackBreakpoint; - eventCallbacks.SingleStep =callbackSingleStep; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_LOAD, - NULL) == NSK_TRUE) && - (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_BREAKPOINT, - NULL) == NSK_TRUE ) ) { - nsk_printf("Agent :: NOTIFICATIONS ARE ENABLED \n"); - } else { - nsk_printf(" Error in Eanableing Notifications.."); - } - } - return JNI_OK; -} - - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t002_hs203t002_popThreadFrame(JNIEnv * jni, - jclass clas, - jthread thread) { - jvmtiError err ; - jboolean retvalue; - jint state; - nsk_printf("Agent:: POPING THE FRAME....\n"); - retvalue = JNI_FALSE; - (*jvmti)->GetThreadState(jvmti, thread, &state); - if ( state & JVMTI_THREAD_STATE_SUSPENDED) { - err = (*jvmti)->PopFrame(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf("Agent:: NO Errors poped very well ..\n"); - retvalue = JNI_TRUE; - } else { - nsk_printf(" ## Error occured %s \n",TranslateError(err)); - } - } else { - nsk_printf("Agent:: Thread was not suspened.. check for capabilities, and java method signature \n"); - } - return retvalue; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t002_hs203t002_resumeThread(JNIEnv * jni, - jclass clas, - jthread thread) { - jvmtiError err ; - jboolean retvalue; - retvalue = JNI_FALSE; - err =(*jvmti)->SetEventNotificationMode(jvmti,JVMTI_DISABLE,JVMTI_EVENT_SINGLE_STEP,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: cleared Single Step event"); - } else { - nsk_printf(" Agent :: Failed to clear Single Step Event"); - } - err =(*jvmti)->SetEventNotificationMode(jvmti,JVMTI_DISABLE,JVMTI_EVENT_BREAKPOINT,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: cleared Break point event"); - } else { - nsk_printf(" Agent :: Failed to clear Single Step Event"); - } - err = (*jvmti)->ResumeThread(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Thread Resumed.."); - } else { - nsk_printf(" Failed.. to Resume the thread."); - } - return retvalue; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t002_hs203t002_suspendThread(JNIEnv * jni, - jclass clas, - jthread thread) { - jvmtiError err ; - jboolean retvalue; - retvalue = JNI_FALSE; - err = (*jvmti)->SuspendThread(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Thread suspended.."); - retvalue= JNI_TRUE; - } else { - nsk_printf(" ## Error occured %s \n",TranslateError(err)); - } - return retvalue; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/hs203t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/hs203t002.cpp new file mode 100644 index 00000000000..a48126a49b4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/hs203t002.cpp @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include +#include "jvmti_tools.h" +#include "JVMTITools.h" + +/* + T002: + 1. Set a breakpoint in method b(). + 2. Call method a() which calls b(). + Upon reaching the breakpoint, enable SingleStep. + 3. Redefine class within SingleStep callback. New class version + contains the same method b() and the changed method a(). Stepping + should be continued in the method b(). + 4. Pop a currently executed frame. Stepping should be continued + on invoke instruction of the obsolete method a(). + 5. Pop a frame once more. Stepping should be continued + on invoke instruction of main method and then in the changed + method b(). +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t002/MyThread" +#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t002/MyThread" +#define METHOD_NAME "doTask2" +#define METHOD_SIGN "()V" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS203/hs203t002/MyThread;" +static jint redefineNumber; +static jvmtiEnv * jvmti; + +JNIEXPORT void JNICALL +callbackClassLoad(jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread, + jclass klass) { + char * className; + char * generic; + redefineNumber=0; + jvmti->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + jmethodID method; + method = jni->GetMethodID(klass,METHOD_NAME,METHOD_SIGN); + if (method != NULL) { + jlocation start; + jlocation end; + jvmtiError err ; + err=jvmti->GetMethodLocation(method, &start, &end); + if (err == JVMTI_ERROR_NONE) { + nsk_printf("Agent:: NO ERRORS FOUND \n"); + err= jvmti->SetBreakpoint(method, start); + if ( err == JVMTI_ERROR_NONE) { + nsk_printf("Agent:: Breakpoint set \n"); + } else { + nsk_printf("Agent:: ***ERROR OCCURED ... in SET BREAK POINT ERROR \n"); + } + } else { + nsk_printf("Agent:: ***ERROR OCCURED .. in METHOD LOCATION FINDER \n"); + } + } else { + nsk_printf("Agent:: ***ERROR OCCURED .. COUND NOT FIND THE METHOD AND SIGNATURE SPECIFIED \n"); + } + } +} + +void JNICALL callbackSingleStep(jvmtiEnv *jvmti, + JNIEnv* jni, jthread thread, + jmethodID method, jlocation location) { + jclass threadClass; + jvmtiError err; + char fileName[512]; + + threadClass = jni->FindClass(SEARCH_NAME); + nsk_printf(" %d..",redefineNumber); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); + + if( nsk_jvmti_redefineClass(jvmti, threadClass,fileName) == NSK_TRUE ) { + nsk_printf("Agent:: Redefined..\n"); + } else { + nsk_printf(" Failed to redefine..\n"); + return; + } + err=jvmti->SuspendThread(thread); + if ( err == JVMTI_ERROR_NONE ) { + nsk_printf("Agent:: Succeded in suspending..\n"); + } else { + nsk_printf(" ## Error occured %s \n",TranslateError(err)); + } +} + +void JNICALL callbackBreakpoint(jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread, + jmethodID method, + jlocation location) { + nsk_printf("Agent::... BreakPoint Reached..\n"); + if ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_SINGLE_STEP,thread) == JNI_OK ) { + nsk_printf(" .... Enabled..\n"); + } + return; +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs203t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs203t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs203t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_suspend=1; + caps.can_pop_frame=1; + caps.can_generate_breakpoint_events=1; + caps.can_generate_all_class_hook_events=1; + caps.can_generate_single_step_events=1; + jvmti->AddCapabilities(&caps); + + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassLoad =callbackClassLoad; + eventCallbacks.Breakpoint = callbackBreakpoint; + eventCallbacks.SingleStep =callbackSingleStep; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_LOAD, + NULL) == NSK_TRUE) && + (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_BREAKPOINT, + NULL) == NSK_TRUE ) ) { + nsk_printf("Agent :: NOTIFICATIONS ARE ENABLED \n"); + } else { + nsk_printf(" Error in Eanableing Notifications.."); + } + } + return JNI_OK; +} + + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t002_hs203t002_popThreadFrame(JNIEnv * jni, + jclass clas, + jthread thread) { + jvmtiError err ; + jboolean retvalue; + jint state; + nsk_printf("Agent:: POPING THE FRAME....\n"); + retvalue = JNI_FALSE; + jvmti->GetThreadState(thread, &state); + if ( state & JVMTI_THREAD_STATE_SUSPENDED) { + err = jvmti->PopFrame(thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf("Agent:: NO Errors poped very well ..\n"); + retvalue = JNI_TRUE; + } else { + nsk_printf(" ## Error occured %s \n",TranslateError(err)); + } + } else { + nsk_printf("Agent:: Thread was not suspened.. check for capabilities, and java method signature \n"); + } + return retvalue; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t002_hs203t002_resumeThread(JNIEnv * jni, + jclass clas, + jthread thread) { + jvmtiError err ; + jboolean retvalue; + retvalue = JNI_FALSE; + err =jvmti->SetEventNotificationMode(JVMTI_DISABLE,JVMTI_EVENT_SINGLE_STEP,thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: cleared Single Step event"); + } else { + nsk_printf(" Agent :: Failed to clear Single Step Event"); + } + err =jvmti->SetEventNotificationMode(JVMTI_DISABLE,JVMTI_EVENT_BREAKPOINT,thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: cleared Break point event"); + } else { + nsk_printf(" Agent :: Failed to clear Single Step Event"); + } + err = jvmti->ResumeThread(thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Thread Resumed.."); + } else { + nsk_printf(" Failed.. to Resume the thread."); + } + return retvalue; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t002_hs203t002_suspendThread(JNIEnv * jni, + jclass clas, + jthread thread) { + jvmtiError err ; + jboolean retvalue; + retvalue = JNI_FALSE; + err = jvmti->SuspendThread(thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Thread suspended.."); + retvalue= JNI_TRUE; + } else { + nsk_printf(" ## Error occured %s \n",TranslateError(err)); + } + return retvalue; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/libhs203t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/libhs203t002.c deleted file mode 100644 index 053494019d7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/libhs203t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs203t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/libhs203t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/libhs203t002.cpp new file mode 100644 index 00000000000..7a287e45a25 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t002/libhs203t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs203t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/hs203t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/hs203t003.c deleted file mode 100644 index ea720fad138..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/hs203t003.c +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "agent_common.h" -#include -#include -#include "jvmti_tools.h" -#include "jni_tools.h" -#include "JVMTITools.h" -/* - hs203T003: - 1. Set FieldAccessWatch, FieldModificatoinWatch for a field. - 2. Upon access/modification of the field within a method, redefine - a class with the changed field version, and pop a currently executed - frame within FieldAccess/FieldModification callback. - -*/ -#ifdef __cplusplus -extern "C" { -#endif -#define DIR_NAME "newclass" -#define PATH_FORMAT "%s%02d/%s" - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t003/MyThread" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS203/hs203t003/MyThread;" -#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t003/MyThread" -#define FIELDNAME "threadState" -#define TYPE "I" - -static jint redefineNumber; -static jvmtiEnv * jvmti; -static int redefineCnt=0; - -JNIEXPORT void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni, - jthread thread, - jclass klass) { - char * className; - char * generic; - redefineNumber=0; - className=NULL; - generic=NULL; - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB4(GetClassSignature, - jvmti_env, klass, &className, &generic) ) ) { - nsk_printf("#error Agent :: while getting classname Signature.\n"); - nsk_jvmti_agentFailed(); - } else { - if (strcmp(className,CLASS_NAME) == 0) { - jfieldID field; - /* get the field id and set watch on that .*/ - if (! NSK_JNI_VERIFY(jni, (field = NSK_CPP_STUB4(GetFieldID, - jni, klass, FIELDNAME, TYPE)) != NULL) ) { - nsk_printf(" Agent :: (*JNI)->GetFieldID(jni, ... ) returns `null`.\n"); - nsk_jvmti_agentFailed(); - } else if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetFieldAccessWatch, - jvmti_env, klass, field) ) ) { - nsk_printf("#error Agent :: occured while jvmti->SetFieldAccessWatch(... ) .\n"); - nsk_jvmti_agentFailed(); - } - } - } -} - -JNIEXPORT void JNICALL callbackFieldAccess(jvmtiEnv *jvmti_env, - JNIEnv* jni, - jthread thread, - jmethodID method, - jlocation location, - jclass field_klass, - jobject object, - jfieldID field) { - jclass clas; - char fileName[512]; - if (redefineCnt < 10) { - redefineCnt++; - return; - } - redefineNumber=0; - if (! NSK_JNI_VERIFY(jni, (clas = NSK_CPP_STUB2(FindClass, jni, SEARCH_NAME)) != NULL) ) { - nsk_printf(" Agent :: (*JNI)->FindClass(jni, %s) returns `null`.\n",SEARCH_NAME); - nsk_jvmti_agentFailed(); - } else { - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti_env, clas, fileName ) != NSK_TRUE) { - nsk_printf(" Agent :: Failed to redefine.\n"); - nsk_jvmti_agentFailed(); - } else { - nsk_printf(" Agent :: Redefined.\n"); - nsk_printf(" Agent :: Suspendeding thread.\n"); - /* pop the current working frame. */ - if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB2(SuspendThread, jvmti_env, thread) ) ) { - nsk_printf("#error Agent :: occured suspending Thread.\n"); - nsk_jvmti_agentFailed(); - } else { - nsk_printf(" Agent :: Succeded in suspending.\n"); - } - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs203t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs203t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs203t003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(GetEnv, vm, - (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { - nsk_printf(" Agent :: Could not load JVMTI interface.\n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("#error Agent :: Failed to parse options.\n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_suspend=1; - caps.can_pop_frame=1; - caps.can_generate_all_class_hook_events=1; - caps.can_generate_field_access_events=1; - if (! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, jvmti, &caps) )) { - nsk_printf("#error Agent :: while adding capabilities.\n"); - return JNI_ERR; - } - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare =callbackClassPrepare; - eventCallbacks.FieldAccess= callbackFieldAccess; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) { - nsk_printf("#error Agent :: while setting event callbacks.\n"); - return JNI_ERR; - } - if ( ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_PREPARE, NULL) - == NSK_TRUE ) && - ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_FIELD_ACCESS, NULL) - == NSK_TRUE ) ) { - nsk_printf(" Agent :: Notifications are enabled.\n"); - } else { - nsk_printf("#error Agent :: Eanableing Notifications.\n"); - return JNI_ERR; - } - } - return JNI_OK; -} - - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t003_hs203t003_popThreadFrame(JNIEnv * jni, - jclass clas, - jthread thread) { - jboolean retvalue; - jint state; - retvalue = JNI_FALSE; - if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(GetThreadState, jvmti, thread, &state) ) ) { - nsk_printf(" Agent :: Error while getting thread state.\n"); - nsk_jvmti_agentFailed(); - } else { - if ( state & JVMTI_THREAD_STATE_SUSPENDED) { - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2( PopFrame, jvmti, thread) ) ) { - nsk_printf("#error Agent :: while poping thread's frame.\n"); - nsk_jvmti_agentFailed(); - } else { - nsk_printf(" Agent :: poped thread frame.\n"); - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB4 (SetEventNotificationMode, jvmti, - JVMTI_DISABLE, JVMTI_EVENT_FIELD_ACCESS, NULL) ) ) { - nsk_printf("#error Agent :: failed to disable notification JVMTI_EVENT_FIELD ACCESS.\n"); - nsk_jvmti_agentFailed(); - } else { - nsk_printf(" Agent :: Disabled notification JVMTI_EVENT_FIELD ACCESS. \n"); - retvalue = JNI_TRUE; - } - } - } else { - nsk_printf("#error Agent :: Thread was not suspened."); - nsk_jvmti_agentFailed(); - } - } - return retvalue; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t003_hs203t003_resumeThread(JNIEnv * jni, - jclass clas, - jthread thread) { - jboolean retvalue; - retvalue = JNI_FALSE; - if ( !NSK_JVMTI_VERIFY( NSK_CPP_STUB2 ( ResumeThread, jvmti, thread)) ) { - nsk_printf("#error Agent :: while resuming thread.\n"); - nsk_jvmti_agentFailed(); - } else { - nsk_printf(" Agent :: Thread resumed.\n"); - retvalue= JNI_TRUE; - } - return retvalue; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/hs203t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/hs203t003.cpp new file mode 100644 index 00000000000..5a4b8fc4602 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/hs203t003.cpp @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "agent_common.h" +#include +#include +#include "jvmti_tools.h" +#include "jni_tools.h" +#include "JVMTITools.h" +/* + hs203T003: + 1. Set FieldAccessWatch, FieldModificatoinWatch for a field. + 2. Upon access/modification of the field within a method, redefine + a class with the changed field version, and pop a currently executed + frame within FieldAccess/FieldModification callback. + +*/ +#ifdef __cplusplus +extern "C" { +#endif +#define DIR_NAME "newclass" +#define PATH_FORMAT "%s%02d/%s" + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t003/MyThread" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS203/hs203t003/MyThread;" +#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t003/MyThread" +#define FIELDNAME "threadState" +#define TYPE "I" + +static jint redefineNumber; +static jvmtiEnv * jvmti; +static int redefineCnt=0; + +JNIEXPORT void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni, + jthread thread, + jclass klass) { + char * className; + char * generic; + redefineNumber=0; + className=NULL; + generic=NULL; + if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB4(GetClassSignature, + jvmti_env, klass, &className, &generic) ) ) { + nsk_printf("#error Agent :: while getting classname Signature.\n"); + nsk_jvmti_agentFailed(); + } else { + if (strcmp(className,CLASS_NAME) == 0) { + jfieldID field; + /* get the field id and set watch on that .*/ + if (! NSK_JNI_VERIFY(jni, (field = NSK_CPP_STUB4(GetFieldID, + jni, klass, FIELDNAME, TYPE)) != NULL) ) { + nsk_printf(" Agent :: (*JNI)->GetFieldID(jni, ... ) returns `null`.\n"); + nsk_jvmti_agentFailed(); + } else if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetFieldAccessWatch, + jvmti_env, klass, field) ) ) { + nsk_printf("#error Agent :: occured while jvmti->SetFieldAccessWatch(... ) .\n"); + nsk_jvmti_agentFailed(); + } + } + } +} + +JNIEXPORT void JNICALL callbackFieldAccess(jvmtiEnv *jvmti_env, + JNIEnv* jni, + jthread thread, + jmethodID method, + jlocation location, + jclass field_klass, + jobject object, + jfieldID field) { + jclass clas; + char fileName[512]; + if (redefineCnt < 10) { + redefineCnt++; + return; + } + redefineNumber=0; + if (! NSK_JNI_VERIFY(jni, (clas = NSK_CPP_STUB2(FindClass, jni, SEARCH_NAME)) != NULL) ) { + nsk_printf(" Agent :: (*JNI)->FindClass(jni, %s) returns `null`.\n",SEARCH_NAME); + nsk_jvmti_agentFailed(); + } else { + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti_env, clas, fileName ) != NSK_TRUE) { + nsk_printf(" Agent :: Failed to redefine.\n"); + nsk_jvmti_agentFailed(); + } else { + nsk_printf(" Agent :: Redefined.\n"); + nsk_printf(" Agent :: Suspendeding thread.\n"); + /* pop the current working frame. */ + if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB2(SuspendThread, jvmti_env, thread) ) ) { + nsk_printf("#error Agent :: occured suspending Thread.\n"); + nsk_jvmti_agentFailed(); + } else { + nsk_printf(" Agent :: Succeded in suspending.\n"); + } + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs203t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs203t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs203t003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + if ( ! NSK_VERIFY ( JNI_OK == NSK_CPP_STUB3(GetEnv, vm, + (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { + nsk_printf(" Agent :: Could not load JVMTI interface.\n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("#error Agent :: Failed to parse options.\n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_suspend=1; + caps.can_pop_frame=1; + caps.can_generate_all_class_hook_events=1; + caps.can_generate_field_access_events=1; + if (! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, jvmti, &caps) )) { + nsk_printf("#error Agent :: while adding capabilities.\n"); + return JNI_ERR; + } + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare =callbackClassPrepare; + eventCallbacks.FieldAccess= callbackFieldAccess; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) { + nsk_printf("#error Agent :: while setting event callbacks.\n"); + return JNI_ERR; + } + if ( ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_PREPARE, NULL) + == NSK_TRUE ) && + ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_FIELD_ACCESS, NULL) + == NSK_TRUE ) ) { + nsk_printf(" Agent :: Notifications are enabled.\n"); + } else { + nsk_printf("#error Agent :: Eanableing Notifications.\n"); + return JNI_ERR; + } + } + return JNI_OK; +} + + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t003_hs203t003_popThreadFrame(JNIEnv * jni, + jclass clas, + jthread thread) { + jboolean retvalue; + jint state; + retvalue = JNI_FALSE; + if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(GetThreadState, jvmti, thread, &state) ) ) { + nsk_printf(" Agent :: Error while getting thread state.\n"); + nsk_jvmti_agentFailed(); + } else { + if ( state & JVMTI_THREAD_STATE_SUSPENDED) { + if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2( PopFrame, jvmti, thread) ) ) { + nsk_printf("#error Agent :: while poping thread's frame.\n"); + nsk_jvmti_agentFailed(); + } else { + nsk_printf(" Agent :: poped thread frame.\n"); + if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB4 (SetEventNotificationMode, jvmti, + JVMTI_DISABLE, JVMTI_EVENT_FIELD_ACCESS, NULL) ) ) { + nsk_printf("#error Agent :: failed to disable notification JVMTI_EVENT_FIELD ACCESS.\n"); + nsk_jvmti_agentFailed(); + } else { + nsk_printf(" Agent :: Disabled notification JVMTI_EVENT_FIELD ACCESS. \n"); + retvalue = JNI_TRUE; + } + } + } else { + nsk_printf("#error Agent :: Thread was not suspened."); + nsk_jvmti_agentFailed(); + } + } + return retvalue; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t003_hs203t003_resumeThread(JNIEnv * jni, + jclass clas, + jthread thread) { + jboolean retvalue; + retvalue = JNI_FALSE; + if ( !NSK_JVMTI_VERIFY( NSK_CPP_STUB2 ( ResumeThread, jvmti, thread)) ) { + nsk_printf("#error Agent :: while resuming thread.\n"); + nsk_jvmti_agentFailed(); + } else { + nsk_printf(" Agent :: Thread resumed.\n"); + retvalue= JNI_TRUE; + } + return retvalue; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/libhs203t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/libhs203t003.c deleted file mode 100644 index aeeacbe708a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/libhs203t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs203t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/libhs203t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/libhs203t003.cpp new file mode 100644 index 00000000000..278b406976a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/libhs203t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs203t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/hs203t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/hs203t004.c deleted file mode 100644 index d00b2e0b31c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/hs203t004.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "agent_common.h" -#include -#include -#include "jvmti_tools.h" -#include "JVMTITools.h" -#include "jni_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t004/MyThread" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS203/hs203t004/MyThread;" -#define METHOD_NAME "doTask2" - -static jint redefineNumber; -static jvmtiEnv * jvmti; - -JNIEXPORT void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni, - jthread thread, - jclass klass) { - char * className; - className=NULL; - - if (!NSK_JVMTI_VERIFY (NSK_CPP_STUB4(GetClassSignature, - jvmti_env, klass, &className, NULL) ) ) { - NSK_COMPLAIN0("#error Agent :: while getting classname.\n"); - nsk_jvmti_agentFailed(); - } else { - if (strcmp(className, CLASS_NAME) == 0) { - if (nsk_jvmti_enableNotification(jvmti_env, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL) == NSK_TRUE ) { - NSK_DISPLAY0(" Agent :: notification enabled for COMPILED_METHOD_LOAD.\n"); - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(GenerateEvents, jvmti_env, - JVMTI_EVENT_COMPILED_METHOD_LOAD ) )) { - NSK_COMPLAIN0("#error Agent :: occured while enabling compiled method events.\n"); - nsk_jvmti_agentFailed(); - } - } - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)className))) { - NSK_COMPLAIN1("#error Agent :: failed to Deallocate className = %s.", className); - nsk_jvmti_agentFailed(); - } - } -} - - -JNIEXPORT void JNICALL callbackCompiledMethodLoad(jvmtiEnv *jvmti_env, - jmethodID method, - jint code_size, - const void* code_addr, - jint map_length, - const jvmtiAddrLocationMap* map, - const void* compile_info) { - jclass threadClass; - if (redefineNumber == 0) { - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, method, &threadClass) ) ) { - NSK_COMPLAIN0("#error Agent :: while geting the declaring class.\n"); - nsk_jvmti_agentFailed(); - } else { - char *className; - char *methodName; - - className = NULL; - methodName = NULL; - - if ( ! NSK_JVMTI_VERIFY (NSK_CPP_STUB4(GetClassSignature, - jvmti_env, threadClass, &className, NULL) ) ) { - NSK_COMPLAIN0("#error Agent :: while getting classname.\n"); - nsk_jvmti_agentFailed(); - return; - } - - if ( ! NSK_JVMTI_VERIFY (NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &methodName, NULL, NULL) ) ) { - NSK_COMPLAIN0("#error Agent :: while getting methodname.\n"); - nsk_jvmti_agentFailed(); - return; - } - - if ((strcmp(className, CLASS_NAME) == 0) && (strcmp(methodName, METHOD_NAME) == 0)) { - char fileName[512]; - - NSK_DISPLAY2(" Agent :: Got CompiledMethodLoadEvent for class: %s, method: %s.\n", className, methodName); - NSK_DISPLAY0(" Agent :: redefining class.\n"); - - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); - - if ( nsk_jvmti_redefineClass(jvmti_env, threadClass, fileName) == NSK_TRUE) { - NSK_DISPLAY0(" Agent :: Successfully redefined.\n"); - redefineNumber++; - } else { - NSK_COMPLAIN0("#error Agent :: Failed to redefine.\n"); - nsk_jvmti_agentFailed(); - } - } - - if ( className != NULL ) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)className))) { - NSK_COMPLAIN1("#error Agent :: failed to Deallocate className = %s.", className); - nsk_jvmti_agentFailed(); - } - } - if ( methodName != NULL ) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)methodName))) { - NSK_COMPLAIN1("#error Agent :: failed to Deallocate methodName = %s.", methodName); - nsk_jvmti_agentFailed(); - } - } - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs203t004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs203t004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs203t004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - redefineNumber=0; - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(GetEnv, vm, - (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { - NSK_DISPLAY0("#error Agent :: Could not load JVMTI interface.\n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - memset(&caps, 0, sizeof(caps)); - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - NSK_DISPLAY0("#error Agent :: Failed to parse options.\n"); - return JNI_ERR; - } - caps.can_redefine_classes = 1; - caps.can_suspend = 1; - caps.can_pop_frame = 1; - caps.can_generate_all_class_hook_events = 1; - caps.can_generate_compiled_method_load_events = 1; - if (! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, jvmti, &caps) )) { - NSK_DISPLAY0("#error Agent :: occured while adding capabilities.\n"); - return JNI_ERR; - } - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare =callbackClassPrepare; - eventCallbacks.CompiledMethodLoad=callbackCompiledMethodLoad; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) { - NSK_COMPLAIN0("#error Agent :: occured while setting event callback.\n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE) { - NSK_DISPLAY0(" Agent :: Notifications are enabled.\n"); - } else { - NSK_COMPLAIN0("#error Agent :: Error in enableing Notifications.\n"); - return JNI_ERR; - } - } - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t004_hs203t004_suspendThread(JNIEnv * jni, - jobject clas, - jthread thread) { - NSK_DISPLAY0(" Agent :: Suspending Thread.\n"); - if ( NSK_JVMTI_VERIFY( NSK_CPP_STUB2(SuspendThread, jvmti, thread) ) ) { - NSK_DISPLAY0(" Agent :: Succeded in suspending.\n"); - } else { - NSK_COMPLAIN0("#error Agent :: occured while suspending thread.\n"); - nsk_jvmti_agentFailed(); - } -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t004_hs203t004_popThreadFrame(JNIEnv * jni, - jobject clas, - jthread thread) { - jboolean retvalue; - jint state; - - NSK_DISPLAY0(" Agent :: nsk.jvmti.scenarios.hotswap.HS203.hs203t004.popThreadFrame(... ).\n"); - retvalue = JNI_FALSE; - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(GetThreadState, jvmti, - thread, &state) ) ) { - NSK_COMPLAIN0("#error Agent :: while getting thread's state.\n"); - nsk_jvmti_agentFailed(); - } else { - if ( state & JVMTI_THREAD_STATE_SUSPENDED) { - if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB2(PopFrame, jvmti, thread) ) ){ - NSK_DISPLAY0("#error Agent :: occured while poping thread's frame.\n"); - nsk_jvmti_agentFailed(); - } else { - if ( NSK_JVMTI_VERIFY( NSK_CPP_STUB4(SetEventNotificationMode, jvmti, - JVMTI_DISABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL) ) ) { - NSK_DISPLAY0(" Agent :: Disabled JVMTI_EVENT_COMPILED_METHOD_LOAD.\n"); - retvalue = JNI_TRUE; - } else { - NSK_COMPLAIN0("#error Agent :: Failed to disable JVMTI_EVENT_COMPILED_METHOD_LOAD.\n"); - nsk_jvmti_agentFailed(); - } - } - } else { - NSK_COMPLAIN0("#error Agent :: Thread was not suspened.\n"); - nsk_jvmti_agentFailed(); - } - } - return retvalue; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t004_hs203t004_resumeThread(JNIEnv * jni, - jclass clas, - jthread thread) { - jboolean retvalue; - - retvalue = JNI_FALSE; - if ( NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(ResumeThread, jvmti, thread))) { - NSK_DISPLAY0(" Agent :: Thread resumed.\n"); - retvalue= JNI_TRUE; - } else { - NSK_COMPLAIN0("#error Agent :: Failed to resume the thread.\n"); - nsk_jvmti_agentFailed(); - } - return retvalue; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/hs203t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/hs203t004.cpp new file mode 100644 index 00000000000..49574c02ce3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/hs203t004.cpp @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "agent_common.h" +#include +#include +#include "jvmti_tools.h" +#include "JVMTITools.h" +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS203/hs203t004/MyThread" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS203/hs203t004/MyThread;" +#define METHOD_NAME "doTask2" + +static jint redefineNumber; +static jvmtiEnv * jvmti; + +JNIEXPORT void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni, + jthread thread, + jclass klass) { + char * className; + className=NULL; + + if (!NSK_JVMTI_VERIFY (NSK_CPP_STUB4(GetClassSignature, + jvmti_env, klass, &className, NULL) ) ) { + NSK_COMPLAIN0("#error Agent :: while getting classname.\n"); + nsk_jvmti_agentFailed(); + } else { + if (strcmp(className, CLASS_NAME) == 0) { + if (nsk_jvmti_enableNotification(jvmti_env, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL) == NSK_TRUE ) { + NSK_DISPLAY0(" Agent :: notification enabled for COMPILED_METHOD_LOAD.\n"); + if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(GenerateEvents, jvmti_env, + JVMTI_EVENT_COMPILED_METHOD_LOAD ) )) { + NSK_COMPLAIN0("#error Agent :: occured while enabling compiled method events.\n"); + nsk_jvmti_agentFailed(); + } + } + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)className))) { + NSK_COMPLAIN1("#error Agent :: failed to Deallocate className = %s.", className); + nsk_jvmti_agentFailed(); + } + } +} + + +JNIEXPORT void JNICALL callbackCompiledMethodLoad(jvmtiEnv *jvmti_env, + jmethodID method, + jint code_size, + const void* code_addr, + jint map_length, + const jvmtiAddrLocationMap* map, + const void* compile_info) { + jclass threadClass; + if (redefineNumber == 0) { + if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, method, &threadClass) ) ) { + NSK_COMPLAIN0("#error Agent :: while geting the declaring class.\n"); + nsk_jvmti_agentFailed(); + } else { + char *className; + char *methodName; + + className = NULL; + methodName = NULL; + + if ( ! NSK_JVMTI_VERIFY (NSK_CPP_STUB4(GetClassSignature, + jvmti_env, threadClass, &className, NULL) ) ) { + NSK_COMPLAIN0("#error Agent :: while getting classname.\n"); + nsk_jvmti_agentFailed(); + return; + } + + if ( ! NSK_JVMTI_VERIFY (NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &methodName, NULL, NULL) ) ) { + NSK_COMPLAIN0("#error Agent :: while getting methodname.\n"); + nsk_jvmti_agentFailed(); + return; + } + + if ((strcmp(className, CLASS_NAME) == 0) && (strcmp(methodName, METHOD_NAME) == 0)) { + char fileName[512]; + + NSK_DISPLAY2(" Agent :: Got CompiledMethodLoadEvent for class: %s, method: %s.\n", className, methodName); + NSK_DISPLAY0(" Agent :: redefining class.\n"); + + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); + + if ( nsk_jvmti_redefineClass(jvmti_env, threadClass, fileName) == NSK_TRUE) { + NSK_DISPLAY0(" Agent :: Successfully redefined.\n"); + redefineNumber++; + } else { + NSK_COMPLAIN0("#error Agent :: Failed to redefine.\n"); + nsk_jvmti_agentFailed(); + } + } + + if ( className != NULL ) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)className))) { + NSK_COMPLAIN1("#error Agent :: failed to Deallocate className = %s.", className); + nsk_jvmti_agentFailed(); + } + } + if ( methodName != NULL ) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)methodName))) { + NSK_COMPLAIN1("#error Agent :: failed to Deallocate methodName = %s.", methodName); + nsk_jvmti_agentFailed(); + } + } + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs203t004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs203t004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs203t004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + redefineNumber=0; + if ( ! NSK_VERIFY ( JNI_OK == NSK_CPP_STUB3(GetEnv, vm, + (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { + NSK_DISPLAY0("#error Agent :: Could not load JVMTI interface.\n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + memset(&caps, 0, sizeof(caps)); + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + NSK_DISPLAY0("#error Agent :: Failed to parse options.\n"); + return JNI_ERR; + } + caps.can_redefine_classes = 1; + caps.can_suspend = 1; + caps.can_pop_frame = 1; + caps.can_generate_all_class_hook_events = 1; + caps.can_generate_compiled_method_load_events = 1; + if (! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, jvmti, &caps) )) { + NSK_DISPLAY0("#error Agent :: occured while adding capabilities.\n"); + return JNI_ERR; + } + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare =callbackClassPrepare; + eventCallbacks.CompiledMethodLoad=callbackCompiledMethodLoad; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) { + NSK_COMPLAIN0("#error Agent :: occured while setting event callback.\n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE) { + NSK_DISPLAY0(" Agent :: Notifications are enabled.\n"); + } else { + NSK_COMPLAIN0("#error Agent :: Error in enableing Notifications.\n"); + return JNI_ERR; + } + } + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t004_hs203t004_suspendThread(JNIEnv * jni, + jobject clas, + jthread thread) { + NSK_DISPLAY0(" Agent :: Suspending Thread.\n"); + if ( NSK_JVMTI_VERIFY( NSK_CPP_STUB2(SuspendThread, jvmti, thread) ) ) { + NSK_DISPLAY0(" Agent :: Succeded in suspending.\n"); + } else { + NSK_COMPLAIN0("#error Agent :: occured while suspending thread.\n"); + nsk_jvmti_agentFailed(); + } +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t004_hs203t004_popThreadFrame(JNIEnv * jni, + jobject clas, + jthread thread) { + jboolean retvalue; + jint state; + + NSK_DISPLAY0(" Agent :: nsk.jvmti.scenarios.hotswap.HS203.hs203t004.popThreadFrame(... ).\n"); + retvalue = JNI_FALSE; + if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(GetThreadState, jvmti, + thread, &state) ) ) { + NSK_COMPLAIN0("#error Agent :: while getting thread's state.\n"); + nsk_jvmti_agentFailed(); + } else { + if ( state & JVMTI_THREAD_STATE_SUSPENDED) { + if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB2(PopFrame, jvmti, thread) ) ){ + NSK_DISPLAY0("#error Agent :: occured while poping thread's frame.\n"); + nsk_jvmti_agentFailed(); + } else { + if ( NSK_JVMTI_VERIFY( NSK_CPP_STUB4(SetEventNotificationMode, jvmti, + JVMTI_DISABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL) ) ) { + NSK_DISPLAY0(" Agent :: Disabled JVMTI_EVENT_COMPILED_METHOD_LOAD.\n"); + retvalue = JNI_TRUE; + } else { + NSK_COMPLAIN0("#error Agent :: Failed to disable JVMTI_EVENT_COMPILED_METHOD_LOAD.\n"); + nsk_jvmti_agentFailed(); + } + } + } else { + NSK_COMPLAIN0("#error Agent :: Thread was not suspened.\n"); + nsk_jvmti_agentFailed(); + } + } + return retvalue; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t004_hs203t004_resumeThread(JNIEnv * jni, + jclass clas, + jthread thread) { + jboolean retvalue; + + retvalue = JNI_FALSE; + if ( NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(ResumeThread, jvmti, thread))) { + NSK_DISPLAY0(" Agent :: Thread resumed.\n"); + retvalue= JNI_TRUE; + } else { + NSK_COMPLAIN0("#error Agent :: Failed to resume the thread.\n"); + nsk_jvmti_agentFailed(); + } + return retvalue; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/libhs203t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/libhs203t004.c deleted file mode 100644 index 9eca0ac7a65..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/libhs203t004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs203t004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/libhs203t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/libhs203t004.cpp new file mode 100644 index 00000000000..61d164084f8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t004/libhs203t004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs203t004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001.c deleted file mode 100644 index 0286a95c289..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001.c +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include - -#include "jni_tools.h" -#include "jvmti_tools.h" - - -#ifdef __cplusplus -extern "C" { -#endif -static JNIEnv* jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; -static jint testStep; -static jint redefineNumber; -static unsigned char* newClassBytes; -static unsigned char* path; -static jthread testedThread; -static jclass testClass; -static jclass myTestClass; - -#define NAME "nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001R" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001R;" -#define PATH_TO_NEW_BYTECODE "pathToNewByteCode" -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001R" -static jint newClassSize; - -char *getClassName(jvmtiEnv *jvmti, jclass klass) { - char * className; - char * generic; - if( !NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti, klass, &className, &generic))) { - nsk_jvmti_setFailStatus(); - } - return className; -} - -JNIEXPORT void JNICALL -callbackClassLoad(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * name; - name = getClassName(jvmti_env,klass); - if( (strcmp(name,CLASS_NAME ) == 0) && (redefineNumber== 1) ) { - char fileName[512]; - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - NSK_DISPLAY1(">>>>>>CallbackClassLoad ... Name=%s... >>\n",name); - if ( nsk_jvmti_redefineClass(jvmti, klass, fileName) == NSK_TRUE) { - NSK_DISPLAY0("\nMyClass :: Successfully redefined..\n"); - redefineNumber++; - } else { - NSK_COMPLAIN0("\nMyClass :: Failed to redefine ..\n"); - } - /* if( (myTestClass =NSK_CPP_STUB2(NewGlobalRef,jni_env, klass)) == NULL) { - NSK_COMPLAIN0("Failed to create global ref..."); - } - */ - } -} - -JNIEXPORT void JNICALL -callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * name; - name = getClassName(jvmti_env, klass); - if ( (strcmp(name, CLASS_NAME) ==0 ) && (redefineNumber == 0) ) { - char fileName[512]; - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - NSK_DISPLAY1(">>>>>>callbackClassPrepare ... Name=%s... >>\n",name); - if ( nsk_jvmti_redefineClass(jvmti, klass, fileName) == NSK_TRUE) { - NSK_DISPLAY0("\nMyClass :: Successfully redefined..\n"); - redefineNumber++; - } else { - NSK_COMPLAIN0("\nMyClass :: Failed to redefine ..\n"); - } - if( (myTestClass = NSK_CPP_STUB2(NewGlobalRef,jni_env, klass)) == NULL) { - NSK_COMPLAIN0("Failed to create global ref..."); - } - } -} - -JNIEXPORT void JNICALL -callbackClassFileLoadHock(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jclass class_being_redefined, - jobject loader, - const char* name, - jobject protection_domain, - jint class_data_len, - const unsigned char* class_data, - jint* new_class_data_len, - unsigned char** new_class_data) { - if (name != NULL && strcmp(name, NAME)==0 && (redefineNumber == 1 )) { - NSK_DISPLAY1(">>>>>>callbackClassFileLoadHock ... Name=%s... >>\n",name); - /*redefineClass(jvmti_env, myTestClass);*/ - } -} - -JNIEXPORT void JNICALL -#ifdef STATIC_BUILD -Agent_OnUnload_hs204t001(JavaVM *jvm) -#else -Agent_OnUnload(JavaVM *jvm) -#endif -{ - NSK_DISPLAY0(" VM ... Going Down.. (C/C++) \n"); - return; -} - -static void JNICALL agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - redefineNumber = 0; - jni = agentJNI; - testStep=1; - NSK_DISPLAY0("\n\n>>>> Debugge started, waiting for class loading \n"); - (*jni)->DeleteGlobalRef(jni,testClass); - (*jni)->DeleteGlobalRef(jni, testedThread); - NSK_DISPLAY0("Waiting for debuggee to become ready\n"); - if (!nsk_jvmti_waitForSync(timeout)) { - return; - } - testStep = 1; - NSK_DISPLAY0("\n\n>>>> Debugge started, waiting for class loading \n"); - if (!nsk_jvmti_resumeSync()) - return; - NSK_DISPLAY0("Waiting for debuggee's threads to finish\n"); - if (!nsk_jvmti_waitForSync(timeout)) - return; - (*jni)->DeleteGlobalRef(jni, testClass); - (*jni)->DeleteGlobalRef(jni, testedThread); - NSK_DISPLAY0("Let debuggee to finish\n"); - if (!nsk_jvmti_resumeSync()) - return; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs204t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs204t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs204t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - NSK_DISPLAY0(" VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - NSK_COMPLAIN0(" Could not load JVMTI interface \n"); - } else { - /* Open simple block for better memor usage. */ - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - - /* - set capabilities of - 1.ClassFileLoadHock, - 2.ClassLoad(doesn;t require any capabilities to set). - 3.ClassPrepare (doesn;t require any capabilitiesto set). - 4.Redefine (default). - 5.PopFrame. - */ - caps.can_generate_all_class_hook_events=1; - caps.can_access_local_variables = 1; - caps.can_generate_single_step_events=1; - caps.can_redefine_classes = 1; - caps.can_suspend = 1; - caps.can_pop_frame=1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - /* - set the method and other functions.. - */ - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassLoad = callbackClassLoad; - eventCallbacks.ClassPrepare=callbackClassPrepare; - eventCallbacks.ClassFileLoadHook=callbackClassFileLoadHock; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - NSK_COMPLAIN0("Error setting event callbacks"); - return JNI_ERR; - } - } - { - nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_SINGLE_STEP, testedThread); - nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_LOAD, testedThread); - nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, testedThread); - nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, testedThread); - nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,testedThread); - } - - if (!nsk_jvmti_setAgentProc(agentProc, NULL)) { - NSK_COMPLAIN0("setAgentProc failed"); - } - if (!nsk_jvmti_parseOptions(options)) { - NSK_COMPLAIN0("Cannot parse options"); - } - NSK_DISPLAY1("Wait time: %d\n",nsk_jvmti_getWaitTime()); - timeout=nsk_jvmti_getWaitTime(); - NSK_DISPLAY1(" returning back.. enter timeout-->%d \n",timeout); - return JNI_OK; - } - // TODO: shouldn't we return JNI_ERR if GetEnv failed? - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS204_hs204t001_hs204t001_setThread(JNIEnv * env, - jclass klass, - jobject thread) { - NSK_DISPLAY0(" Inside the setThread Method"); - if (!NSK_JNI_VERIFY(env, (testClass =(jclass) NSK_CPP_STUB2(NewGlobalRef, env, klass)) != NULL)) - nsk_jvmti_setFailStatus(); - if (!NSK_JNI_VERIFY(env, (testedThread =NSK_CPP_STUB2(NewGlobalRef, env, thread)) != NULL)) - nsk_jvmti_setFailStatus(); -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS204_hs204t001_hs204t001_suspendThread(JNIEnv * env, - jclass klass, - jobject thread) { - jint state; - NSK_DISPLAY0("---suspend thread .. \n"); - if (NSK_CPP_STUB3(GetThreadState,jvmti,thread, &state) == JVMTI_ERROR_NONE) { - NSK_DISPLAY0(" No Errors in finding state of the thread.\n"); - if (state & JVMTI_THREAD_STATE_ALIVE) { - NSK_DISPLAY0(" Thread state is alive .. So can be suspend should be possible ..\n"); - nsk_jvmti_disableNotification(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); - if (!NSK_JVMTI_VERIFY( NSK_CPP_STUB2(SuspendThread, jvmti, thread))) { - NSK_COMPLAIN0("TEST FAILED: unable to suspend the thread \n"); - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } else { - NSK_DISPLAY0(" Sucessfully suspended Thread..\n" ); - } - } else { - NSK_COMPLAIN0("Was not able to suspend a thread..\n"); - return NSK_FALSE; - } - } - return NSK_TRUE; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS204_hs204t001_hs204t001_popFrame(JNIEnv * env, - jclass klass, - jthread thread) { - jint state; - NSK_DISPLAY0("Inside pop_Frame method.....\n"); - if (NSK_CPP_STUB3(GetThreadState,jvmti,thread, &state) == JVMTI_ERROR_NONE) { - NSK_DISPLAY0(" Got the state of thread \n"); - if ( state & JVMTI_THREAD_STATE_SUSPENDED) { - NSK_DISPLAY0(" Thread is already in suspended mode..\n"); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(PopFrame, jvmti, thread))) { - NSK_COMPLAIN0(" TEST FAILED: UNABLE TO POP FRAME \n"); - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } else { - NSK_DISPLAY0(" Poped frame safely.."); - } - /* We should resume that thread for next execution.. */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(ResumeThread, jvmti, thread))) { - NSK_COMPLAIN0(" TEST FAILED: UNABLE TO Resume thread \n"); - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } else { - NSK_DISPLAY0(" Resumed.. thread for next set of executions..."); - } - } else { - NSK_DISPLAY0(" Thread is not in Suspened State for poping its status.."); - } - } - return NSK_TRUE; -} -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001.cpp new file mode 100644 index 00000000000..c36fdf41774 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001.cpp @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include + +#include "jni_tools.h" +#include "jvmti_tools.h" + + +#ifdef __cplusplus +extern "C" { +#endif +static JNIEnv* jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; +static jint testStep; +static jint redefineNumber; +static unsigned char* newClassBytes; +static unsigned char* path; +static jthread testedThread; +static jclass testClass; +static jclass myTestClass; + +#define NAME "nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001R" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001R;" +#define PATH_TO_NEW_BYTECODE "pathToNewByteCode" +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001R" +static jint newClassSize; + +char *getClassName(jvmtiEnv *jvmti, jclass klass) { + char * className; + char * generic; + if( !NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti, klass, &className, &generic))) { + nsk_jvmti_setFailStatus(); + } + return className; +} + +JNIEXPORT void JNICALL +callbackClassLoad(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * name; + name = getClassName(jvmti_env,klass); + if( (strcmp(name,CLASS_NAME ) == 0) && (redefineNumber== 1) ) { + char fileName[512]; + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + NSK_DISPLAY1(">>>>>>CallbackClassLoad ... Name=%s... >>\n",name); + if ( nsk_jvmti_redefineClass(jvmti, klass, fileName) == NSK_TRUE) { + NSK_DISPLAY0("\nMyClass :: Successfully redefined..\n"); + redefineNumber++; + } else { + NSK_COMPLAIN0("\nMyClass :: Failed to redefine ..\n"); + } + /* if( (myTestClass =NSK_CPP_STUB2(NewGlobalRef,jni_env, klass)) == NULL) { + NSK_COMPLAIN0("Failed to create global ref..."); + } + */ + } +} + +JNIEXPORT void JNICALL +callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * name; + name = getClassName(jvmti_env, klass); + if ( (strcmp(name, CLASS_NAME) ==0 ) && (redefineNumber == 0) ) { + char fileName[512]; + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + NSK_DISPLAY1(">>>>>>callbackClassPrepare ... Name=%s... >>\n",name); + if ( nsk_jvmti_redefineClass(jvmti, klass, fileName) == NSK_TRUE) { + NSK_DISPLAY0("\nMyClass :: Successfully redefined..\n"); + redefineNumber++; + } else { + NSK_COMPLAIN0("\nMyClass :: Failed to redefine ..\n"); + } + if( (myTestClass = (jclass) NSK_CPP_STUB2(NewGlobalRef,jni_env, klass)) == NULL) { + NSK_COMPLAIN0("Failed to create global ref..."); + } + } +} + +JNIEXPORT void JNICALL +callbackClassFileLoadHock(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jclass class_being_redefined, + jobject loader, + const char* name, + jobject protection_domain, + jint class_data_len, + const unsigned char* class_data, + jint* new_class_data_len, + unsigned char** new_class_data) { + if (name != NULL && strcmp(name, NAME)==0 && (redefineNumber == 1 )) { + NSK_DISPLAY1(">>>>>>callbackClassFileLoadHock ... Name=%s... >>\n",name); + /*redefineClass(jvmti_env, myTestClass);*/ + } +} + +JNIEXPORT void JNICALL +#ifdef STATIC_BUILD +Agent_OnUnload_hs204t001(JavaVM *jvm) +#else +Agent_OnUnload(JavaVM *jvm) +#endif +{ + NSK_DISPLAY0(" VM ... Going Down.. (C/C++) \n"); + return; +} + +static void JNICALL agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + redefineNumber = 0; + jni = agentJNI; + testStep=1; + NSK_DISPLAY0("\n\n>>>> Debugge started, waiting for class loading \n"); + jni->DeleteGlobalRef(testClass); + jni->DeleteGlobalRef(testedThread); + NSK_DISPLAY0("Waiting for debuggee to become ready\n"); + if (!nsk_jvmti_waitForSync(timeout)) { + return; + } + testStep = 1; + NSK_DISPLAY0("\n\n>>>> Debugge started, waiting for class loading \n"); + if (!nsk_jvmti_resumeSync()) + return; + NSK_DISPLAY0("Waiting for debuggee's threads to finish\n"); + if (!nsk_jvmti_waitForSync(timeout)) + return; + jni->DeleteGlobalRef(testClass); + jni->DeleteGlobalRef(testedThread); + NSK_DISPLAY0("Let debuggee to finish\n"); + if (!nsk_jvmti_resumeSync()) + return; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs204t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs204t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs204t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + NSK_DISPLAY0(" VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + NSK_COMPLAIN0(" Could not load JVMTI interface \n"); + } else { + /* Open simple block for better memor usage. */ + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + + /* + set capabilities of + 1.ClassFileLoadHock, + 2.ClassLoad(doesn;t require any capabilities to set). + 3.ClassPrepare (doesn;t require any capabilitiesto set). + 4.Redefine (default). + 5.PopFrame. + */ + caps.can_generate_all_class_hook_events=1; + caps.can_access_local_variables = 1; + caps.can_generate_single_step_events=1; + caps.can_redefine_classes = 1; + caps.can_suspend = 1; + caps.can_pop_frame=1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + /* + set the method and other functions.. + */ + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassLoad = callbackClassLoad; + eventCallbacks.ClassPrepare=callbackClassPrepare; + eventCallbacks.ClassFileLoadHook=callbackClassFileLoadHock; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + NSK_COMPLAIN0("Error setting event callbacks"); + return JNI_ERR; + } + } + { + nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_SINGLE_STEP, testedThread); + nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_LOAD, testedThread); + nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, testedThread); + nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, testedThread); + nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,testedThread); + } + + if (!nsk_jvmti_setAgentProc(agentProc, NULL)) { + NSK_COMPLAIN0("setAgentProc failed"); + } + if (!nsk_jvmti_parseOptions(options)) { + NSK_COMPLAIN0("Cannot parse options"); + } + NSK_DISPLAY1("Wait time: %d\n",nsk_jvmti_getWaitTime()); + timeout=nsk_jvmti_getWaitTime(); + NSK_DISPLAY1(" returning back.. enter timeout-->%d \n",timeout); + return JNI_OK; + } + // TODO: shouldn't we return JNI_ERR if GetEnv failed? + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS204_hs204t001_hs204t001_setThread(JNIEnv * env, + jclass klass, + jobject thread) { + NSK_DISPLAY0(" Inside the setThread Method"); + if (!NSK_JNI_VERIFY(env, (testClass =(jclass) NSK_CPP_STUB2(NewGlobalRef, env, klass)) != NULL)) + nsk_jvmti_setFailStatus(); + if (!NSK_JNI_VERIFY(env, (testedThread =NSK_CPP_STUB2(NewGlobalRef, env, thread)) != NULL)) + nsk_jvmti_setFailStatus(); +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS204_hs204t001_hs204t001_suspendThread(JNIEnv * env, + jclass klass, + jobject thread) { + jint state; + NSK_DISPLAY0("---suspend thread .. \n"); + if (NSK_CPP_STUB3(GetThreadState,jvmti,thread, &state) == JVMTI_ERROR_NONE) { + NSK_DISPLAY0(" No Errors in finding state of the thread.\n"); + if (state & JVMTI_THREAD_STATE_ALIVE) { + NSK_DISPLAY0(" Thread state is alive .. So can be suspend should be possible ..\n"); + nsk_jvmti_disableNotification(jvmti, JVMTI_EVENT_SINGLE_STEP, thread); + if (!NSK_JVMTI_VERIFY( NSK_CPP_STUB2(SuspendThread, jvmti, thread))) { + NSK_COMPLAIN0("TEST FAILED: unable to suspend the thread \n"); + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } else { + NSK_DISPLAY0(" Sucessfully suspended Thread..\n" ); + } + } else { + NSK_COMPLAIN0("Was not able to suspend a thread..\n"); + return NSK_FALSE; + } + } + return NSK_TRUE; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS204_hs204t001_hs204t001_popFrame(JNIEnv * env, + jclass klass, + jthread thread) { + jint state; + NSK_DISPLAY0("Inside pop_Frame method.....\n"); + if (NSK_CPP_STUB3(GetThreadState,jvmti,thread, &state) == JVMTI_ERROR_NONE) { + NSK_DISPLAY0(" Got the state of thread \n"); + if ( state & JVMTI_THREAD_STATE_SUSPENDED) { + NSK_DISPLAY0(" Thread is already in suspended mode..\n"); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(PopFrame, jvmti, thread))) { + NSK_COMPLAIN0(" TEST FAILED: UNABLE TO POP FRAME \n"); + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } else { + NSK_DISPLAY0(" Poped frame safely.."); + } + /* We should resume that thread for next execution.. */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(ResumeThread, jvmti, thread))) { + NSK_COMPLAIN0(" TEST FAILED: UNABLE TO Resume thread \n"); + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } else { + NSK_DISPLAY0(" Resumed.. thread for next set of executions..."); + } + } else { + NSK_DISPLAY0(" Thread is not in Suspened State for poping its status.."); + } + } + return NSK_TRUE; +} +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/libhs204t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/libhs204t001.c deleted file mode 100644 index 4e4a0ef54a0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/libhs204t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs204t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/libhs204t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/libhs204t001.cpp new file mode 100644 index 00000000000..50680d2da16 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/libhs204t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs204t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/hs204t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/hs204t002.c deleted file mode 100644 index e298cbd9a61..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/hs204t002.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include -#include "jvmti_tools.h" -#include "JVMTITools.h" -/* - *1. Enable event ClassPrepare. - *2. Upon occurrence of ClassPrepare, set a breakpoint in class static - * initializer. - *3. Upon reaching the breakpoint, redefine the class and pop - *a currently executed frame of the static initializer. -*/ -#ifdef __cplusplus -extern "C" { -#endif -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS204/hs204t002/MyThread" - -#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS204/hs204t002/MyThread" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS204/hs204t002/MyThread;" -#define METHOD_NAME "" -#define METHOD_SIGNATURE "()V" -static jint redefineNumber; -static jvmtiEnv * jvmti; - -JNIEXPORT void JNICALL -callbackClassPrepare(jvmtiEnv *jvmti, - JNIEnv* jni, - jthread thread, - jclass klass) { - char * className; - char * generic; - redefineNumber=0; - (*jvmti)->GetClassSignature(jvmti, klass, &className, &generic); - /* printf("Agent::Class Name %s \n",className); */ - if( (strcmp(className, CLASS_NAME) == 0 ) ) { - jclass cls; - cls = (*jni)->FindClass(jni,SEARCH_NAME); - if (cls == NULL) { - printf("Agent::CLS is null"); - } else { - jmethodID method; - method = (*jni)->GetMethodID(jni,cls, METHOD_NAME,METHOD_SIGNATURE); - if (method == NULL) { - printf("Agent::Method is null "); - } else { - jlocation start; - jlocation end; - jvmtiError err ; - err=(*jvmti)->GetMethodLocation(jvmti, method, &start, &end); - if ( err != JVMTI_ERROR_NONE) { - printf("Agent::Errors in finding start and end for the method \n"); - } else { - printf("Agent Start = %"LL"d and end = %"LL"d \n", start , end); - printf("Agent::setting break points.."); - err= (*jvmti)->SetBreakpoint(jvmti,method, start+1); - if (err == JVMTI_ERROR_DUPLICATE) { - printf("Agent::JVMTI_ERROR_DUPLICATE"); - } else if (err ==JVMTI_ERROR_INVALID_METHODID ) { - printf("Agent::JVMTI_ERROR_INVALID_METHODID "); - } else if ( err == JVMTI_ERROR_INVALID_LOCATION) { - printf("Agent::JVMTI_ERROR_INVALID_LOCATION "); - } else if ( err == JVMTI_ERROR_NONE) { - printf("Agent::NO ERRORS "); - } else { - printf("Agent::VERY VERY INVALID STATE "); - } - } - } - } - } - return; -} -void JNICALL callbackBreakpoint(jvmtiEnv *jvmti_env, - JNIEnv* jni, - jthread thread, - jmethodID method, - jlocation loc) { - jclass cls; - char fileName[512]; - - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - cls = (*jni)->FindClass(jni,SEARCH_NAME); - printf("Agent:: Break Pont Reached.."); - if ( nsk_jvmti_redefineClass(jvmti, cls, fileName ) == NSK_TRUE) { - nsk_printf("\nMyClass :: Successfully redefined..\n"); - } else { - nsk_printf("\nMyClass :: Failed to redefine ..\n"); - } -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs204t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs204t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs204t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - - jint rc ; - printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - memset(&caps, 0, sizeof(caps)); - if (!nsk_jvmti_parseOptions(options)) { - nsk_printf(" NSK Failed to parse.."); - return JNI_ERR; - } - /* - required to set a prepareClassLoad not required call - and setBreakPoint is required. - and redefine is required.. - */ - caps.can_redefine_classes = 1; - caps.can_generate_breakpoint_events=1; - caps.can_redefine_classes = 1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = callbackClassPrepare; - eventCallbacks.Breakpoint = callbackBreakpoint; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - - if (rc != JVMTI_ERROR_NONE) { - printf("Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - - nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE , NULL); - nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_BREAKPOINT, NULL); - } - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/hs204t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/hs204t002.cpp new file mode 100644 index 00000000000..223e402a8b9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/hs204t002.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include +#include "jvmti_tools.h" +#include "JVMTITools.h" +/* + *1. Enable event ClassPrepare. + *2. Upon occurrence of ClassPrepare, set a breakpoint in class static + * initializer. + *3. Upon reaching the breakpoint, redefine the class and pop + *a currently executed frame of the static initializer. +*/ +#ifdef __cplusplus +extern "C" { +#endif +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS204/hs204t002/MyThread" + +#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS204/hs204t002/MyThread" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS204/hs204t002/MyThread;" +#define METHOD_NAME "" +#define METHOD_SIGNATURE "()V" +static jint redefineNumber; +static jvmtiEnv * jvmti; + +JNIEXPORT void JNICALL +callbackClassPrepare(jvmtiEnv *jvmti, + JNIEnv* jni, + jthread thread, + jclass klass) { + char * className; + char * generic; + redefineNumber=0; + jvmti->GetClassSignature(klass, &className, &generic); + /* printf("Agent::Class Name %s \n",className); */ + if( (strcmp(className, CLASS_NAME) == 0 ) ) { + jclass cls; + cls = jni->FindClass(SEARCH_NAME); + if (cls == NULL) { + printf("Agent::CLS is null"); + } else { + jmethodID method; + method = jni->GetMethodID(cls, METHOD_NAME,METHOD_SIGNATURE); + if (method == NULL) { + printf("Agent::Method is null "); + } else { + jlocation start; + jlocation end; + jvmtiError err ; + err=jvmti->GetMethodLocation(method, &start, &end); + if ( err != JVMTI_ERROR_NONE) { + printf("Agent::Errors in finding start and end for the method \n"); + } else { + printf("Agent Start = %" LL "d and end = %" LL "d \n", start , end); + printf("Agent::setting break points.."); + err= jvmti->SetBreakpoint(method, start+1); + if (err == JVMTI_ERROR_DUPLICATE) { + printf("Agent::JVMTI_ERROR_DUPLICATE"); + } else if (err ==JVMTI_ERROR_INVALID_METHODID ) { + printf("Agent::JVMTI_ERROR_INVALID_METHODID "); + } else if ( err == JVMTI_ERROR_INVALID_LOCATION) { + printf("Agent::JVMTI_ERROR_INVALID_LOCATION "); + } else if ( err == JVMTI_ERROR_NONE) { + printf("Agent::NO ERRORS "); + } else { + printf("Agent::VERY VERY INVALID STATE "); + } + } + } + } + } + return; +} +void JNICALL callbackBreakpoint(jvmtiEnv *jvmti_env, + JNIEnv* jni, + jthread thread, + jmethodID method, + jlocation loc) { + jclass cls; + char fileName[512]; + + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + cls = jni->FindClass(SEARCH_NAME); + printf("Agent:: Break Pont Reached.."); + if ( nsk_jvmti_redefineClass(jvmti, cls, fileName ) == NSK_TRUE) { + nsk_printf("\nMyClass :: Successfully redefined..\n"); + } else { + nsk_printf("\nMyClass :: Failed to redefine ..\n"); + } +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs204t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs204t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs204t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + + jint rc ; + printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + memset(&caps, 0, sizeof(caps)); + if (!nsk_jvmti_parseOptions(options)) { + nsk_printf(" NSK Failed to parse.."); + return JNI_ERR; + } + /* + required to set a prepareClassLoad not required call + and setBreakPoint is required. + and redefine is required.. + */ + caps.can_redefine_classes = 1; + caps.can_generate_breakpoint_events=1; + caps.can_redefine_classes = 1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = callbackClassPrepare; + eventCallbacks.Breakpoint = callbackBreakpoint; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + + if (rc != JVMTI_ERROR_NONE) { + printf("Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + + nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE , NULL); + nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_BREAKPOINT, NULL); + } + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/libhs204t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/libhs204t002.c deleted file mode 100644 index 00b9914a024..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/libhs204t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs204t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/libhs204t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/libhs204t002.cpp new file mode 100644 index 00000000000..1e65144749d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t002/libhs204t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs204t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/hs204t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/hs204t003.c deleted file mode 100644 index 218c4577d9e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/hs204t003.c +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" -#include "jni_tools.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS204/hs204t003/MyThread" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS204/hs204t003/MyThread;" -#define FIELDNAME "intState" -#define TYPE "I" - -static jint redefineNumber; -static jvmtiEnv * jvmti; -static jclass watchFieldClass; - -JNIEXPORT void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni, - jthread thread, - jclass klass) { - char * className; - char * generic; - - className = NULL; - generic = NULL; - redefineNumber=0; - if ( !NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti_env, - klass, &className, &generic)) ) { - NSK_DISPLAY0(" Agent :: Failed get class signature.\n"); - nsk_jvmti_agentFailed(); - } else { - if( (strcmp(className, CLASS_NAME) == 0 ) ) { - jfieldID fieldId; - if ( ! NSK_JNI_VERIFY(jni, (fieldId = NSK_CPP_STUB4(GetStaticFieldID, - jni, klass, FIELDNAME, TYPE) ) != NULL ) ) { - NSK_DISPLAY0(" Agent :: Failed to get FieldId.\n"); - nsk_jvmti_agentFailed(); - } else { - if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(SetFieldAccessWatch, - jvmti_env, klass, fieldId) ) ) { - NSK_DISPLAY0(" Agent :: Failed to set watch point on a field.\n"); - nsk_jvmti_agentFailed(); - } else { - nsk_jvmti_enableNotification(jvmti_env, JVMTI_EVENT_FIELD_ACCESS, NULL); - if (! NSK_JNI_VERIFY(jni, - ( watchFieldClass = (jclass) - NSK_CPP_STUB2(NewGlobalRef, jni, klass) ) - != NULL ) ) { - NSK_DISPLAY0(" Agent :: Failed to get global reference for class.\n"); - nsk_jvmti_agentFailed(); - } - NSK_DISPLAY0(" Agent :: SetFieldAccessWatch.\n"); - } - } - NSK_DISPLAY1(" Agent :: Leaving callbackClassPrepare for class = %s .\n", className); - } - } - - if ( className != NULL ) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)className))) { - NSK_DISPLAY1(" Agent :: #error failed to Deallocate className = %s.", className); - nsk_jvmti_agentFailed(); - } - } - - if ( generic != NULL ) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)generic))) { - NSK_DISPLAY1(" Agent :: #error failed to Deallocate class signature = %s.", generic); - nsk_jvmti_agentFailed(); - } - } - return; -} - -JNIEXPORT void JNICALL callbackFieldAccess(jvmtiEnv *jvmti_env, - JNIEnv* jni, - jthread thread, - jmethodID method, - jlocation location, - jclass field_klass, - jobject object, - jfieldID field) { - char fileName[512]; - char * className; - char * generic; - - className = NULL; - generic = NULL; - if (redefineNumber != 0 ) { - return; - } - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti_env, - field_klass, &className, &generic)) ) { - NSK_DISPLAY0(" Agent :: Failed get class signature.\n"); - nsk_jvmti_agentFailed(); - } else { - if( (strcmp(className, CLASS_NAME) == 0 ) ) { - jvmtiThreadInfo info; - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti_env, field_klass, fileName) == NSK_TRUE ) { - NSK_DISPLAY0(" Agent :: Successfully redefined.\n"); - redefineNumber++; - } else { - NSK_DISPLAY0(" Agent :: Failed to redefine.\n"); - nsk_jvmti_agentFailed(); - } - NSK_DISPLAY0(" Agent :: Before attempting thread suspend.\n"); - if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(GetThreadInfo, jvmti_env, thread , &info)) ) { - NSK_DISPLAY0(" Agent :: error getting thread info "); - nsk_jvmti_agentFailed(); - } else { - NSK_DISPLAY1(" Agent :: Thread Name = %s .\n", info.name); - } - if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB2(SuspendThread, jvmti_env, thread)) ) { - NSK_DISPLAY0(" Agent :: Failed to suspend thread.\n"); - nsk_jvmti_agentFailed(); - } - } - } - - if ( className != NULL ) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)className))) { - NSK_DISPLAY1(" Agent :: #error failed to Deallocate className = %s.", className); - nsk_jvmti_agentFailed(); - } - } - - if ( generic != NULL ) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)generic))) { - NSK_DISPLAY1(" Agent :: #error failed to Deallocate class signature = %s.", generic); - nsk_jvmti_agentFailed(); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs204t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs204t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs204t003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(GetEnv, vm, - (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { - NSK_DISPLAY0("Agent :: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - memset(&caps, 0, sizeof(caps)); - if (!nsk_jvmti_parseOptions(options)) { - NSK_DISPLAY0(" NSK Failed to parse.."); - return JNI_ERR; - } - caps.can_redefine_classes = 1; - caps.can_generate_field_access_events = 1; - caps.can_pop_frame = 1; - caps.can_suspend = 1; - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB2( AddCapabilities, jvmti, &caps)) ) { - NSK_DISPLAY0(" Agent :: Failed add required capabilities\n."); - return JNI_ERR; - } - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = callbackClassPrepare; - eventCallbacks.FieldAccess = callbackFieldAccess; - if (!NSK_JVMTI_VERIFY( NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks) ) ) ) { - NSK_DISPLAY0(" Agent :: Error occured while setting event call back \n"); - return JNI_ERR; - } - nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL); - } - return JNI_OK; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS204_hs204t003_hs204t003_popFrame(JNIEnv * jni, - jobject object, - jthread thread) { - jboolean retvalue; - jint state; - retvalue = JNI_FALSE; - if (! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(GetThreadState, jvmti, thread, &state)) ){ - NSK_DISPLAY0(" Agent :: Error getting thread state.\n"); - nsk_jvmti_agentFailed(); - } else { - if ( state & JVMTI_THREAD_STATE_SUSPENDED) { - NSK_DISPLAY0(" Agent :: Thread state = JVMTI_THREAD_STATE_SUSPENDED.\n"); - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(PopFrame, jvmti, thread) ) ) { - NSK_DISPLAY0("#error Agent :: Jvmti failed to do popFrame.\n"); - nsk_jvmti_agentFailed(); - } else { - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(ResumeThread, jvmti, thread)) ) { - NSK_DISPLAY0(" Agent :: Error occured in resuming a thread.\n"); - nsk_jvmti_agentFailed(); - } else { - jfieldID fieldId; - if ( ! NSK_JNI_VERIFY(jni, (fieldId = NSK_CPP_STUB4(GetStaticFieldID, - jni, watchFieldClass, FIELDNAME, TYPE) ) != NULL ) ) { - NSK_DISPLAY0(" Agent :: Failed to get FieldId before droping watchers.\n"); - nsk_jvmti_agentFailed(); - } else { - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(ClearFieldAccessWatch, - jvmti, watchFieldClass, fieldId)) ) { - NSK_DISPLAY0(" Agent :: failed to drop field watces.\n"); - nsk_jvmti_agentFailed(); - } else { - NSK_DISPLAY0(" Agent :: Sucessfully droped watches.\n"); - retvalue = JNI_TRUE; - } - } - } - } - } else { - NSK_DISPLAY0(" Agent :: Thread should be suspended to its pop frame.\n"); - } - } - return retvalue; -} -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/hs204t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/hs204t003.cpp new file mode 100644 index 00000000000..ad8f2719d0b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/hs204t003.cpp @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" +#include "jni_tools.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS204/hs204t003/MyThread" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS204/hs204t003/MyThread;" +#define FIELDNAME "intState" +#define TYPE "I" + +static jint redefineNumber; +static jvmtiEnv * jvmti; +static jclass watchFieldClass; + +JNIEXPORT void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni, + jthread thread, + jclass klass) { + char * className; + char * generic; + + className = NULL; + generic = NULL; + redefineNumber=0; + if ( !NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti_env, + klass, &className, &generic)) ) { + NSK_DISPLAY0(" Agent :: Failed get class signature.\n"); + nsk_jvmti_agentFailed(); + } else { + if( (strcmp(className, CLASS_NAME) == 0 ) ) { + jfieldID fieldId; + if ( ! NSK_JNI_VERIFY(jni, (fieldId = NSK_CPP_STUB4(GetStaticFieldID, + jni, klass, FIELDNAME, TYPE) ) != NULL ) ) { + NSK_DISPLAY0(" Agent :: Failed to get FieldId.\n"); + nsk_jvmti_agentFailed(); + } else { + if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(SetFieldAccessWatch, + jvmti_env, klass, fieldId) ) ) { + NSK_DISPLAY0(" Agent :: Failed to set watch point on a field.\n"); + nsk_jvmti_agentFailed(); + } else { + nsk_jvmti_enableNotification(jvmti_env, JVMTI_EVENT_FIELD_ACCESS, NULL); + if (! NSK_JNI_VERIFY(jni, + ( watchFieldClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, klass) ) + != NULL ) ) { + NSK_DISPLAY0(" Agent :: Failed to get global reference for class.\n"); + nsk_jvmti_agentFailed(); + } + NSK_DISPLAY0(" Agent :: SetFieldAccessWatch.\n"); + } + } + NSK_DISPLAY1(" Agent :: Leaving callbackClassPrepare for class = %s .\n", className); + } + } + + if ( className != NULL ) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)className))) { + NSK_DISPLAY1(" Agent :: #error failed to Deallocate className = %s.", className); + nsk_jvmti_agentFailed(); + } + } + + if ( generic != NULL ) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)generic))) { + NSK_DISPLAY1(" Agent :: #error failed to Deallocate class signature = %s.", generic); + nsk_jvmti_agentFailed(); + } + } + return; +} + +JNIEXPORT void JNICALL callbackFieldAccess(jvmtiEnv *jvmti_env, + JNIEnv* jni, + jthread thread, + jmethodID method, + jlocation location, + jclass field_klass, + jobject object, + jfieldID field) { + char fileName[512]; + char * className; + char * generic; + + className = NULL; + generic = NULL; + if (redefineNumber != 0 ) { + return; + } + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti_env, + field_klass, &className, &generic)) ) { + NSK_DISPLAY0(" Agent :: Failed get class signature.\n"); + nsk_jvmti_agentFailed(); + } else { + if( (strcmp(className, CLASS_NAME) == 0 ) ) { + jvmtiThreadInfo info; + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti_env, field_klass, fileName) == NSK_TRUE ) { + NSK_DISPLAY0(" Agent :: Successfully redefined.\n"); + redefineNumber++; + } else { + NSK_DISPLAY0(" Agent :: Failed to redefine.\n"); + nsk_jvmti_agentFailed(); + } + NSK_DISPLAY0(" Agent :: Before attempting thread suspend.\n"); + if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(GetThreadInfo, jvmti_env, thread , &info)) ) { + NSK_DISPLAY0(" Agent :: error getting thread info "); + nsk_jvmti_agentFailed(); + } else { + NSK_DISPLAY1(" Agent :: Thread Name = %s .\n", info.name); + } + if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB2(SuspendThread, jvmti_env, thread)) ) { + NSK_DISPLAY0(" Agent :: Failed to suspend thread.\n"); + nsk_jvmti_agentFailed(); + } + } + } + + if ( className != NULL ) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)className))) { + NSK_DISPLAY1(" Agent :: #error failed to Deallocate className = %s.", className); + nsk_jvmti_agentFailed(); + } + } + + if ( generic != NULL ) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)generic))) { + NSK_DISPLAY1(" Agent :: #error failed to Deallocate class signature = %s.", generic); + nsk_jvmti_agentFailed(); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs204t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs204t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs204t003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + if ( ! NSK_VERIFY ( JNI_OK == NSK_CPP_STUB3(GetEnv, vm, + (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { + NSK_DISPLAY0("Agent :: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + memset(&caps, 0, sizeof(caps)); + if (!nsk_jvmti_parseOptions(options)) { + NSK_DISPLAY0(" NSK Failed to parse.."); + return JNI_ERR; + } + caps.can_redefine_classes = 1; + caps.can_generate_field_access_events = 1; + caps.can_pop_frame = 1; + caps.can_suspend = 1; + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB2( AddCapabilities, jvmti, &caps)) ) { + NSK_DISPLAY0(" Agent :: Failed add required capabilities\n."); + return JNI_ERR; + } + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = callbackClassPrepare; + eventCallbacks.FieldAccess = callbackFieldAccess; + if (!NSK_JVMTI_VERIFY( NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks) ) ) ) { + NSK_DISPLAY0(" Agent :: Error occured while setting event call back \n"); + return JNI_ERR; + } + nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL); + } + return JNI_OK; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS204_hs204t003_hs204t003_popFrame(JNIEnv * jni, + jobject object, + jthread thread) { + jboolean retvalue; + jint state; + retvalue = JNI_FALSE; + if (! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(GetThreadState, jvmti, thread, &state)) ){ + NSK_DISPLAY0(" Agent :: Error getting thread state.\n"); + nsk_jvmti_agentFailed(); + } else { + if ( state & JVMTI_THREAD_STATE_SUSPENDED) { + NSK_DISPLAY0(" Agent :: Thread state = JVMTI_THREAD_STATE_SUSPENDED.\n"); + if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(PopFrame, jvmti, thread) ) ) { + NSK_DISPLAY0("#error Agent :: Jvmti failed to do popFrame.\n"); + nsk_jvmti_agentFailed(); + } else { + if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(ResumeThread, jvmti, thread)) ) { + NSK_DISPLAY0(" Agent :: Error occured in resuming a thread.\n"); + nsk_jvmti_agentFailed(); + } else { + jfieldID fieldId; + if ( ! NSK_JNI_VERIFY(jni, (fieldId = NSK_CPP_STUB4(GetStaticFieldID, + jni, watchFieldClass, FIELDNAME, TYPE) ) != NULL ) ) { + NSK_DISPLAY0(" Agent :: Failed to get FieldId before droping watchers.\n"); + nsk_jvmti_agentFailed(); + } else { + if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(ClearFieldAccessWatch, + jvmti, watchFieldClass, fieldId)) ) { + NSK_DISPLAY0(" Agent :: failed to drop field watces.\n"); + nsk_jvmti_agentFailed(); + } else { + NSK_DISPLAY0(" Agent :: Sucessfully droped watches.\n"); + retvalue = JNI_TRUE; + } + } + } + } + } else { + NSK_DISPLAY0(" Agent :: Thread should be suspended to its pop frame.\n"); + } + } + return retvalue; +} +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/libhs204t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/libhs204t003.c deleted file mode 100644 index c9eb3331933..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/libhs204t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs204t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/libhs204t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/libhs204t003.cpp new file mode 100644 index 00000000000..d698bd6fe95 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t003/libhs204t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs204t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/hs204t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/hs204t004.c deleted file mode 100644 index 2513c757b15..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/hs204t004.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include -#include "jvmti_tools.h" -#include "JVMTITools.h" - -/* -1. Enable event ClassPrepare. -2. Upon ClassPrepare occurrence, enable FieldAccessWatch for a field to be initialized by the initializer. -3. Upon accessing the field by the initializer, redefine the class and pop a currently executed - frame of the initializer within incoming FieldAccess callback. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -#define METHOD_NAME "loadClass" -#define SIGNATURE "(Ljava/lang/String;)Ljava/lang/Class;" -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS204/hs204t004/MyClassLoader" -#define CLASS_LOADER_CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS204/hs204t004/MyClassLoader;" -/* for redefine..*/ -static jint redefineNumber; -static jvmtiEnv * jvmti; -static jclass cloader; - -JNIEXPORT void JNICALL -callbackClassLoad(jvmtiEnv *jvmti_env, - JNIEnv* jni, - jthread thread, - jclass klass) { - char * className; - char * generic; - redefineNumber=0; - (*jvmti)->GetClassSignature(jvmti, klass, &className, &generic); - if (strcmp(className, CLASS_LOADER_CLASS_NAME) == 0) { - if (klass != NULL) { - jmethodID method; - cloader = klass; - method = (*jni)->GetMethodID(jni,klass,METHOD_NAME,SIGNATURE); - if (method != NULL) { - jlocation start; - jlocation end; - jvmtiError err ; - err=(*jvmti)->GetMethodLocation(jvmti, method, &start, &end); - if (err == JVMTI_ERROR_NONE) { - nsk_printf("Agent:: NO ERRORS FOUND \n"); - err= (*jvmti)->SetBreakpoint(jvmti,method, start+1); - if ( err == JVMTI_ERROR_NONE) { - nsk_printf("Agent:: Breakpoint set \n"); - } else { - nsk_printf("Agent:: ***ERROR OCCURED ... in SET BREAK POINT ERROR \n"); - } - } else { - nsk_printf("Agent:: ***ERROR OCCURED .. in METHOD LOCATION FINDER \n"); - } - } else { - nsk_printf("Agent:: ***ERROR OCCURED .. COUND NOT FIND THE METHOD AND SIGNATURE SPECIFIED \n"); - } - } else { - nsk_printf("Agent:: ***ERROR OCCURED .. CLASS SPECIFIED WAS NOT FOUND \n"); - } - } -} - -void JNICALL callbackBreakpoint(jvmtiEnv *jvmti_env, - JNIEnv* jni, - jthread thread, - jmethodID method, - jlocation loc) { - jvmtiError err ; - jclass clas; - char fileName[512]; - clas = (*jni)->FindClass(jni,CLASS_LOADER_CLASS_NAME); - nsk_printf("Agent:: Break Pont Reached..\n"); - /* Redefine the class loader and then pop the - frame and resume the thread..*/ - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass( jvmti_env, clas, fileName) == NSK_TRUE) { - nsk_printf("\nMyClass :: Successfully redefined..\n"); - } else { - nsk_printf("\nMyClass :: Failed to redefine ..\n"); - } - nsk_printf(" End of REDEFINE CLASS LOADER \n"); - err=(*jvmti)->SuspendThread(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf("Agent:: Succeded in suspending..\n"); - } else if (err == JVMTI_ERROR_THREAD_SUSPENDED) { - nsk_printf("Agent:: JVMTI_ERROR_THREAD_SUSPENDED \n"); - } else if ( err == JVMTI_ERROR_INVALID_THREAD) { - nsk_printf("Agent:: JVMTI_ERROR_INVALID_THREAD \n"); - } else if ( err == JVMTI_ERROR_THREAD_NOT_ALIVE) { - nsk_printf("Agent:: JVMTI_ERROR_THREAD_NOT_ALIVE \n"); - } else { - nsk_printf(" Else error "); - } -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs204t004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs204t004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs204t004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - memset(&caps, 0, sizeof(caps)); - if (!nsk_jvmti_parseOptions(options)) { - nsk_printf(" NSK Failed to parse.."); - return JNI_ERR; - } - caps.can_redefine_classes = 1; - caps.can_suspend=1; - caps.can_pop_frame=1; - caps.can_generate_breakpoint_events=1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassLoad =callbackClassLoad; - eventCallbacks.Breakpoint = callbackBreakpoint; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_LOAD, NULL); - nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_BREAKPOINT, NULL); - } - return JNI_OK; - } - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS204_hs204t004_hs204t004_popFrame(JNIEnv * jni, - jclass clas, - jthread thread) { - jvmtiError err ; - jboolean retvalue; - jint state; - nsk_printf("Agent:: POPING THE FRAME....\n"); - retvalue = JNI_FALSE; - (*jvmti)->GetThreadState(jvmti, thread, &state); - if ( state & JVMTI_THREAD_STATE_IN_NATIVE) nsk_printf("JVMTI_THREAD_STATE_IN_NATIVE"); - if ( state & JVMTI_THREAD_STATE_INTERRUPTED) nsk_printf( "JVMTI_THREAD_STATE_INTERRUPTED"); - if ( state & JVMTI_THREAD_STATE_WAITING) nsk_printf(" JVMTI_THREAD_STATE_WAITING"); - if ( state & JVMTI_THREAD_STATE_SUSPENDED) { - nsk_printf("Agent:: Thread state .. JVMTI_THREAD_STATE_SUSPENDED \n"); - err = (*jvmti)->PopFrame(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - nsk_printf("Agent:: NO Errors poped very well ..\n"); - err = (*jvmti)->ResumeThread(jvmti,thread); - if (err == JVMTI_ERROR_NONE) { - retvalue = JNI_TRUE; - } else { - nsk_printf("Agent:: Error occured in resuming a thread..\n"); - } - } else { - nsk_printf("Agent:: some other error ..%s \n",TranslateError(err)); - } - } else { - nsk_printf("Agent:: Thread is not suspended ..\n"); - } - return retvalue; -} - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/hs204t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/hs204t004.cpp new file mode 100644 index 00000000000..627f1499649 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/hs204t004.cpp @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include +#include "jvmti_tools.h" +#include "JVMTITools.h" + +/* +1. Enable event ClassPrepare. +2. Upon ClassPrepare occurrence, enable FieldAccessWatch for a field to be initialized by the initializer. +3. Upon accessing the field by the initializer, redefine the class and pop a currently executed + frame of the initializer within incoming FieldAccess callback. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +#define METHOD_NAME "loadClass" +#define SIGNATURE "(Ljava/lang/String;)Ljava/lang/Class;" +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS204/hs204t004/MyClassLoader" +#define CLASS_LOADER_CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS204/hs204t004/MyClassLoader;" +/* for redefine..*/ +static jint redefineNumber; +static jvmtiEnv * jvmti; +static jclass cloader; + +JNIEXPORT void JNICALL +callbackClassLoad(jvmtiEnv *jvmti_env, + JNIEnv* jni, + jthread thread, + jclass klass) { + char * className; + char * generic; + redefineNumber=0; + jvmti->GetClassSignature(klass, &className, &generic); + if (strcmp(className, CLASS_LOADER_CLASS_NAME) == 0) { + if (klass != NULL) { + jmethodID method; + cloader = klass; + method = jni->GetMethodID(klass,METHOD_NAME,SIGNATURE); + if (method != NULL) { + jlocation start; + jlocation end; + jvmtiError err ; + err=jvmti->GetMethodLocation(method, &start, &end); + if (err == JVMTI_ERROR_NONE) { + nsk_printf("Agent:: NO ERRORS FOUND \n"); + err= jvmti->SetBreakpoint(method, start+1); + if ( err == JVMTI_ERROR_NONE) { + nsk_printf("Agent:: Breakpoint set \n"); + } else { + nsk_printf("Agent:: ***ERROR OCCURED ... in SET BREAK POINT ERROR \n"); + } + } else { + nsk_printf("Agent:: ***ERROR OCCURED .. in METHOD LOCATION FINDER \n"); + } + } else { + nsk_printf("Agent:: ***ERROR OCCURED .. COUND NOT FIND THE METHOD AND SIGNATURE SPECIFIED \n"); + } + } else { + nsk_printf("Agent:: ***ERROR OCCURED .. CLASS SPECIFIED WAS NOT FOUND \n"); + } + } +} + +void JNICALL callbackBreakpoint(jvmtiEnv *jvmti_env, + JNIEnv* jni, + jthread thread, + jmethodID method, + jlocation loc) { + jvmtiError err ; + jclass clas; + char fileName[512]; + clas = jni->FindClass(CLASS_LOADER_CLASS_NAME); + nsk_printf("Agent:: Break Pont Reached..\n"); + /* Redefine the class loader and then pop the + frame and resume the thread..*/ + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass( jvmti_env, clas, fileName) == NSK_TRUE) { + nsk_printf("\nMyClass :: Successfully redefined..\n"); + } else { + nsk_printf("\nMyClass :: Failed to redefine ..\n"); + } + nsk_printf(" End of REDEFINE CLASS LOADER \n"); + err=jvmti->SuspendThread(thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf("Agent:: Succeded in suspending..\n"); + } else if (err == JVMTI_ERROR_THREAD_SUSPENDED) { + nsk_printf("Agent:: JVMTI_ERROR_THREAD_SUSPENDED \n"); + } else if ( err == JVMTI_ERROR_INVALID_THREAD) { + nsk_printf("Agent:: JVMTI_ERROR_INVALID_THREAD \n"); + } else if ( err == JVMTI_ERROR_THREAD_NOT_ALIVE) { + nsk_printf("Agent:: JVMTI_ERROR_THREAD_NOT_ALIVE \n"); + } else { + nsk_printf(" Else error "); + } +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs204t004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs204t004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs204t004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + memset(&caps, 0, sizeof(caps)); + if (!nsk_jvmti_parseOptions(options)) { + nsk_printf(" NSK Failed to parse.."); + return JNI_ERR; + } + caps.can_redefine_classes = 1; + caps.can_suspend=1; + caps.can_pop_frame=1; + caps.can_generate_breakpoint_events=1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassLoad =callbackClassLoad; + eventCallbacks.Breakpoint = callbackBreakpoint; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_LOAD, NULL); + nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_BREAKPOINT, NULL); + } + return JNI_OK; + } + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS204_hs204t004_hs204t004_popFrame(JNIEnv * jni, + jclass clas, + jthread thread) { + jvmtiError err ; + jboolean retvalue; + jint state; + nsk_printf("Agent:: POPING THE FRAME....\n"); + retvalue = JNI_FALSE; + jvmti->GetThreadState(thread, &state); + if ( state & JVMTI_THREAD_STATE_IN_NATIVE) nsk_printf("JVMTI_THREAD_STATE_IN_NATIVE"); + if ( state & JVMTI_THREAD_STATE_INTERRUPTED) nsk_printf( "JVMTI_THREAD_STATE_INTERRUPTED"); + if ( state & JVMTI_THREAD_STATE_WAITING) nsk_printf(" JVMTI_THREAD_STATE_WAITING"); + if ( state & JVMTI_THREAD_STATE_SUSPENDED) { + nsk_printf("Agent:: Thread state .. JVMTI_THREAD_STATE_SUSPENDED \n"); + err = jvmti->PopFrame(thread); + if (err == JVMTI_ERROR_NONE) { + nsk_printf("Agent:: NO Errors poped very well ..\n"); + err = jvmti->ResumeThread(thread); + if (err == JVMTI_ERROR_NONE) { + retvalue = JNI_TRUE; + } else { + nsk_printf("Agent:: Error occured in resuming a thread..\n"); + } + } else { + nsk_printf("Agent:: some other error ..%s \n",TranslateError(err)); + } + } else { + nsk_printf("Agent:: Thread is not suspended ..\n"); + } + return retvalue; +} + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/libhs204t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/libhs204t004.c deleted file mode 100644 index 43a9b61630a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/libhs204t004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs204t004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/libhs204t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/libhs204t004.cpp new file mode 100644 index 00000000000..a20d714219f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t004/libhs204t004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs204t004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/hs301t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/hs301t001.c deleted file mode 100644 index 0503aab0e1e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/hs301t001.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" -#include "jni_tools.h" -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t001/MyClass" -#define DIR_NAME "newclass" -#define PATH_FORMAT "%s%02d/%s" -#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t001/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS301/hs301t001/MyClass;" -static jvmtiEnv * jvmti; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs301t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs301t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs301t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - nsk_printf("Agent:: Agent_OnLoad .\n"); - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(GetEnv, vm, - (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { - nsk_printf("Agent:: Could not load JVMTI interface.\n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options.\n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - if (! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, jvmti, &caps) )) { - nsk_printf(" Agent:: Error occured while adding capabilities.\n"); - return JNI_ERR; - } - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) { - nsk_printf(" Agent:: Error occured while setting event call back.\n"); - return JNI_ERR; - } - } - return JNI_OK; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS301_hs301t001_hs301t001_redefine(JNIEnv * jni, jobject jboj) { - jclass cls; - jboolean ret; - char fileName[512]; - int redefineNumber; - - - redefineNumber=0; - //cls= NSK_CPP_STUB2(FindClass, jni, SEARCH_NAME); - if (! NSK_JNI_VERIFY(jni, (cls = NSK_CPP_STUB2(FindClass, jni, SEARCH_NAME)) != NULL) ) { - nsk_printf("Agent:: (*JNI)->FindClass(jni, %s) returns `null`.\n",SEARCH_NAME); - return NSK_FALSE; - } - ret = JNI_FALSE; - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti, cls, fileName) == NSK_TRUE ) { - nsk_printf("Agent:: Redefine successful.\n"); - ret = JNI_TRUE; - } else { - nsk_printf("#error Agent :: Redefine failed.\n"); - } - return ret; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/hs301t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/hs301t001.cpp new file mode 100644 index 00000000000..479511ec705 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/hs301t001.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" +#include "jni_tools.h" +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t001/MyClass" +#define DIR_NAME "newclass" +#define PATH_FORMAT "%s%02d/%s" +#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t001/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS301/hs301t001/MyClass;" +static jvmtiEnv * jvmti; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs301t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs301t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs301t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + nsk_printf("Agent:: Agent_OnLoad .\n"); + if ( ! NSK_VERIFY ( JNI_OK == NSK_CPP_STUB3(GetEnv, vm, + (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { + nsk_printf("Agent:: Could not load JVMTI interface.\n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options.\n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + if (! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, jvmti, &caps) )) { + nsk_printf(" Agent:: Error occured while adding capabilities.\n"); + return JNI_ERR; + } + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) { + nsk_printf(" Agent:: Error occured while setting event call back.\n"); + return JNI_ERR; + } + } + return JNI_OK; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS301_hs301t001_hs301t001_redefine(JNIEnv * jni, jobject jboj) { + jclass cls; + jboolean ret; + char fileName[512]; + int redefineNumber; + + + redefineNumber=0; + //cls= NSK_CPP_STUB2(FindClass, jni, SEARCH_NAME); + if (! NSK_JNI_VERIFY(jni, (cls = NSK_CPP_STUB2(FindClass, jni, SEARCH_NAME)) != NULL) ) { + nsk_printf("Agent:: (*JNI)->FindClass(jni, %s) returns `null`.\n",SEARCH_NAME); + return NSK_FALSE; + } + ret = JNI_FALSE; + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti, cls, fileName) == NSK_TRUE ) { + nsk_printf("Agent:: Redefine successful.\n"); + ret = JNI_TRUE; + } else { + nsk_printf("#error Agent :: Redefine failed.\n"); + } + return ret; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/libhs301t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/libhs301t001.c deleted file mode 100644 index 6c6cfef712c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/libhs301t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs301t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/libhs301t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/libhs301t001.cpp new file mode 100644 index 00000000000..22f3ed4d618 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t001/libhs301t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs301t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/hs301t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/hs301t002.c deleted file mode 100644 index 93aeec3821c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/hs301t002.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/** - * Please see the ./hs301t002.README file for detailed explanation of this testcase. - * - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" -#include "jni_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t002/MyClass" -#define DIR_NAME "newclass" -#define PATH_FORMAT "%s%02d/%s" -#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t002/MyClass" - -static jvmtiEnv * jvmti; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs301t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs301t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs301t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - nsk_printf(" Agent:: VM Started.\n"); - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(GetEnv, vm, - (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { - nsk_printf(" Agent ::Agent failed to get jvmti env.\n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf(" Agent:: ## error agent Failed to parse options.\n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, jvmti, &caps) ) ) { - nsk_printf(" Agent:: Error occured while adding capabilities.\n"); - return JNI_ERR; - } - } - return JNI_OK; -} - -/** - * fixed JNI signature, and droped jclass clsa (paramter from here as it was not used). - * - */ -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_hotswap_HS301_hs301t002_hs301t002_redefine(JNIEnv * jni, jobject obj) { - jclass cls; - jboolean ret; - char fileName[512]; - int redefineNumber ; - - redefineNumber=0; - ret = JNI_FALSE; - if (!NSK_JNI_VERIFY(jni, (cls = NSK_CPP_STUB2(FindClass, jni, SEARCH_NAME)) != NULL)) { - nsk_printf("Agent:: (*JNI)->FindClass(jni, %s) returns `null`.\n", SEARCH_NAME); - return NSK_FALSE; - } - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti, cls, fileName) == NSK_TRUE) { - nsk_printf("Agent:: MyClass :: Successfully redefined.\n"); - ret = JNI_TRUE; - } else { - nsk_printf("Agent:: MyClass :: Failed to redefine.\n"); - } - return ret; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/hs301t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/hs301t002.cpp new file mode 100644 index 00000000000..d3263f76076 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/hs301t002.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * Please see the ./hs301t002.README file for detailed explanation of this testcase. + * + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t002/MyClass" +#define DIR_NAME "newclass" +#define PATH_FORMAT "%s%02d/%s" +#define SEARCH_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t002/MyClass" + +static jvmtiEnv * jvmti; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs301t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs301t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs301t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + nsk_printf(" Agent:: VM Started.\n"); + if ( ! NSK_VERIFY ( JNI_OK == NSK_CPP_STUB3(GetEnv, vm, + (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { + nsk_printf(" Agent ::Agent failed to get jvmti env.\n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf(" Agent:: ## error agent Failed to parse options.\n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, jvmti, &caps) ) ) { + nsk_printf(" Agent:: Error occured while adding capabilities.\n"); + return JNI_ERR; + } + } + return JNI_OK; +} + +/** + * fixed JNI signature, and droped jclass clsa (paramter from here as it was not used). + * + */ +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_hotswap_HS301_hs301t002_hs301t002_redefine(JNIEnv * jni, jobject obj) { + jclass cls; + jboolean ret; + char fileName[512]; + int redefineNumber ; + + redefineNumber=0; + ret = JNI_FALSE; + if (!NSK_JNI_VERIFY(jni, (cls = NSK_CPP_STUB2(FindClass, jni, SEARCH_NAME)) != NULL)) { + nsk_printf("Agent:: (*JNI)->FindClass(jni, %s) returns `null`.\n", SEARCH_NAME); + return NSK_FALSE; + } + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti, cls, fileName) == NSK_TRUE) { + nsk_printf("Agent:: MyClass :: Successfully redefined.\n"); + ret = JNI_TRUE; + } else { + nsk_printf("Agent:: MyClass :: Failed to redefine.\n"); + } + return ret; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/libhs301t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/libhs301t002.c deleted file mode 100644 index 8a976abd116..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/libhs301t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs301t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/libhs301t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/libhs301t002.cpp new file mode 100644 index 00000000000..e938804b522 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t002/libhs301t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs301t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/hs301t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/hs301t003.c deleted file mode 100644 index e537ebf4cc2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/hs301t003.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t003/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS301/hs301t003/MyClass;" - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB4(GetClassSignature, - jvmti_env, klass, &className, &generic) ) ) { - nsk_printf(" Agent:: Error while getting ClassFileName Signature "); - } else { - if (strcmp(className, CLASS_NAME ) == 0) { - int redefineNumber =0; - char fileName[512]; - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, - fileName, sizeof(fileName)/sizeof(char)); - nsk_jvmti_disableNotification(jvmti_env, - JVMTI_EVENT_CLASS_LOAD, NULL ); - if (nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE) { - nsk_printf("\n Redefine successful.\n"); - } else { - nsk_printf("\n Redefine failed.\n"); - } - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs301t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs301t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs301t003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jvmtiEnv * jvmti; - nsk_printf("Agent:: Agent_OnLoad.\n"); - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(GetEnv, vm, - (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { - nsk_printf("Agent:: Could not load JVMTI interface.\n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options.\n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - if (! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, jvmti, &caps) )) { - nsk_printf(" Agent:: Error occured while adding capabilities.\n"); - return JNI_ERR; - } - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) { - nsk_printf(" Agent:: Error occured while setting event call back.\n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Agent:: Enabled notification.\n"); - } else { - nsk_printf(" Agent:: Failed to enable notification.\n"); - } - } - return JNI_OK; -} -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/hs301t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/hs301t003.cpp new file mode 100644 index 00000000000..125e93098e1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/hs301t003.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t003/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS301/hs301t003/MyClass;" + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB4(GetClassSignature, + jvmti_env, klass, &className, &generic) ) ) { + nsk_printf(" Agent:: Error while getting ClassFileName Signature "); + } else { + if (strcmp(className, CLASS_NAME ) == 0) { + int redefineNumber =0; + char fileName[512]; + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, + fileName, sizeof(fileName)/sizeof(char)); + nsk_jvmti_disableNotification(jvmti_env, + JVMTI_EVENT_CLASS_LOAD, NULL ); + if (nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE) { + nsk_printf("\n Redefine successful.\n"); + } else { + nsk_printf("\n Redefine failed.\n"); + } + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs301t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs301t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs301t003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jvmtiEnv * jvmti; + nsk_printf("Agent:: Agent_OnLoad.\n"); + if ( ! NSK_VERIFY ( JNI_OK == NSK_CPP_STUB3(GetEnv, vm, + (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { + nsk_printf("Agent:: Could not load JVMTI interface.\n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options.\n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + if (! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, jvmti, &caps) )) { + nsk_printf(" Agent:: Error occured while adding capabilities.\n"); + return JNI_ERR; + } + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) { + nsk_printf(" Agent:: Error occured while setting event call back.\n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Agent:: Enabled notification.\n"); + } else { + nsk_printf(" Agent:: Failed to enable notification.\n"); + } + } + return JNI_OK; +} +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/libhs301t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/libhs301t003.c deleted file mode 100644 index 80ce0739b4a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/libhs301t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs301t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/libhs301t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/libhs301t003.cpp new file mode 100644 index 00000000000..25ae8496d6a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t003/libhs301t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs301t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/hs301t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/hs301t004.c deleted file mode 100644 index ad5cc83be4f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/hs301t004.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t004/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS301/hs301t004/MyClass;" - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber=0; - if (! NSK_JVMTI_VERIFY( NSK_CPP_STUB4(GetClassSignature, - jvmti_env, klass, &className, &generic)) ) { - nsk_printf(" Agent :: Error occured in getting class signature.\n"); - return; - } else { - if (strcmp(className, CLASS_NAME) == 0) { - int redefineNumber =0; - char fileName[512]; - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if (nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { - nsk_printf("Agent:: Redefine successful.\n"); - } else { - nsk_printf("Agent:: Redefine failed.\n"); - } - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs301t004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs301t004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs301t004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jvmtiEnv * jvmti; - nsk_printf("Agent:: VM Started.\n"); - if (! NSK_JVMTI_VERIFY (NSK_CPP_STUB3(GetEnv, - vm, (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, - jvmti, &caps) )) { - nsk_printf(" Agent:: Error occured while adding capabilities.\n"); - return JNI_ERR; - } - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &eventCallbacks, sizeof(eventCallbacks)) ) ) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled notification.\n"); - } else { - nsk_printf(" Failed to enable notifications.\n"); - } - } - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/hs301t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/hs301t004.cpp new file mode 100644 index 00000000000..d5444f44f4d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/hs301t004.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t004/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS301/hs301t004/MyClass;" + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber=0; + if (! NSK_JVMTI_VERIFY( NSK_CPP_STUB4(GetClassSignature, + jvmti_env, klass, &className, &generic)) ) { + nsk_printf(" Agent :: Error occured in getting class signature.\n"); + return; + } else { + if (strcmp(className, CLASS_NAME) == 0) { + int redefineNumber =0; + char fileName[512]; + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if (nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { + nsk_printf("Agent:: Redefine successful.\n"); + } else { + nsk_printf("Agent:: Redefine failed.\n"); + } + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs301t004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs301t004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs301t004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jvmtiEnv * jvmti; + nsk_printf("Agent:: VM Started.\n"); + if (! NSK_VERIFY ( JNI_OK == NSK_CPP_STUB3(GetEnv, + vm, (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(AddCapabilities, + jvmti, &caps) )) { + nsk_printf(" Agent:: Error occured while adding capabilities.\n"); + return JNI_ERR; + } + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &eventCallbacks, sizeof(eventCallbacks)) ) ) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled notification.\n"); + } else { + nsk_printf(" Failed to enable notifications.\n"); + } + } + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/libhs301t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/libhs301t004.c deleted file mode 100644 index 490aeb363b6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/libhs301t004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs301t004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/libhs301t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/libhs301t004.cpp new file mode 100644 index 00000000000..16b082d20b7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t004/libhs301t004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs301t004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/hs301t005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/hs301t005.c deleted file mode 100644 index f43f9c889db..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/hs301t005.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - - -#ifdef __cplusplus -extern "C" { -#endif -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t005/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS301/hs301t005/MyClass;" - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - (*jvmti)->GetClassSignature(jvmti, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - int redefineNumber =0; - char fileName[512]; - nsk_jvmti_disableNotification(jvmti, JVMTI_EVENT_CLASS_LOAD, NULL ); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); - if (nsk_jvmti_redefineClass(jvmti, klass, fileName) == NSK_TRUE) { - nsk_printf("\n Redefine successful ..\n"); - } else { - nsk_printf("\n Redefine failed..\n"); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs301t005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs301t005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs301t005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/hs301t005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/hs301t005.cpp new file mode 100644 index 00000000000..ef7f32cebec --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/hs301t005.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + + +#ifdef __cplusplus +extern "C" { +#endif +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS301/hs301t005/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS301/hs301t005/MyClass;" + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + jvmti->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + int redefineNumber =0; + char fileName[512]; + nsk_jvmti_disableNotification(jvmti, JVMTI_EVENT_CLASS_LOAD, NULL ); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); + if (nsk_jvmti_redefineClass(jvmti, klass, fileName) == NSK_TRUE) { + nsk_printf("\n Redefine successful ..\n"); + } else { + nsk_printf("\n Redefine failed..\n"); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs301t005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs301t005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs301t005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/libhs301t005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/libhs301t005.c deleted file mode 100644 index cffaf0d6105..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/libhs301t005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs301t005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/libhs301t005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/libhs301t005.cpp new file mode 100644 index 00000000000..8a3dacf092d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS301/hs301t005/libhs301t005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs301t005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/hs302t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/hs302t001.c deleted file mode 100644 index 0c2e86c5cbf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/hs302t001.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t001/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t001/MyClass;" - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber=0; - (*jvmti_env)->GetClassSignature(jvmti_env, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0 ) { - char fileName[512]; - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { - nsk_printf("Redefine successful ..\n"); - } else { - nsk_printf("# error :: Redefine failed..\n"); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs302t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs302t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs302t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/hs302t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/hs302t001.cpp new file mode 100644 index 00000000000..54dbc05e419 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/hs302t001.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t001/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t001/MyClass;" + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber=0; + jvmti_env->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0 ) { + char fileName[512]; + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { + nsk_printf("Redefine successful ..\n"); + } else { + nsk_printf("# error :: Redefine failed..\n"); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs302t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs302t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs302t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/libhs302t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/libhs302t001.c deleted file mode 100644 index 5c7bd50ceb7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/libhs302t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs302t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/libhs302t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/libhs302t001.cpp new file mode 100644 index 00000000000..6eb14100ea7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t001/libhs302t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs302t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/hs302t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/hs302t002.c deleted file mode 100644 index a9b4f465da4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/hs302t002.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t002/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t002/MyClass;" - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber; - redefineNumber=0; - (*jvmti_env)->GetClassSignature(jvmti_env, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - char fileName[512]; - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName ) == NSK_TRUE ) { - nsk_printf("Redefine successful ..\n"); - } else { - nsk_printf("Redefine failed .. \n"); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs302t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs302t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs302t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - - if ( nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, - sizeof(eventCallbacks)); - - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, - NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/hs302t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/hs302t002.cpp new file mode 100644 index 00000000000..0ad25f30bf7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/hs302t002.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t002/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t002/MyClass;" + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber; + redefineNumber=0; + jvmti_env->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + char fileName[512]; + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName ) == NSK_TRUE ) { + nsk_printf("Redefine successful ..\n"); + } else { + nsk_printf("Redefine failed .. \n"); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs302t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs302t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs302t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + + if ( nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, + sizeof(eventCallbacks)); + + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, + NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/libhs302t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/libhs302t002.c deleted file mode 100644 index b14c2745198..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/libhs302t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs302t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/libhs302t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/libhs302t002.cpp new file mode 100644 index 00000000000..a588f827a65 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t002/libhs302t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs302t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/hs302t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/hs302t003.c deleted file mode 100644 index 4a0e70b0cb0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/hs302t003.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t003/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t003/MyClass;" - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber=0; - (*jvmti_env)->GetClassSignature(jvmti_env, klass, &className, &generic); - if ( strcmp(className,CLASS_NAME) == 0 ) { - char fileName[512]; - - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { - nsk_printf("Redefine successful ..\n"); - } else { - nsk_printf("Redefine failed .. \n"); - } - } -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs302t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs302t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs302t003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/hs302t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/hs302t003.cpp new file mode 100644 index 00000000000..a320ef410a4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/hs302t003.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t003/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t003/MyClass;" + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber=0; + jvmti_env->GetClassSignature(klass, &className, &generic); + if ( strcmp(className,CLASS_NAME) == 0 ) { + char fileName[512]; + + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char)); + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { + nsk_printf("Redefine successful ..\n"); + } else { + nsk_printf("Redefine failed .. \n"); + } + } +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs302t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs302t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs302t003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/libhs302t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/libhs302t003.c deleted file mode 100644 index a8fa7fb232a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/libhs302t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs302t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/libhs302t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/libhs302t003.cpp new file mode 100644 index 00000000000..3e65d8ffd03 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t003/libhs302t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs302t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/hs302t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/hs302t004.c deleted file mode 100644 index 77db278e80d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/hs302t004.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t004r/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t004r/MyClass;" - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber=0; - (*jvmti_env)->GetClassSignature(jvmti_env, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - char fileName[512]; - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - if ( nsk_jvmti_redefineClass(jvmti_env, klass,fileName) == NSK_TRUE ) { - nsk_printf("Redefine successful ..\n"); - } else { - nsk_printf("# error :: Redefine failed..\n"); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs302t004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs302t004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs302t004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/hs302t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/hs302t004.cpp new file mode 100644 index 00000000000..3d260eac68e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/hs302t004.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t004r/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t004r/MyClass;" + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber=0; + jvmti_env->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + char fileName[512]; + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + if ( nsk_jvmti_redefineClass(jvmti_env, klass,fileName) == NSK_TRUE ) { + nsk_printf("Redefine successful ..\n"); + } else { + nsk_printf("# error :: Redefine failed..\n"); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs302t004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs302t004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs302t004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/libhs302t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/libhs302t004.c deleted file mode 100644 index 1727caec61e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/libhs302t004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs302t004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/libhs302t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/libhs302t004.cpp new file mode 100644 index 00000000000..e278abda2c2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t004/libhs302t004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs302t004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/hs302t005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/hs302t005.c deleted file mode 100644 index dcb4ad3c84c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/hs302t005.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t005r/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t005r/MyClass;" - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber=0; - (*jvmti_env)->GetClassSignature(jvmti_env, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - char fileName[512]; - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti_env, klass,fileName) == NSK_TRUE ) { - nsk_printf("Redefine successful ..\n"); - } else { - nsk_printf("# error :: Redefine failed..\n"); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs302t005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs302t005(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs302t005(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/hs302t005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/hs302t005.cpp new file mode 100644 index 00000000000..255f618d006 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/hs302t005.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t005r/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t005r/MyClass;" + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber=0; + jvmti_env->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + char fileName[512]; + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti_env, klass,fileName) == NSK_TRUE ) { + nsk_printf("Redefine successful ..\n"); + } else { + nsk_printf("# error :: Redefine failed..\n"); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs302t005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs302t005(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs302t005(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/libhs302t005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/libhs302t005.c deleted file mode 100644 index 532a07bf96e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/libhs302t005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs302t005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/libhs302t005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/libhs302t005.cpp new file mode 100644 index 00000000000..a16418a0dd5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t005/libhs302t005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs302t005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/hs302t006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/hs302t006.c deleted file mode 100644 index 6e719279ab4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/hs302t006.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t006r/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t006r/MyClass;" - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber=0; - (*jvmti_env)->GetClassSignature(jvmti_env, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - char fileName[512]; - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { - nsk_printf("Redefine successful ..\n"); - } else { - nsk_printf("# error :: Redefine failed..\n"); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs302t006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs302t006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs302t006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/hs302t006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/hs302t006.cpp new file mode 100644 index 00000000000..e7983158ec0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/hs302t006.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t006r/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t006r/MyClass;" + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber=0; + jvmti_env->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + char fileName[512]; + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { + nsk_printf("Redefine successful ..\n"); + } else { + nsk_printf("# error :: Redefine failed..\n"); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs302t006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs302t006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs302t006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/libhs302t006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/libhs302t006.c deleted file mode 100644 index 6785b90eb50..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/libhs302t006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs302t006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/libhs302t006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/libhs302t006.cpp new file mode 100644 index 00000000000..72399e50242 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t006/libhs302t006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs302t006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/hs302t007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/hs302t007.c deleted file mode 100644 index 1ab1068d6f4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/hs302t007.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" -#ifdef __cplusplus -extern "C" { -#endif -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t007r/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t007r/MyClass;" -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber=0; - (*jvmti_env)->GetClassSignature(jvmti_env, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - char fileName[512]; - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { - nsk_printf("Redefine successful ..\n"); - } else { - nsk_printf("# error :: Redefine failed..\n"); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs302t007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs302t007(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs302t007(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/hs302t007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/hs302t007.cpp new file mode 100644 index 00000000000..a2c66c22ad2 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/hs302t007.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" +#ifdef __cplusplus +extern "C" { +#endif +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t007r/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t007r/MyClass;" +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber=0; + jvmti_env->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + char fileName[512]; + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { + nsk_printf("Redefine successful ..\n"); + } else { + nsk_printf("# error :: Redefine failed..\n"); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs302t007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs302t007(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs302t007(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/libhs302t007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/libhs302t007.c deleted file mode 100644 index 36ca44f66e0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/libhs302t007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs302t007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/libhs302t007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/libhs302t007.cpp new file mode 100644 index 00000000000..41d4bc83204 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t007/libhs302t007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs302t007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/hs302t008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/hs302t008.c deleted file mode 100644 index 0dc9a392a85..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/hs302t008.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t008r/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t008r/MyClass;" - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber=0; - (*jvmti_env)->GetClassSignature(jvmti_env, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - char fileName[512]; - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { - nsk_printf("Redefine successful ..\n"); - } else { - nsk_printf("# error :: Redefine failed..\n"); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs302t008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs302t008(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs302t008(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/hs302t008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/hs302t008.cpp new file mode 100644 index 00000000000..ef61ee35728 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/hs302t008.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t008r/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t008r/MyClass;" + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber=0; + jvmti_env->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + char fileName[512]; + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { + nsk_printf("Redefine successful ..\n"); + } else { + nsk_printf("# error :: Redefine failed..\n"); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs302t008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs302t008(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs302t008(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/libhs302t008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/libhs302t008.c deleted file mode 100644 index 51294353f62..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/libhs302t008.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs302t008.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/libhs302t008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/libhs302t008.cpp new file mode 100644 index 00000000000..652c820c97d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t008/libhs302t008.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs302t008.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/hs302t009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/hs302t009.c deleted file mode 100644 index 57fbd7cc96f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/hs302t009.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t009r/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t009r/MyClass;" - - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber=0; - (*jvmti_env)->GetClassSignature(jvmti_env, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - - char fileName[512]; - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti_env, klass,fileName) == NSK_TRUE ) { - nsk_printf("Redefine successful ..\n"); - } else { - nsk_printf("# error :: Redefine failed..\n"); - } - } -} -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs302t009(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs302t009(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs302t009(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/hs302t009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/hs302t009.cpp new file mode 100644 index 00000000000..1028b5ae352 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/hs302t009.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t009r/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t009r/MyClass;" + + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber=0; + jvmti_env->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + + char fileName[512]; + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti_env, klass,fileName) == NSK_TRUE ) { + nsk_printf("Redefine successful ..\n"); + } else { + nsk_printf("# error :: Redefine failed..\n"); + } + } +} +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs302t009(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs302t009(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs302t009(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/libhs302t009.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/libhs302t009.c deleted file mode 100644 index d11171f0a17..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/libhs302t009.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs302t009.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/libhs302t009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/libhs302t009.cpp new file mode 100644 index 00000000000..de8fda22b4b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t009/libhs302t009.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs302t009.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/hs302t010.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/hs302t010.c deleted file mode 100644 index e81c11ed39d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/hs302t010.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t010r/MyClass" -#define PATH_FORMAT "%s%02d/%s" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t010r/MyClass;" -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber=0; - (*jvmti_env)->GetClassSignature(jvmti_env, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - char fileName[512]; - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { - nsk_printf("Redefine successful ..\n"); - } else { - nsk_printf("# error :: Redefine failed..\n"); - } - } -} -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs302t010(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs302t010(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs302t010(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/hs302t010.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/hs302t010.cpp new file mode 100644 index 00000000000..5c16ca6056e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/hs302t010.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t010r/MyClass" +#define PATH_FORMAT "%s%02d/%s" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t010r/MyClass;" +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber=0; + jvmti_env->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + char fileName[512]; + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { + nsk_printf("Redefine successful ..\n"); + } else { + nsk_printf("# error :: Redefine failed..\n"); + } + } +} +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs302t010(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs302t010(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs302t010(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/libhs302t010.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/libhs302t010.c deleted file mode 100644 index 6e05a68785e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/libhs302t010.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs302t010.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/libhs302t010.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/libhs302t010.cpp new file mode 100644 index 00000000000..2f4f593bea9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t010/libhs302t010.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs302t010.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/hs302t011.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/hs302t011.c deleted file mode 100644 index 4d9fde8befd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/hs302t011.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t011r/MyClass" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t011r/MyClass;" - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber=0; - (*jvmti_env)->GetClassSignature(jvmti_env, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - char fileName[512]; - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { - nsk_printf("Redefine successful ..\n"); - } else { - nsk_printf("# error :: Redefine failed..\n"); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs302t011(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs302t011(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs302t011(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint rc ; - jvmtiEnv * jvmti; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/hs302t011.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/hs302t011.cpp new file mode 100644 index 00000000000..e25ca09ae40 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/hs302t011.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t011r/MyClass" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t011r/MyClass;" + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber=0; + jvmti_env->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + char fileName[512]; + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { + nsk_printf("Redefine successful ..\n"); + } else { + nsk_printf("# error :: Redefine failed..\n"); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs302t011(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs302t011(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs302t011(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint rc ; + jvmtiEnv * jvmti; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/libhs302t011.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/libhs302t011.c deleted file mode 100644 index e0603848058..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/libhs302t011.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs302t011.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/libhs302t011.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/libhs302t011.cpp new file mode 100644 index 00000000000..543ac9fe4e7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t011/libhs302t011.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs302t011.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/hs302t012.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/hs302t012.c deleted file mode 100644 index 512c96a0c1d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/hs302t012.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "agent_common.h" -#include -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t012r/MyClass" -#define DIR_NAME "newclass" -#define PATH_FORMAT "%s%02d/%s" -#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t012r/MyClass;" - -void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jclass klass) { - char * className; - char * generic; - int redefineNumber=0; - (*jvmti_env)->GetClassSignature(jvmti_env, klass, &className, &generic); - if (strcmp(className,CLASS_NAME) == 0) { - char fileName[512]; - nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); - nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, - sizeof(fileName)/sizeof(char)); - if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { - nsk_printf("Redefine successful ..\n"); - } else { - nsk_printf("# error :: Redefine failed..\n"); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_hs302t012(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_hs302t012(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_hs302t012(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jvmtiEnv * jvmti; - jint rc ; - nsk_printf("Agent:: VM.. Started..\n"); - rc=(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if ( rc!= JNI_OK ) { - nsk_printf("Agent:: Could not load JVMTI interface \n"); - return JNI_ERR; - } else { - jvmtiCapabilities caps; - jvmtiEventCallbacks eventCallbacks; - if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { - nsk_printf("# error agent Failed to parse options \n"); - return JNI_ERR; - } - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_all_class_hook_events=1; - (*jvmti)->AddCapabilities(jvmti, &caps); - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ClassPrepare = &callbackClassPrepare; - rc=(*jvmti)->SetEventCallbacks(jvmti,&eventCallbacks, sizeof(eventCallbacks)); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Agent:: Error occured while setting event call back \n"); - return JNI_ERR; - } - if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { - nsk_printf(" Enabled. noftification.."); - } else { - nsk_printf(" Failed to Enable .."); - } - } - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/hs302t012.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/hs302t012.cpp new file mode 100644 index 00000000000..f2eb8de5341 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/hs302t012.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "agent_common.h" +#include +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME "nsk/jvmti/scenarios/hotswap/HS302/hs302t012r/MyClass" +#define DIR_NAME "newclass" +#define PATH_FORMAT "%s%02d/%s" +#define CLASS_NAME "Lnsk/jvmti/scenarios/hotswap/HS302/hs302t012r/MyClass;" + +void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass) { + char * className; + char * generic; + int redefineNumber=0; + jvmti_env->GetClassSignature(klass, &className, &generic); + if (strcmp(className,CLASS_NAME) == 0) { + char fileName[512]; + nsk_jvmti_disableNotification(jvmti_env, JVMTI_EVENT_CLASS_PREPARE, NULL ); + nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, + sizeof(fileName)/sizeof(char)); + if ( nsk_jvmti_redefineClass(jvmti_env, klass, fileName) == NSK_TRUE ) { + nsk_printf("Redefine successful ..\n"); + } else { + nsk_printf("# error :: Redefine failed..\n"); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_hs302t012(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_hs302t012(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_hs302t012(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jvmtiEnv * jvmti; + jint rc ; + nsk_printf("Agent:: VM.. Started..\n"); + rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if ( rc!= JNI_OK ) { + nsk_printf("Agent:: Could not load JVMTI interface \n"); + return JNI_ERR; + } else { + jvmtiCapabilities caps; + jvmtiEventCallbacks eventCallbacks; + if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) { + nsk_printf("# error agent Failed to parse options \n"); + return JNI_ERR; + } + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_all_class_hook_events=1; + jvmti->AddCapabilities(&caps); + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ClassPrepare = &callbackClassPrepare; + rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Agent:: Error occured while setting event call back \n"); + return JNI_ERR; + } + if ( nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) { + nsk_printf(" Enabled. noftification.."); + } else { + nsk_printf(" Failed to Enable .."); + } + } + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/libhs302t012.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/libhs302t012.c deleted file mode 100644 index 1c86c36cee3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/libhs302t012.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "hs302t012.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/libhs302t012.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/libhs302t012.cpp new file mode 100644 index 00000000000..ce06713ff6e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS302/hs302t012/libhs302t012.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "hs302t012.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/ji01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/ji01t001.c deleted file mode 100644 index 57109b84404..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/ji01t001.c +++ /dev/null @@ -1,452 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include - -#include -#include "agent_common.h" - -#include "JVMTITools.h" -#include "jvmti_tools.h" -#include "nsk_tools.h" - -/* ====================================================================== */ - -static const char *classSig = - "Lnsk/jvmti/scenarios/jni_interception/JI01/ji01t001;"; - -static jvmtiEnv *jvmti = NULL; -static jrawMonitorID eventLock; -static jvmtiEventCallbacks callbacks; -static jint result = NSK_STATUS_PASSED; - -/* the original JNI function table */ -static jniNativeInterface *orig_jni_functions = NULL; - -/* the redirected JNI function table */ -static jniNativeInterface *redir_jni_functions = NULL; - -/* number of the redirected JNI function calls */ -static volatile int fnd_calls = 0; - -/* ====================================================================== */ -/** redirected JNI functions **/ -jclass JNICALL MyFindClass(JNIEnv *env, const char *name) { - if (isThreadExpected(jvmti, NULL)) { - fnd_calls++; - - NSK_DISPLAY1("MyFindClass: the function was called successfully: number of calls so far = %d\n", fnd_calls); - } - - return orig_jni_functions->FindClass(env, name); -} - -/* ====================================================================== */ -static int getVMPhase(jvmtiEnv *jvmti) { - jvmtiPhase phase; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - GetPhase - , jvmti - , &phase - ) - ) - ) - exit(NSK_STATUS_FAILED); - - return phase; -} - -/* ====================================================================== */ -static void doRedirect(jvmtiEnv *jvmti, int phase) { - jvmtiError err; - NSK_DISPLAY0("doRedirect: obtaining the JNI function table ...\n"); - - // Store original function table - if (!NSK_VERIFY( - (err = NSK_CPP_STUB2( - GetJNIFunctionTable - , jvmti - , &orig_jni_functions - )) == JVMTI_ERROR_NONE || phase != JVMTI_PHASE_LIVE - ) - ) - { - NSK_COMPLAIN2("TEST FAILED: failed to get original JNI function table during %s: %s\n" - , TranslatePhase(phase) - , TranslateError(err) - ); - - result = NSK_STATUS_FAILED; - exit(NSK_STATUS_FAILED); - } - else { - NSK_DISPLAY3("CHECK PASSED: the original JNI function table %s during %s phase: %s\n" - , (err == JVMTI_ERROR_NONE) ? "has been obtained" : "hasn't been obtained" - , TranslatePhase(phase) - , TranslateError(err) - ); - } - - // Get a duplicate of the function table for future modification - if (!NSK_VERIFY( - (err = NSK_CPP_STUB2( - GetJNIFunctionTable - , jvmti - , &redir_jni_functions - )) == JVMTI_ERROR_NONE || phase != JVMTI_PHASE_LIVE - ) - ) - { - NSK_COMPLAIN2("TEST FAILED: failed to get JNI function table for interception during %s: %s\n" - , TranslatePhase(phase) - , TranslateError(err) - ); - - result = NSK_STATUS_FAILED; - exit(NSK_STATUS_FAILED); - } - else { - NSK_DISPLAY3("CHECK PASSED: the original JNI function table for interception %s during %s phase: %s\n" - , (err == JVMTI_ERROR_NONE) ? "has been obtained" : "hasn't been obtained" - , TranslatePhase(phase) - , TranslateError(err) - ); - } - - // Redefine desired JNI functions - if (phase == JVMTI_PHASE_LIVE) { - NSK_DISPLAY0("doRedirect: overwriting the function FindClass; ...\n"); - redir_jni_functions->FindClass = MyFindClass; - } - - // Set new JNI function table - if (!NSK_VERIFY( - (err = NSK_CPP_STUB2( - SetJNIFunctionTable - , jvmti - , redir_jni_functions - )) == JVMTI_ERROR_NONE || phase != JVMTI_PHASE_LIVE - ) - ) - { - NSK_COMPLAIN2("TEST FAILED: failed to set redirected JNI function table during %s: %s\n" - , TranslatePhase(phase) - , TranslateError(err) - ); - - result = NSK_STATUS_FAILED; - exit(NSK_STATUS_FAILED); - } - else { - NSK_DISPLAY3("CHECK PASSED: the redirected JNI function table %s during %s phase: %s\n" - , (err == JVMTI_ERROR_NONE) ? "has been set" : "hasn't been set" - , TranslatePhase(phase) - , TranslateError(err) - ); - } -} - -/* ====================================================================== */ -static void doRestore(jvmtiEnv *jvmti) { - NSK_DISPLAY0("doRestore: restoring the original JNI function table ...\n"); - - // Set new JNI function table - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - SetJNIFunctionTable - , jvmti - , orig_jni_functions - ) - ) - ) - { - NSK_COMPLAIN0("TEST FAILED: failed to restore original JNI function table\n"); - - result = NSK_STATUS_FAILED; - exit(NSK_STATUS_FAILED); - } - - NSK_DISPLAY0("doRestore: the original JNI function table is restored successfully\n"); -} - -/* ====================================================================== */ -static void lock(jvmtiEnv *jvmti) { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - RawMonitorEnter - , jvmti - , eventLock - ) - ) - ) - { - result = NSK_STATUS_FAILED; - exit(NSK_STATUS_FAILED); - } -} - -/* ====================================================================== */ -static void unlock(jvmtiEnv *jvmti) { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2( - RawMonitorExit - , jvmti - , eventLock - ) - ) - ) - { - result = NSK_STATUS_FAILED; - exit(NSK_STATUS_FAILED); - } -} - -/* ====================================================================== */ -static void checkCall(JNIEnv *env - , int step - , const char *callBackFunc - , const char *msg - , int exFndCalls - ) -{ - jclass cls; - - NSK_TRACE( - (cls = NSK_CPP_STUB2( - FindClass - , env - , classSig - )) - ); - - NSK_TRACE( - NSK_CPP_STUB1(ExceptionClear, env) - ); - - // The check should pass if the actual number of invocations is not less that the expected number (fnd_calls >= exFndCalls). - // If the invocation is not expected (exFndCalls == 0), fnd_calls should be also == 0. - if ((exFndCalls > 0 && fnd_calls >= exFndCalls) || (fnd_calls == exFndCalls)) { - NSK_DISPLAY5("CHECK PASSED: %s: the %s JNI function FindClass() has been %s during %s phase\n\t%d intercepted call(s) as expected\n" - , callBackFunc - , (step==1) ? "tested" : "original" - , (step==1) ? "redirected" : "restored" - , msg - , fnd_calls - ); - - if (fnd_calls != exFndCalls) { - NSK_COMPLAIN2("WARNING: the number of occured calls (%d) exceeds the expected number of calls (%d).\n" - , fnd_calls - , exFndCalls - ); - } - } else { - result = NSK_STATUS_FAILED; - - NSK_COMPLAIN6("TEST FAILED: %s: the %s JNI function FindClass() has not been %s during %s phase\n\t%d intercepted call(s) instead of %d as expected\n" - , callBackFunc - , (step==1) ? "tested" : "original" - , (step==1) ? "redirected" : "restored" - , msg - , fnd_calls - , exFndCalls - ); - } -} - -/* ====================================================================== */ -// callback functions -void JNICALL -VMInit(jvmtiEnv *jvmti, JNIEnv *env, jthread thread) { - jvmtiPhase phase = getVMPhase(jvmti); - - NSK_TRACE(lock(jvmti)); - - NSK_DISPLAY1("b) VMInit: the current phase of VM execution %s\n" - , TranslatePhase(phase) - ); - - // check JNI function table interception - fnd_calls = 0; - NSK_TRACE(doRedirect(jvmti, phase)); - NSK_TRACE(checkCall(env, 1, "VMInit", TranslatePhase(phase), 1)); - - // check restored JNI function table - fnd_calls = 0; - NSK_TRACE(doRestore(jvmti)); - NSK_TRACE(checkCall(env, 2, "VMInit", TranslatePhase(phase), 0)); - - NSK_TRACE(unlock(jvmti)); -} - -/* ====================================================================== */ -void JNICALL -VMDeath(jvmtiEnv *jvmti, JNIEnv *env) { - jvmtiPhase phase = getVMPhase(jvmti); - - NSK_TRACE(lock(jvmti)); - - NSK_DISPLAY1("c) VMDeath: the current phase of VM execution %s\n" - , TranslatePhase(phase) - ); - - // check JNI function table interception - fnd_calls = 0; - NSK_TRACE(doRedirect(jvmti, phase)); - NSK_TRACE(checkCall(env, 1, "VMDeath", TranslatePhase(phase), 1)); - - // check restored JNI function table - fnd_calls = 0; - NSK_TRACE(doRestore(jvmti)); - NSK_TRACE(checkCall(env, 2, "VMDeath", TranslatePhase(phase), 0)); - - (void) memset(&callbacks, 0, sizeof(callbacks)); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - SetEventCallbacks - , jvmti - , &callbacks - , sizeof(callbacks) - ) - ) - ) - result = NSK_STATUS_FAILED; - - NSK_TRACE(unlock(jvmti)); - - if (result == NSK_STATUS_FAILED) { - exit(NSK_STATUS_FAILED); - } -} - -/* ====================================================================== */ -JNIEXPORT jint JNICALL -Java_nsk_jvmti_scenarios_jni_1interception_JI01_ji01t001_check(JNIEnv *env, jobject obj) { - return result; -} - -/* ====================================================================== */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ji01t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ji01t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ji01t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - if (!NSK_VERIFY( - nsk_jvmti_parseOptions(options) - ) - ) - return JNI_ERR; - - - if (!NSK_VERIFY( - NSK_CPP_STUB3( - GetEnv - , jvm - , (void **) &jvmti - , JVMTI_VERSION_1_1 - ) == JNI_OK - && jvmti != NULL - ) - ) - return JNI_ERR; - - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - CreateRawMonitor - , jvmti - , "_event_lock" - , &eventLock - ) - ) - ) - return JNI_ERR; - - NSK_DISPLAY1("a) Trying to intercept JNI functions during %s phase ...\n" - , TranslatePhase(getVMPhase(jvmti)) - ); - - NSK_TRACE(doRedirect(jvmti, getVMPhase(jvmti))); - - NSK_DISPLAY0("Setting event callbacks...\n"); - - (void) memset(&callbacks, 0, sizeof(callbacks)); - callbacks.VMInit = &VMInit; - callbacks.VMDeath = &VMDeath; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3( - SetEventCallbacks - , jvmti - , &callbacks - , sizeof(callbacks) - ) - ) - ) - return JNI_ERR; - - - NSK_DISPLAY0("Event callbacks are set\nEnabling events...\n"); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4( - SetEventNotificationMode - , jvmti - , JVMTI_ENABLE - , JVMTI_EVENT_VM_INIT - , NULL - ) - ) - ) - return JNI_ERR; - - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4( - SetEventNotificationMode - , jvmti - , JVMTI_ENABLE - , JVMTI_EVENT_VM_DEATH - , NULL - ) - ) - ) - return JNI_ERR; - - NSK_DISPLAY0("Events are enabled\n"); - - return JNI_OK; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/ji01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/ji01t001.cpp new file mode 100644 index 00000000000..fdc6118e0dd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/ji01t001.cpp @@ -0,0 +1,460 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include + +#include +#include "agent_common.h" + +#include "JVMTITools.h" +#include "jvmti_tools.h" +#include "nsk_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ====================================================================== */ + +static const char *classSig = + "Lnsk/jvmti/scenarios/jni_interception/JI01/ji01t001;"; + +static jvmtiEnv *jvmti = NULL; +static jrawMonitorID eventLock; +static jvmtiEventCallbacks callbacks; +static jint result = NSK_STATUS_PASSED; + +/* the original JNI function table */ +static jniNativeInterface *orig_jni_functions = NULL; + +/* the redirected JNI function table */ +static jniNativeInterface *redir_jni_functions = NULL; + +/* number of the redirected JNI function calls */ +static volatile int fnd_calls = 0; + +/* ====================================================================== */ +/** redirected JNI functions **/ +jclass JNICALL MyFindClass(JNIEnv *env, const char *name) { + if (isThreadExpected(jvmti, NULL)) { + fnd_calls++; + + NSK_DISPLAY1("MyFindClass: the function was called successfully: number of calls so far = %d\n", fnd_calls); + } + + return orig_jni_functions->FindClass(env, name); +} + +/* ====================================================================== */ +static jvmtiPhase getVMPhase(jvmtiEnv *jvmti) { + jvmtiPhase phase; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + GetPhase + , jvmti + , &phase + ) + ) + ) + exit(NSK_STATUS_FAILED); + + return phase; +} + +/* ====================================================================== */ +static void doRedirect(jvmtiEnv *jvmti, jvmtiPhase phase) { + jvmtiError err; + NSK_DISPLAY0("doRedirect: obtaining the JNI function table ...\n"); + + // Store original function table + if (!NSK_VERIFY( + (err = NSK_CPP_STUB2( + GetJNIFunctionTable + , jvmti + , &orig_jni_functions + )) == JVMTI_ERROR_NONE || phase != JVMTI_PHASE_LIVE + ) + ) + { + NSK_COMPLAIN2("TEST FAILED: failed to get original JNI function table during %s: %s\n" + , TranslatePhase(phase) + , TranslateError(err) + ); + + result = NSK_STATUS_FAILED; + exit(NSK_STATUS_FAILED); + } + else { + NSK_DISPLAY3("CHECK PASSED: the original JNI function table %s during %s phase: %s\n" + , (err == JVMTI_ERROR_NONE) ? "has been obtained" : "hasn't been obtained" + , TranslatePhase(phase) + , TranslateError(err) + ); + } + + // Get a duplicate of the function table for future modification + if (!NSK_VERIFY( + (err = NSK_CPP_STUB2( + GetJNIFunctionTable + , jvmti + , &redir_jni_functions + )) == JVMTI_ERROR_NONE || phase != JVMTI_PHASE_LIVE + ) + ) + { + NSK_COMPLAIN2("TEST FAILED: failed to get JNI function table for interception during %s: %s\n" + , TranslatePhase(phase) + , TranslateError(err) + ); + + result = NSK_STATUS_FAILED; + exit(NSK_STATUS_FAILED); + } + else { + NSK_DISPLAY3("CHECK PASSED: the original JNI function table for interception %s during %s phase: %s\n" + , (err == JVMTI_ERROR_NONE) ? "has been obtained" : "hasn't been obtained" + , TranslatePhase(phase) + , TranslateError(err) + ); + } + + // Redefine desired JNI functions + if (phase == JVMTI_PHASE_LIVE) { + NSK_DISPLAY0("doRedirect: overwriting the function FindClass; ...\n"); + redir_jni_functions->FindClass = MyFindClass; + } + + // Set new JNI function table + if (!NSK_VERIFY( + (err = NSK_CPP_STUB2( + SetJNIFunctionTable + , jvmti + , redir_jni_functions + )) == JVMTI_ERROR_NONE || phase != JVMTI_PHASE_LIVE + ) + ) + { + NSK_COMPLAIN2("TEST FAILED: failed to set redirected JNI function table during %s: %s\n" + , TranslatePhase(phase) + , TranslateError(err) + ); + + result = NSK_STATUS_FAILED; + exit(NSK_STATUS_FAILED); + } + else { + NSK_DISPLAY3("CHECK PASSED: the redirected JNI function table %s during %s phase: %s\n" + , (err == JVMTI_ERROR_NONE) ? "has been set" : "hasn't been set" + , TranslatePhase(phase) + , TranslateError(err) + ); + } +} + +/* ====================================================================== */ +static void doRestore(jvmtiEnv *jvmti) { + NSK_DISPLAY0("doRestore: restoring the original JNI function table ...\n"); + + // Set new JNI function table + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + SetJNIFunctionTable + , jvmti + , orig_jni_functions + ) + ) + ) + { + NSK_COMPLAIN0("TEST FAILED: failed to restore original JNI function table\n"); + + result = NSK_STATUS_FAILED; + exit(NSK_STATUS_FAILED); + } + + NSK_DISPLAY0("doRestore: the original JNI function table is restored successfully\n"); +} + +/* ====================================================================== */ +static void lock(jvmtiEnv *jvmti) { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + RawMonitorEnter + , jvmti + , eventLock + ) + ) + ) + { + result = NSK_STATUS_FAILED; + exit(NSK_STATUS_FAILED); + } +} + +/* ====================================================================== */ +static void unlock(jvmtiEnv *jvmti) { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2( + RawMonitorExit + , jvmti + , eventLock + ) + ) + ) + { + result = NSK_STATUS_FAILED; + exit(NSK_STATUS_FAILED); + } +} + +/* ====================================================================== */ +static void checkCall(JNIEnv *env + , int step + , const char *callBackFunc + , const char *msg + , int exFndCalls + ) +{ + jclass cls; + + NSK_TRACE( + (cls = NSK_CPP_STUB2( + FindClass + , env + , classSig + )) + ); + + NSK_TRACE( + NSK_CPP_STUB1(ExceptionClear, env) + ); + + // The check should pass if the actual number of invocations is not less that the expected number (fnd_calls >= exFndCalls). + // If the invocation is not expected (exFndCalls == 0), fnd_calls should be also == 0. + if ((exFndCalls > 0 && fnd_calls >= exFndCalls) || (fnd_calls == exFndCalls)) { + NSK_DISPLAY5("CHECK PASSED: %s: the %s JNI function FindClass() has been %s during %s phase\n\t%d intercepted call(s) as expected\n" + , callBackFunc + , (step==1) ? "tested" : "original" + , (step==1) ? "redirected" : "restored" + , msg + , fnd_calls + ); + + if (fnd_calls != exFndCalls) { + NSK_COMPLAIN2("WARNING: the number of occured calls (%d) exceeds the expected number of calls (%d).\n" + , fnd_calls + , exFndCalls + ); + } + } else { + result = NSK_STATUS_FAILED; + + NSK_COMPLAIN6("TEST FAILED: %s: the %s JNI function FindClass() has not been %s during %s phase\n\t%d intercepted call(s) instead of %d as expected\n" + , callBackFunc + , (step==1) ? "tested" : "original" + , (step==1) ? "redirected" : "restored" + , msg + , fnd_calls + , exFndCalls + ); + } +} + +/* ====================================================================== */ +// callback functions +void JNICALL +VMInit(jvmtiEnv *jvmti, JNIEnv *env, jthread thread) { + jvmtiPhase phase = getVMPhase(jvmti); + + NSK_TRACE(lock(jvmti)); + + NSK_DISPLAY1("b) VMInit: the current phase of VM execution %s\n" + , TranslatePhase(phase) + ); + + // check JNI function table interception + fnd_calls = 0; + NSK_TRACE(doRedirect(jvmti, phase)); + NSK_TRACE(checkCall(env, 1, "VMInit", TranslatePhase(phase), 1)); + + // check restored JNI function table + fnd_calls = 0; + NSK_TRACE(doRestore(jvmti)); + NSK_TRACE(checkCall(env, 2, "VMInit", TranslatePhase(phase), 0)); + + NSK_TRACE(unlock(jvmti)); +} + +/* ====================================================================== */ +void JNICALL +VMDeath(jvmtiEnv *jvmti, JNIEnv *env) { + jvmtiPhase phase = getVMPhase(jvmti); + + NSK_TRACE(lock(jvmti)); + + NSK_DISPLAY1("c) VMDeath: the current phase of VM execution %s\n" + , TranslatePhase(phase) + ); + + // check JNI function table interception + fnd_calls = 0; + NSK_TRACE(doRedirect(jvmti, phase)); + NSK_TRACE(checkCall(env, 1, "VMDeath", TranslatePhase(phase), 1)); + + // check restored JNI function table + fnd_calls = 0; + NSK_TRACE(doRestore(jvmti)); + NSK_TRACE(checkCall(env, 2, "VMDeath", TranslatePhase(phase), 0)); + + (void) memset(&callbacks, 0, sizeof(callbacks)); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + SetEventCallbacks + , jvmti + , &callbacks + , sizeof(callbacks) + ) + ) + ) + result = NSK_STATUS_FAILED; + + NSK_TRACE(unlock(jvmti)); + + if (result == NSK_STATUS_FAILED) { + exit(NSK_STATUS_FAILED); + } +} + +/* ====================================================================== */ +JNIEXPORT jint JNICALL +Java_nsk_jvmti_scenarios_jni_1interception_JI01_ji01t001_check(JNIEnv *env, jobject obj) { + return result; +} + +/* ====================================================================== */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ji01t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ji01t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ji01t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + if (!NSK_VERIFY( + nsk_jvmti_parseOptions(options) + ) + ) + return JNI_ERR; + + + if (!NSK_VERIFY( + NSK_CPP_STUB3( + GetEnv + , jvm + , (void **) &jvmti + , JVMTI_VERSION_1_1 + ) == JNI_OK + && jvmti != NULL + ) + ) + return JNI_ERR; + + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + CreateRawMonitor + , jvmti + , "_event_lock" + , &eventLock + ) + ) + ) + return JNI_ERR; + + NSK_DISPLAY1("a) Trying to intercept JNI functions during %s phase ...\n" + , TranslatePhase(getVMPhase(jvmti)) + ); + + NSK_TRACE(doRedirect(jvmti, getVMPhase(jvmti))); + + NSK_DISPLAY0("Setting event callbacks...\n"); + + (void) memset(&callbacks, 0, sizeof(callbacks)); + callbacks.VMInit = &VMInit; + callbacks.VMDeath = &VMDeath; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3( + SetEventCallbacks + , jvmti + , &callbacks + , sizeof(callbacks) + ) + ) + ) + return JNI_ERR; + + + NSK_DISPLAY0("Event callbacks are set\nEnabling events...\n"); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4( + SetEventNotificationMode + , jvmti + , JVMTI_ENABLE + , JVMTI_EVENT_VM_INIT + , NULL + ) + ) + ) + return JNI_ERR; + + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4( + SetEventNotificationMode + , jvmti + , JVMTI_ENABLE + , JVMTI_EVENT_VM_DEATH + , NULL + ) + ) + ) + return JNI_ERR; + + NSK_DISPLAY0("Events are enabled\n"); + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/libji01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/libji01t001.c deleted file mode 100644 index 326007c173a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/libji01t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ji01t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/libji01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/libji01t001.cpp new file mode 100644 index 00000000000..60e9affdf82 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI01/ji01t001/libji01t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ji01t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/ji03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/ji03t001.c deleted file mode 100644 index e4b95a8a6c3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/ji03t001.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include - -#include -#include "agent_common.h" - -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - #ifdef __cplusplus - #define JNI_ENV_ARG(x, y) y - #define JNI_ENV_PTR(x) x - #else - #define JNI_ENV_ARG(x, y) x, y - #define JNI_ENV_PTR(x) (*x) - #endif -#endif - -#ifndef JNI_ENV_ARG1 - #ifdef __cplusplus - #define JNI_ENV_ARG1(x) - #else - #define JNI_ENV_ARG1(x) x - #endif -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static int verbose = 0; - -/* the original JNI function table */ -static jniNativeInterface *orig_jni_functions = NULL; - -/* the redirected JNI function table */ -static jniNativeInterface *redir_jni_functions = NULL; - -/* number of the redirected JNI function calls */ -int call_count = 0; - -jint JNICALL MyGetVersion(JNIEnv *env) { - call_count++; - if (verbose) - printf("\nMyGetVersion: the function called successfully: getVer_count=%d\n", - call_count); - return - orig_jni_functions->GetVersion(JNI_ENV_ARG1(env)); -} - -void doRedirect(JNIEnv *env) { - jvmtiError err; - - if (verbose) - printf("\ndoRedirect: obtaining the JNI function ...\n"); - - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &orig_jni_functions)) != - JVMTI_ERROR_NONE) { - printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get original JNI function table")); - result = STATUS_FAILED; - } - - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &redir_jni_functions)) != - JVMTI_ERROR_NONE) { - printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get redirected JNI function table")); - result = STATUS_FAILED; - } - if (verbose) - printf("doRedirect: the JNI function table obtained successfully\n\toverwriting the function GetVersion ...\n"); - - redir_jni_functions->GetVersion = MyGetVersion; - - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, redir_jni_functions)) != - JVMTI_ERROR_NONE) { - printf("(%s,%d): TEST FAILED: failed to set new JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to set new JNI function table")); - result = STATUS_FAILED; - } - - if (verbose) - printf("doRedirect: the function GetVersion is overwritten successfully\n"); -} - -void doRestore(JNIEnv *env) { - jvmtiError err; - - if (verbose) - printf("\ndoRestore: restoring the original JNI function ...\n"); - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, orig_jni_functions)) != - JVMTI_ERROR_NONE) { - printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to restore original JNI function table")); - result = STATUS_FAILED; - } - if (verbose) - printf("doRestore: the original function GetVersion is restored successfully\n"); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_scenarios_jni_1interception_JI03_ji03t001_check(JNIEnv *env, jclass cls) { - jint ver; - - if (jvmti == NULL) { - printf("(%s,%d): TEST FAILURE: JVMTI client was not properly loaded\n", - __FILE__, __LINE__); - return STATUS_FAILED; - } - - if (verbose) - printf("\na) invoking the original function GetVersion() ...\n"); - - ver = JNI_ENV_PTR(env)->GetVersion(JNI_ENV_ARG1(env)); - - if (verbose) - printf("JNIenv version=%d\n", ver); - - /* check JNI function table interception */ - doRedirect(env); - - if (verbose) - printf("\nb) invoking the redirected function GetVersion() ...\n"); - ver = JNI_ENV_PTR(env)->GetVersion(JNI_ENV_ARG1(env)); - - if (call_count == 1) { - if (verbose) - printf("JNIenv version=%d\nCHECK PASSED: the redirected JNI function has been invoked:\n\t1 intercepted call as expected\n", - ver); - } - else { - printf("(%s,%d): TEST FAILED: the tested JNI function has not been redirected:\n\t%d intercepted call(s) instead of 1 as expected\n", - __FILE__, __LINE__, call_count); - result = STATUS_FAILED; - } - - /* check restored JNI function table */ - call_count = 0; - doRestore(env); - - if (verbose) - printf("\nc) invoking the restored function GetVersion ...\n"); - ver = JNI_ENV_PTR(env)->GetVersion(JNI_ENV_ARG1(env)); - - if (call_count == 0) { - if (verbose) - printf("JNIenv version=%d\nCHECK PASSED: the original JNI function has been restored:\n\t0 intercepted call(s) as expected\n", - ver); - } - else { - printf("(%s,%d): TEST FAILED: the tested JNI function has not been restored:\n\t%d intercepted call(s) instead of 0 as expected\n", - __FILE__, __LINE__, call_count); - result = STATUS_FAILED; - } - - return result; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ji03t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ji03t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ji03t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "-verbose") == 0) - verbose = 1; - - if (verbose) - printf("verbose mode on\n"); - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); - return JNI_ERR; - } - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/ji03t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/ji03t001.cpp new file mode 100644 index 00000000000..83342aad368 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/ji03t001.cpp @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include + +#include +#include "agent_common.h" + +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + #ifdef __cplusplus + #define JNI_ENV_ARG(x, y) y + #define JNI_ENV_PTR(x) x + #else + #define JNI_ENV_ARG(x, y) x, y + #define JNI_ENV_PTR(x) (*x) + #endif +#endif + +#ifndef JNI_ENV_ARG1 + #ifdef __cplusplus + #define JNI_ENV_ARG1(x) + #else + #define JNI_ENV_ARG1(x) x + #endif +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static int verbose = 0; + +/* the original JNI function table */ +static jniNativeInterface *orig_jni_functions = NULL; + +/* the redirected JNI function table */ +static jniNativeInterface *redir_jni_functions = NULL; + +/* number of the redirected JNI function calls */ +int call_count = 0; + +jint JNICALL MyGetVersion(JNIEnv *env) { + call_count++; + if (verbose) + printf("\nMyGetVersion: the function called successfully: getVer_count=%d\n", + call_count); + return + orig_jni_functions->GetVersion(env); +} + +void doRedirect(JNIEnv *env) { + jvmtiError err; + + if (verbose) + printf("\ndoRedirect: obtaining the JNI function ...\n"); + + if ((err = jvmti->GetJNIFunctionTable(&orig_jni_functions)) != + JVMTI_ERROR_NONE) { + printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get original JNI function table")); + result = STATUS_FAILED; + } + + if ((err = jvmti->GetJNIFunctionTable(&redir_jni_functions)) != + JVMTI_ERROR_NONE) { + printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get redirected JNI function table")); + result = STATUS_FAILED; + } + if (verbose) + printf("doRedirect: the JNI function table obtained successfully\n\toverwriting the function GetVersion ...\n"); + + redir_jni_functions->GetVersion = MyGetVersion; + + if ((err = jvmti->SetJNIFunctionTable(redir_jni_functions)) != + JVMTI_ERROR_NONE) { + printf("(%s,%d): TEST FAILED: failed to set new JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to set new JNI function table")); + result = STATUS_FAILED; + } + + if (verbose) + printf("doRedirect: the function GetVersion is overwritten successfully\n"); +} + +void doRestore(JNIEnv *env) { + jvmtiError err; + + if (verbose) + printf("\ndoRestore: restoring the original JNI function ...\n"); + if ((err = jvmti->SetJNIFunctionTable(orig_jni_functions)) != + JVMTI_ERROR_NONE) { + printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to restore original JNI function table")); + result = STATUS_FAILED; + } + if (verbose) + printf("doRestore: the original function GetVersion is restored successfully\n"); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_scenarios_jni_1interception_JI03_ji03t001_check(JNIEnv *env, jclass cls) { + jint ver; + + if (jvmti == NULL) { + printf("(%s,%d): TEST FAILURE: JVMTI client was not properly loaded\n", + __FILE__, __LINE__); + return STATUS_FAILED; + } + + if (verbose) + printf("\na) invoking the original function GetVersion() ...\n"); + + ver = JNI_ENV_PTR(env)->GetVersion(JNI_ENV_ARG1(env)); + + if (verbose) + printf("JNIenv version=%d\n", ver); + + /* check JNI function table interception */ + doRedirect(env); + + if (verbose) + printf("\nb) invoking the redirected function GetVersion() ...\n"); + ver = JNI_ENV_PTR(env)->GetVersion(JNI_ENV_ARG1(env)); + + if (call_count == 1) { + if (verbose) + printf("JNIenv version=%d\nCHECK PASSED: the redirected JNI function has been invoked:\n\t1 intercepted call as expected\n", + ver); + } + else { + printf("(%s,%d): TEST FAILED: the tested JNI function has not been redirected:\n\t%d intercepted call(s) instead of 1 as expected\n", + __FILE__, __LINE__, call_count); + result = STATUS_FAILED; + } + + /* check restored JNI function table */ + call_count = 0; + doRestore(env); + + if (verbose) + printf("\nc) invoking the restored function GetVersion ...\n"); + ver = JNI_ENV_PTR(env)->GetVersion(JNI_ENV_ARG1(env)); + + if (call_count == 0) { + if (verbose) + printf("JNIenv version=%d\nCHECK PASSED: the original JNI function has been restored:\n\t0 intercepted call(s) as expected\n", + ver); + } + else { + printf("(%s,%d): TEST FAILED: the tested JNI function has not been restored:\n\t%d intercepted call(s) instead of 0 as expected\n", + __FILE__, __LINE__, call_count); + result = STATUS_FAILED; + } + + return result; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ji03t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ji03t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ji03t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "-verbose") == 0) + verbose = 1; + + if (verbose) + printf("verbose mode on\n"); + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/libji03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/libji03t001.c deleted file mode 100644 index e492511d2a3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/libji03t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ji03t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/libji03t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/libji03t001.cpp new file mode 100644 index 00000000000..36800955f4d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t001/libji03t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ji03t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/ji03t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/ji03t002.c deleted file mode 100644 index 8acaa6ee159..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/ji03t002.c +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include - -#include -#include "agent_common.h" - -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - #ifdef __cplusplus - #define JNI_ENV_ARG(x, y) y - #define JNI_ENV_PTR(x) x - #else - #define JNI_ENV_ARG(x, y) x, y - #define JNI_ENV_PTR(x) (*x) - #endif -#endif - -#ifndef JNI_ENV_ARG1 - #ifdef __cplusplus - #define JNI_ENV_ARG1(x) - #else - #define JNI_ENV_ARG1(x) x - #endif -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static int verbose = 0; - -#define METH_NUM 2 /* overall number of methods */ -typedef struct { /* line numbers of a method */ - int inst; /* type of a method: 0- static; 1- instance */ - char *m_name; /* a method name */ - char *m_sign; /* JVM signature of a method */ - jmethodID mid; /* method ID */ - char *f_name; /* field name for checking the method calls */ - jfieldID fid; /* field ID for checking the method calls */ - int jni_calls; /* number of the redirected JNI function calls */ - int java_calls; /* number of java method calls */ -} methInfo; - -static methInfo meth_info[] = { - {0, "statMeth", "(I)D", NULL, "statMeth_calls", NULL, 0, 0}, - {1, "voidMeth", "()V", NULL, "voidMeth_calls", NULL, 0, 0} -}; - -/* the original JNI function table */ -static jniNativeInterface *orig_jni_functions = NULL; - -/* the redirected JNI function table */ -static jniNativeInterface *redir_jni_functions = NULL; - -/** redirected JNI functions **/ -jdouble JNICALL MyCallStaticDoubleMethod(JNIEnv *env, jclass cls, jmethodID mid, ...) { - va_list args; - jdouble res; - - meth_info[0].jni_calls++; - if (verbose) - printf("\nMyCallStaticDoubleMethod: the function called successfully: number of calls=%d\n", - meth_info[0].jni_calls); - - va_start(args, mid); - res = orig_jni_functions->CallStaticDoubleMethodV( - JNI_ENV_ARG(env, cls), mid, args); - va_end(args); - - if (verbose) - printf("MyCallStaticDoubleMethod: returning\n"); - return res; -} - -void JNICALL MyCallVoidMethod(JNIEnv *env, jobject obj, jmethodID mid, ...) { - va_list args; - - meth_info[1].jni_calls++; - if (verbose) - printf("\nMyCallVoidMethod: the function called successfully: number of calls=%d\n", - meth_info[1].jni_calls); - - va_start(args, mid); - orig_jni_functions->CallVoidMethodV( - JNI_ENV_ARG(env, obj), mid, args); - va_end(args); - - if (verbose) - printf("MyCallVoidMethod: returning\n"); -} -/*****************************/ - -void doRedirect(JNIEnv *env, jclass cls) { - int i; - jvmtiError err; - - if (verbose) - printf("\ndoRedirect: obtaining the JNI function table ...\n"); - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &orig_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get original JNI function table")); - } - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &redir_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get redirected JNI function table")); - } - if (verbose) - printf("doRedirect: the JNI function table obtained successfully\n"); - - for (i=0; iGetMethodID( - JNI_ENV_ARG(env, cls), - meth_info[i].m_name, meth_info[i].m_sign); - } - else { /* a static method */ - meth_info[i].mid = JNI_ENV_PTR(env)->GetStaticMethodID( - JNI_ENV_ARG(env, cls), - meth_info[i].m_name, meth_info[i].m_sign); - } - if (meth_info[i].mid == NULL) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILURE: failed to get the ID for the method \"%s %s\"\n", - __FILE__, __LINE__, meth_info[i].m_name, meth_info[i].m_sign); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get the ID for a method")); - } - - if (verbose) - printf("\ndoRedirect: obtaining field ID for \"%s\"...\n", - meth_info[i].f_name); - if ((meth_info[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( - JNI_ENV_ARG(env, cls), meth_info[i].f_name, "I")) == 0) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get ID for the field %s\n", - __FILE__, __LINE__, meth_info[i].f_name); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "cannot get field ID")); - } - - switch(i) { - case 0: - if (verbose) - printf("\ndoRedirect: overwriting the function CallStaticDoubleMethod ...\n"); - redir_jni_functions->CallStaticDoubleMethod = MyCallStaticDoubleMethod; - break; - case 1: - if (verbose) - printf("\ndoRedirect: overwriting the function CallVoidMethod ...\n"); - redir_jni_functions->CallVoidMethod = MyCallVoidMethod; - break; - } - } - - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, redir_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to set new JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to set new JNI function table")); - } - - if (verbose) - printf("\ndoRedirect: the functions are overwritten successfully\n"); -} - -void doRestore(JNIEnv *env) { - jvmtiError err; - - if (verbose) - printf("\ndoRestore: restoring the original JNI function table ...\n"); - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, orig_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to restore original JNI function table")); - } - if (verbose) - printf("doRestore: the original JNI function table is restored successfully\n"); -} - -int getFieldVal(JNIEnv *env, jobject obj, jfieldID fid) { - return JNI_ENV_PTR(env)->GetStaticIntField( - JNI_ENV_ARG(env, obj), fid); -} - -void doCall(JNIEnv *env, jobject obj, jclass objCls, const char *msg) { - int i; - jdouble dVal; - - for (i=0; iCallStaticDoubleMethod( - JNI_ENV_ARG(env, objCls), meth_info[i].mid, 73); - break; - case 1: - JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG(env, obj), - meth_info[i].mid); - break; - } - - if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: exception occured during the execution of the %s method\n", - __FILE__, __LINE__, msg); - JNI_ENV_PTR(env)->ExceptionDescribe(JNI_ENV_ARG1(env)); - JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); - } - - meth_info[i].java_calls = getFieldVal(env, objCls, meth_info[i].fid); - - if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: exception occured during getting value of the %s fieldn", - __FILE__, __LINE__, meth_info[i].f_name); - JNI_ENV_PTR(env)->ExceptionDescribe(JNI_ENV_ARG1(env)); - JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); - } - - } -} - -void checkCall(int step, int exJniCalls, int exJavaCalls) { - int i; - - for (i=0; iGetObjectClass(JNI_ENV_ARG(env, obj)); - - /* 1: check the JNI function table interception */ - if (verbose) - printf("\na) Checking the JNI function table interception ...\n"); - doRedirect(env, objCls); - doCall(env, obj, objCls, "redirected"); - checkCall(1, 1, 1); - - /* 2: check the restored JNI function table */ - if (verbose) - printf("\nb) Checking the restored JNI function table ...\n"); - doRestore(env); - doCall(env, obj, objCls, "restored"); - checkCall(2, 0, 2); - - return result; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ji03t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ji03t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ji03t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "-verbose") == 0) - verbose = 1; - - if (verbose) - printf("verbose mode on\n"); - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); - return JNI_ERR; - } - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/ji03t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/ji03t002.cpp new file mode 100644 index 00000000000..e512ac68494 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/ji03t002.cpp @@ -0,0 +1,360 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include + +#include +#include "agent_common.h" + +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + #ifdef __cplusplus + #define JNI_ENV_ARG(x, y) y + #define JNI_ENV_PTR(x) x + #else + #define JNI_ENV_ARG(x, y) x, y + #define JNI_ENV_PTR(x) (*x) + #endif +#endif + +#ifndef JNI_ENV_ARG1 + #ifdef __cplusplus + #define JNI_ENV_ARG1(x) + #else + #define JNI_ENV_ARG1(x) x + #endif +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static int verbose = 0; + +#define METH_NUM 2 /* overall number of methods */ +typedef struct { /* line numbers of a method */ + int inst; /* type of a method: 0- static; 1- instance */ + const char *m_name; /* a method name */ + const char *m_sign; /* JVM signature of a method */ + jmethodID mid; /* method ID */ + const char *f_name; /* field name for checking the method calls */ + jfieldID fid; /* field ID for checking the method calls */ + int jni_calls; /* number of the redirected JNI function calls */ + int java_calls; /* number of java method calls */ +} methInfo; + +static methInfo meth_info[] = { + {0, "statMeth", "(I)D", NULL, "statMeth_calls", NULL, 0, 0}, + {1, "voidMeth", "()V", NULL, "voidMeth_calls", NULL, 0, 0} +}; + +/* the original JNI function table */ +static jniNativeInterface *orig_jni_functions = NULL; + +/* the redirected JNI function table */ +static jniNativeInterface *redir_jni_functions = NULL; + +/** redirected JNI functions **/ +jdouble JNICALL MyCallStaticDoubleMethodV(JNIEnv *env, jclass cls, jmethodID mid, va_list args) { + jdouble res; + + meth_info[0].jni_calls++; + if (verbose) + printf("\nMyCallStaticDoubleMethodV: the function called successfully: number of calls=%d\n", + meth_info[0].jni_calls); + + res = orig_jni_functions->CallStaticDoubleMethodV(env, cls, mid, args); + + if (verbose) + printf("MyCallStaticDoubleMethodV: returning\n"); + return res; +} + +void JNICALL MyCallVoidMethodV(JNIEnv *env, jobject obj, jmethodID mid, va_list args) { + meth_info[1].jni_calls++; + if (verbose) + printf("\nMyCallVoidMethodV: the function called successfully: number of calls=%d\n", + meth_info[1].jni_calls); + + orig_jni_functions->CallVoidMethodV(env, obj, mid, args); + + if (verbose) + printf("MyCallVoidMethod: returning\n"); +} +/*****************************/ + +void doRedirect(JNIEnv *env, jclass cls) { + int i; + jvmtiError err; + + if (verbose) + printf("\ndoRedirect: obtaining the JNI function table ...\n"); + if ((err = jvmti->GetJNIFunctionTable(&orig_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get original JNI function table")); + } + if ((err = jvmti->GetJNIFunctionTable(&redir_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get redirected JNI function table")); + } + if (verbose) + printf("doRedirect: the JNI function table obtained successfully\n"); + + for (i=0; iGetMethodID( + JNI_ENV_ARG(env, cls), + meth_info[i].m_name, meth_info[i].m_sign); + } + else { /* a static method */ + meth_info[i].mid = JNI_ENV_PTR(env)->GetStaticMethodID( + JNI_ENV_ARG(env, cls), + meth_info[i].m_name, meth_info[i].m_sign); + } + if (meth_info[i].mid == NULL) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILURE: failed to get the ID for the method \"%s %s\"\n", + __FILE__, __LINE__, meth_info[i].m_name, meth_info[i].m_sign); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get the ID for a method")); + } + + if (verbose) + printf("\ndoRedirect: obtaining field ID for \"%s\"...\n", + meth_info[i].f_name); + if ((meth_info[i].fid = JNI_ENV_PTR(env)->GetStaticFieldID( + JNI_ENV_ARG(env, cls), meth_info[i].f_name, "I")) == 0) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get ID for the field %s\n", + __FILE__, __LINE__, meth_info[i].f_name); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "cannot get field ID")); + } + + switch(i) { + case 0: + if (verbose) + printf("\ndoRedirect: overwriting the function CallStaticDoubleMethodV ...\n"); + redir_jni_functions->CallStaticDoubleMethodV = MyCallStaticDoubleMethodV; + break; + case 1: + if (verbose) + printf("\ndoRedirect: overwriting the function CallVoidMethodV ...\n"); + redir_jni_functions->CallVoidMethodV = MyCallVoidMethodV; + break; + } + } + + if ((err = jvmti->SetJNIFunctionTable(redir_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to set new JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to set new JNI function table")); + } + + if (verbose) + printf("\ndoRedirect: the functions are overwritten successfully\n"); +} + +void doRestore(JNIEnv *env) { + jvmtiError err; + + if (verbose) + printf("\ndoRestore: restoring the original JNI function table ...\n"); + if ((err = jvmti->SetJNIFunctionTable(orig_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to restore original JNI function table")); + } + if (verbose) + printf("doRestore: the original JNI function table is restored successfully\n"); +} + +int getFieldVal(JNIEnv *env, jclass cls, jfieldID fid) { + return JNI_ENV_PTR(env)->GetStaticIntField( + JNI_ENV_ARG(env, cls), fid); +} + +void doCall(JNIEnv *env, jobject obj, jclass objCls, const char *msg) { + int i; + jdouble dVal; + + for (i=0; iCallStaticDoubleMethod(objCls, meth_info[i].mid, 73); + break; + case 1: + JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG(env, obj), + meth_info[i].mid); + break; + } + + if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: exception occured during the execution of the %s method\n", + __FILE__, __LINE__, msg); + JNI_ENV_PTR(env)->ExceptionDescribe(JNI_ENV_ARG1(env)); + JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); + } + + meth_info[i].java_calls = getFieldVal(env, objCls, meth_info[i].fid); + + if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: exception occured during getting value of the %s fieldn", + __FILE__, __LINE__, meth_info[i].f_name); + JNI_ENV_PTR(env)->ExceptionDescribe(JNI_ENV_ARG1(env)); + JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); + } + + } +} + +void checkCall(int step, int exJniCalls, int exJavaCalls) { + int i; + + for (i=0; iGetObjectClass(JNI_ENV_ARG(env, obj)); + + /* 1: check the JNI function table interception */ + if (verbose) + printf("\na) Checking the JNI function table interception ...\n"); + doRedirect(env, objCls); + doCall(env, obj, objCls, "redirected"); + checkCall(1, 1, 1); + + /* 2: check the restored JNI function table */ + if (verbose) + printf("\nb) Checking the restored JNI function table ...\n"); + doRestore(env); + doCall(env, obj, objCls, "restored"); + checkCall(2, 0, 2); + + return result; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ji03t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ji03t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ji03t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "-verbose") == 0) + verbose = 1; + + if (verbose) + printf("verbose mode on\n"); + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/libji03t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/libji03t002.c deleted file mode 100644 index 59734739229..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/libji03t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ji03t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/libji03t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/libji03t002.cpp new file mode 100644 index 00000000000..d2c546a38ec --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t002/libji03t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ji03t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/ji03t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/ji03t003.c deleted file mode 100644 index 236a9d6dcdd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/ji03t003.c +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include - -#include -#include "agent_common.h" - -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - #ifdef __cplusplus - #define JNI_ENV_ARG(x, y) y - #define JNI_ENV_PTR(x) x - #else - #define JNI_ENV_ARG(x, y) x, y - #define JNI_ENV_PTR(x) (*x) - #endif -#endif - -#ifndef JNI_ENV_ARG1 - #ifdef __cplusplus - #define JNI_ENV_ARG1(x) - #else - #define JNI_ENV_ARG1(x) x - #endif -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static int verbose = 0; - -static const char *javaField = "exc"; -static const char *excClassSig = - "Lnsk/jvmti/scenarios/jni_interception/JI03/ji03t003Exc;"; - -/* the original JNI function table */ -static jniNativeInterface *orig_jni_functions = NULL; - -/* the redirected JNI function table */ -static jniNativeInterface *redir_jni_functions = NULL; - -/* number of the redirected JNI function calls */ -int throw_calls = 0; -int thrownew_calls = 0; -int excoccur_calls = 0; - -/** redirected JNI functions **/ -jint JNICALL MyThrow(JNIEnv *env, jthrowable thrw) { - jint res; - - throw_calls++; - if (verbose) - printf("\nMyThrow: the function called successfully: number of calls=%d\n", - throw_calls); - - res = orig_jni_functions->Throw( - JNI_ENV_ARG(env, thrw)); - - if (verbose) - printf("MyThrow: returning res=%d\n",res); - return res; -} - -jint JNICALL MyThrowNew(JNIEnv *env, jclass cls, const char *msg) { - jint res; - - thrownew_calls++; - if (verbose) - printf("\nMyThrowNew: the function called successfully: number of calls=%d\n", - thrownew_calls); - - res = orig_jni_functions->ThrowNew( - JNI_ENV_ARG(env, cls), msg); - - if (verbose) - printf("MyThrowNew: returning res=%d\n",res); - return res; -} - -jthrowable JNICALL MyExceptionOccurred(JNIEnv *env) { - if (isThreadExpected(jvmti, NULL)) { - excoccur_calls++; - if (verbose) - printf("\nMyExceptionOccurred: the function called successfully: number of calls=%d\n", - excoccur_calls); - } - - return orig_jni_functions->ExceptionOccurred( - JNI_ENV_ARG1(env)); -} -/*****************************/ - -void doRedirect(JNIEnv *env) { - jvmtiError err; - - if (verbose) - printf("\ndoRedirect: obtaining the JNI function table ...\n"); - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &orig_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get original JNI function table")); - } - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &redir_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get redirected JNI function table")); - } - if (verbose) - printf("doRedirect: the JNI function table obtained successfully\n"); - - if (verbose) - printf("\ndoRedirect: overwriting the functions Throw,ThrowNew,ExceptionOccured ...\n"); - redir_jni_functions->Throw = MyThrow; - redir_jni_functions->ThrowNew = MyThrowNew; - redir_jni_functions->ExceptionOccurred = MyExceptionOccurred; - - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, redir_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to set new JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to set new JNI function table")); - } - - if (verbose) - printf("\ndoRedirect: the functions are overwritten successfully\n"); -} - -void doRestore(JNIEnv *env) { - jvmtiError err; - - if (verbose) - printf("\ndoRestore: restoring the original JNI function table ...\n"); - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, orig_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to restore original JNI function table")); - } - if (verbose) - printf("doRestore: the original JNI function table is restored successfully\n"); -} - -void doExc(JNIEnv *env, jthrowable thrw, jclass thrCls, const char *msg) { - jint res; - - if ((res = JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG(env, thrCls), msg)) != 0) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to throw new exception\n", - __FILE__, __LINE__); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to failed to throw new exception")); - } - - if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { - if (verbose) - printf("\nCHECK PASSED: exception %s thrown by ThrowNew()\n\tis detected by ExceptionOccurred() successfully\n", - msg); - JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); - } - else { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: exception %s thrown by ThrowNew()\n\tis not detected by ExceptionOccurred()\n", - __FILE__, __LINE__, msg); - } - - if ((res = JNI_ENV_PTR(env)->Throw(JNI_ENV_ARG(env, thrw))) != 0) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to throw exception\n", - __FILE__, __LINE__); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to failed to throw new exception")); - } - - if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { - if (verbose) - printf("(%s,%d): CHECK PASSED: exception %s thrown by Throw()\n\tis detected by ExceptionOccurred() successfully\n", - __FILE__, __LINE__, msg); - JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); - } - else { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: exception %s thrown by Throw()\n\tis not detected by ExceptionOccurred()\n", - __FILE__, __LINE__, msg); - } -} - -void checkCall(int step, int exThrCalls, int exThrNewCalls, int exExcOccCalls) { - if (throw_calls == exThrCalls) { - if (verbose) - printf("\nCHECK PASSED: the %s JNI function Throw() has been %s:\n\t%d intercepted call(s) as expected\n", - (step==1)?"tested":"original", - (step==1)?"redirected":"restored", - throw_calls); - } - else { - result = STATUS_FAILED; - printf("\nTEST FAILED: the %s JNI function Throw() has not been %s:\n\t%d intercepted call(s) instead of %d as expected\n", - (step==1)?"tested":"original", - (step==1)?"redirected":"restored", - throw_calls, exThrCalls); - } - throw_calls = 0; /* zeroing an interception counter */ - - if (thrownew_calls == exThrNewCalls) { - if (verbose) - printf("\nCHECK PASSED: the %s JNI function ThrowNew() has been %s:\n\t%d intercepted call(s) as expected\n", - (step==1)?"tested":"original", - (step==1)?"redirected":"restored", - thrownew_calls); - } - else { - result = STATUS_FAILED; - printf("\nTEST FAILED: the %s JNI function ThrowNew() has not been %s:\n\t%d intercepted call(s) instead of %d as expected\n", - (step==1)?"tested":"original", - (step==1)?"redirected":"restored", - thrownew_calls, exThrNewCalls); - } - thrownew_calls = 0; /* zeroing an interception counter */ - - if (excoccur_calls == exExcOccCalls) { - if (verbose) - printf("\nCHECK PASSED: the %s JNI function ExceptionOccurred() has been %s:\n\t%d intercepted call(s) as expected\n", - (step==1)?"tested":"original", - (step==1)?"redirected":"restored", - excoccur_calls); - } - else { - result = STATUS_FAILED; - printf("\nTEST FAILED: the %s JNI function ExceptionOccurred() has not been %s:\n\t%d intercepted call(s) instead of %d as expected\n", - (step==1)?"tested":"original", - (step==1)?"redirected":"restored", - excoccur_calls, exExcOccCalls); - } - excoccur_calls = 0; /* zeroing an interception counter */ -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_scenarios_jni_1interception_JI03_ji03t003_check(JNIEnv *env, jobject obj) { - jfieldID fid; - jobject thrwObj; - jclass thrw; - jclass objCls; - - if (jvmti == NULL) { - printf("(%s,%d): TEST FAILURE: JVMTI client was not properly loaded\n", - __FILE__, __LINE__); - return STATUS_FAILED; - } - - objCls = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, obj)); - - if (verbose) - printf("\ncheck: obtaining field ID for \"name=%s signature=%s\"...\n", - javaField, excClassSig); - if ((fid = JNI_ENV_PTR(env)->GetFieldID( - JNI_ENV_ARG(env, objCls), javaField, excClassSig)) == 0) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get ID for the field \"%s\"\n", - __FILE__, __LINE__, javaField); - return result; - } - - if (verbose) - printf("check: obtaining the value of the field \"%s\"...\n", - javaField); - thrwObj = JNI_ENV_PTR(env)->GetObjectField( - JNI_ENV_ARG(env, obj), fid); - - if (verbose) - printf("check: obtaining the class of the object for \"%s\"...\n", - javaField); - thrw = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, thrwObj)); - - /* 1: check the JNI function table interception */ - if (verbose) - printf("\na) Checking the JNI function table interception ...\n"); - doRedirect(env); - doExc(env, thrwObj, thrw, "redirected"); - checkCall(1, 1, 1, 2); - - /* 2: check the restored JNI function table */ - if (verbose) - printf("\nb) Checking the restored JNI function table ...\n"); - doRestore(env); - doExc(env, thrwObj, thrw, "restored"); - checkCall(2, 0, 0, 0); - - JNI_ENV_PTR(env)->DeleteLocalRef(JNI_ENV_ARG(env, thrw)); - JNI_ENV_PTR(env)->DeleteLocalRef(JNI_ENV_ARG(env, thrwObj)); - - return result; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ji03t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ji03t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ji03t003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "-verbose") == 0) - verbose = 1; - - if (verbose) - printf("verbose mode on\n"); - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); - return JNI_ERR; - } - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/ji03t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/ji03t003.cpp new file mode 100644 index 00000000000..a9adfea4afe --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/ji03t003.cpp @@ -0,0 +1,364 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include + +#include +#include "agent_common.h" + +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + #ifdef __cplusplus + #define JNI_ENV_ARG(x, y) y + #define JNI_ENV_PTR(x) x + #else + #define JNI_ENV_ARG(x, y) x, y + #define JNI_ENV_PTR(x) (*x) + #endif +#endif + +#ifndef JNI_ENV_ARG1 + #ifdef __cplusplus + #define JNI_ENV_ARG1(x) + #else + #define JNI_ENV_ARG1(x) x + #endif +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static int verbose = 0; + +static const char *javaField = "exc"; +static const char *excClassSig = + "Lnsk/jvmti/scenarios/jni_interception/JI03/ji03t003Exc;"; + +/* the original JNI function table */ +static jniNativeInterface *orig_jni_functions = NULL; + +/* the redirected JNI function table */ +static jniNativeInterface *redir_jni_functions = NULL; + +/* number of the redirected JNI function calls */ +int throw_calls = 0; +int thrownew_calls = 0; +int excoccur_calls = 0; + +/** redirected JNI functions **/ +jint JNICALL MyThrow(JNIEnv *env, jthrowable thrw) { + jint res; + + throw_calls++; + if (verbose) + printf("\nMyThrow: the function called successfully: number of calls=%d\n", + throw_calls); + + res = orig_jni_functions->Throw(env, thrw); + + if (verbose) + printf("MyThrow: returning res=%d\n",res); + return res; +} + +jint JNICALL MyThrowNew(JNIEnv *env, jclass cls, const char *msg) { + jint res; + + thrownew_calls++; + if (verbose) + printf("\nMyThrowNew: the function called successfully: number of calls=%d\n", + thrownew_calls); + + res = orig_jni_functions->ThrowNew(env, cls, msg); + + if (verbose) + printf("MyThrowNew: returning res=%d\n",res); + return res; +} + +jthrowable JNICALL MyExceptionOccurred(JNIEnv *env) { + if (isThreadExpected(jvmti, NULL)) { + excoccur_calls++; + if (verbose) + printf("\nMyExceptionOccurred: the function called successfully: number of calls=%d\n", + excoccur_calls); + } + + return orig_jni_functions->ExceptionOccurred(env); +} +/*****************************/ + +void doRedirect(JNIEnv *env) { + jvmtiError err; + + if (verbose) + printf("\ndoRedirect: obtaining the JNI function table ...\n"); + if ((err = jvmti->GetJNIFunctionTable(&orig_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get original JNI function table")); + } + if ((err = jvmti->GetJNIFunctionTable(&redir_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get redirected JNI function table")); + } + if (verbose) + printf("doRedirect: the JNI function table obtained successfully\n"); + + if (verbose) + printf("\ndoRedirect: overwriting the functions Throw,ThrowNew,ExceptionOccured ...\n"); + redir_jni_functions->Throw = MyThrow; + redir_jni_functions->ThrowNew = MyThrowNew; + redir_jni_functions->ExceptionOccurred = MyExceptionOccurred; + + if ((err = jvmti->SetJNIFunctionTable(redir_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to set new JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to set new JNI function table")); + } + + if (verbose) + printf("\ndoRedirect: the functions are overwritten successfully\n"); +} + +void doRestore(JNIEnv *env) { + jvmtiError err; + + if (verbose) + printf("\ndoRestore: restoring the original JNI function table ...\n"); + if ((err = jvmti->SetJNIFunctionTable(orig_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to restore original JNI function table")); + } + if (verbose) + printf("doRestore: the original JNI function table is restored successfully\n"); +} + +void doExc(JNIEnv *env, jthrowable thrw, jclass thrCls, const char *msg) { + jint res; + + if ((res = JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG(env, thrCls), msg)) != 0) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to throw new exception\n", + __FILE__, __LINE__); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to failed to throw new exception")); + } + + if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { + if (verbose) + printf("\nCHECK PASSED: exception %s thrown by ThrowNew()\n\tis detected by ExceptionOccurred() successfully\n", + msg); + JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); + } + else { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: exception %s thrown by ThrowNew()\n\tis not detected by ExceptionOccurred()\n", + __FILE__, __LINE__, msg); + } + + if ((res = JNI_ENV_PTR(env)->Throw(JNI_ENV_ARG(env, thrw))) != 0) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to throw exception\n", + __FILE__, __LINE__); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to failed to throw new exception")); + } + + if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { + if (verbose) + printf("(%s,%d): CHECK PASSED: exception %s thrown by Throw()\n\tis detected by ExceptionOccurred() successfully\n", + __FILE__, __LINE__, msg); + JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); + } + else { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: exception %s thrown by Throw()\n\tis not detected by ExceptionOccurred()\n", + __FILE__, __LINE__, msg); + } +} + +void checkCall(int step, int exThrCalls, int exThrNewCalls, int exExcOccCalls) { + if (throw_calls == exThrCalls) { + if (verbose) + printf("\nCHECK PASSED: the %s JNI function Throw() has been %s:\n\t%d intercepted call(s) as expected\n", + (step==1)?"tested":"original", + (step==1)?"redirected":"restored", + throw_calls); + } + else { + result = STATUS_FAILED; + printf("\nTEST FAILED: the %s JNI function Throw() has not been %s:\n\t%d intercepted call(s) instead of %d as expected\n", + (step==1)?"tested":"original", + (step==1)?"redirected":"restored", + throw_calls, exThrCalls); + } + throw_calls = 0; /* zeroing an interception counter */ + + if (thrownew_calls == exThrNewCalls) { + if (verbose) + printf("\nCHECK PASSED: the %s JNI function ThrowNew() has been %s:\n\t%d intercepted call(s) as expected\n", + (step==1)?"tested":"original", + (step==1)?"redirected":"restored", + thrownew_calls); + } + else { + result = STATUS_FAILED; + printf("\nTEST FAILED: the %s JNI function ThrowNew() has not been %s:\n\t%d intercepted call(s) instead of %d as expected\n", + (step==1)?"tested":"original", + (step==1)?"redirected":"restored", + thrownew_calls, exThrNewCalls); + } + thrownew_calls = 0; /* zeroing an interception counter */ + + if (excoccur_calls == exExcOccCalls) { + if (verbose) + printf("\nCHECK PASSED: the %s JNI function ExceptionOccurred() has been %s:\n\t%d intercepted call(s) as expected\n", + (step==1)?"tested":"original", + (step==1)?"redirected":"restored", + excoccur_calls); + } + else { + result = STATUS_FAILED; + printf("\nTEST FAILED: the %s JNI function ExceptionOccurred() has not been %s:\n\t%d intercepted call(s) instead of %d as expected\n", + (step==1)?"tested":"original", + (step==1)?"redirected":"restored", + excoccur_calls, exExcOccCalls); + } + excoccur_calls = 0; /* zeroing an interception counter */ +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_scenarios_jni_1interception_JI03_ji03t003_check(JNIEnv *env, jobject obj) { + jfieldID fid; + jthrowable thrwObj; + jclass thrw; + jclass objCls; + + if (jvmti == NULL) { + printf("(%s,%d): TEST FAILURE: JVMTI client was not properly loaded\n", + __FILE__, __LINE__); + return STATUS_FAILED; + } + + objCls = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, obj)); + + if (verbose) + printf("\ncheck: obtaining field ID for \"name=%s signature=%s\"...\n", + javaField, excClassSig); + if ((fid = JNI_ENV_PTR(env)->GetFieldID( + JNI_ENV_ARG(env, objCls), javaField, excClassSig)) == 0) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get ID for the field \"%s\"\n", + __FILE__, __LINE__, javaField); + return result; + } + + if (verbose) + printf("check: obtaining the value of the field \"%s\"...\n", + javaField); + thrwObj = (jthrowable) JNI_ENV_PTR(env)->GetObjectField( + JNI_ENV_ARG(env, obj), fid); + + if (verbose) + printf("check: obtaining the class of the object for \"%s\"...\n", + javaField); + thrw = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, thrwObj)); + + /* 1: check the JNI function table interception */ + if (verbose) + printf("\na) Checking the JNI function table interception ...\n"); + doRedirect(env); + doExc(env, thrwObj, thrw, "redirected"); + checkCall(1, 1, 1, 2); + + /* 2: check the restored JNI function table */ + if (verbose) + printf("\nb) Checking the restored JNI function table ...\n"); + doRestore(env); + doExc(env, thrwObj, thrw, "restored"); + checkCall(2, 0, 0, 0); + + JNI_ENV_PTR(env)->DeleteLocalRef(JNI_ENV_ARG(env, thrw)); + JNI_ENV_PTR(env)->DeleteLocalRef(JNI_ENV_ARG(env, thrwObj)); + + return result; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ji03t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ji03t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ji03t003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "-verbose") == 0) + verbose = 1; + + if (verbose) + printf("verbose mode on\n"); + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/libji03t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/libji03t003.c deleted file mode 100644 index adc7bcb701c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/libji03t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ji03t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/libji03t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/libji03t003.cpp new file mode 100644 index 00000000000..79825bd9e71 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/libji03t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ji03t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/ji03t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/ji03t004.c deleted file mode 100644 index f6b750e43f4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/ji03t004.c +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include - -#include -#include "agent_common.h" - -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - #ifdef __cplusplus - #define JNI_ENV_ARG(x, y) y - #define JNI_ENV_PTR(x) x - #else - #define JNI_ENV_ARG(x, y) x, y - #define JNI_ENV_PTR(x) (*x) - #endif -#endif - -#ifndef JNI_ENV_ARG1 - #ifdef __cplusplus - #define JNI_ENV_ARG1(x) - #else - #define JNI_ENV_ARG1(x) x - #endif -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static int verbose = 0; - -static const char *classSig = - "Lnsk/jvmti/scenarios/jni_interception/JI03/ji03t004a;"; - -/* the original JNI function table */ -static jniNativeInterface *orig_jni_functions = NULL; - -/* the redirected JNI function table */ -static jniNativeInterface *redir_jni_functions = NULL; - -/* number of the redirected JNI function calls */ -int allobj_calls = 0; -int newobj_calls = 0; - -/** redirected JNI functions **/ -jobject JNICALL MyAllocObject(JNIEnv *env, jclass cls) { - allobj_calls++; - if (verbose) - printf("\nMyAllocObject: the function called successfully: number of calls=%d\n", - allobj_calls); - - return orig_jni_functions->AllocObject( - JNI_ENV_ARG(env, cls)); -} - -jobject JNICALL MyNewObjectV(JNIEnv *env, jclass cls, jmethodID ctorId, va_list args) { - newobj_calls++; - if (verbose) - printf("\nMyNewObjectV: the function called successfully: number of calls=%d\n", - newobj_calls); - - return orig_jni_functions->NewObjectV( - JNI_ENV_ARG(env, cls), ctorId, args); -} -/*****************************/ - -void doRedirect(JNIEnv *env) { - jvmtiError err; - - if (verbose) - printf("\ndoRedirect: obtaining the JNI function table ...\n"); - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &orig_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get original JNI function table")); - } - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &redir_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get redirected JNI function table")); - } - if (verbose) - printf("doRedirect: the JNI function table obtained successfully\n"); - - if (verbose) - printf("\ndoRedirect: overwriting the functions AllocObject,NewObjectV ...\n"); - redir_jni_functions->AllocObject = MyAllocObject; - redir_jni_functions->NewObjectV = MyNewObjectV; - - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, redir_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to set new JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to set new JNI function table")); - } - - if (verbose) - printf("\ndoRedirect: the functions are overwritten successfully\n"); -} - -void doRestore(JNIEnv *env) { - jvmtiError err; - - if (verbose) - printf("\ndoRestore: restoring the original JNI function table ...\n"); - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, orig_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n", - __FILE__, __LINE__, TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to restore original JNI function table")); - } - if (verbose) - printf("doRestore: the original JNI function table is restored successfully\n"); -} - -void doExec(JNIEnv *env, jclass allCls, jmethodID ctorId, const char *msg, ...) { - jobject allObj; - jobject newObj; - va_list args; - va_start(args, msg); - if ((allObj = JNI_ENV_PTR(env)->AllocObject(JNI_ENV_ARG(env, allCls))) - == NULL) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to call %s AllocObject()\n", - __FILE__, __LINE__, msg); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to failed to call AllocObject()")); - } - - if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: exception occured during the call of %s AllocObject()\n", - __FILE__, __LINE__, msg); - JNI_ENV_PTR(env)->ExceptionDescribe(JNI_ENV_ARG1(env)); - JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); - } - - newObj = JNI_ENV_PTR(env)->NewObjectV(JNI_ENV_ARG(env, allCls), ctorId, args); - if (newObj == NULL) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: failed to call %s NewObjectV()\n", - __FILE__, __LINE__, msg); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to failed to call NewObjectV()")); - } - - if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { - result = STATUS_FAILED; - printf("(%s,%d): TEST FAILED: exception occured during the call of %s AllocObject()\n", - __FILE__, __LINE__, msg); - JNI_ENV_PTR(env)->ExceptionDescribe(JNI_ENV_ARG1(env)); - JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); - } - va_end(args); - JNI_ENV_PTR(env)->DeleteLocalRef(JNI_ENV_ARG(env, allObj)); - JNI_ENV_PTR(env)->DeleteLocalRef(JNI_ENV_ARG(env, newObj)); -} - -void checkCall(int step, int exAllObjCalls, int exNewObjCalls) { - if (allobj_calls == exAllObjCalls) { - if (verbose) - printf("\nCHECK PASSED: the %s JNI function AllocObject() has been %s:\n\t%d intercepted call(s) as expected\n", - (step==1)?"tested":"original", - (step==1)?"redirected":"restored", - allobj_calls); - } - else { - result = STATUS_FAILED; - printf("\nTEST FAILED: the %s JNI function AllocObject() has not been %s:\t%d intercepted call(s) instead of %d as expected\n\n", - (step==1)?"tested":"original", - (step==1)?"redirected":"restored", - allobj_calls, exAllObjCalls); - } - allobj_calls = 0; /* zeroing an interception counter */ - - if (newobj_calls == exNewObjCalls) { - if (verbose) - printf("\nCHECK PASSED: the %s JNI function NewObjectV() has been %s:\n\t%d intercepted call(s) as expected\n", - (step==1)?"tested":"original", - (step==1)?"redirected":"restored", - newobj_calls); - } - else { - result = STATUS_FAILED; - printf("\nTEST FAILED: the %s JNI function NewObjectV() has not been %s:\n\t%d intercepted call(s) instead of %d as expected\n", - (step==1)?"tested":"original", - (step==1)?"redirected":"restored", - newobj_calls, exNewObjCalls); - } - newobj_calls = 0; /* zeroing an interception counter */ -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_scenarios_jni_1interception_JI03_ji03t004_check(JNIEnv *env, jobject obj) { - jmethodID ctorId; - jclass objCls; - - if (jvmti == NULL) { - printf("(%s,%d): TEST FAILURE: JVMTI client was not properly loaded\n", - __FILE__, __LINE__); - return STATUS_FAILED; - } - - if ((objCls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, classSig))) - == NULL) { - printf("(%s,%d): TEST FAILED: failed to call FindClass() for \"%s\"\n", - __FILE__, __LINE__, classSig); - return STATUS_FAILED; - } - - if ((ctorId = JNI_ENV_PTR(env)->GetMethodID( - JNI_ENV_ARG(env, objCls), "", "()V")) - == NULL) { - printf("(%s,%d): TEST FAILED: failed to call GetMethodID() for a constructor\n", - __FILE__, __LINE__); - return STATUS_FAILED; - } - - /* 1: check the JNI function table interception */ - if (verbose) - printf("\na) Checking the JNI function table interception ...\n"); - doRedirect(env); - doExec(env, objCls, ctorId, "redirected"); - checkCall(1, 1, 1); - - /* 2: check the restored JNI function table */ - if (verbose) - printf("\nb) Checking the restored JNI function table ...\n"); - doRestore(env); - doExec(env, objCls, ctorId, "restored"); - checkCall(2, 0, 0); - - return result; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ji03t004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ji03t004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ji03t004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "-verbose") == 0) - verbose = 1; - - if (verbose) - printf("verbose mode on\n"); - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); - return JNI_ERR; - } - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/ji03t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/ji03t004.cpp new file mode 100644 index 00000000000..6c826ede465 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/ji03t004.cpp @@ -0,0 +1,307 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include + +#include +#include "agent_common.h" + +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + #ifdef __cplusplus + #define JNI_ENV_ARG(x, y) y + #define JNI_ENV_PTR(x) x + #else + #define JNI_ENV_ARG(x, y) x, y + #define JNI_ENV_PTR(x) (*x) + #endif +#endif + +#ifndef JNI_ENV_ARG1 + #ifdef __cplusplus + #define JNI_ENV_ARG1(x) + #else + #define JNI_ENV_ARG1(x) x + #endif +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static int verbose = 0; + +static const char *classSig = + "Lnsk/jvmti/scenarios/jni_interception/JI03/ji03t004a;"; + +/* the original JNI function table */ +static jniNativeInterface *orig_jni_functions = NULL; + +/* the redirected JNI function table */ +static jniNativeInterface *redir_jni_functions = NULL; + +/* number of the redirected JNI function calls */ +int allobj_calls = 0; +int newobj_calls = 0; + +/** redirected JNI functions **/ +jobject JNICALL MyAllocObject(JNIEnv *env, jclass cls) { + allobj_calls++; + if (verbose) + printf("\nMyAllocObject: the function called successfully: number of calls=%d\n", + allobj_calls); + + return orig_jni_functions->AllocObject(env, cls); +} + +jobject JNICALL MyNewObjectV(JNIEnv *env, jclass cls, jmethodID ctorId, va_list args) { + newobj_calls++; + if (verbose) + printf("\nMyNewObjectV: the function called successfully: number of calls=%d\n", + newobj_calls); + + return orig_jni_functions->NewObjectV(env, cls, ctorId, args); +} +/*****************************/ + +void doRedirect(JNIEnv *env) { + jvmtiError err; + + if (verbose) + printf("\ndoRedirect: obtaining the JNI function table ...\n"); + if ((err = jvmti->GetJNIFunctionTable(&orig_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get original JNI function table")); + } + if ((err = jvmti->GetJNIFunctionTable(&redir_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get redirected JNI function table")); + } + if (verbose) + printf("doRedirect: the JNI function table obtained successfully\n"); + + if (verbose) + printf("\ndoRedirect: overwriting the functions AllocObject,NewObjectV ...\n"); + redir_jni_functions->AllocObject = MyAllocObject; + redir_jni_functions->NewObjectV = MyNewObjectV; + + if ((err = jvmti->SetJNIFunctionTable(redir_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to set new JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to set new JNI function table")); + } + + if (verbose) + printf("\ndoRedirect: the functions are overwritten successfully\n"); +} + +void doRestore(JNIEnv *env) { + jvmtiError err; + + if (verbose) + printf("\ndoRestore: restoring the original JNI function table ...\n"); + if ((err = jvmti->SetJNIFunctionTable(orig_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n", + __FILE__, __LINE__, TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to restore original JNI function table")); + } + if (verbose) + printf("doRestore: the original JNI function table is restored successfully\n"); +} + +void doExec(JNIEnv *env, jclass allCls, jmethodID ctorId, const char *msg, ...) { + jobject allObj; + jobject newObj; + va_list args; + va_start(args, msg); + if ((allObj = JNI_ENV_PTR(env)->AllocObject(JNI_ENV_ARG(env, allCls))) + == NULL) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to call %s AllocObject()\n", + __FILE__, __LINE__, msg); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to failed to call AllocObject()")); + } + + if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: exception occured during the call of %s AllocObject()\n", + __FILE__, __LINE__, msg); + JNI_ENV_PTR(env)->ExceptionDescribe(JNI_ENV_ARG1(env)); + JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); + } + + newObj = JNI_ENV_PTR(env)->NewObjectV(JNI_ENV_ARG(env, allCls), ctorId, args); + if (newObj == NULL) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: failed to call %s NewObjectV()\n", + __FILE__, __LINE__, msg); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to failed to call NewObjectV()")); + } + + if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { + result = STATUS_FAILED; + printf("(%s,%d): TEST FAILED: exception occured during the call of %s AllocObject()\n", + __FILE__, __LINE__, msg); + JNI_ENV_PTR(env)->ExceptionDescribe(JNI_ENV_ARG1(env)); + JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); + } + va_end(args); + JNI_ENV_PTR(env)->DeleteLocalRef(JNI_ENV_ARG(env, allObj)); + JNI_ENV_PTR(env)->DeleteLocalRef(JNI_ENV_ARG(env, newObj)); +} + +void checkCall(int step, int exAllObjCalls, int exNewObjCalls) { + if (allobj_calls == exAllObjCalls) { + if (verbose) + printf("\nCHECK PASSED: the %s JNI function AllocObject() has been %s:\n\t%d intercepted call(s) as expected\n", + (step==1)?"tested":"original", + (step==1)?"redirected":"restored", + allobj_calls); + } + else { + result = STATUS_FAILED; + printf("\nTEST FAILED: the %s JNI function AllocObject() has not been %s:\t%d intercepted call(s) instead of %d as expected\n\n", + (step==1)?"tested":"original", + (step==1)?"redirected":"restored", + allobj_calls, exAllObjCalls); + } + allobj_calls = 0; /* zeroing an interception counter */ + + if (newobj_calls == exNewObjCalls) { + if (verbose) + printf("\nCHECK PASSED: the %s JNI function NewObjectV() has been %s:\n\t%d intercepted call(s) as expected\n", + (step==1)?"tested":"original", + (step==1)?"redirected":"restored", + newobj_calls); + } + else { + result = STATUS_FAILED; + printf("\nTEST FAILED: the %s JNI function NewObjectV() has not been %s:\n\t%d intercepted call(s) instead of %d as expected\n", + (step==1)?"tested":"original", + (step==1)?"redirected":"restored", + newobj_calls, exNewObjCalls); + } + newobj_calls = 0; /* zeroing an interception counter */ +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_scenarios_jni_1interception_JI03_ji03t004_check(JNIEnv *env, jobject obj) { + jmethodID ctorId; + jclass objCls; + + if (jvmti == NULL) { + printf("(%s,%d): TEST FAILURE: JVMTI client was not properly loaded\n", + __FILE__, __LINE__); + return STATUS_FAILED; + } + + if ((objCls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, classSig))) + == NULL) { + printf("(%s,%d): TEST FAILED: failed to call FindClass() for \"%s\"\n", + __FILE__, __LINE__, classSig); + return STATUS_FAILED; + } + + if ((ctorId = JNI_ENV_PTR(env)->GetMethodID( + JNI_ENV_ARG(env, objCls), "", "()V")) + == NULL) { + printf("(%s,%d): TEST FAILED: failed to call GetMethodID() for a constructor\n", + __FILE__, __LINE__); + return STATUS_FAILED; + } + + /* 1: check the JNI function table interception */ + if (verbose) + printf("\na) Checking the JNI function table interception ...\n"); + doRedirect(env); + doExec(env, objCls, ctorId, "redirected"); + checkCall(1, 1, 1); + + /* 2: check the restored JNI function table */ + if (verbose) + printf("\nb) Checking the restored JNI function table ...\n"); + doRestore(env); + doExec(env, objCls, ctorId, "restored"); + checkCall(2, 0, 0); + + return result; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ji03t004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ji03t004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ji03t004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "-verbose") == 0) + verbose = 1; + + if (verbose) + printf("verbose mode on\n"); + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("(%s,%d): Failed to call GetEnv\n", __FILE__, __LINE__); + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/libji03t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/libji03t004.c deleted file mode 100644 index 33ece98f4cd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/libji03t004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ji03t004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/libji03t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/libji03t004.cpp new file mode 100644 index 00000000000..630f6e7cce3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t004/libji03t004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ji03t004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI05/ji05t001/ji05t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI05/ji05t001/ji05t001.c deleted file mode 100644 index b83aeb78a42..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI05/ji05t001/ji05t001.c +++ /dev/null @@ -1,477 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include - -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" -#include "native_thread.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - #ifdef __cplusplus - #define JNI_ENV_ARG(x, y) y - #define JNI_ENV_PTR(x) x - #else - #define JNI_ENV_ARG(x, y) x, y - #define JNI_ENV_PTR(x) (*x) - #endif -#endif - -#ifndef JNI_ENV_ARG1 - #ifdef __cplusplus - #define JNI_ENV_ARG1(x) - #else - #define JNI_ENV_ARG1(x) x - #endif -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define TRIES 30 -#define AGENTS 2 - -static JavaVM *vm; - -static jvmtiEnv *jvmti[AGENTS]; /* JVMTI env of an agent */ -static void *agentThr[AGENTS]; -static volatile int redir[AGENTS]; /* redirection in an agent done */ -static volatile int thrstarted[AGENTS]; /* an agent started */ - -static volatile int verbose = 0; - -static volatile jint result = PASSED; - -/* the original JNI function table */ -static jniNativeInterface *orig_jni_functions[AGENTS]; - -/* the redirected JNI function table */ -static jniNativeInterface *redir_jni_functions[AGENTS]; - -/* number of the redirected JNI function calls */ -static volatile int redir_calls[AGENTS]; - -static void doRedirect(JNIEnv*, jvmtiEnv*, int); -static void provokeIntercept(JNIEnv*, const char*); -static int checkIntercept(int, int, int); -static int initAgent(int); -static void startAgent(int); -static int agentA(void*); -static int agentB(void*); -static void JNICALL VMInitA(jvmtiEnv*, JNIEnv*, jthread); -static void JNICALL VMInitB(jvmtiEnv*, JNIEnv*, jthread); - -/** redirected JNI functions **/ -/* function redirected inside the agent A */ -jint JNICALL MyGetVersionA(JNIEnv *env) { - redir_calls[0]++; - - NSK_DISPLAY1("\nMyGetVersionA: the function called successfully: number of calls=%d\n", - redir_calls[0]); - - return orig_jni_functions[0]->GetVersion( - JNI_ENV_ARG1(env)); -} - -/* function redirected inside the agent B */ -jint JNICALL MyGetVersionB(JNIEnv *env) { - redir_calls[1]++; - - NSK_DISPLAY1("\nMyGetVersionB: the function called successfully: number of calls=%d\n", - redir_calls[1]); - - return (orig_jni_functions[1])->GetVersion( - JNI_ENV_ARG1(env)); -} -/*****************************/ - -static void doRedirect(JNIEnv *env, jvmtiEnv *jvmti, int indx) { - jvmtiError err; - - NSK_DISPLAY1("\n%s JVMTI env: doRedirect: obtaining the JNI function table ...\n", - (indx==0)?"first":"second"); - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &orig_jni_functions[indx])) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - NSK_COMPLAIN2("TEST FAILED: %s JVMTI env: failed to get original JNI function table: %s\n", - (indx==0)?"first":"second", TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get original JNI function table")); - } - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &redir_jni_functions[indx])) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - NSK_COMPLAIN2("TEST FAILED: %s JVMTI env: failed to get redirected JNI function table: %s\n", - (indx==0)?"first":"second", TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get redirected JNI function table")); - } - - NSK_DISPLAY1("%s JVMTI env: doRedirect: the JNI function table obtained successfully\n\ -\toverwriting the function GetVersion() ...\n", - (indx==0)?"first":"second"); - redir_jni_functions[indx]->GetVersion = - (indx==0)?MyGetVersionA:MyGetVersionB; - - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, redir_jni_functions[indx])) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - NSK_COMPLAIN2("TEST FAILED: %s JVMTI env: failed to set new JNI function table: %s\n", - (indx==0)?"first":"second", TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to set new JNI function table")); - } - - NSK_DISPLAY1("%s JVMTI env: doRedirect: the functions are overwritten successfully\n", - (indx==0)?"first":"second"); -} - -static void provokeIntercept(JNIEnv *env, const char *name) { - jint res; - - res = JNI_ENV_PTR(env)-> - GetVersion(JNI_ENV_ARG1(env)); - NSK_DISPLAY2("\nGetVersion() called by the agent %s returns %d\n", - name, res); -} - -static int checkIntercept(int indx, int env_num, int exCalls) { - if (redir_calls[indx] == exCalls) { - NSK_DISPLAY5("\nCHECK PASSED: GetVersion() interception set in the %s JVMTI env %s properly:\n\ -\t%d interception(s) with the%s%s JVMTI env as expected\n", - (indx==0)?"first":"second", - (exCalls==0)?"overwritten by another environment":"works", - redir_calls[indx], - (indx==env_num)?" same ":" ", - (env_num==0)?"first":"second"); - } - else { - result = STATUS_FAILED; - NSK_COMPLAIN6("\nTEST FAILED: GetVersion() interception set in the %s JVMTI env doesn't %s properly:\n\ -\t%d interception(s) with the%s%s JVMTI env instead of %d as expected\n", - (indx==0)?"first":"second", - (exCalls==0)?"overwritten by another environment":"work", - redir_calls[indx], - (indx==env_num)?" same ":" ", - (env_num==0)?"first":"second", - exCalls); - return STATUS_FAILED; - } - - return PASSED; -} - -static int initAgent(int indx) { - jvmtiEventCallbacks callbacks; /* callback functions */ - int exitCode = PASSED; - jvmtiError err; - jint res; - - thrstarted[indx] = redir[indx] = redir_calls[indx] = 0; - - NSK_DISPLAY1("\nagent %s initializer: obtaining the JVMTI env ...\n", - (indx==0)?"A":"B"); - res = JNI_ENV_PTR(vm)-> - GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti[indx]), JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti[indx] == NULL) { - NSK_COMPLAIN1("TEST FAILURE: failed to call GetEnv for the agent %s\n", - (indx==0)?"A":"B"); - result = STATUS_FAILED; - return STATUS_FAILED; - } - - NSK_DISPLAY1("\nagent %s initializer: the JVMTI env obtained\n\tsetting event callbacks ...\n", - (indx==0)?"A":"B"); - (void) memset(&callbacks, 0, sizeof(callbacks)); - switch(indx) { - case 0: - callbacks.VMInit = &VMInitA; - break; - case 1: - callbacks.VMInit = &VMInitB; - break; - } - if ((err = (*jvmti[indx])->SetEventCallbacks(jvmti[indx], - &callbacks, sizeof(callbacks))) != JVMTI_ERROR_NONE) { - NSK_COMPLAIN1("TEST FAILURE: failed to set event callbacks: %s\n", - TranslateError(err)); - result = STATUS_FAILED; - return STATUS_FAILED; - } - - NSK_DISPLAY1("\nagent %s initializer: setting event callbacks done\n\tenabling events ...\n", - (indx==0)?"A":"B"); - if ((err = (*jvmti[indx])->SetEventNotificationMode(jvmti[indx], - JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL)) != JVMTI_ERROR_NONE) { /* enable event globally */ - NSK_COMPLAIN2("TEST FAILURE: failed to enable JVMTI_EVENT_VM_INIT event for the agent %s: %s\n", - (indx==0)?"A":"B", TranslateError(err)); - result = STATUS_FAILED; - return STATUS_FAILED; - } - NSK_DISPLAY2("\nagent %s initializer: enabling events done, returning exit code %d\n", - (indx==0)?"A":"B", exitCode); - - return exitCode; -} - -static void startAgent(int indx) { - int tries = 0; - - NSK_DISPLAY1("\nstartAgent: starting agent %s thread ...\n", - (indx==0)?"A":"B"); - agentThr[indx] = THREAD_new((indx==0)?agentA:agentB, - (indx==0)?"agent A":"agent B"); - if (THREAD_start(agentThr[indx]) == NULL) { - NSK_COMPLAIN1("TEST FAILURE: cannot start the agent %s thread\n", - (indx==0)?"A":"B"); - exit(STATUS_FAILED); - } - - NSK_DISPLAY1("\nstartAgent: waiting for the agent %s to be started ...\n", - (indx==0)?"A":"B"); - do { - THREAD_sleep(1); - tries++; - if (tries > TRIES) { - NSK_COMPLAIN2("TEST FAILURE: the agent %s thread is still not started after %d attempts\n", - (indx==0)?"A":"B", TRIES); - exit(STATUS_FAILED); - } - } while(thrstarted[indx] != 1); - - NSK_DISPLAY1("\nstartAgent: the agent %s thread started\n", - (indx==0)?"A":"B"); -} - -/* agent thread procedures */ -static int agentA(void *context) { - JNIEnv *env; - jint res; - int tries = 0; - int i; - int exitCode = PASSED; - - NSK_DISPLAY0("\nthe agent A started\n\tattaching the thread to the VM ...\n"); - if ((res = - JNI_ENV_PTR(vm)->AttachCurrentThread( - JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) { - NSK_COMPLAIN1("TEST FAILURE: AttachCurrentThread() returns: %d\n", - res); - exit(STATUS_FAILED); - } - - /* intercept the JNI function table */ - /* check the interception set in another JVMTI env */ - NSK_DISPLAY0("\n>>> TEST CASE #1) First JVMTI env: checking the redirection set in the same env ...\n\ -\nagent A (first JVMTI env): redirecting the function table ...\n"); - doRedirect(env, jvmti[0], 0); - - /* check that the interception has been set properly */ - NSK_DISPLAY0("\nagent A (first JVMTI env): checking that the interception has been set properly ...\n"); - provokeIntercept(env, "A"); - checkIntercept(0, 0, 1); /* expected interceptions: 1 */ - NSK_DISPLAY0("\n<<< TEST CASE #1) done\n"); - - /* the flag set too late in order to make sure that - the agent B will be started _after_ the interception */ - thrstarted[0] = 1; - - redir[0] = 1; - - NSK_DISPLAY0("\nagent A: waiting for the redirection in agent B ...\n"); - do { - THREAD_sleep(1); - tries++; - if (tries > TRIES) { - NSK_COMPLAIN1("TEST FAILURE: failed to wait for the redirection in agent B after %d attempts\n", - TRIES); - exit(STATUS_FAILED); - } - } while(redir[1] != 1); - - /* check the interception set in another JVMTI env */ - NSK_DISPLAY0("\n>>> TEST CASE #4) First JVMTI env: checking the redirection set in second JVMTI env ...\n"); - for (i=0; iDetachCurrentThread(JNI_ENV_ARG1(vm))) != 0) { - NSK_COMPLAIN1("TEST WARNING: agent A: DetachCurrentThread() returns: %d\n", res); - } - return exitCode; -} - -static int agentB(void *context) { - JNIEnv *env; - jint res; - int tries = 0; - int i; - int exitCode = PASSED; - - NSK_DISPLAY0("\nthe agent B started\n\tattaching the thread to the VM ...\n"); - if ((res = - JNI_ENV_PTR(vm)->AttachCurrentThread( - JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) { - NSK_COMPLAIN1("TEST FAILURE: AttachCurrentThread() returns: %d\n", - res); - exit(STATUS_FAILED); - } - - thrstarted[1] = 1; - - NSK_DISPLAY0("\nagent B: waiting for the redirection in agent A ...\n"); - do { - THREAD_sleep(1); - tries++; - if (tries > TRIES) { - NSK_COMPLAIN1("TEST FAILURE: failed to wait for the redirection in agent A after %d attempts\n", - TRIES); - exit(STATUS_FAILED); - } - } while(redir[0] != 1); - - /* check the interception set in another JVMTI env */ - NSK_DISPLAY0("\n>>> TEST CASE #2) Second JVMTI env: checking the redirection set in first JVMTI env ...\n"); - for (i=0; i>> TEST CASE #3) Second JVMTI env: checking the redirection set in the same env ...\n\ -\nagent B (second JVMTI env): redirecting the function table ...\n"); - doRedirect(env, jvmti[1], 1); - - for (i=0; iDetachCurrentThread(JNI_ENV_ARG1(vm))) != 0) { - NSK_COMPLAIN1("TEST WARNING: agent B: DetachCurrentThread() returns: %d\n", res); - } - return exitCode; -} -/*********************/ - -/* callback functions */ -void JNICALL -VMInitA(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - NSK_DISPLAY0("\nagent A: VMInit event\n"); - - startAgent(0); -} - -void JNICALL -VMInitB(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - NSK_DISPLAY0("\nagent B: VMInit event\n"); - - startAgent(1); -} -/*********************/ - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_scenarios_jni_1interception_JI05_ji05t001_getResult(JNIEnv *env, jobject obj) { - int i; - - for (i=0; i +#include +#include +#include + +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" +#include "native_thread.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + #ifdef __cplusplus + #define JNI_ENV_ARG(x, y) y + #define JNI_ENV_PTR(x) x + #else + #define JNI_ENV_ARG(x, y) x, y + #define JNI_ENV_PTR(x) (*x) + #endif +#endif + +#ifndef JNI_ENV_ARG1 + #ifdef __cplusplus + #define JNI_ENV_ARG1(x) + #else + #define JNI_ENV_ARG1(x) x + #endif +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define TRIES 30 +#define AGENTS 2 + +static JavaVM *vm; + +static jvmtiEnv *jvmti[AGENTS]; /* JVMTI env of an agent */ +static void *agentThr[AGENTS]; +static volatile int redir[AGENTS]; /* redirection in an agent done */ +static volatile int thrstarted[AGENTS]; /* an agent started */ + +static volatile int verbose = 0; + +static volatile jint result = PASSED; + +/* the original JNI function table */ +static jniNativeInterface *orig_jni_functions[AGENTS]; + +/* the redirected JNI function table */ +static jniNativeInterface *redir_jni_functions[AGENTS]; + +/* number of the redirected JNI function calls */ +static volatile int redir_calls[AGENTS]; + +static void doRedirect(JNIEnv*, jvmtiEnv*, int); +static void provokeIntercept(JNIEnv*, const char*); +static int checkIntercept(int, int, int); +static int initAgent(int); +static void startAgent(int); +static int agentA(void*); +static int agentB(void*); +static void JNICALL VMInitA(jvmtiEnv*, JNIEnv*, jthread); +static void JNICALL VMInitB(jvmtiEnv*, JNIEnv*, jthread); + +/** redirected JNI functions **/ +/* function redirected inside the agent A */ +jint JNICALL MyGetVersionA(JNIEnv *env) { + redir_calls[0]++; + + NSK_DISPLAY1("\nMyGetVersionA: the function called successfully: number of calls=%d\n", + redir_calls[0]); + + return orig_jni_functions[0]->GetVersion(env); +} + +/* function redirected inside the agent B */ +jint JNICALL MyGetVersionB(JNIEnv *env) { + redir_calls[1]++; + + NSK_DISPLAY1("\nMyGetVersionB: the function called successfully: number of calls=%d\n", + redir_calls[1]); + + return (orig_jni_functions[1])->GetVersion(env); +} +/*****************************/ + +static void doRedirect(JNIEnv *env, jvmtiEnv *jvmti, int indx) { + jvmtiError err; + + NSK_DISPLAY1("\n%s JVMTI env: doRedirect: obtaining the JNI function table ...\n", + (indx==0)?"first":"second"); + if ((err = jvmti->GetJNIFunctionTable(&orig_jni_functions[indx])) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + NSK_COMPLAIN2("TEST FAILED: %s JVMTI env: failed to get original JNI function table: %s\n", + (indx==0)?"first":"second", TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get original JNI function table")); + } + if ((err = jvmti->GetJNIFunctionTable(&redir_jni_functions[indx])) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + NSK_COMPLAIN2("TEST FAILED: %s JVMTI env: failed to get redirected JNI function table: %s\n", + (indx==0)?"first":"second", TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get redirected JNI function table")); + } + + NSK_DISPLAY1("%s JVMTI env: doRedirect: the JNI function table obtained successfully\n\ +\toverwriting the function GetVersion() ...\n", + (indx==0)?"first":"second"); + redir_jni_functions[indx]->GetVersion = + (indx==0)?MyGetVersionA:MyGetVersionB; + + if ((err = jvmti->SetJNIFunctionTable(redir_jni_functions[indx])) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + NSK_COMPLAIN2("TEST FAILED: %s JVMTI env: failed to set new JNI function table: %s\n", + (indx==0)?"first":"second", TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to set new JNI function table")); + } + + NSK_DISPLAY1("%s JVMTI env: doRedirect: the functions are overwritten successfully\n", + (indx==0)?"first":"second"); +} + +static void provokeIntercept(JNIEnv *env, const char *name) { + jint res; + + res = JNI_ENV_PTR(env)-> + GetVersion(JNI_ENV_ARG1(env)); + NSK_DISPLAY2("\nGetVersion() called by the agent %s returns %d\n", + name, res); +} + +static int checkIntercept(int indx, int env_num, int exCalls) { + if (redir_calls[indx] == exCalls) { + NSK_DISPLAY5("\nCHECK PASSED: GetVersion() interception set in the %s JVMTI env %s properly:\n\ +\t%d interception(s) with the%s%s JVMTI env as expected\n", + (indx==0)?"first":"second", + (exCalls==0)?"overwritten by another environment":"works", + redir_calls[indx], + (indx==env_num)?" same ":" ", + (env_num==0)?"first":"second"); + } + else { + result = STATUS_FAILED; + NSK_COMPLAIN6("\nTEST FAILED: GetVersion() interception set in the %s JVMTI env doesn't %s properly:\n\ +\t%d interception(s) with the%s%s JVMTI env instead of %d as expected\n", + (indx==0)?"first":"second", + (exCalls==0)?"overwritten by another environment":"work", + redir_calls[indx], + (indx==env_num)?" same ":" ", + (env_num==0)?"first":"second", + exCalls); + return STATUS_FAILED; + } + + return PASSED; +} + +static int initAgent(int indx) { + jvmtiEventCallbacks callbacks; /* callback functions */ + int exitCode = PASSED; + jvmtiError err; + jint res; + + thrstarted[indx] = redir[indx] = redir_calls[indx] = 0; + + NSK_DISPLAY1("\nagent %s initializer: obtaining the JVMTI env ...\n", + (indx==0)?"A":"B"); + res = JNI_ENV_PTR(vm)-> + GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti[indx]), JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti[indx] == NULL) { + NSK_COMPLAIN1("TEST FAILURE: failed to call GetEnv for the agent %s\n", + (indx==0)?"A":"B"); + result = STATUS_FAILED; + return STATUS_FAILED; + } + + NSK_DISPLAY1("\nagent %s initializer: the JVMTI env obtained\n\tsetting event callbacks ...\n", + (indx==0)?"A":"B"); + (void) memset(&callbacks, 0, sizeof(callbacks)); + switch(indx) { + case 0: + callbacks.VMInit = &VMInitA; + break; + case 1: + callbacks.VMInit = &VMInitB; + break; + } + if ((err = jvmti[indx]->SetEventCallbacks( + &callbacks, sizeof(callbacks))) != JVMTI_ERROR_NONE) { + NSK_COMPLAIN1("TEST FAILURE: failed to set event callbacks: %s\n", + TranslateError(err)); + result = STATUS_FAILED; + return STATUS_FAILED; + } + + NSK_DISPLAY1("\nagent %s initializer: setting event callbacks done\n\tenabling events ...\n", + (indx==0)?"A":"B"); + if ((err = jvmti[indx]->SetEventNotificationMode( + JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL)) != JVMTI_ERROR_NONE) { /* enable event globally */ + NSK_COMPLAIN2("TEST FAILURE: failed to enable JVMTI_EVENT_VM_INIT event for the agent %s: %s\n", + (indx==0)?"A":"B", TranslateError(err)); + result = STATUS_FAILED; + return STATUS_FAILED; + } + NSK_DISPLAY2("\nagent %s initializer: enabling events done, returning exit code %d\n", + (indx==0)?"A":"B", exitCode); + + return exitCode; +} + +static void startAgent(int indx) { + int tries = 0; + + NSK_DISPLAY1("\nstartAgent: starting agent %s thread ...\n", + (indx==0)?"A":"B"); + void* context = (void*) ((indx==0)?"agent A":"agent B"); + agentThr[indx] = THREAD_new((indx==0)?agentA:agentB, context); + if (THREAD_start(agentThr[indx]) == NULL) { + NSK_COMPLAIN1("TEST FAILURE: cannot start the agent %s thread\n", + (indx==0)?"A":"B"); + exit(STATUS_FAILED); + } + + NSK_DISPLAY1("\nstartAgent: waiting for the agent %s to be started ...\n", + (indx==0)?"A":"B"); + do { + THREAD_sleep(1); + tries++; + if (tries > TRIES) { + NSK_COMPLAIN2("TEST FAILURE: the agent %s thread is still not started after %d attempts\n", + (indx==0)?"A":"B", TRIES); + exit(STATUS_FAILED); + } + } while(thrstarted[indx] != 1); + + NSK_DISPLAY1("\nstartAgent: the agent %s thread started\n", + (indx==0)?"A":"B"); +} + +/* agent thread procedures */ +static int agentA(void *context) { + JNIEnv *env; + jint res; + int tries = 0; + int i; + int exitCode = PASSED; + + NSK_DISPLAY0("\nthe agent A started\n\tattaching the thread to the VM ...\n"); + if ((res = + JNI_ENV_PTR(vm)->AttachCurrentThread( + JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) { + NSK_COMPLAIN1("TEST FAILURE: AttachCurrentThread() returns: %d\n", + res); + exit(STATUS_FAILED); + } + + /* intercept the JNI function table */ + /* check the interception set in another JVMTI env */ + NSK_DISPLAY0("\n>>> TEST CASE #1) First JVMTI env: checking the redirection set in the same env ...\n\ +\nagent A (first JVMTI env): redirecting the function table ...\n"); + doRedirect(env, jvmti[0], 0); + + /* check that the interception has been set properly */ + NSK_DISPLAY0("\nagent A (first JVMTI env): checking that the interception has been set properly ...\n"); + provokeIntercept(env, "A"); + checkIntercept(0, 0, 1); /* expected interceptions: 1 */ + NSK_DISPLAY0("\n<<< TEST CASE #1) done\n"); + + /* the flag set too late in order to make sure that + the agent B will be started _after_ the interception */ + thrstarted[0] = 1; + + redir[0] = 1; + + NSK_DISPLAY0("\nagent A: waiting for the redirection in agent B ...\n"); + do { + THREAD_sleep(1); + tries++; + if (tries > TRIES) { + NSK_COMPLAIN1("TEST FAILURE: failed to wait for the redirection in agent B after %d attempts\n", + TRIES); + exit(STATUS_FAILED); + } + } while(redir[1] != 1); + + /* check the interception set in another JVMTI env */ + NSK_DISPLAY0("\n>>> TEST CASE #4) First JVMTI env: checking the redirection set in second JVMTI env ...\n"); + for (i=0; iDetachCurrentThread(JNI_ENV_ARG1(vm))) != 0) { + NSK_COMPLAIN1("TEST WARNING: agent A: DetachCurrentThread() returns: %d\n", res); + } + return exitCode; +} + +static int agentB(void *context) { + JNIEnv *env; + jint res; + int tries = 0; + int i; + int exitCode = PASSED; + + NSK_DISPLAY0("\nthe agent B started\n\tattaching the thread to the VM ...\n"); + if ((res = + JNI_ENV_PTR(vm)->AttachCurrentThread( + JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) { + NSK_COMPLAIN1("TEST FAILURE: AttachCurrentThread() returns: %d\n", + res); + exit(STATUS_FAILED); + } + + thrstarted[1] = 1; + + NSK_DISPLAY0("\nagent B: waiting for the redirection in agent A ...\n"); + do { + THREAD_sleep(1); + tries++; + if (tries > TRIES) { + NSK_COMPLAIN1("TEST FAILURE: failed to wait for the redirection in agent A after %d attempts\n", + TRIES); + exit(STATUS_FAILED); + } + } while(redir[0] != 1); + + /* check the interception set in another JVMTI env */ + NSK_DISPLAY0("\n>>> TEST CASE #2) Second JVMTI env: checking the redirection set in first JVMTI env ...\n"); + for (i=0; i>> TEST CASE #3) Second JVMTI env: checking the redirection set in the same env ...\n\ +\nagent B (second JVMTI env): redirecting the function table ...\n"); + doRedirect(env, jvmti[1], 1); + + for (i=0; iDetachCurrentThread(JNI_ENV_ARG1(vm))) != 0) { + NSK_COMPLAIN1("TEST WARNING: agent B: DetachCurrentThread() returns: %d\n", res); + } + return exitCode; +} +/*********************/ + +/* callback functions */ +void JNICALL +VMInitA(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + NSK_DISPLAY0("\nagent A: VMInit event\n"); + + startAgent(0); +} + +void JNICALL +VMInitB(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + NSK_DISPLAY0("\nagent B: VMInit event\n"); + + startAgent(1); +} +/*********************/ + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_scenarios_jni_1interception_JI05_ji05t001_getResult(JNIEnv *env, jobject obj) { + int i; + + for (i=0; i -#include -#include -#include - -#include -#include "agent_common.h" - -#include "nsk_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" -#include "native_thread.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - #ifdef __cplusplus - #define JNI_ENV_ARG(x, y) y - #define JNI_ENV_PTR(x) x - #else - #define JNI_ENV_ARG(x, y) x, y - #define JNI_ENV_PTR(x) (*x) - #endif -#endif - -#ifndef JNI_ENV_ARG1 - #ifdef __cplusplus - #define JNI_ENV_ARG1(x) - #else - #define JNI_ENV_ARG1(x) x - #endif -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define TRIES 30 -#define MAX_THREADS 5 - -// Helper for thread detach and terminate -#define THREAD_return(status) \ - do { \ - int res = JNI_ENV_PTR(vm)->DetachCurrentThread(JNI_ENV_ARG1(vm)); \ - if (res != 0) \ - NSK_COMPLAIN1("TEST WARNING: DetachCurrentThread() returns: %d\n", res); \ - else \ - NSK_DISPLAY0("Detaching thread ...\n"); \ - return status; \ - } while (0) - - -static const char *javaField = "_ji06t001a"; -static const char *classSig = - "Lnsk/jvmti/scenarios/jni_interception/JI06/ji06t001a;"; - -static JavaVM *vm; -static jvmtiEnv *jvmti = NULL; - -static volatile int verbose = 0; - -static volatile jint result = PASSED; -static volatile int monEntered = 0; /* the monitor entered */ -static volatile int thrStarted[MAX_THREADS]; /* a thread started */ -static volatile int releaseMon = 0; /* flag to release the monitor */ - -static volatile jobject clsObj; -static jrawMonitorID countLock; - -/* the original JNI function table */ -static jniNativeInterface *orig_jni_functions = NULL; - -/* the redirected JNI function table */ -static jniNativeInterface *redir_jni_functions = NULL; - -/* number of the redirected JNI function calls */ -static volatile int monent_calls = 0; - -static void lock() { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, - jvmti, countLock))) - exit(STATUS_FAILED); -} - -static void unlock() { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, - jvmti, countLock))) - exit(STATUS_FAILED); -} - -/** redirected JNI functions **/ -jint JNICALL MyMonitorEnter(JNIEnv *env, jobject obj) { - lock(); - monent_calls++; - unlock(); - - NSK_DISPLAY1("MyMonitorEnter: the function called successfully: number of calls=%d\n", - monent_calls); - - return orig_jni_functions->MonitorEnter( - JNI_ENV_ARG(env, obj)); -} -/*****************************/ - -static jint enterMonitor(JNIEnv *env, const char *thr) { - jint result; - - if ((result = JNI_ENV_PTR(env)-> - MonitorEnter(JNI_ENV_ARG(env, clsObj))) != 0) { - NSK_COMPLAIN2("TEST FAILURE: %s: MonitorEnter() returns: %d\n", - thr, result); - return STATUS_FAILED; - } - if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { - NSK_COMPLAIN1("TEST FAILURE: %s: exception occured\n", - thr); - JNI_ENV_PTR(env)->ExceptionDescribe(JNI_ENV_ARG1(env)); - JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); - return STATUS_FAILED; - } - - return PASSED; -} - -static jint exitMonitor(JNIEnv *env, const char *thr) { - jint result; - - if ((result = JNI_ENV_PTR(env)-> - MonitorExit(JNI_ENV_ARG(env, clsObj))) != 0) { - NSK_COMPLAIN2("TEST FAILURE: %s: MonitorExit() returns: %d\n", - thr, result); - return STATUS_FAILED; - } - - return PASSED; -} - -static void doRedirect(JNIEnv *env) { - jvmtiError err; - - NSK_DISPLAY0("doRedirect: obtaining the JNI function table ...\n"); - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &orig_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - NSK_COMPLAIN1("TEST FAILED: failed to get original JNI function table: %s\n", - TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get original JNI function table")); - } - if ((err = (*jvmti)->GetJNIFunctionTable(jvmti, &redir_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - NSK_COMPLAIN1("TEST FAILED: failed to get redirected JNI function table: %s\n", - TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get redirected JNI function table")); - } - - NSK_DISPLAY0("doRedirect: the JNI function table obtained successfully\n\ -\toverwriting the function MonitorEnter ...\n"); - - redir_jni_functions->MonitorEnter = MyMonitorEnter; - - if ((err = (*jvmti)->SetJNIFunctionTable(jvmti, redir_jni_functions)) != - JVMTI_ERROR_NONE) { - result = STATUS_FAILED; - NSK_COMPLAIN1("TEST FAILED: failed to set new JNI function table: %s\n", - TranslateError(err)); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to set new JNI function table")); - } - - NSK_DISPLAY0("doRedirect: the functions are overwritten successfully\n"); -} - -static void checkCall(int exMonEntCalls) { - if (monent_calls >= exMonEntCalls) { - NSK_DISPLAY1("CHECK PASSED: the tested JNI function MonitorEnter() has been redirected:\n\ -\tat least %d intercepted call(s) as expected", - monent_calls); - } - else { - result = STATUS_FAILED; - NSK_COMPLAIN2("TEST FAILED: the tested JNI function MonitorEnter() has not been redirected properly:\n\ -\tonly %d intercepted call(s) instead of at least %d as expected\n", - monent_calls, exMonEntCalls); - } -} - -/* thread procedures */ -static int waitingThread(void *context) { - JNIEnv *env; - int exitCode = PASSED; - jint res; - int tries = 0; - /* 4932877 fix in accordance with ANSI C: thread context of type void* -> int* -> int */ - int indx = *((int *) context); - - NSK_DISPLAY1("waitingThread: thread #%d started\n\ -\tattaching the thread to the VM ...\n", - indx); - if ((res = - JNI_ENV_PTR(vm)->AttachCurrentThread( - JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) { - NSK_COMPLAIN1("TEST FAILURE: waitingThread: AttachCurrentThread() returns: %d\n", - res); - return STATUS_FAILED; - } - - NSK_DISPLAY1("waitingThread: thread #%d is trying to enter the monitor ...\n", - indx); - - thrStarted[indx-1] = 1; /* the thread is started */ - - if (enterMonitor(env, "waitingThread") == STATUS_FAILED) - THREAD_return(STATUS_FAILED); - if (verbose) - printf("waitingThread: thread #%d entered the monitor\n", - indx); - if (exitMonitor(env, "waitingThread") == STATUS_FAILED) - THREAD_return(STATUS_FAILED); - - NSK_DISPLAY2("waitingThread: thread #%d exits the monitor\n\treturning %d\n", - indx, exitCode); - THREAD_return(exitCode); -} - -static int ownerThread(void *context) { - JNIEnv *env; - int exitCode = PASSED; - jint res; - int tries = 0; - - NSK_DISPLAY0("ownerThread: thread started\n\tattaching the thread to the VM ...\n"); - if ((res = - JNI_ENV_PTR(vm)->AttachCurrentThread( - JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) { - NSK_COMPLAIN1("TEST FAILURE: ownerThread: AttachCurrentThread() returns: %d\n", - res); - return STATUS_FAILED; - } - - NSK_DISPLAY0("ownerThread: trying to enter the monitor ...\n"); - if (enterMonitor(env, "ownerThread") == STATUS_FAILED) - THREAD_return(STATUS_FAILED); - - monEntered = 1; /* the monitor has been entered */ - NSK_DISPLAY1("ownerThread: entered the monitor: monEntered=%d\n\ -\twaiting ...\n", - monEntered); - do { - THREAD_sleep(1); - tries++; - if (tries > TRIES) { - NSK_COMPLAIN1("TEST FAILED: ownerThread: time exceed after %d attempts\n", - TRIES); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "ownerThread: time exceed")); - } - } while(releaseMon != 1); - - if (exitMonitor(env, "ownerThread") == STATUS_FAILED) - THREAD_return(STATUS_FAILED); - - NSK_DISPLAY1("ownerThread: exits the monitor\n\treturning %d\n", - exitCode); - - THREAD_return(exitCode); -} - -static int redirectorThread(void *context) { - JNIEnv *env; - int exitCode = PASSED; - jint res; - int tries = 0; - - NSK_DISPLAY0("redirectorThread: thread started\n\tattaching the thread to the VM ...\n"); - if ((res = - JNI_ENV_PTR(vm)->AttachCurrentThread( - JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) { - NSK_COMPLAIN1("TEST FAILURE: redirectorThread: AttachCurrentThread() returns: %d\n", - res); - return STATUS_FAILED; - } - - NSK_DISPLAY0("redirectorThread: trying to redirect the MonitorEnter() ...\n"); - doRedirect(env); - - NSK_DISPLAY1("redirectorThread: the MonitorEnter() redirected\n\treturning %d\n", - exitCode); - - THREAD_return(exitCode); -} -/*********************/ - -static jobject getObjectFromField(JNIEnv *env, jobject obj) { - jfieldID fid; - jclass _objCls; - - _objCls = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, obj)); - - NSK_DISPLAY2("getObjectFromField: obtaining field ID for name=\"%s\" signature=\"%s\"...\n", - javaField, classSig); - if ((fid = JNI_ENV_PTR(env)->GetFieldID( - JNI_ENV_ARG(env, _objCls), javaField, classSig)) == 0) { - result = STATUS_FAILED; - NSK_COMPLAIN1("TEST FAILURE: failed to get ID for the field \"%s\"\n", - javaField); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to get ID for the java field")); - } - - return JNI_ENV_PTR(env)->GetObjectField( - JNI_ENV_ARG(env, obj), fid); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_scenarios_jni_1interception_JI06_ji06t001_check(JNIEnv *env, jobject obj) { - char *ownContext = "ownerThr"; - char *redirContext = "redirectorThr"; - int exitCode = PASSED; - void *ownThr = NULL; - void *redirThr = NULL; - void *waitThr[MAX_THREADS]; - int waitContElem[MAX_THREADS]; /* context of a particular waiting thread */ - int i; - int tries = 0; - - if (jvmti == NULL) { - NSK_COMPLAIN0("TEST FAILURE: JVMTI client was not properly loaded\n"); - return STATUS_FAILED; - } - -/* prepare the testing */ - if ((clsObj = JNI_ENV_PTR(env)->NewGlobalRef( - JNI_ENV_ARG(env, getObjectFromField(env, obj)))) == NULL) { - NSK_COMPLAIN1("TEST FAILURE: cannot create a new global reference of class \"%s\"\n", - classSig); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - "failed to create a new global reference")); - } - - NSK_DISPLAY0("starting monitor owner thread ...\n"); - ownThr = THREAD_new(ownerThread, ownContext); - if (THREAD_start(ownThr) == NULL) { - NSK_COMPLAIN0("TEST FAILURE: cannot start monitor owner thread\n"); - exit(STATUS_FAILED); - } - - NSK_DISPLAY0("waiting for the monitor to be entered ...\n"); - do { - THREAD_sleep(1); - tries++; - if (tries > TRIES) { - NSK_COMPLAIN1("TEST FAILURE: the monitor is still not entered by the owner thread after %d attempts\n", - TRIES); - JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, - " the monitor is still not entered by the owner thread")); - } - } while(monEntered != 1); - - for (i=0; i int* -> void* */ - waitThr[i] = THREAD_new(waitingThread, (void *) &(waitContElem[i])); - if (THREAD_start(waitThr[i]) == NULL) { - NSK_COMPLAIN1("TEST FAILURE: cannot start waiting thread #%d\n", - i+1); - exit(STATUS_FAILED); - } - - tries = 0; - do { - THREAD_sleep(1); - tries++; - if (tries > TRIES) { - NSK_COMPLAIN1("TEST FAILURE: waiting thread #%d is still not started\n", - i+1); - exit(STATUS_FAILED); - } - } while(thrStarted[i] != 1); - NSK_DISPLAY1("the waiting thread #%d started\n", - i+1); - } - -/* begin the testing */ - NSK_DISPLAY0(">>> TEST CASE a) Trying to redirect the JNI function ...\n\ -\nstarting redirector thread ...\n"); - redirThr = THREAD_new(redirectorThread, redirContext); - if (THREAD_start(redirThr) == NULL) { - NSK_COMPLAIN0("TEST FAILURE: cannot start redirector thread\n"); - exit(STATUS_FAILED); - } - - NSK_DISPLAY0("waiting for the redirector thread ...\n"); - THREAD_waitFor(redirThr); - if (THREAD_status(redirThr) != PASSED) - exitCode = result = STATUS_FAILED; - if (exitCode == STATUS_FAILED) - NSK_COMPLAIN1("the redirector thread done with the code %d\n", - THREAD_status(redirThr)); - else - NSK_DISPLAY1("the redirector thread done with the code %d\n", - THREAD_status(redirThr)); - free(redirThr); - - releaseMon = 1; - - NSK_DISPLAY0("waiting for the monitor owner thread ...\n"); - THREAD_waitFor(ownThr); - if (THREAD_status(ownThr) != PASSED) - exitCode = result = STATUS_FAILED; - if (exitCode == STATUS_FAILED) - NSK_COMPLAIN1("the monitor owner thread done with the code %d\n", - THREAD_status(ownThr)); - else - NSK_DISPLAY1("the monitor owner thread done with the code %d\n", - THREAD_status(ownThr)); - free(ownThr); - NSK_DISPLAY0("<<<\n\n"); - -/* verification of the interception */ - NSK_DISPLAY0(">>> TEST CASE b) Exercising the interception ...\n\ -\nmain thread: trying to enter the monitor ...\n"); - if (enterMonitor(env, "mainThread") == STATUS_FAILED) - exitCode = STATUS_FAILED; - NSK_DISPLAY0("main thread: entered the monitor\n"); - if (exitMonitor(env, "mainThread") == STATUS_FAILED) - exitCode = STATUS_FAILED; - NSK_DISPLAY0("main thread: exited the monitor\n"); - - NSK_DISPLAY0("starting a separate verification thread ...\n"); - waitContElem[MAX_THREADS-1] = MAX_THREADS; - /* 4932877 fix in accordance with ANSI C: thread context of type int -> int* -> void* */ - waitThr[MAX_THREADS-1] = THREAD_new(waitingThread, - (void *) &(waitContElem[MAX_THREADS-1])); - if (THREAD_start(waitThr[MAX_THREADS-1]) == NULL) { - NSK_COMPLAIN0("TEST FAILURE: cannot start verification thread\n"); - exit(STATUS_FAILED); - } - NSK_DISPLAY0("the verification thread started\n"); - -/* finish the testing */ - for (i=0; iDeleteGlobalRef(JNI_ENV_ARG(env, clsObj)); - NSK_DISPLAY0("<<<\n\n"); - - NSK_DISPLAY0(">>> TEST CASE c) Checking number of the intercepted calls ...\n"); - checkCall(2); - NSK_DISPLAY0("<<<\n\n"); - - return result; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ji06t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ji06t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ji06t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - vm = jvm; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, - jvmti, "_counter_lock", &countLock))) - return JNI_ERR; - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/ji06t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/ji06t001.cpp new file mode 100644 index 00000000000..7264c2db9fa --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/ji06t001.cpp @@ -0,0 +1,528 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include + +#include +#include "agent_common.h" + +#include "nsk_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" +#include "native_thread.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + #ifdef __cplusplus + #define JNI_ENV_ARG(x, y) y + #define JNI_ENV_PTR(x) x + #else + #define JNI_ENV_ARG(x, y) x, y + #define JNI_ENV_PTR(x) (*x) + #endif +#endif + +#ifndef JNI_ENV_ARG1 + #ifdef __cplusplus + #define JNI_ENV_ARG1(x) + #else + #define JNI_ENV_ARG1(x) x + #endif +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define TRIES 30 +#define MAX_THREADS 5 + +// Helper for thread detach and terminate +#define THREAD_return(status) \ + do { \ + int res = JNI_ENV_PTR(vm)->DetachCurrentThread(JNI_ENV_ARG1(vm)); \ + if (res != 0) \ + NSK_COMPLAIN1("TEST WARNING: DetachCurrentThread() returns: %d\n", res); \ + else \ + NSK_DISPLAY0("Detaching thread ...\n"); \ + return status; \ + } while (0) + + +static const char *javaField = "_ji06t001a"; +static const char *classSig = + "Lnsk/jvmti/scenarios/jni_interception/JI06/ji06t001a;"; + +static JavaVM *vm; +static jvmtiEnv *jvmti = NULL; + +static volatile int verbose = 0; + +static volatile jint result = PASSED; +static volatile int monEntered = 0; /* the monitor entered */ +static volatile int thrStarted[MAX_THREADS]; /* a thread started */ +static volatile int releaseMon = 0; /* flag to release the monitor */ + +static volatile jobject clsObj; +static jrawMonitorID countLock; + +/* the original JNI function table */ +static jniNativeInterface *orig_jni_functions = NULL; + +/* the redirected JNI function table */ +static jniNativeInterface *redir_jni_functions = NULL; + +/* number of the redirected JNI function calls */ +static volatile int monent_calls = 0; + +static void lock() { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, + jvmti, countLock))) + exit(STATUS_FAILED); +} + +static void unlock() { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, + jvmti, countLock))) + exit(STATUS_FAILED); +} + +/** redirected JNI functions **/ +jint JNICALL MyMonitorEnter(JNIEnv *env, jobject obj) { + lock(); + monent_calls++; + unlock(); + + NSK_DISPLAY1("MyMonitorEnter: the function called successfully: number of calls=%d\n", + monent_calls); + + return orig_jni_functions->MonitorEnter(env, obj); +} +/*****************************/ + +static jint enterMonitor(JNIEnv *env, const char *thr) { + jint result; + + if ((result = JNI_ENV_PTR(env)-> + MonitorEnter(JNI_ENV_ARG(env, clsObj))) != 0) { + NSK_COMPLAIN2("TEST FAILURE: %s: MonitorEnter() returns: %d\n", + thr, result); + return STATUS_FAILED; + } + if (JNI_ENV_PTR(env)->ExceptionOccurred(JNI_ENV_ARG1(env))) { + NSK_COMPLAIN1("TEST FAILURE: %s: exception occured\n", + thr); + JNI_ENV_PTR(env)->ExceptionDescribe(JNI_ENV_ARG1(env)); + JNI_ENV_PTR(env)->ExceptionClear(JNI_ENV_ARG1(env)); + return STATUS_FAILED; + } + + return PASSED; +} + +static jint exitMonitor(JNIEnv *env, const char *thr) { + jint result; + + if ((result = JNI_ENV_PTR(env)-> + MonitorExit(JNI_ENV_ARG(env, clsObj))) != 0) { + NSK_COMPLAIN2("TEST FAILURE: %s: MonitorExit() returns: %d\n", + thr, result); + return STATUS_FAILED; + } + + return PASSED; +} + +static void doRedirect(JNIEnv *env) { + jvmtiError err; + + NSK_DISPLAY0("doRedirect: obtaining the JNI function table ...\n"); + if ((err = jvmti->GetJNIFunctionTable(&orig_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + NSK_COMPLAIN1("TEST FAILED: failed to get original JNI function table: %s\n", + TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get original JNI function table")); + } + if ((err = jvmti->GetJNIFunctionTable(&redir_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + NSK_COMPLAIN1("TEST FAILED: failed to get redirected JNI function table: %s\n", + TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get redirected JNI function table")); + } + + NSK_DISPLAY0("doRedirect: the JNI function table obtained successfully\n\ +\toverwriting the function MonitorEnter ...\n"); + + redir_jni_functions->MonitorEnter = MyMonitorEnter; + + if ((err = jvmti->SetJNIFunctionTable(redir_jni_functions)) != + JVMTI_ERROR_NONE) { + result = STATUS_FAILED; + NSK_COMPLAIN1("TEST FAILED: failed to set new JNI function table: %s\n", + TranslateError(err)); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to set new JNI function table")); + } + + NSK_DISPLAY0("doRedirect: the functions are overwritten successfully\n"); +} + +static void checkCall(int exMonEntCalls) { + if (monent_calls >= exMonEntCalls) { + NSK_DISPLAY1("CHECK PASSED: the tested JNI function MonitorEnter() has been redirected:\n\ +\tat least %d intercepted call(s) as expected", + monent_calls); + } + else { + result = STATUS_FAILED; + NSK_COMPLAIN2("TEST FAILED: the tested JNI function MonitorEnter() has not been redirected properly:\n\ +\tonly %d intercepted call(s) instead of at least %d as expected\n", + monent_calls, exMonEntCalls); + } +} + +/* thread procedures */ +static int waitingThread(void *context) { + JNIEnv *env; + int exitCode = PASSED; + jint res; + int tries = 0; + /* 4932877 fix in accordance with ANSI C: thread context of type void* -> int* -> int */ + int indx = *((int *) context); + + NSK_DISPLAY1("waitingThread: thread #%d started\n\ +\tattaching the thread to the VM ...\n", + indx); + if ((res = + JNI_ENV_PTR(vm)->AttachCurrentThread( + JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) { + NSK_COMPLAIN1("TEST FAILURE: waitingThread: AttachCurrentThread() returns: %d\n", + res); + return STATUS_FAILED; + } + + NSK_DISPLAY1("waitingThread: thread #%d is trying to enter the monitor ...\n", + indx); + + thrStarted[indx-1] = 1; /* the thread is started */ + + if (enterMonitor(env, "waitingThread") == STATUS_FAILED) + THREAD_return(STATUS_FAILED); + if (verbose) + printf("waitingThread: thread #%d entered the monitor\n", + indx); + if (exitMonitor(env, "waitingThread") == STATUS_FAILED) + THREAD_return(STATUS_FAILED); + + NSK_DISPLAY2("waitingThread: thread #%d exits the monitor\n\treturning %d\n", + indx, exitCode); + THREAD_return(exitCode); +} + +static int ownerThread(void *context) { + JNIEnv *env; + int exitCode = PASSED; + jint res; + int tries = 0; + + NSK_DISPLAY0("ownerThread: thread started\n\tattaching the thread to the VM ...\n"); + if ((res = + JNI_ENV_PTR(vm)->AttachCurrentThread( + JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) { + NSK_COMPLAIN1("TEST FAILURE: ownerThread: AttachCurrentThread() returns: %d\n", + res); + return STATUS_FAILED; + } + + NSK_DISPLAY0("ownerThread: trying to enter the monitor ...\n"); + if (enterMonitor(env, "ownerThread") == STATUS_FAILED) + THREAD_return(STATUS_FAILED); + + monEntered = 1; /* the monitor has been entered */ + NSK_DISPLAY1("ownerThread: entered the monitor: monEntered=%d\n\ +\twaiting ...\n", + monEntered); + do { + THREAD_sleep(1); + tries++; + if (tries > TRIES) { + NSK_COMPLAIN1("TEST FAILED: ownerThread: time exceed after %d attempts\n", + TRIES); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "ownerThread: time exceed")); + } + } while(releaseMon != 1); + + if (exitMonitor(env, "ownerThread") == STATUS_FAILED) + THREAD_return(STATUS_FAILED); + + NSK_DISPLAY1("ownerThread: exits the monitor\n\treturning %d\n", + exitCode); + + THREAD_return(exitCode); +} + +static int redirectorThread(void *context) { + JNIEnv *env; + int exitCode = PASSED; + jint res; + int tries = 0; + + NSK_DISPLAY0("redirectorThread: thread started\n\tattaching the thread to the VM ...\n"); + if ((res = + JNI_ENV_PTR(vm)->AttachCurrentThread( + JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) { + NSK_COMPLAIN1("TEST FAILURE: redirectorThread: AttachCurrentThread() returns: %d\n", + res); + return STATUS_FAILED; + } + + NSK_DISPLAY0("redirectorThread: trying to redirect the MonitorEnter() ...\n"); + doRedirect(env); + + NSK_DISPLAY1("redirectorThread: the MonitorEnter() redirected\n\treturning %d\n", + exitCode); + + THREAD_return(exitCode); +} +/*********************/ + +static jobject getObjectFromField(JNIEnv *env, jobject obj) { + jfieldID fid; + jclass _objCls; + + _objCls = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG(env, obj)); + + NSK_DISPLAY2("getObjectFromField: obtaining field ID for name=\"%s\" signature=\"%s\"...\n", + javaField, classSig); + if ((fid = JNI_ENV_PTR(env)->GetFieldID( + JNI_ENV_ARG(env, _objCls), javaField, classSig)) == 0) { + result = STATUS_FAILED; + NSK_COMPLAIN1("TEST FAILURE: failed to get ID for the field \"%s\"\n", + javaField); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to get ID for the java field")); + } + + return JNI_ENV_PTR(env)->GetObjectField( + JNI_ENV_ARG(env, obj), fid); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_scenarios_jni_1interception_JI06_ji06t001_check(JNIEnv *env, jobject obj) { + char *ownContext = (char*) "ownerThr"; + char *redirContext = (char*) "redirectorThr"; + int exitCode = PASSED; + void *ownThr = NULL; + void *redirThr = NULL; + void *waitThr[MAX_THREADS]; + int waitContElem[MAX_THREADS]; /* context of a particular waiting thread */ + int i; + int tries = 0; + + if (jvmti == NULL) { + NSK_COMPLAIN0("TEST FAILURE: JVMTI client was not properly loaded\n"); + return STATUS_FAILED; + } + +/* prepare the testing */ + if ((clsObj = JNI_ENV_PTR(env)->NewGlobalRef( + JNI_ENV_ARG(env, getObjectFromField(env, obj)))) == NULL) { + NSK_COMPLAIN1("TEST FAILURE: cannot create a new global reference of class \"%s\"\n", + classSig); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + "failed to create a new global reference")); + } + + NSK_DISPLAY0("starting monitor owner thread ...\n"); + ownThr = THREAD_new(ownerThread, ownContext); + if (THREAD_start(ownThr) == NULL) { + NSK_COMPLAIN0("TEST FAILURE: cannot start monitor owner thread\n"); + exit(STATUS_FAILED); + } + + NSK_DISPLAY0("waiting for the monitor to be entered ...\n"); + do { + THREAD_sleep(1); + tries++; + if (tries > TRIES) { + NSK_COMPLAIN1("TEST FAILURE: the monitor is still not entered by the owner thread after %d attempts\n", + TRIES); + JNI_ENV_PTR(env)->FatalError(JNI_ENV_ARG(env, + " the monitor is still not entered by the owner thread")); + } + } while(monEntered != 1); + + for (i=0; i int* -> void* */ + waitThr[i] = THREAD_new(waitingThread, (void *) &(waitContElem[i])); + if (THREAD_start(waitThr[i]) == NULL) { + NSK_COMPLAIN1("TEST FAILURE: cannot start waiting thread #%d\n", + i+1); + exit(STATUS_FAILED); + } + + tries = 0; + do { + THREAD_sleep(1); + tries++; + if (tries > TRIES) { + NSK_COMPLAIN1("TEST FAILURE: waiting thread #%d is still not started\n", + i+1); + exit(STATUS_FAILED); + } + } while(thrStarted[i] != 1); + NSK_DISPLAY1("the waiting thread #%d started\n", + i+1); + } + +/* begin the testing */ + NSK_DISPLAY0(">>> TEST CASE a) Trying to redirect the JNI function ...\n\ +\nstarting redirector thread ...\n"); + redirThr = THREAD_new(redirectorThread, redirContext); + if (THREAD_start(redirThr) == NULL) { + NSK_COMPLAIN0("TEST FAILURE: cannot start redirector thread\n"); + exit(STATUS_FAILED); + } + + NSK_DISPLAY0("waiting for the redirector thread ...\n"); + THREAD_waitFor(redirThr); + if (THREAD_status(redirThr) != PASSED) + exitCode = result = STATUS_FAILED; + if (exitCode == STATUS_FAILED) + NSK_COMPLAIN1("the redirector thread done with the code %d\n", + THREAD_status(redirThr)); + else + NSK_DISPLAY1("the redirector thread done with the code %d\n", + THREAD_status(redirThr)); + free(redirThr); + + releaseMon = 1; + + NSK_DISPLAY0("waiting for the monitor owner thread ...\n"); + THREAD_waitFor(ownThr); + if (THREAD_status(ownThr) != PASSED) + exitCode = result = STATUS_FAILED; + if (exitCode == STATUS_FAILED) + NSK_COMPLAIN1("the monitor owner thread done with the code %d\n", + THREAD_status(ownThr)); + else + NSK_DISPLAY1("the monitor owner thread done with the code %d\n", + THREAD_status(ownThr)); + free(ownThr); + NSK_DISPLAY0("<<<\n\n"); + +/* verification of the interception */ + NSK_DISPLAY0(">>> TEST CASE b) Exercising the interception ...\n\ +\nmain thread: trying to enter the monitor ...\n"); + if (enterMonitor(env, "mainThread") == STATUS_FAILED) + exitCode = STATUS_FAILED; + NSK_DISPLAY0("main thread: entered the monitor\n"); + if (exitMonitor(env, "mainThread") == STATUS_FAILED) + exitCode = STATUS_FAILED; + NSK_DISPLAY0("main thread: exited the monitor\n"); + + NSK_DISPLAY0("starting a separate verification thread ...\n"); + waitContElem[MAX_THREADS-1] = MAX_THREADS; + /* 4932877 fix in accordance with ANSI C: thread context of type int -> int* -> void* */ + waitThr[MAX_THREADS-1] = THREAD_new(waitingThread, + (void *) &(waitContElem[MAX_THREADS-1])); + if (THREAD_start(waitThr[MAX_THREADS-1]) == NULL) { + NSK_COMPLAIN0("TEST FAILURE: cannot start verification thread\n"); + exit(STATUS_FAILED); + } + NSK_DISPLAY0("the verification thread started\n"); + +/* finish the testing */ + for (i=0; iDeleteGlobalRef(JNI_ENV_ARG(env, clsObj)); + NSK_DISPLAY0("<<<\n\n"); + + NSK_DISPLAY0(">>> TEST CASE c) Checking number of the intercepted calls ...\n"); + checkCall(2); + NSK_DISPLAY0("<<<\n\n"); + + return result; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ji06t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ji06t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ji06t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + vm = jvm; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, + jvmti, "_counter_lock", &countLock))) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/libji06t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/libji06t001.c deleted file mode 100644 index 630988e0002..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/libji06t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ji06t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/libji06t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/libji06t001.cpp new file mode 100644 index 00000000000..51a5a87e40f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/libji06t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ji06t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001.c deleted file mode 100644 index 9d135fc4edb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma01t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001.cpp new file mode 100644 index 00000000000..03db3e4852c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma01t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001a.c deleted file mode 100644 index 6cd3c47552d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma01t001a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001a.cpp new file mode 100644 index 00000000000..92cb5e00b46 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/libma01t001a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma01t001a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/ma01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/ma01t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/ma01t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/ma01t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/ma01t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/ma01t001a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/ma01t001a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA01/ma01t001/ma01t001a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001.c deleted file mode 100644 index c598402993d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma02t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001.cpp new file mode 100644 index 00000000000..527863dfd20 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma02t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001a.c deleted file mode 100644 index f225b440b23..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma02t001a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001a.cpp new file mode 100644 index 00000000000..9cbd1c80310 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/libma02t001a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma02t001a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/ma02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/ma02t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/ma02t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/ma02t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/ma02t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/ma02t001a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/ma02t001a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA02/ma02t001/ma02t001a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001.c deleted file mode 100644 index b4e28af9ad0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma03t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001.cpp new file mode 100644 index 00000000000..f740f1e6baa --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma03t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001a.c deleted file mode 100644 index f43bfc88195..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma03t001a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001a.cpp new file mode 100644 index 00000000000..21d858f215c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/libma03t001a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma03t001a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/ma03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/ma03t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/ma03t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/ma03t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/ma03t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/ma03t001a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/ma03t001a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA03/ma03t001/ma03t001a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001.c deleted file mode 100644 index ea8a6ea120a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma04t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001.cpp new file mode 100644 index 00000000000..8d4c551800f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma04t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001a.c deleted file mode 100644 index e34ca7861ee..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma04t001a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001a.cpp new file mode 100644 index 00000000000..11c330b36b7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/libma04t001a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma04t001a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/ma04t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/ma04t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/ma04t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/ma04t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/ma04t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/ma04t001a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/ma04t001a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t001/ma04t001a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002.c deleted file mode 100644 index 095c98e1ac0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma04t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002.cpp new file mode 100644 index 00000000000..22768055b05 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma04t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002a.c deleted file mode 100644 index 469564ec06c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma04t002a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002a.cpp new file mode 100644 index 00000000000..3b65ee9d761 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/libma04t002a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma04t002a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002.c deleted file mode 100644 index 4e3807267d8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002.c +++ /dev/null @@ -1,353 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#define PASSED 0 -#define STATUS_FAILED 2 -#define SAMPLE_TAG ((jlong) 111111) - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* test objects */ -static jobject testedObject = NULL; -static jobject testedInstance = NULL; -static jclass testedClass = NULL; -static int ObjectsCount = 0; - -/* ========================================================================== */ - -/** callback functions **/ - -static jvmtiIterationControl JNICALL heap_object_callback - (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) -{ - char buffer[32]; - - if (*tag_ptr != 0) { - NSK_DISPLAY1("tag = %s\n", jlong_to_string(*tag_ptr, buffer)); - if (*tag_ptr == SAMPLE_TAG) { - ObjectsCount++; - } else { - NSK_COMPLAIN1("testedObject tagged incorrectly, expected=%s,", - jlong_to_string(SAMPLE_TAG, buffer)); - NSK_COMPLAIN1(" got=%s\n", jlong_to_string(*tag_ptr, buffer)); - nsk_jvmti_setFailStatus(); - } - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* ========================================================================== */ - -static int prepare(JNIEnv* jni) { - const char* CLASS_NAME = "nsk/jvmti/scenarios/multienv/MA04/ma04t002"; - const char* FIELD_NAME = "testedObject1"; - const char* FIELD_SIGNATURE = "Ljava/lang/Object;"; - const char* INSTANCE_NAME = "testedInstance1"; - const char* INSTANCE_SIGNATURE = "Lnsk/jvmti/scenarios/multienv/MA04/ma04t002;"; - jfieldID fid = NULL; - - NSK_DISPLAY0("Obtain tested object from a static field of debugee class\n"); - - NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) - return NSK_FALSE; - - NSK_DISPLAY2("Find field: %s:%s\n", FIELD_NAME, FIELD_SIGNATURE); - if (!NSK_JNI_VERIFY(jni, (fid = - NSK_CPP_STUB4(GetStaticFieldID, jni, testedClass, - FIELD_NAME, FIELD_SIGNATURE)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (testedObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, testedClass, fid)) != NULL)) - return NSK_FALSE; - - NSK_DISPLAY2("Find class instance: %s:%s\n", - INSTANCE_NAME, INSTANCE_SIGNATURE); - if (!NSK_JNI_VERIFY(jni, (fid = - NSK_CPP_STUB4(GetStaticFieldID, jni, testedClass, - INSTANCE_NAME, INSTANCE_SIGNATURE)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (testedInstance = - NSK_CPP_STUB3(GetStaticObjectField, jni, testedClass, fid)) != NULL)) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - jint dummy; - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!prepare(jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Testcase #1: check that there are no tagged objects\n"); - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 0) { - NSK_COMPLAIN1("Some objects were unexpectedly tagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 0) { - NSK_COMPLAIN1("Some objects were unexpectedly tagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 0) { - NSK_COMPLAIN1("Some class instances were unexpectedly tagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - testedClass, JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 0) { - NSK_COMPLAIN1("Some class instances were unexpectedly tagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, testedObject, - SAMPLE_TAG))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - - NSK_DISPLAY0("Testcase #2: check that there is only one object tagged\n"); - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 1) { - NSK_COMPLAIN1("Expected 1 object to be tagged: %d\n", ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 1) { - NSK_COMPLAIN1("Expected 1 object to be tagged: %d\n", ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_UNTAGGED, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 0) { - NSK_COMPLAIN1("Some tagged objects were unexpectedly shown as untagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, testedInstance, - SAMPLE_TAG))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - - NSK_DISPLAY0("Testcase #3: check that there is only one class object tagged\n"); - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 1) { - NSK_COMPLAIN1("Expected 1 class instance to be tagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 1) { - NSK_COMPLAIN1("Expected 1 class instance to be tagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_UNTAGGED, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 0) { - NSK_COMPLAIN1("Some tagged class instances were unexpectedly shown as untagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ma04t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ma04t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ma04t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiEventCallbacks callbacks; - jvmtiCapabilities caps; - - NSK_DISPLAY0("Agent_OnLoad\n"); - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - caps.can_generate_object_free_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - memset(&callbacks, 0, sizeof(callbacks)); - if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks))) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002.cpp new file mode 100644 index 00000000000..88319c1069f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002.cpp @@ -0,0 +1,353 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#define PASSED 0 +#define STATUS_FAILED 2 +#define SAMPLE_TAG ((jlong) 111111) + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* test objects */ +static jobject testedObject = NULL; +static jobject testedInstance = NULL; +static jclass testedClass = NULL; +static int ObjectsCount = 0; + +/* ========================================================================== */ + +/** callback functions **/ + +static jvmtiIterationControl JNICALL heap_object_callback + (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) +{ + char buffer[32]; + + if (*tag_ptr != 0) { + NSK_DISPLAY1("tag = %s\n", jlong_to_string(*tag_ptr, buffer)); + if (*tag_ptr == SAMPLE_TAG) { + ObjectsCount++; + } else { + NSK_COMPLAIN1("testedObject tagged incorrectly, expected=%s,", + jlong_to_string(SAMPLE_TAG, buffer)); + NSK_COMPLAIN1(" got=%s\n", jlong_to_string(*tag_ptr, buffer)); + nsk_jvmti_setFailStatus(); + } + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* ========================================================================== */ + +static int prepare(JNIEnv* jni) { + const char* CLASS_NAME = "nsk/jvmti/scenarios/multienv/MA04/ma04t002"; + const char* FIELD_NAME = "testedObject1"; + const char* FIELD_SIGNATURE = "Ljava/lang/Object;"; + const char* INSTANCE_NAME = "testedInstance1"; + const char* INSTANCE_SIGNATURE = "Lnsk/jvmti/scenarios/multienv/MA04/ma04t002;"; + jfieldID fid = NULL; + + NSK_DISPLAY0("Obtain tested object from a static field of debugee class\n"); + + NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (testedClass = + NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) + return NSK_FALSE; + + NSK_DISPLAY2("Find field: %s:%s\n", FIELD_NAME, FIELD_SIGNATURE); + if (!NSK_JNI_VERIFY(jni, (fid = + NSK_CPP_STUB4(GetStaticFieldID, jni, testedClass, + FIELD_NAME, FIELD_SIGNATURE)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (testedObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, testedClass, fid)) != NULL)) + return NSK_FALSE; + + NSK_DISPLAY2("Find class instance: %s:%s\n", + INSTANCE_NAME, INSTANCE_SIGNATURE); + if (!NSK_JNI_VERIFY(jni, (fid = + NSK_CPP_STUB4(GetStaticFieldID, jni, testedClass, + INSTANCE_NAME, INSTANCE_SIGNATURE)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (testedInstance = + NSK_CPP_STUB3(GetStaticObjectField, jni, testedClass, fid)) != NULL)) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + jint dummy; + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!prepare(jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Testcase #1: check that there are no tagged objects\n"); + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 0) { + NSK_COMPLAIN1("Some objects were unexpectedly tagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 0) { + NSK_COMPLAIN1("Some objects were unexpectedly tagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 0) { + NSK_COMPLAIN1("Some class instances were unexpectedly tagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + testedClass, JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 0) { + NSK_COMPLAIN1("Some class instances were unexpectedly tagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, testedObject, + SAMPLE_TAG))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + + NSK_DISPLAY0("Testcase #2: check that there is only one object tagged\n"); + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 1) { + NSK_COMPLAIN1("Expected 1 object to be tagged: %d\n", ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 1) { + NSK_COMPLAIN1("Expected 1 object to be tagged: %d\n", ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_UNTAGGED, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 0) { + NSK_COMPLAIN1("Some tagged objects were unexpectedly shown as untagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, testedInstance, + SAMPLE_TAG))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + + NSK_DISPLAY0("Testcase #3: check that there is only one class object tagged\n"); + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 1) { + NSK_COMPLAIN1("Expected 1 class instance to be tagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 1) { + NSK_COMPLAIN1("Expected 1 class instance to be tagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_UNTAGGED, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 0) { + NSK_COMPLAIN1("Some tagged class instances were unexpectedly shown as untagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ma04t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ma04t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ma04t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiEventCallbacks callbacks; + jvmtiCapabilities caps; + + NSK_DISPLAY0("Agent_OnLoad\n"); + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + caps.can_generate_object_free_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + memset(&callbacks, 0, sizeof(callbacks)); + if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks))) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002a.c deleted file mode 100644 index 61c2591240d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002a.c +++ /dev/null @@ -1,353 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#define PASSED 0 -#define STATUS_FAILED 2 -#define SAMPLE_TAG ((jlong) 222222) - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* test objects */ -static jobject testedObject = NULL; -static jobject testedInstance = NULL; -static jclass testedClass = NULL; -static int ObjectsCount = 0; - -/* ========================================================================== */ - -/** callback functions **/ - -static jvmtiIterationControl JNICALL heap_object_callback - (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) -{ - char buffer[32]; - - if (*tag_ptr != 0) { - NSK_DISPLAY1("tag = %s\n", jlong_to_string(*tag_ptr, buffer)); - if (*tag_ptr == SAMPLE_TAG) { - ObjectsCount++; - } else { - NSK_COMPLAIN1("testedObject tagged incorrectly, expected=%s,", - jlong_to_string(SAMPLE_TAG, buffer)); - NSK_COMPLAIN1(" got=%s\n", jlong_to_string(*tag_ptr, buffer)); - nsk_jvmti_setFailStatus(); - } - } - - return JVMTI_ITERATION_CONTINUE; -} - -/* ========================================================================== */ - -static int prepare(JNIEnv* jni) { - const char* CLASS_NAME = "nsk/jvmti/scenarios/multienv/MA04/ma04t002"; - const char* FIELD_NAME = "testedObject2"; - const char* FIELD_SIGNATURE = "Ljava/lang/Object;"; - const char* INSTANCE_NAME = "testedInstance2"; - const char* INSTANCE_SIGNATURE = "Lnsk/jvmti/scenarios/multienv/MA04/ma04t002;"; - jfieldID fid = NULL; - - NSK_DISPLAY0("Obtain tested object from a static field of debugee class\n"); - - NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) - return NSK_FALSE; - - NSK_DISPLAY2("Find field: %s:%s\n", FIELD_NAME, FIELD_SIGNATURE); - if (!NSK_JNI_VERIFY(jni, (fid = - NSK_CPP_STUB4(GetStaticFieldID, jni, testedClass, - FIELD_NAME, FIELD_SIGNATURE)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (testedObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, testedClass, fid)) != NULL)) - return NSK_FALSE; - - NSK_DISPLAY2("Find class instance: %s:%s\n", - INSTANCE_NAME, INSTANCE_SIGNATURE); - if (!NSK_JNI_VERIFY(jni, (fid = - NSK_CPP_STUB4(GetStaticFieldID, jni, testedClass, - INSTANCE_NAME, INSTANCE_SIGNATURE)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (testedInstance = - NSK_CPP_STUB3(GetStaticObjectField, jni, testedClass, fid)) != NULL)) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - jint dummy; - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!prepare(jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Testcase #1: check that there are no tagged objects\n"); - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 0) { - NSK_COMPLAIN1("Some objects were unexpectedly tagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 0) { - NSK_COMPLAIN1("Some objects were unexpectedly tagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 0) { - NSK_COMPLAIN1("Some class instances were unexpectedly tagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 0) { - NSK_COMPLAIN1("Some class instances were unexpectedly tagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, testedObject, - SAMPLE_TAG))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - - NSK_DISPLAY0("Testcase #2: check that there is only one object tagged\n"); - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 1) { - NSK_COMPLAIN1("Expected 1 object to be tagged: %d\n", ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 1) { - NSK_COMPLAIN1("Expected 1 object to be tagged: %d\n", ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_UNTAGGED, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 0) { - NSK_COMPLAIN1("Some tagged objects were unexpectedly shown as untagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, testedInstance, - SAMPLE_TAG))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - - - NSK_DISPLAY0("Testcase #3: check that there is only one class object tagged\n"); - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 1) { - NSK_COMPLAIN1("Expected 1 class instance to be tagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, - testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 1) { - NSK_COMPLAIN1("Expected 1 class instance to be tagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - ObjectsCount = 0; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, - JVMTI_HEAP_OBJECT_UNTAGGED, heap_object_callback, &dummy))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); - if (ObjectsCount != 0) { - NSK_COMPLAIN1("Some tagged class instances were unexpectedly shown as untagged: %d\n", - ObjectsCount); - nsk_jvmti_setFailStatus(); - } - - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ma04t002a(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ma04t002a(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ma04t002a(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiEventCallbacks callbacks; - jvmtiCapabilities caps; - - NSK_DISPLAY0("Agent_OnLoad\n"); - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - caps.can_generate_object_free_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - memset(&callbacks, 0, sizeof(callbacks)); - if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks))) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002a.cpp new file mode 100644 index 00000000000..6913563887f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002a.cpp @@ -0,0 +1,353 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#define PASSED 0 +#define STATUS_FAILED 2 +#define SAMPLE_TAG ((jlong) 222222) + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* test objects */ +static jobject testedObject = NULL; +static jobject testedInstance = NULL; +static jclass testedClass = NULL; +static int ObjectsCount = 0; + +/* ========================================================================== */ + +/** callback functions **/ + +static jvmtiIterationControl JNICALL heap_object_callback + (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) +{ + char buffer[32]; + + if (*tag_ptr != 0) { + NSK_DISPLAY1("tag = %s\n", jlong_to_string(*tag_ptr, buffer)); + if (*tag_ptr == SAMPLE_TAG) { + ObjectsCount++; + } else { + NSK_COMPLAIN1("testedObject tagged incorrectly, expected=%s,", + jlong_to_string(SAMPLE_TAG, buffer)); + NSK_COMPLAIN1(" got=%s\n", jlong_to_string(*tag_ptr, buffer)); + nsk_jvmti_setFailStatus(); + } + } + + return JVMTI_ITERATION_CONTINUE; +} + +/* ========================================================================== */ + +static int prepare(JNIEnv* jni) { + const char* CLASS_NAME = "nsk/jvmti/scenarios/multienv/MA04/ma04t002"; + const char* FIELD_NAME = "testedObject2"; + const char* FIELD_SIGNATURE = "Ljava/lang/Object;"; + const char* INSTANCE_NAME = "testedInstance2"; + const char* INSTANCE_SIGNATURE = "Lnsk/jvmti/scenarios/multienv/MA04/ma04t002;"; + jfieldID fid = NULL; + + NSK_DISPLAY0("Obtain tested object from a static field of debugee class\n"); + + NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (testedClass = + NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) + return NSK_FALSE; + + NSK_DISPLAY2("Find field: %s:%s\n", FIELD_NAME, FIELD_SIGNATURE); + if (!NSK_JNI_VERIFY(jni, (fid = + NSK_CPP_STUB4(GetStaticFieldID, jni, testedClass, + FIELD_NAME, FIELD_SIGNATURE)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (testedObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, testedClass, fid)) != NULL)) + return NSK_FALSE; + + NSK_DISPLAY2("Find class instance: %s:%s\n", + INSTANCE_NAME, INSTANCE_SIGNATURE); + if (!NSK_JNI_VERIFY(jni, (fid = + NSK_CPP_STUB4(GetStaticFieldID, jni, testedClass, + INSTANCE_NAME, INSTANCE_SIGNATURE)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (testedInstance = + NSK_CPP_STUB3(GetStaticObjectField, jni, testedClass, fid)) != NULL)) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + jint dummy; + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!prepare(jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Testcase #1: check that there are no tagged objects\n"); + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 0) { + NSK_COMPLAIN1("Some objects were unexpectedly tagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 0) { + NSK_COMPLAIN1("Some objects were unexpectedly tagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 0) { + NSK_COMPLAIN1("Some class instances were unexpectedly tagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 0) { + NSK_COMPLAIN1("Some class instances were unexpectedly tagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, testedObject, + SAMPLE_TAG))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + + NSK_DISPLAY0("Testcase #2: check that there is only one object tagged\n"); + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 1) { + NSK_COMPLAIN1("Expected 1 object to be tagged: %d\n", ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 1) { + NSK_COMPLAIN1("Expected 1 object to be tagged: %d\n", ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_UNTAGGED, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 0) { + NSK_COMPLAIN1("Some tagged objects were unexpectedly shown as untagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, testedInstance, + SAMPLE_TAG))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + + + NSK_DISPLAY0("Testcase #3: check that there is only one class object tagged\n"); + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 1) { + NSK_COMPLAIN1("Expected 1 class instance to be tagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti, + testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 1) { + NSK_COMPLAIN1("Expected 1 class instance to be tagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + ObjectsCount = 0; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti, + JVMTI_HEAP_OBJECT_UNTAGGED, heap_object_callback, &dummy))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount); + if (ObjectsCount != 0) { + NSK_COMPLAIN1("Some tagged class instances were unexpectedly shown as untagged: %d\n", + ObjectsCount); + nsk_jvmti_setFailStatus(); + } + + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ma04t002a(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ma04t002a(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ma04t002a(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiEventCallbacks callbacks; + jvmtiCapabilities caps; + + NSK_DISPLAY0("Agent_OnLoad\n"); + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + caps.can_generate_object_free_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + memset(&callbacks, 0, sizeof(callbacks)); + if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks))) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003.c deleted file mode 100644 index 3a4e0f4dddc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma04t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003.cpp new file mode 100644 index 00000000000..f68089439d8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma04t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003a.c deleted file mode 100644 index eeaf8b06331..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma04t003a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003a.cpp new file mode 100644 index 00000000000..fb60a7e784e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/libma04t003a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma04t003a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/ma04t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/ma04t003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/ma04t003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/ma04t003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/ma04t003a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/ma04t003a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/ma04t003a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t003/ma04t003a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001.c deleted file mode 100644 index 8fc6f900e65..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma05t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001.cpp new file mode 100644 index 00000000000..55a9e08f55e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma05t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001a.c deleted file mode 100644 index 01deb42560b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma05t001a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001a.cpp new file mode 100644 index 00000000000..49f32bfc7e8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/libma05t001a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma05t001a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/ma05t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/ma05t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/ma05t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/ma05t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/ma05t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/ma05t001a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/ma05t001a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA05/ma05t001/ma05t001a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001.c deleted file mode 100644 index e507fb1167e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma06t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001.cpp new file mode 100644 index 00000000000..d33ad8b7190 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma06t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001a.c deleted file mode 100644 index a798bbe79b0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma06t001a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001a.cpp new file mode 100644 index 00000000000..1af18370645 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/libma06t001a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma06t001a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001.c deleted file mode 100644 index 80c1d7be807..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#define PASSED 0 -#define STATUS_FAILED 2 - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* test objects */ -static jclass testedClass = NULL; -static jint klass_byte_count = 0; -static unsigned char *klass_bytes = NULL; -static int magicIndex = 0; -static int ClassFileLoadHookEventFlag = NSK_FALSE; - -const char* CLASS_NAME = "nsk/jvmti/scenarios/multienv/MA06/ma06t001a"; -static const jint magicNumber = 0x12345678; - -/* ========================================================================== */ - -/** callback functions **/ - -static void JNICALL -ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jclass class_being_redefined, jobject loader, - const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - jint i; - - if (name != NULL && (strcmp(name, CLASS_NAME) == 0)) { - ClassFileLoadHookEventFlag = NSK_TRUE; - NSK_DISPLAY0("ClassFileLoadHook event\n"); - - if (class_being_redefined == NULL) { - /* sent by class load */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, - jvmti_env, class_data_len, &klass_bytes))) - nsk_jvmti_setFailStatus(); - else { - memcpy(klass_bytes, class_data, class_data_len); - klass_byte_count = class_data_len; - for (i = 0; i < klass_byte_count - 3; i++) { - if (((jint)klass_bytes[i+3] | - ((jint)klass_bytes[i+2] << 8) | - ((jint)klass_bytes[i+1] << 16) | - ((jint)klass_bytes[i] << 24)) == magicNumber) { - magicIndex = i; - break; - } - } - if (klass_byte_count == 0) { - NSK_COMPLAIN0("Cannot find magic number\n"); - nsk_jvmti_setFailStatus(); - } - } - } - } -} - -/* ========================================================================== */ - -static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { - - NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -static int redefine(jvmtiEnv* jvmti, jint value) { - jvmtiClassDefinition class_def; - - if (!NSK_VERIFY(klass_byte_count != 0 && klass_bytes != NULL)) - return NSK_FALSE; - - if (!NSK_VERIFY(magicIndex != 0)) - return NSK_FALSE; - - NSK_DISPLAY1("Redefining with %d\n", value); - - klass_bytes[magicIndex] = 0; - klass_bytes[magicIndex+1] = 0; - klass_bytes[magicIndex+2] = 0; - klass_bytes[magicIndex+3] = (jbyte)value; - - class_def.klass = testedClass; - class_def.class_byte_count = klass_byte_count; - class_def.class_bytes = klass_bytes; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &class_def))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { - NSK_COMPLAIN0("Missing initial ClassFileLoadHook event\n"); - nsk_jvmti_setFailStatus(); - return; - } - - ClassFileLoadHookEventFlag = NSK_FALSE; - - if (!prepare(jvmti, jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - if (!redefine(jvmti, 1)) - nsk_jvmti_setFailStatus(); - - /* resume debugee and wait for sync */ - if (!nsk_jvmti_resumeSync()) - return; - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { - NSK_COMPLAIN0("Missing ClassFileLoadHook event #1\n"); - nsk_jvmti_setFailStatus(); - } - - ClassFileLoadHookEventFlag = NSK_FALSE; - - /* resume debugee and wait for sync */ - if (!nsk_jvmti_resumeSync()) - return; - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { - NSK_COMPLAIN0("Missing ClassFileLoadHook event #3\n"); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) - nsk_jvmti_setFailStatus(); - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ma06t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ma06t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ma06t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiEventCallbacks callbacks; - jvmtiCapabilities caps; - - NSK_DISPLAY0("Agent_OnLoad\n"); - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks))) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001.cpp new file mode 100644 index 00000000000..9f8f8d1383b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001.cpp @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#define PASSED 0 +#define STATUS_FAILED 2 + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* test objects */ +static jclass testedClass = NULL; +static jint klass_byte_count = 0; +static unsigned char *klass_bytes = NULL; +static int magicIndex = 0; +static int ClassFileLoadHookEventFlag = NSK_FALSE; + +const char* CLASS_NAME = "nsk/jvmti/scenarios/multienv/MA06/ma06t001a"; +static const jint magicNumber = 0x12345678; + +/* ========================================================================== */ + +/** callback functions **/ + +static void JNICALL +ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jclass class_being_redefined, jobject loader, + const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + jint i; + + if (name != NULL && (strcmp(name, CLASS_NAME) == 0)) { + ClassFileLoadHookEventFlag = NSK_TRUE; + NSK_DISPLAY0("ClassFileLoadHook event\n"); + + if (class_being_redefined == NULL) { + /* sent by class load */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, + jvmti_env, class_data_len, &klass_bytes))) + nsk_jvmti_setFailStatus(); + else { + memcpy(klass_bytes, class_data, class_data_len); + klass_byte_count = class_data_len; + for (i = 0; i < klass_byte_count - 3; i++) { + if (((jint)klass_bytes[i+3] | + ((jint)klass_bytes[i+2] << 8) | + ((jint)klass_bytes[i+1] << 16) | + ((jint)klass_bytes[i] << 24)) == magicNumber) { + magicIndex = i; + break; + } + } + if (klass_byte_count == 0) { + NSK_COMPLAIN0("Cannot find magic number\n"); + nsk_jvmti_setFailStatus(); + } + } + } + } +} + +/* ========================================================================== */ + +static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { + + NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (testedClass = + NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +static int redefine(jvmtiEnv* jvmti, jint value) { + jvmtiClassDefinition class_def; + + if (!NSK_VERIFY(klass_byte_count != 0 && klass_bytes != NULL)) + return NSK_FALSE; + + if (!NSK_VERIFY(magicIndex != 0)) + return NSK_FALSE; + + NSK_DISPLAY1("Redefining with %d\n", value); + + klass_bytes[magicIndex] = 0; + klass_bytes[magicIndex+1] = 0; + klass_bytes[magicIndex+2] = 0; + klass_bytes[magicIndex+3] = (jbyte)value; + + class_def.klass = testedClass; + class_def.class_byte_count = klass_byte_count; + class_def.class_bytes = klass_bytes; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &class_def))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { + NSK_COMPLAIN0("Missing initial ClassFileLoadHook event\n"); + nsk_jvmti_setFailStatus(); + return; + } + + ClassFileLoadHookEventFlag = NSK_FALSE; + + if (!prepare(jvmti, jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + if (!redefine(jvmti, 1)) + nsk_jvmti_setFailStatus(); + + /* resume debugee and wait for sync */ + if (!nsk_jvmti_resumeSync()) + return; + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { + NSK_COMPLAIN0("Missing ClassFileLoadHook event #1\n"); + nsk_jvmti_setFailStatus(); + } + + ClassFileLoadHookEventFlag = NSK_FALSE; + + /* resume debugee and wait for sync */ + if (!nsk_jvmti_resumeSync()) + return; + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { + NSK_COMPLAIN0("Missing ClassFileLoadHook event #3\n"); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) + nsk_jvmti_setFailStatus(); + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ma06t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ma06t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ma06t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiEventCallbacks callbacks; + jvmtiCapabilities caps; + + NSK_DISPLAY0("Agent_OnLoad\n"); + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks))) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001a.c deleted file mode 100644 index fd4993443a8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001a.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#define PASSED 0 -#define STATUS_FAILED 2 - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* test objects */ -static jclass testedClass = NULL; -static jint klass_byte_count = 0; -static unsigned char *klass_bytes = NULL; -static int magicIndex = 0; -static int ClassFileLoadHookEventFlag = NSK_FALSE; - -const char* CLASS_NAME = "nsk/jvmti/scenarios/multienv/MA06/ma06t001a"; -static const jint magicNumber = 0x12345678; - -/* ========================================================================== */ - -/** callback functions **/ - -static void JNICALL -ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jclass class_being_redefined, jobject loader, - const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - jint i; - - if (name != NULL && (strcmp(name, CLASS_NAME) == 0)) { - ClassFileLoadHookEventFlag = NSK_TRUE; - NSK_DISPLAY0("ClassFileLoadHook event\n"); - - if (class_being_redefined == NULL) { - /* sent by class load */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, - jvmti_env, class_data_len, &klass_bytes))) - nsk_jvmti_setFailStatus(); - else { - memcpy(klass_bytes, class_data, class_data_len); - klass_byte_count = class_data_len; - for (i = 0; i < klass_byte_count - 3; i++) { - if (((jint)klass_bytes[i+3] | - ((jint)klass_bytes[i+2] << 8) | - ((jint)klass_bytes[i+1] << 16) | - ((jint)klass_bytes[i] << 24)) == magicNumber) { - magicIndex = i; - break; - } - } - if (klass_byte_count == 0) { - NSK_COMPLAIN0("Cannot find magic number\n"); - nsk_jvmti_setFailStatus(); - } - } - } - } -} - -/* ========================================================================== */ - -static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { - - NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (testedClass = - NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -static int redefine(jvmtiEnv* jvmti, jint value) { - jvmtiClassDefinition class_def; - - if (!NSK_VERIFY(klass_byte_count != 0 && klass_bytes != NULL)) - return NSK_FALSE; - - if (!NSK_VERIFY(magicIndex != 0)) - return NSK_FALSE; - - NSK_DISPLAY1("Redefining with %d\n", value); - - klass_bytes[magicIndex] = 0; - klass_bytes[magicIndex+1] = 0; - klass_bytes[magicIndex+2] = 0; - klass_bytes[magicIndex+3] = (jbyte)value; - - class_def.klass = testedClass; - class_def.class_byte_count = klass_byte_count; - class_def.class_bytes = klass_bytes; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &class_def))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { - NSK_COMPLAIN0("Missing initial ClassFileLoadHook event\n"); - nsk_jvmti_setFailStatus(); - return; - } - - ClassFileLoadHookEventFlag = NSK_FALSE; - - if (!prepare(jvmti, jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* resume debugee and wait for sync */ - if (!nsk_jvmti_resumeSync()) - return; - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { - NSK_COMPLAIN0("Missing ClassFileLoadHook event #1\n"); - nsk_jvmti_setFailStatus(); - } - - ClassFileLoadHookEventFlag = NSK_FALSE; - - /* resume debugee and wait for sync */ - if (!nsk_jvmti_resumeSync()) - return; - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!redefine(jvmti, 2)) - nsk_jvmti_setFailStatus(); - - if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { - NSK_COMPLAIN0("Missing ClassFileLoadHook event #3\n"); - nsk_jvmti_setFailStatus(); - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) - nsk_jvmti_setFailStatus(); - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ma06t001a(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ma06t001a(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ma06t001a(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiEventCallbacks callbacks; - jvmtiCapabilities caps; - - NSK_DISPLAY0("Agent_OnLoad\n"); - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks))) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001a.cpp new file mode 100644 index 00000000000..5cb39669d97 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA06/ma06t001/ma06t001a.cpp @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#define PASSED 0 +#define STATUS_FAILED 2 + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* test objects */ +static jclass testedClass = NULL; +static jint klass_byte_count = 0; +static unsigned char *klass_bytes = NULL; +static int magicIndex = 0; +static int ClassFileLoadHookEventFlag = NSK_FALSE; + +const char* CLASS_NAME = "nsk/jvmti/scenarios/multienv/MA06/ma06t001a"; +static const jint magicNumber = 0x12345678; + +/* ========================================================================== */ + +/** callback functions **/ + +static void JNICALL +ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jclass class_being_redefined, jobject loader, + const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + jint i; + + if (name != NULL && (strcmp(name, CLASS_NAME) == 0)) { + ClassFileLoadHookEventFlag = NSK_TRUE; + NSK_DISPLAY0("ClassFileLoadHook event\n"); + + if (class_being_redefined == NULL) { + /* sent by class load */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, + jvmti_env, class_data_len, &klass_bytes))) + nsk_jvmti_setFailStatus(); + else { + memcpy(klass_bytes, class_data, class_data_len); + klass_byte_count = class_data_len; + for (i = 0; i < klass_byte_count - 3; i++) { + if (((jint)klass_bytes[i+3] | + ((jint)klass_bytes[i+2] << 8) | + ((jint)klass_bytes[i+1] << 16) | + ((jint)klass_bytes[i] << 24)) == magicNumber) { + magicIndex = i; + break; + } + } + if (klass_byte_count == 0) { + NSK_COMPLAIN0("Cannot find magic number\n"); + nsk_jvmti_setFailStatus(); + } + } + } + } +} + +/* ========================================================================== */ + +static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { + + NSK_DISPLAY1("Find class: %s\n", CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (testedClass = + NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL)) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +static int redefine(jvmtiEnv* jvmti, jint value) { + jvmtiClassDefinition class_def; + + if (!NSK_VERIFY(klass_byte_count != 0 && klass_bytes != NULL)) + return NSK_FALSE; + + if (!NSK_VERIFY(magicIndex != 0)) + return NSK_FALSE; + + NSK_DISPLAY1("Redefining with %d\n", value); + + klass_bytes[magicIndex] = 0; + klass_bytes[magicIndex+1] = 0; + klass_bytes[magicIndex+2] = 0; + klass_bytes[magicIndex+3] = (jbyte)value; + + class_def.klass = testedClass; + class_def.class_byte_count = klass_byte_count; + class_def.class_bytes = klass_bytes; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, jvmti, 1, &class_def))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { + NSK_COMPLAIN0("Missing initial ClassFileLoadHook event\n"); + nsk_jvmti_setFailStatus(); + return; + } + + ClassFileLoadHookEventFlag = NSK_FALSE; + + if (!prepare(jvmti, jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* resume debugee and wait for sync */ + if (!nsk_jvmti_resumeSync()) + return; + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { + NSK_COMPLAIN0("Missing ClassFileLoadHook event #1\n"); + nsk_jvmti_setFailStatus(); + } + + ClassFileLoadHookEventFlag = NSK_FALSE; + + /* resume debugee and wait for sync */ + if (!nsk_jvmti_resumeSync()) + return; + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!redefine(jvmti, 2)) + nsk_jvmti_setFailStatus(); + + if (!NSK_VERIFY(ClassFileLoadHookEventFlag)) { + NSK_COMPLAIN0("Missing ClassFileLoadHook event #3\n"); + nsk_jvmti_setFailStatus(); + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) + nsk_jvmti_setFailStatus(); + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass)); + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ma06t001a(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ma06t001a(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ma06t001a(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiEventCallbacks callbacks; + jvmtiCapabilities caps; + + NSK_DISPLAY0("Agent_OnLoad\n"); + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks))) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001.c deleted file mode 100644 index b70da794f12..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma07t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001.cpp new file mode 100644 index 00000000000..ab712ffa5e6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma07t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001a.c deleted file mode 100644 index a8ff1879fbb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma07t001a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001a.cpp new file mode 100644 index 00000000000..9ee5b1dae38 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/libma07t001a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma07t001a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/ma07t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/ma07t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/ma07t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/ma07t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/ma07t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/ma07t001a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/ma07t001a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA07/ma07t001/ma07t001a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001.c deleted file mode 100644 index f49ef7b7db5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma08t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001.cpp new file mode 100644 index 00000000000..09db14e669e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma08t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001a.c deleted file mode 100644 index 0ab9b2a6480..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma08t001a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001a.cpp new file mode 100644 index 00000000000..3f699467cf9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/libma08t001a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma08t001a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/ma08t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/ma08t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/ma08t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/ma08t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/ma08t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/ma08t001a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/ma08t001a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/ma08t001a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001.c deleted file mode 100644 index 24c6ab6e0e0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001.cpp new file mode 100644 index 00000000000..e6f34aa30b8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001a.c deleted file mode 100644 index 49d29eec1f6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t001a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001a.cpp new file mode 100644 index 00000000000..dca1cb5efdd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/libma10t001a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t001a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/ma10t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/ma10t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/ma10t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/ma10t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/ma10t001a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/ma10t001a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/ma10t001a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t001/ma10t001a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002.c deleted file mode 100644 index 65978af649d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002.cpp new file mode 100644 index 00000000000..31dfda2fe8f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002a.c deleted file mode 100644 index 571fe349e42..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t002a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002a.cpp new file mode 100644 index 00000000000..583ebe037ae --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/libma10t002a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t002a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/ma10t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/ma10t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/ma10t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/ma10t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/ma10t002a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/ma10t002a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/ma10t002a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/ma10t002a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003.c deleted file mode 100644 index da656e33e6c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003.cpp new file mode 100644 index 00000000000..ca0cba60e2f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003a.c deleted file mode 100644 index 476b8b014f0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t003a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003a.cpp new file mode 100644 index 00000000000..5523e9423fe --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/libma10t003a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t003a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/ma10t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/ma10t003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/ma10t003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/ma10t003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/ma10t003a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/ma10t003a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/ma10t003a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t003/ma10t003a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004.c deleted file mode 100644 index ccded8a015f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004.cpp new file mode 100644 index 00000000000..34890a33877 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004a.c deleted file mode 100644 index d0fbe6e36d5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t004a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004a.cpp new file mode 100644 index 00000000000..a55984172d5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/libma10t004a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t004a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/ma10t004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/ma10t004.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/ma10t004.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/ma10t004.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/ma10t004a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/ma10t004a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/ma10t004a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t004/ma10t004a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005.c deleted file mode 100644 index c1449767aea..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005.cpp new file mode 100644 index 00000000000..cf8aab4bdad --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005a.c deleted file mode 100644 index 11a2e74905e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t005a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005a.cpp new file mode 100644 index 00000000000..1b70a38d170 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/libma10t005a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t005a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/ma10t005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/ma10t005.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/ma10t005.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/ma10t005.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/ma10t005a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/ma10t005a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/ma10t005a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t005/ma10t005a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006.c deleted file mode 100644 index 0ad240dc7c1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006.cpp new file mode 100644 index 00000000000..d121269bdb1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006a.c deleted file mode 100644 index 43ecdd03530..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t006a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006a.cpp new file mode 100644 index 00000000000..8784672c682 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/libma10t006a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t006a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006.c deleted file mode 100644 index bf7c5f09dac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#define PASSED 0 -#define STATUS_FAILED 2 - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* event counts */ -static int CompiledMethodLoadEventsCount = 0; -static int CompiledMethodUnloadEventsCount = 0; - -/* ========================================================================== */ - -/** callback functions **/ - -static void JNICALL -CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, - jint code_size, const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - char *name = NULL; - char *signature = NULL; - - CompiledMethodLoadEventsCount++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &name, &signature, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY3("CompiledMethodLoad event: %s%s (0x%p)\n", - name, signature, code_addr); - if (name != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - if (signature != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); -} - -static void JNICALL -CompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - char *name = NULL; - char *sig = NULL; - jvmtiError err; - CompiledMethodUnloadEventsCount++; - - NSK_DISPLAY0("CompiledMethodUnload event received\n"); - // Check for the case that the class has been unloaded - err = (*jvmti_env)->GetMethodName(jvmti_env, method, &name, &sig, NULL); - if (err == JVMTI_ERROR_NONE) { - NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", - name, sig, code_addr); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); - } -} - -/* ========================================================================== */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY1("CompiledMethodLoad events received: %d\n", - CompiledMethodLoadEventsCount); - if (CompiledMethodLoadEventsCount == 0) { - NSK_DISPLAY0("# WARNING: no CompiledMethodLoad events\n"); - NSK_DISPLAY0("# (VM might not compile any methods at all)\n"); - } - - NSK_DISPLAY1("CompiledMethodUnload events received: %d\n", - CompiledMethodUnloadEventsCount); - if (CompiledMethodUnloadEventsCount == 0) { - NSK_DISPLAY0("# WARNING: no CompiledMethodUnload events\n"); - NSK_DISPLAY0("# (VM might not compile any methods at all)\n"); - } - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ma10t006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ma10t006(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ma10t006(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiCapabilities caps; - jvmtiEventCallbacks callbacks; - - NSK_DISPLAY0("Agent_OnLoad\n"); - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_compiled_method_load_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.CompiledMethodLoad = &CompiledMethodLoad; - callbacks.CompiledMethodUnload = &CompiledMethodUnload; - if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks))) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_UNLOAD, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006.cpp new file mode 100644 index 00000000000..8fd45bea33d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#define PASSED 0 +#define STATUS_FAILED 2 + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* event counts */ +static int CompiledMethodLoadEventsCount = 0; +static int CompiledMethodUnloadEventsCount = 0; + +/* ========================================================================== */ + +/** callback functions **/ + +static void JNICALL +CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, + jint code_size, const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + char *name = NULL; + char *signature = NULL; + + CompiledMethodLoadEventsCount++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &name, &signature, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY3("CompiledMethodLoad event: %s%s (0x%p)\n", + name, signature, code_addr); + if (name != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + if (signature != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); +} + +static void JNICALL +CompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + char *name = NULL; + char *sig = NULL; + jvmtiError err; + CompiledMethodUnloadEventsCount++; + + NSK_DISPLAY0("CompiledMethodUnload event received\n"); + // Check for the case that the class has been unloaded + err = jvmti_env->GetMethodName(method, &name, &sig, NULL); + if (err == JVMTI_ERROR_NONE) { + NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", + name, sig, code_addr); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); + } +} + +/* ========================================================================== */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY1("CompiledMethodLoad events received: %d\n", + CompiledMethodLoadEventsCount); + if (CompiledMethodLoadEventsCount == 0) { + NSK_DISPLAY0("# WARNING: no CompiledMethodLoad events\n"); + NSK_DISPLAY0("# (VM might not compile any methods at all)\n"); + } + + NSK_DISPLAY1("CompiledMethodUnload events received: %d\n", + CompiledMethodUnloadEventsCount); + if (CompiledMethodUnloadEventsCount == 0) { + NSK_DISPLAY0("# WARNING: no CompiledMethodUnload events\n"); + NSK_DISPLAY0("# (VM might not compile any methods at all)\n"); + } + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ma10t006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ma10t006(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ma10t006(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiCapabilities caps; + jvmtiEventCallbacks callbacks; + + NSK_DISPLAY0("Agent_OnLoad\n"); + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_compiled_method_load_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.CompiledMethodLoad = &CompiledMethodLoad; + callbacks.CompiledMethodUnload = &CompiledMethodUnload; + if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks))) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_UNLOAD, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006a.c deleted file mode 100644 index 0088c3c51b4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006a.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "agent_common.h" -#include "jvmti_tools.h" - -#define PASSED 0 -#define STATUS_FAILED 2 - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -/* scaffold objects */ -static jlong timeout = 0; - -/* event counts */ -static int CompiledMethodLoadEventsCount = 0; -static int CompiledMethodUnloadEventsCount = 0; - -/* ========================================================================== */ - -/** callback functions **/ - -static void JNICALL -CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, - jint code_size, const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - char *name = NULL; - char *signature = NULL; - - CompiledMethodLoadEventsCount++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &name, &signature, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY3("CompiledMethodLoad event: %s%s (0x%p)\n", - name, signature, code_addr); - if (name != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - if (signature != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); -} - -static void JNICALL -CompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - char *name = NULL; - char *sig = NULL; - jvmtiError err; - - CompiledMethodUnloadEventsCount++; - - NSK_DISPLAY0("CompiledMethodUnload event received\n"); - // Check for the case that the class has been unloaded - err = (*jvmti_env)->GetMethodName(jvmti_env, method, &name, &sig, NULL); - if (err == JVMTI_ERROR_NONE) { - NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", - name, sig, code_addr); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); - } -} - -/* ========================================================================== */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - NSK_DISPLAY1("CompiledMethodLoad events received: %d\n", - CompiledMethodLoadEventsCount); - if (!NSK_VERIFY(CompiledMethodLoadEventsCount == 0)) - nsk_jvmti_setFailStatus(); - - NSK_DISPLAY1("CompiledMethodUnload events received: %d\n", - CompiledMethodUnloadEventsCount); - if (!NSK_VERIFY(CompiledMethodUnloadEventsCount == 0)) - nsk_jvmti_setFailStatus(); - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_ma10t006a(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_ma10t006a(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_ma10t006a(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiCapabilities caps; - jvmtiEventCallbacks callbacks; - - NSK_DISPLAY0("Agent_OnLoad\n"); - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_compiled_method_load_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.CompiledMethodLoad = &CompiledMethodLoad; - callbacks.CompiledMethodUnload = &CompiledMethodUnload; - if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006a.cpp new file mode 100644 index 00000000000..fae3294af7b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006a.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "agent_common.h" +#include "jvmti_tools.h" + +#define PASSED 0 +#define STATUS_FAILED 2 + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +/* scaffold objects */ +static jlong timeout = 0; + +/* event counts */ +static int CompiledMethodLoadEventsCount = 0; +static int CompiledMethodUnloadEventsCount = 0; + +/* ========================================================================== */ + +/** callback functions **/ + +static void JNICALL +CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, + jint code_size, const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + char *name = NULL; + char *signature = NULL; + + CompiledMethodLoadEventsCount++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &name, &signature, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY3("CompiledMethodLoad event: %s%s (0x%p)\n", + name, signature, code_addr); + if (name != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + if (signature != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); +} + +static void JNICALL +CompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + char *name = NULL; + char *sig = NULL; + jvmtiError err; + + CompiledMethodUnloadEventsCount++; + + NSK_DISPLAY0("CompiledMethodUnload event received\n"); + // Check for the case that the class has been unloaded + err = jvmti_env->GetMethodName(method, &name, &sig, NULL); + if (err == JVMTI_ERROR_NONE) { + NSK_DISPLAY3("for: \tmethod: name=\"%s\" signature=\"%s\"\n\tnative address=0x%p\n", + name, sig, code_addr); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); + } +} + +/* ========================================================================== */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + NSK_DISPLAY1("CompiledMethodLoad events received: %d\n", + CompiledMethodLoadEventsCount); + if (!NSK_VERIFY(CompiledMethodLoadEventsCount == 0)) + nsk_jvmti_setFailStatus(); + + NSK_DISPLAY1("CompiledMethodUnload events received: %d\n", + CompiledMethodUnloadEventsCount); + if (!NSK_VERIFY(CompiledMethodUnloadEventsCount == 0)) + nsk_jvmti_setFailStatus(); + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_ma10t006a(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_ma10t006a(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_ma10t006a(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiCapabilities caps; + jvmtiEventCallbacks callbacks; + + NSK_DISPLAY0("Agent_OnLoad\n"); + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_compiled_method_load_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.CompiledMethodLoad = &CompiledMethodLoad; + callbacks.CompiledMethodUnload = &CompiledMethodUnload; + if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007.c deleted file mode 100644 index 664e7474642..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t007.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007.cpp new file mode 100644 index 00000000000..7a8db44e4fa --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t007.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007a.c deleted file mode 100644 index bd45d121bf0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t007a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007a.cpp new file mode 100644 index 00000000000..16542b6a221 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/libma10t007a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t007a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/ma10t007.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/ma10t007.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/ma10t007.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/ma10t007.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/ma10t007a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/ma10t007a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/ma10t007a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t007/ma10t007a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008.c deleted file mode 100644 index 56cbbfae7e7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t008.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008.cpp new file mode 100644 index 00000000000..9ea41aee3a5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t008.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008a.c deleted file mode 100644 index e11752173fa..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008a.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "ma10t008a.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008a.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008a.cpp new file mode 100644 index 00000000000..d4f6a45add5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/libma10t008a.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "ma10t008a.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/ma10t008.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/ma10t008.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/ma10t008.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/ma10t008.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/ma10t008a.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/ma10t008a.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/ma10t008a.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t008/ma10t008a.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/libsp01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/libsp01t001.c deleted file mode 100644 index 4beedf067fc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/libsp01t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp01t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/libsp01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/libsp01t001.cpp new file mode 100644 index 00000000000..275e6a68c13 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/libsp01t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp01t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/sp01t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/sp01t001.c deleted file mode 100644 index a74cd2787f6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/sp01t001.c +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -/* ============================================================================= */ - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/scenarios/sampling/SP01/sp01t001" -#define THREAD_CLASS_NAME "nsk/jvmti/scenarios/sampling/SP01/sp01t001Thread" -#define THREADS_FIELD_NAME "threads" -#define THREADS_FIELD_SIG "[L"THREAD_CLASS_NAME";" - -/* scaffold objects */ -static JNIEnv* jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; - -/* number of tested threads */ -#define THREADS_COUNT 2 - -/* names of tested threads */ -static const char* threadsName[THREADS_COUNT] = { - "NotStarted", - "Finished" -}; - -#define JVMTI_THREAD_STATE_NOT_STARTED 0 -/* expected states of tested threads */ -static jint threadsState[THREADS_COUNT] = { - JVMTI_THREAD_STATE_NOT_STARTED, /* JVMTI_THREAD_STATUS_NOT_STARTED */ - JVMTI_THREAD_STATE_TERMINATED /* JVMTI_THREAD_STATUS_ZOMBIE */ -}; - -/* references to tested threads */ -static jthread threadsList[THREADS_COUNT]; - -/* ============================================================================= */ - -/* testcase(s) */ -static int prepare(); -static int checkThreads(const char* kind); -static int clean(); - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - jni = agentJNI; - - /* wait for initial sync */ - if (!nsk_jvmti_waitForSync(timeout)) - return; - - /* perform testcase(s) */ - { - /* obtain threads list */ - if (!prepare()) { - nsk_jvmti_setFailStatus(); - return; - } - - /* testcase #1: check not alive threads */ - NSK_DISPLAY0("Testcase #1: check state of not alive threads\n"); - if (!checkThreads("not alive")) - return; - - /* clean threads references */ - if (!clean()) { - nsk_jvmti_setFailStatus(); - return; - } - } - - /* resume debugee after last sync */ - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ============================================================================= */ - -/** - * Prepare data: - * - get threads array from static field - * - get each thread from array - * - make global refs - */ -static int prepare() { - jclass debugeeClass = NULL; - jfieldID threadsFieldID = NULL; - jobjectArray threadsArray = NULL; - jsize threadsArrayLength = 0; - jsize i; - - /* find debugee class */ - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) - return NSK_FALSE; - - /* find static field with threads array */ - if (!NSK_JNI_VERIFY(jni, (threadsFieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - THREADS_FIELD_NAME, THREADS_FIELD_SIG)) != NULL)) - return NSK_FALSE; - - /* get threads array from static field */ - if (!NSK_JNI_VERIFY(jni, (threadsArray = (jobjectArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, threadsFieldID)) != NULL)) - return NSK_FALSE; - - /* check array length */ - if (!NSK_JNI_VERIFY(jni, (threadsArrayLength = - NSK_CPP_STUB2(GetArrayLength, jni, threadsArray)) == THREADS_COUNT)) - return NSK_FALSE; - - /* get each thread from array */ - for (i = 0; i < THREADS_COUNT; i++) { - if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread) - NSK_CPP_STUB3(GetObjectArrayElement, jni, threadsArray, i)) != NULL)) - return NSK_FALSE; - } - - /* make global references to threads */ - for (i = 0; i < THREADS_COUNT; i++) { - if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread) - NSK_CPP_STUB2(NewGlobalRef, jni, threadsList[i])) != NULL)) - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/** - * Testcase: check threads state for given suspension - * - * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. - */ -static int checkThreads(const char* kind) { - int i; - - /* check each thread */ - for (i = 0; i < THREADS_COUNT; i++) { - jthread thread = threadsList[i]; - jint state = JVMTI_THREAD_STATE_NOT_STARTED; - - NSK_DISPLAY2(" thread #%d (%s):\n", i, threadsName[i]); - - /* get thread state */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetThreadState, jvmti, threadsList[i], &state))) { - nsk_jvmti_setFailStatus(); - return NSK_TRUE; - } - - /* display thread state */ - NSK_DISPLAY2(" state=%s (%d)\n", - TranslateState(state), (int)state); - - /* check thread state */ - if ((state & threadsState[i]) == 0) { - if (state == JVMTI_THREAD_STATE_NOT_STARTED) { - NSK_DISPLAY1("state of thread #%d is NOT_STARTED\n", kind); - } else { - NSK_COMPLAIN7("Unexpected state of %s thread #%d (%s):\n" - "# got: %s (%d), expected: %s (%d)\n", - kind, i, threadsName[i], - TranslateState(state), (int)state, - TranslateState(threadsState[i]), (int)threadsState[i]); - nsk_jvmti_setFailStatus(); - } - } - - /* check SUSPENDED state flag */ - if (state & JVMTI_THREAD_STATE_SUSPENDED) { - NSK_COMPLAIN3("Unexpected SUSPENDED state flag for %s thread #%d: %d\n", - kind, i, (int)state); - nsk_jvmti_setFailStatus(); - } - - /* check INTERRUPTED state flag */ - if (state & JVMTI_THREAD_STATE_INTERRUPTED) { - NSK_COMPLAIN3("Unexpected INTERRUPTED state flag for %s thread #%d: %d\n", - kind, i, (int)state); - nsk_jvmti_setFailStatus(); - } - - /* check NATIVE state flag */ - if (state & JVMTI_THREAD_STATE_IN_NATIVE) { - NSK_COMPLAIN3("Unexpected NATIVE state flag for %s thread #%d: %d\n", - kind, i, (int)state); - nsk_jvmti_setFailStatus(); - } - } - - /* test may continue */ - return NSK_TRUE; -} - -/** - * Clean data: - * - dispose global references to tested threads - */ -static int clean() { - int i; - - /* dispose global references to threads */ - for (i = 0; i < THREADS_COUNT; i++) { - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, threadsList[i])); - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_sp01t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_sp01t001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_sp01t001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/sp01t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/sp01t001.cpp new file mode 100644 index 00000000000..ade2996dfe4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t001/sp01t001.cpp @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ============================================================================= */ + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/scenarios/sampling/SP01/sp01t001" +#define THREAD_CLASS_NAME "nsk/jvmti/scenarios/sampling/SP01/sp01t001Thread" +#define THREADS_FIELD_NAME "threads" +#define THREADS_FIELD_SIG "[L" THREAD_CLASS_NAME ";" + +/* scaffold objects */ +static JNIEnv* jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; + +/* number of tested threads */ +#define THREADS_COUNT 2 + +/* names of tested threads */ +static const char* threadsName[THREADS_COUNT] = { + "NotStarted", + "Finished" +}; + +#define JVMTI_THREAD_STATE_NOT_STARTED 0 +/* expected states of tested threads */ +static jint threadsState[THREADS_COUNT] = { + JVMTI_THREAD_STATE_NOT_STARTED, /* JVMTI_THREAD_STATUS_NOT_STARTED */ + JVMTI_THREAD_STATE_TERMINATED /* JVMTI_THREAD_STATUS_ZOMBIE */ +}; + +/* references to tested threads */ +static jthread threadsList[THREADS_COUNT]; + +/* ============================================================================= */ + +/* testcase(s) */ +static int prepare(); +static int checkThreads(const char* kind); +static int clean(); + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + jni = agentJNI; + + /* wait for initial sync */ + if (!nsk_jvmti_waitForSync(timeout)) + return; + + /* perform testcase(s) */ + { + /* obtain threads list */ + if (!prepare()) { + nsk_jvmti_setFailStatus(); + return; + } + + /* testcase #1: check not alive threads */ + NSK_DISPLAY0("Testcase #1: check state of not alive threads\n"); + if (!checkThreads("not alive")) + return; + + /* clean threads references */ + if (!clean()) { + nsk_jvmti_setFailStatus(); + return; + } + } + + /* resume debugee after last sync */ + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ============================================================================= */ + +/** + * Prepare data: + * - get threads array from static field + * - get each thread from array + * - make global refs + */ +static int prepare() { + jclass debugeeClass = NULL; + jfieldID threadsFieldID = NULL; + jobjectArray threadsArray = NULL; + jsize threadsArrayLength = 0; + jsize i; + + /* find debugee class */ + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) + return NSK_FALSE; + + /* find static field with threads array */ + if (!NSK_JNI_VERIFY(jni, (threadsFieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + THREADS_FIELD_NAME, THREADS_FIELD_SIG)) != NULL)) + return NSK_FALSE; + + /* get threads array from static field */ + if (!NSK_JNI_VERIFY(jni, (threadsArray = (jobjectArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, threadsFieldID)) != NULL)) + return NSK_FALSE; + + /* check array length */ + if (!NSK_JNI_VERIFY(jni, (threadsArrayLength = + NSK_CPP_STUB2(GetArrayLength, jni, threadsArray)) == THREADS_COUNT)) + return NSK_FALSE; + + /* get each thread from array */ + for (i = 0; i < THREADS_COUNT; i++) { + if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread) + NSK_CPP_STUB3(GetObjectArrayElement, jni, threadsArray, i)) != NULL)) + return NSK_FALSE; + } + + /* make global references to threads */ + for (i = 0; i < THREADS_COUNT; i++) { + if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread) + NSK_CPP_STUB2(NewGlobalRef, jni, threadsList[i])) != NULL)) + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/** + * Testcase: check threads state for given suspension + * + * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. + */ +static int checkThreads(const char* kind) { + int i; + + /* check each thread */ + for (i = 0; i < THREADS_COUNT; i++) { + jthread thread = threadsList[i]; + jint state = JVMTI_THREAD_STATE_NOT_STARTED; + + NSK_DISPLAY2(" thread #%d (%s):\n", i, threadsName[i]); + + /* get thread state */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetThreadState, jvmti, threadsList[i], &state))) { + nsk_jvmti_setFailStatus(); + return NSK_TRUE; + } + + /* display thread state */ + NSK_DISPLAY2(" state=%s (%d)\n", + TranslateState(state), (int)state); + + /* check thread state */ + if ((state & threadsState[i]) == 0) { + if (state == JVMTI_THREAD_STATE_NOT_STARTED) { + NSK_DISPLAY1("state of thread #%d is NOT_STARTED\n", kind); + } else { + NSK_COMPLAIN7("Unexpected state of %s thread #%d (%s):\n" + "# got: %s (%d), expected: %s (%d)\n", + kind, i, threadsName[i], + TranslateState(state), (int)state, + TranslateState(threadsState[i]), (int)threadsState[i]); + nsk_jvmti_setFailStatus(); + } + } + + /* check SUSPENDED state flag */ + if (state & JVMTI_THREAD_STATE_SUSPENDED) { + NSK_COMPLAIN3("Unexpected SUSPENDED state flag for %s thread #%d: %d\n", + kind, i, (int)state); + nsk_jvmti_setFailStatus(); + } + + /* check INTERRUPTED state flag */ + if (state & JVMTI_THREAD_STATE_INTERRUPTED) { + NSK_COMPLAIN3("Unexpected INTERRUPTED state flag for %s thread #%d: %d\n", + kind, i, (int)state); + nsk_jvmti_setFailStatus(); + } + + /* check NATIVE state flag */ + if (state & JVMTI_THREAD_STATE_IN_NATIVE) { + NSK_COMPLAIN3("Unexpected NATIVE state flag for %s thread #%d: %d\n", + kind, i, (int)state); + nsk_jvmti_setFailStatus(); + } + } + + /* test may continue */ + return NSK_TRUE; +} + +/** + * Clean data: + * - dispose global references to tested threads + */ +static int clean() { + int i; + + /* dispose global references to threads */ + for (i = 0; i < THREADS_COUNT; i++) { + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, threadsList[i])); + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_sp01t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_sp01t001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_sp01t001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/libsp01t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/libsp01t002.c deleted file mode 100644 index eff8a284435..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/libsp01t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp01t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/libsp01t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/libsp01t002.cpp new file mode 100644 index 00000000000..f312a082e7a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/libsp01t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp01t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/sp01t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/sp01t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/sp01t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t002/sp01t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/libsp01t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/libsp01t003.c deleted file mode 100644 index fd7767b1197..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/libsp01t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp01t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/libsp01t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/libsp01t003.cpp new file mode 100644 index 00000000000..1caa57a086d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/libsp01t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp01t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/sp01t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/sp01t003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/sp01t003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP01/sp01t003/sp01t003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/libsp02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/libsp02t001.c deleted file mode 100644 index 838e86012f6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/libsp02t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp02t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/libsp02t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/libsp02t001.cpp new file mode 100644 index 00000000000..ef79b544dfd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/libsp02t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp02t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/sp02t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/sp02t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/sp02t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/sp02t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/libsp02t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/libsp02t002.c deleted file mode 100644 index 0456585d61a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/libsp02t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp02t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/libsp02t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/libsp02t002.cpp new file mode 100644 index 00000000000..a5ae0c72a98 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/libsp02t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp02t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/sp02t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/sp02t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/sp02t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t002/sp02t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/libsp02t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/libsp02t003.c deleted file mode 100644 index 4886e8013bc..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/libsp02t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp02t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/libsp02t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/libsp02t003.cpp new file mode 100644 index 00000000000..77baab38119 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/libsp02t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp02t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/sp02t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/sp02t003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/sp02t003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t003/sp02t003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/libsp03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/libsp03t001.c deleted file mode 100644 index 0cc5be554ca..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/libsp03t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp03t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/libsp03t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/libsp03t001.cpp new file mode 100644 index 00000000000..e813a642b94 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/libsp03t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp03t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/sp03t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/sp03t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/sp03t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t001/sp03t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/libsp03t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/libsp03t002.c deleted file mode 100644 index 99a25677fac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/libsp03t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp03t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/libsp03t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/libsp03t002.cpp new file mode 100644 index 00000000000..8658b2c75bf --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/libsp03t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp03t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/sp03t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/sp03t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/sp03t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP03/sp03t002/sp03t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/libsp04t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/libsp04t001.c deleted file mode 100644 index 4777dfe9b00..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/libsp04t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp04t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/libsp04t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/libsp04t001.cpp new file mode 100644 index 00000000000..f19fe0e81b4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/libsp04t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp04t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/sp04t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/sp04t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/sp04t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t001/sp04t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/libsp04t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/libsp04t002.c deleted file mode 100644 index 6684c8d2881..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/libsp04t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp04t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/libsp04t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/libsp04t002.cpp new file mode 100644 index 00000000000..6b97ce3ec76 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/libsp04t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp04t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/sp04t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/sp04t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/sp04t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP04/sp04t002/sp04t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/libsp05t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/libsp05t002.c deleted file mode 100644 index 0ea6a5b5e65..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/libsp05t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp05t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/libsp05t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/libsp05t002.cpp new file mode 100644 index 00000000000..01964795dd4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/libsp05t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp05t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/sp05t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/sp05t002.c deleted file mode 100644 index 17ad934cd33..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/sp05t002.c +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/scenarios/sampling/SP05/sp05t002" -#define THREAD_CLASS_NAME "nsk/jvmti/scenarios/sampling/SP05/sp05t002Thread" -#define THREADS_FIELD_NAME "threads" -#define THREADS_FIELD_SIG "[L"THREAD_CLASS_NAME";" - -/* scaffold objects */ -static JNIEnv* jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; - -/* number of tested threads and events */ -#define THREADS_COUNT 2 -#define EVENTS_COUNT 2 -#define MAX_STACK_DEPTH 64 - -/* tested events */ -static jvmtiEvent eventsList[EVENTS_COUNT] = { - JVMTI_EVENT_THREAD_START, - JVMTI_EVENT_THREAD_END -}; - -/* tested threads names */ -static const char* threadsName[THREADS_COUNT] = { - "threadRunningJava", - "threadRunningNative" -}; - -/* references to tested threads */ -static jthread threadsList[THREADS_COUNT]; - -/* events conunts */ -static volatile int eventsStart = 0; -static volatile int eventsEnd = 0; - -/* ============================================================================= */ - -/* testcase(s) */ -static int prepare(); -static int checkThread(jthread thread, int i, const char* kind); -static int clean(); - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - jni = agentJNI; - - /* wait for initial sync */ - if (!nsk_jvmti_waitForSync(timeout)) - return; - - /* testcase(s) */ - { - /* obtain threads list */ - if (!prepare()) { - nsk_jvmti_setFailStatus(); - return; - } - - /* clean events count */ - eventsStart = 0; - eventsEnd = 0; - - /* testcase #1: check threads on THREAD_START */ - NSK_DISPLAY0("Testcase #1: check threads on THREAD_START\n"); - if (!(NSK_VERIFY(nsk_jvmti_resumeSync()) - && NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))) - return; - - /* testcase #2: check threads on THREAD_END */ - NSK_DISPLAY0("Testcase #2: check threads on THREAD_END\n"); - if (!(NSK_VERIFY(nsk_jvmti_resumeSync()) - && NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))) - return; - - /* check events count */ - if (eventsStart != THREADS_COUNT) { - NSK_COMPLAIN2("Unexpected number of THREAD_START events:\n" - "# received: %d\n" - "# expected: %d\n", - eventsStart, THREADS_COUNT); - } - if (eventsEnd != THREADS_COUNT) { - NSK_COMPLAIN2("Unexpected number of THREAD_END events:\n" - "# received: %d\n" - "# expected: %d\n", - eventsEnd, THREADS_COUNT); - } - - /* clean threads references */ - if (!clean()) { - nsk_jvmti_setFailStatus(); - return; - } - } - - /* resume debugee after last sync */ - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ============================================================================= */ - -/** - * Enable or disable tested events. - */ -static int enableEvents(jvmtiEventMode enable) { - int i; - - for (i = 0; i < EVENTS_COUNT; i++) { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, enable, - eventsList[i], NULL))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - return NSK_TRUE; -} - -/** - * Prepare data: - * - get threads array from static field - * - get each thread from array - * - make global refs - * - enable events - */ -static int prepare() { - jclass debugeeClass = NULL; - jfieldID threadsFieldID = NULL; - jobjectArray threadsArray = NULL; - jsize threadsArrayLength = 0; - jsize i; - - /* find debugee class */ - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) - return NSK_FALSE; - - /* find static field with threads array */ - if (!NSK_JNI_VERIFY(jni, (threadsFieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - THREADS_FIELD_NAME, THREADS_FIELD_SIG)) != NULL)) - return NSK_FALSE; - - /* get threads array from static field */ - if (!NSK_JNI_VERIFY(jni, (threadsArray = (jobjectArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, threadsFieldID)) != NULL)) - return NSK_FALSE; - - /* check array length */ - if (!NSK_JNI_VERIFY(jni, (threadsArrayLength = - NSK_CPP_STUB2(GetArrayLength, jni, threadsArray)) == THREADS_COUNT)) - return NSK_FALSE; - - /* get each thread from array */ - for (i = 0; i < THREADS_COUNT; i++) { - if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread) - NSK_CPP_STUB3(GetObjectArrayElement, jni, threadsArray, i)) != NULL)) - return NSK_FALSE; - } - - /* make global references to threads */ - for (i = 0; i < THREADS_COUNT; i++) { - if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread) - NSK_CPP_STUB2(NewGlobalRef, jni, threadsList[i])) != NULL)) - return NSK_FALSE; - } - - return enableEvents(JVMTI_ENABLE); -} - -/** - * Testcase: check thread's stack on event - * - * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. - */ -static int checkThread(jthread thread, int i, const char* kind) { - jint framesCount = 0; - jint stackDepth = 0; - jvmtiFrameInfo stackFrames[MAX_STACK_DEPTH]; - - NSK_DISPLAY3(" thread #%d (%s): %p\n", i, threadsName[i], (void*)thread); - - /* get frames count */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetFrameCount, jvmti, thread, &framesCount))) { - nsk_jvmti_setFailStatus(); - return NSK_TRUE; - } - NSK_DISPLAY1(" frames count: %d\n", (int)framesCount); - - /* get stack frames */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB6(GetStackTrace, jvmti, thread, 0, MAX_STACK_DEPTH, - stackFrames, &stackDepth))) { - nsk_jvmti_setFailStatus(); - return NSK_TRUE; - } - NSK_DISPLAY1(" stack depth: %d\n", (int)stackDepth); - - /* check against emptyness */ - if (framesCount != 0) { - NSK_COMPLAIN5("Unexpected GetFramesCount() for %s thread #%d (%s):\n" - "# got frames: %d\n" - "# expected: %d\n", - kind, i, threadsName[i], - framesCount, 0); - nsk_jvmti_setFailStatus(); - } - if (stackDepth != 0) { - NSK_COMPLAIN5("Unexpected GetStackTrace() for %s thread #%d (%s):\n" - "# got frames: %d\n" - "# expected: %d\n", - kind, i, threadsName[i], - stackDepth, 0); - nsk_jvmti_setFailStatus(); - } - - /* test may continue */ - return NSK_TRUE; -} - -/** - * Clean data: - * - disable events - * - dispose global references to tested threads - */ -static int clean() { - int i; - - /* disable events */ - enableEvents(JVMTI_DISABLE); - - /* dispose global references to threads */ - for (i = 0; i < THREADS_COUNT; i++) { - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, threadsList[i])); - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** - * THREAD_START callback: - * - check thread's stack on THREAD_START - */ -JNIEXPORT void JNICALL -callbackThreadStart(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) { - int i; - - /* check if thread is not NULL */ - if (!NSK_VERIFY(thread != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* check if event is for tested thread */ - for (i = 0; i < THREADS_COUNT; i++) { - if (NSK_CPP_STUB3(IsSameObject, jni, threadsList[i], thread)) { - NSK_DISPLAY0("SUCCESS: expected THREAD_START event\n"); - eventsStart++; - - /* check thread on event */ - checkThread(thread, i, "starting"); - break; - } - } -} - -/** - * THREAD_END callback: - * - check thread's stack on THREAD_END - */ -JNIEXPORT void JNICALL -callbackThreadEnd(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) { - int i; - - /* check if thread is not NULL */ - if (!NSK_VERIFY(thread != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* check if event is for tested thread */ - for (i = 0; i < THREADS_COUNT; i++) { - if (NSK_CPP_STUB3(IsSameObject, jni, threadsList[i], thread)) { - NSK_DISPLAY0("SUCCESS: expected THREAD_START event\n"); - eventsEnd++; - - /* check thread on event */ - checkThread(thread, i, "finishing"); - break; - } - } -} - -/* ============================================================================= */ - -static volatile int testedThreadRunning = NSK_FALSE; -static volatile int testedThreadShouldFinish = NSK_FALSE; - -/** Native running method in tested thread. */ -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_sampling_SP05_sp05t002ThreadRunningNative_run(JNIEnv* jni, - jobject obj) { - volatile int i = 0, n = 1000; - - /* run in a loop */ - testedThreadRunning = NSK_TRUE; - while (!testedThreadShouldFinish) { - if (n <= 0) - n = 1000; - if (i >= n) - i = 0; - i++; - } - testedThreadRunning = NSK_FALSE; -} - -/** Wait for native method is running. */ -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_sampling_SP05_sp05t002ThreadRunningNative_checkStarted(JNIEnv* jni, - jobject obj) { - while (!testedThreadRunning) { - nsk_jvmti_sleep(1000); - } - return testedThreadRunning ? JNI_TRUE : JNI_FALSE; -} - -/** Let native method to finish. */ -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_sampling_SP05_sp05t002ThreadRunningNative_letFinish(JNIEnv* jni, - jobject obj) { - testedThreadShouldFinish = NSK_TRUE; -} - -/* ============================================================================= */ - -/** Aent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_sp05t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_sp05t002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_sp05t002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* set events callbacks */ - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ThreadStart = callbackThreadStart; - eventCallbacks.ThreadEnd = callbackThreadEnd; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) - return JNI_ERR; - } - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/sp05t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/sp05t002.cpp new file mode 100644 index 00000000000..eb0a6ae8ba6 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t002/sp05t002.cpp @@ -0,0 +1,425 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/scenarios/sampling/SP05/sp05t002" +#define THREAD_CLASS_NAME "nsk/jvmti/scenarios/sampling/SP05/sp05t002Thread" +#define THREADS_FIELD_NAME "threads" +#define THREADS_FIELD_SIG "[L" THREAD_CLASS_NAME ";" + +/* scaffold objects */ +static JNIEnv* jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; + +/* number of tested threads and events */ +#define THREADS_COUNT 2 +#define EVENTS_COUNT 2 +#define MAX_STACK_DEPTH 64 + +/* tested events */ +static jvmtiEvent eventsList[EVENTS_COUNT] = { + JVMTI_EVENT_THREAD_START, + JVMTI_EVENT_THREAD_END +}; + +/* tested threads names */ +static const char* threadsName[THREADS_COUNT] = { + "threadRunningJava", + "threadRunningNative" +}; + +/* references to tested threads */ +static jthread threadsList[THREADS_COUNT]; + +/* events conunts */ +static volatile int eventsStart = 0; +static volatile int eventsEnd = 0; + +/* ============================================================================= */ + +/* testcase(s) */ +static int prepare(); +static int checkThread(jthread thread, int i, const char* kind); +static int clean(); + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + jni = agentJNI; + + /* wait for initial sync */ + if (!nsk_jvmti_waitForSync(timeout)) + return; + + /* testcase(s) */ + { + /* obtain threads list */ + if (!prepare()) { + nsk_jvmti_setFailStatus(); + return; + } + + /* clean events count */ + eventsStart = 0; + eventsEnd = 0; + + /* testcase #1: check threads on THREAD_START */ + NSK_DISPLAY0("Testcase #1: check threads on THREAD_START\n"); + if (!(NSK_VERIFY(nsk_jvmti_resumeSync()) + && NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))) + return; + + /* testcase #2: check threads on THREAD_END */ + NSK_DISPLAY0("Testcase #2: check threads on THREAD_END\n"); + if (!(NSK_VERIFY(nsk_jvmti_resumeSync()) + && NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))) + return; + + /* check events count */ + if (eventsStart != THREADS_COUNT) { + NSK_COMPLAIN2("Unexpected number of THREAD_START events:\n" + "# received: %d\n" + "# expected: %d\n", + eventsStart, THREADS_COUNT); + } + if (eventsEnd != THREADS_COUNT) { + NSK_COMPLAIN2("Unexpected number of THREAD_END events:\n" + "# received: %d\n" + "# expected: %d\n", + eventsEnd, THREADS_COUNT); + } + + /* clean threads references */ + if (!clean()) { + nsk_jvmti_setFailStatus(); + return; + } + } + + /* resume debugee after last sync */ + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ============================================================================= */ + +/** + * Enable or disable tested events. + */ +static int enableEvents(jvmtiEventMode enable) { + int i; + + for (i = 0; i < EVENTS_COUNT; i++) { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, enable, + eventsList[i], NULL))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + return NSK_TRUE; +} + +/** + * Prepare data: + * - get threads array from static field + * - get each thread from array + * - make global refs + * - enable events + */ +static int prepare() { + jclass debugeeClass = NULL; + jfieldID threadsFieldID = NULL; + jobjectArray threadsArray = NULL; + jsize threadsArrayLength = 0; + jsize i; + + /* find debugee class */ + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) + return NSK_FALSE; + + /* find static field with threads array */ + if (!NSK_JNI_VERIFY(jni, (threadsFieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + THREADS_FIELD_NAME, THREADS_FIELD_SIG)) != NULL)) + return NSK_FALSE; + + /* get threads array from static field */ + if (!NSK_JNI_VERIFY(jni, (threadsArray = (jobjectArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, threadsFieldID)) != NULL)) + return NSK_FALSE; + + /* check array length */ + if (!NSK_JNI_VERIFY(jni, (threadsArrayLength = + NSK_CPP_STUB2(GetArrayLength, jni, threadsArray)) == THREADS_COUNT)) + return NSK_FALSE; + + /* get each thread from array */ + for (i = 0; i < THREADS_COUNT; i++) { + if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread) + NSK_CPP_STUB3(GetObjectArrayElement, jni, threadsArray, i)) != NULL)) + return NSK_FALSE; + } + + /* make global references to threads */ + for (i = 0; i < THREADS_COUNT; i++) { + if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread) + NSK_CPP_STUB2(NewGlobalRef, jni, threadsList[i])) != NULL)) + return NSK_FALSE; + } + + return enableEvents(JVMTI_ENABLE); +} + +/** + * Testcase: check thread's stack on event + * + * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. + */ +static int checkThread(jthread thread, int i, const char* kind) { + jint framesCount = 0; + jint stackDepth = 0; + jvmtiFrameInfo stackFrames[MAX_STACK_DEPTH]; + + NSK_DISPLAY3(" thread #%d (%s): %p\n", i, threadsName[i], (void*)thread); + + /* get frames count */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetFrameCount, jvmti, thread, &framesCount))) { + nsk_jvmti_setFailStatus(); + return NSK_TRUE; + } + NSK_DISPLAY1(" frames count: %d\n", (int)framesCount); + + /* get stack frames */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB6(GetStackTrace, jvmti, thread, 0, MAX_STACK_DEPTH, + stackFrames, &stackDepth))) { + nsk_jvmti_setFailStatus(); + return NSK_TRUE; + } + NSK_DISPLAY1(" stack depth: %d\n", (int)stackDepth); + + /* check against emptyness */ + if (framesCount != 0) { + NSK_COMPLAIN5("Unexpected GetFramesCount() for %s thread #%d (%s):\n" + "# got frames: %d\n" + "# expected: %d\n", + kind, i, threadsName[i], + framesCount, 0); + nsk_jvmti_setFailStatus(); + } + if (stackDepth != 0) { + NSK_COMPLAIN5("Unexpected GetStackTrace() for %s thread #%d (%s):\n" + "# got frames: %d\n" + "# expected: %d\n", + kind, i, threadsName[i], + stackDepth, 0); + nsk_jvmti_setFailStatus(); + } + + /* test may continue */ + return NSK_TRUE; +} + +/** + * Clean data: + * - disable events + * - dispose global references to tested threads + */ +static int clean() { + int i; + + /* disable events */ + enableEvents(JVMTI_DISABLE); + + /* dispose global references to threads */ + for (i = 0; i < THREADS_COUNT; i++) { + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, threadsList[i])); + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** + * THREAD_START callback: + * - check thread's stack on THREAD_START + */ +JNIEXPORT void JNICALL +callbackThreadStart(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) { + int i; + + /* check if thread is not NULL */ + if (!NSK_VERIFY(thread != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* check if event is for tested thread */ + for (i = 0; i < THREADS_COUNT; i++) { + if (NSK_CPP_STUB3(IsSameObject, jni, threadsList[i], thread)) { + NSK_DISPLAY0("SUCCESS: expected THREAD_START event\n"); + eventsStart++; + + /* check thread on event */ + checkThread(thread, i, "starting"); + break; + } + } +} + +/** + * THREAD_END callback: + * - check thread's stack on THREAD_END + */ +JNIEXPORT void JNICALL +callbackThreadEnd(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) { + int i; + + /* check if thread is not NULL */ + if (!NSK_VERIFY(thread != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* check if event is for tested thread */ + for (i = 0; i < THREADS_COUNT; i++) { + if (NSK_CPP_STUB3(IsSameObject, jni, threadsList[i], thread)) { + NSK_DISPLAY0("SUCCESS: expected THREAD_START event\n"); + eventsEnd++; + + /* check thread on event */ + checkThread(thread, i, "finishing"); + break; + } + } +} + +/* ============================================================================= */ + +static volatile int testedThreadRunning = NSK_FALSE; +static volatile int testedThreadShouldFinish = NSK_FALSE; + +/** Native running method in tested thread. */ +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_sampling_SP05_sp05t002ThreadRunningNative_run(JNIEnv* jni, + jobject obj) { + volatile int i = 0, n = 1000; + + /* run in a loop */ + testedThreadRunning = NSK_TRUE; + while (!testedThreadShouldFinish) { + if (n <= 0) + n = 1000; + if (i >= n) + i = 0; + i++; + } + testedThreadRunning = NSK_FALSE; +} + +/** Wait for native method is running. */ +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_sampling_SP05_sp05t002ThreadRunningNative_checkStarted(JNIEnv* jni, + jobject obj) { + while (!testedThreadRunning) { + nsk_jvmti_sleep(1000); + } + return testedThreadRunning ? JNI_TRUE : JNI_FALSE; +} + +/** Let native method to finish. */ +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_sampling_SP05_sp05t002ThreadRunningNative_letFinish(JNIEnv* jni, + jobject obj) { + testedThreadShouldFinish = NSK_TRUE; +} + +/* ============================================================================= */ + +/** Aent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_sp05t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_sp05t002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_sp05t002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* set events callbacks */ + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ThreadStart = callbackThreadStart; + eventCallbacks.ThreadEnd = callbackThreadEnd; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) + return JNI_ERR; + } + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/libsp05t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/libsp05t003.c deleted file mode 100644 index b4a3e1c7f8f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/libsp05t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp05t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/libsp05t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/libsp05t003.cpp new file mode 100644 index 00000000000..0c33c03ad14 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/libsp05t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp05t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/sp05t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/sp05t003.c deleted file mode 100644 index 3abe1de5836..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/sp05t003.c +++ /dev/null @@ -1,537 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* constant names */ -#define DEBUGEE_CLASS_NAME "nsk/jvmti/scenarios/sampling/SP05/sp05t003" -#define THREAD_CLASS_NAME "nsk/jvmti/scenarios/sampling/SP05/sp05t003Thread" -#define THREADS_FIELD_NAME "threads" -#define THREADS_FIELD_SIG "[L"THREAD_CLASS_NAME";" - -/* constants */ -#define TIMEOUT_DELTA 1000 - -/* scaffold objects */ -static JNIEnv* jni = NULL; -static jvmtiEnv *jvmti = NULL; -static jlong timeout = 0; - -/* number of tested threads and events */ -#define THREADS_COUNT 2 -#define EVENTS_COUNT 2 -#define MAX_STACK_DEPTH 64 - -/* tested events */ -static jvmtiEvent eventsList[EVENTS_COUNT] = { - JVMTI_EVENT_THREAD_START, - JVMTI_EVENT_THREAD_END -}; - -/* tested threads names */ -static const char* threadsName[THREADS_COUNT] = { - "threadRunningJava", - "threadRunningNative" -}; - -/* references to tested threads */ -static jthread threadsList[THREADS_COUNT]; - -/* events conunts */ -static volatile int eventsStart = 0; -static volatile int eventsEnd = 0; - -/* ============================================================================= */ - -/* testcase(s) */ -static int prepare(); -static int checkThreads(const char* kind); -static int resumeThreads(const char* kind); -static int clean(); - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { - jni = agentJNI; - - /* wait for initial sync */ - if (!nsk_jvmti_waitForSync(timeout)) - return; - - /* testcase(s) */ - { - /* obtain threads list */ - if (!prepare()) { - nsk_jvmti_setFailStatus(); - return; - } - - /* testcase #1: suspend and check threads on THREAD_START event */ - { - eventsStart = 0; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, - JVMTI_EVENT_THREAD_START, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Let threads to start\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - - NSK_DISPLAY0("Wait for THREAD_START events\n"); - { - int i; - - for (i = 0; i * TIMEOUT_DELTA < timeout; i++) { - if (eventsStart >= THREADS_COUNT) - break; - nsk_jvmti_sleep(TIMEOUT_DELTA); - } - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, - JVMTI_EVENT_THREAD_START, NULL))) { - nsk_jvmti_setFailStatus(); - } - - /* check if all threads suspended on THREAD_START events */ - if (eventsStart != THREADS_COUNT) { - NSK_COMPLAIN2("Unexpected number of THREAD_START events:\n" - "# received: %d\n" - "# expected: %d\n", - eventsStart, THREADS_COUNT); - } - - NSK_DISPLAY0("Testcase #1: check threads on THREAD_START\n"); - if (!NSK_VERIFY(checkThreads("starting"))) - return; - - NSK_DISPLAY0("Resume all threads\n"); - if (!NSK_VERIFY(resumeThreads("starting"))) - return; - - NSK_DISPLAY0("Wait for threads to run\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - } - - /* testcase #2: suspend and check threads on THREAD_END event */ - { - eventsEnd = 0; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, - JVMTI_EVENT_THREAD_END, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - - NSK_DISPLAY0("Let threads to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; - - NSK_DISPLAY0("Wait for THREAD_END events\n"); - { - int i; - - for (i = 0; i * TIMEOUT_DELTA < timeout; i++) { - if (eventsEnd >= THREADS_COUNT) - break; - nsk_jvmti_sleep(TIMEOUT_DELTA); - } - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, - JVMTI_EVENT_THREAD_END, NULL))) { - nsk_jvmti_setFailStatus(); - } - - /* check ia all threads suspended on THREAD_END event */ - if (eventsEnd != THREADS_COUNT) { - NSK_COMPLAIN2("Unexpected number of THREAD_END events:\n" - "# received: %d\n" - "# expected: %d\n", - eventsEnd, THREADS_COUNT); - } - - NSK_DISPLAY0("Testcase #2: check threads on THREAD_END\n"); - if (!NSK_VERIFY(checkThreads("finishing"))) - return; - - NSK_DISPLAY0("Resume all threads\n"); - if (!NSK_VERIFY(resumeThreads("finishing"))) - return; - - NSK_DISPLAY0("Wait for threads to finish\n"); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) - return; - } - - /* clean threads references */ - if (!clean()) { - nsk_jvmti_setFailStatus(); - return; - } - } - - /* resume debugee after last sync */ - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ============================================================================= */ - -/** - * Resume all threads in given state. - */ -static int resumeThreads(const char* kind) { - int i; - - for (i = 0; i < THREADS_COUNT; i++) { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(ResumeThread, jvmti, threadsList[i]))) { - nsk_jvmti_setFailStatus(); - } - } - return NSK_TRUE; -} - -/** - * Prepare data: - * - get threads array from static field - * - get each thread from array - * - make global refs - */ -static int prepare() { - jclass debugeeClass = NULL; - jfieldID threadsFieldID = NULL; - jobjectArray threadsArray = NULL; - jsize threadsArrayLength = 0; - jsize i; - - /* find debugee class */ - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) - return NSK_FALSE; - - /* find static field with threads array */ - if (!NSK_JNI_VERIFY(jni, (threadsFieldID = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - THREADS_FIELD_NAME, THREADS_FIELD_SIG)) != NULL)) - return NSK_FALSE; - - /* get threads array from static field */ - if (!NSK_JNI_VERIFY(jni, (threadsArray = (jobjectArray) - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, threadsFieldID)) != NULL)) - return NSK_FALSE; - - /* check array length */ - if (!NSK_JNI_VERIFY(jni, (threadsArrayLength = - NSK_CPP_STUB2(GetArrayLength, jni, threadsArray)) == THREADS_COUNT)) - return NSK_FALSE; - - /* get each thread from array */ - for (i = 0; i < THREADS_COUNT; i++) { - if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread) - NSK_CPP_STUB3(GetObjectArrayElement, jni, threadsArray, i)) != NULL)) - return NSK_FALSE; - } - - /* make global references to threads */ - for (i = 0; i < THREADS_COUNT; i++) { - if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread) - NSK_CPP_STUB2(NewGlobalRef, jni, threadsList[i])) != NULL)) - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/** - * Check thread's stack on event. - * - * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. - */ -static int checkThread(jthread thread, int i, const char* kind) { - jint framesCount = 0; - jint stackDepth = 0; - jvmtiFrameInfo stackFrames[MAX_STACK_DEPTH]; - - NSK_DISPLAY3(" thread #%d (%s): %p\n", i, threadsName[i], (void*)thread); - - /* get frames count */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetFrameCount, jvmti, thread, &framesCount))) { - nsk_jvmti_setFailStatus(); - return NSK_TRUE; - } - NSK_DISPLAY1(" frames count: %d\n", (int)framesCount); - - /* get stack frames */ - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB6(GetStackTrace, jvmti, thread, 0, MAX_STACK_DEPTH, - stackFrames, &stackDepth))) { - nsk_jvmti_setFailStatus(); - return NSK_TRUE; - } - NSK_DISPLAY1(" stack depth: %d\n", (int)stackDepth); - - /* check against emptyness */ - if (framesCount != 0) { - NSK_COMPLAIN5("Unexpected GetFramesCount() for %s thread #%d (%s):\n" - "# got frames: %d\n" - "# expected: %d\n", - kind, i, threadsName[i], - framesCount, 0); - nsk_jvmti_setFailStatus(); - } - if (stackDepth != 0) { - NSK_COMPLAIN5("Unexpected GetStackTrace() for %s thread #%d (%s):\n" - "# got frames: %d\n" - "# expected: %d\n", - kind, i, threadsName[i], - stackDepth, 0); - nsk_jvmti_setFailStatus(); - } - - /* test may continue */ - return NSK_TRUE; -} - -/** - * Testcase: check each thread's stack on event. - * - * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. - */ -static int checkThreads(const char* kind) { - int i; - - for (i = 0; i < THREADS_COUNT; i++) { - if (!checkThread(threadsList[i], i, kind)) - return NSK_FALSE; - } - return NSK_TRUE; -} - -/** - * Clean data: - * - dispose global references to tested threads - */ -static int clean() { - int i; - - /* dispose global references to threads */ - for (i = 0; i < THREADS_COUNT; i++) { - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, threadsList[i])); - } - - return NSK_TRUE; -} - -/* ============================================================================= */ - -/** - * THREAD_START callback: - * - check thread's stack on THREAD_START - */ -JNIEXPORT void JNICALL -callbackThreadStart(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) { - int i; - - /* check if thread is not NULL */ - if (!NSK_VERIFY(thread != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* check if event is for tested thread */ - for (i = 0; i < THREADS_COUNT; i++) { - if (NSK_CPP_STUB3(IsSameObject, jni, threadsList[i], thread)) { - NSK_DISPLAY0("SUCCESS: expected THREAD_START event\n"); - - /* suspend thread */ - NSK_DISPLAY3(" suspend starting thread #%d (%s): %p\n", - i, threadsName[i], (void*)thread); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(SuspendThread, jvmti, thread))) { - nsk_jvmti_setFailStatus(); - return; - } - eventsStart++; - - break; - } - } -} - -/** - * THREAD_END callback: - * - check thread's stack on THREAD_END - */ -JNIEXPORT void JNICALL -callbackThreadEnd(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) { - int i; - - /* check if thread is not NULL */ - if (!NSK_VERIFY(thread != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* check if event is for tested thread */ - for (i = 0; i < THREADS_COUNT; i++) { - if (NSK_CPP_STUB3(IsSameObject, jni, threadsList[i], thread)) { - NSK_DISPLAY0("SUCCESS: expected THREAD_END event\n"); - - /* suspend thread */ - NSK_DISPLAY3(" suspend finishing thread #%d (%s): %p\n", - i, threadsName[i], (void*)thread); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(SuspendThread, jvmti, thread))) { - nsk_jvmti_setFailStatus(); - return; - } - eventsEnd++; - - break; - } - } -} - -/* ============================================================================= */ - -static volatile int testedThreadRunning = NSK_FALSE; -static volatile int testedThreadShouldFinish = NSK_FALSE; - -/** Native running method in tested thread. */ -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_sampling_SP05_sp05t003ThreadRunningNative_run(JNIEnv* jni, - jobject obj) { - volatile int i = 0, n = 1000; - - /* run in a loop */ - testedThreadRunning = NSK_TRUE; - while (!testedThreadShouldFinish) { - if (n <= 0) - n = 1000; - if (i >= n) - i = 0; - i++; - } - testedThreadRunning = NSK_FALSE; -} - -/** Wait for native method is running. */ -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_scenarios_sampling_SP05_sp05t003ThreadRunningNative_checkStarted(JNIEnv* jni, - jobject obj) { - while (!testedThreadRunning) { - nsk_jvmti_sleep(1000); - } - return testedThreadRunning ? JNI_TRUE : JNI_FALSE; -} - -/** Let native method to finish. */ -JNIEXPORT void JNICALL -Java_nsk_jvmti_scenarios_sampling_SP05_sp05t003ThreadRunningNative_letFinish(JNIEnv* jni, - jobject obj) { - testedThreadShouldFinish = NSK_TRUE; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_sp05t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_sp05t003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_sp05t003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* add capabilities for suspending thread */ - { - jvmtiCapabilities suspendCaps; - memset(&suspendCaps, 0, sizeof(suspendCaps)); - suspendCaps.can_suspend = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti, &suspendCaps))) - return JNI_ERR; - } - - /* set events callbacks */ - { - jvmtiEventCallbacks eventCallbacks; - memset(&eventCallbacks, 0, sizeof(eventCallbacks)); - eventCallbacks.ThreadStart = callbackThreadStart; - eventCallbacks.ThreadEnd = callbackThreadEnd; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti, - &eventCallbacks, sizeof(eventCallbacks)))) - return JNI_ERR; - } - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/sp05t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/sp05t003.cpp new file mode 100644 index 00000000000..f7de9fcca0e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP05/sp05t003/sp05t003.cpp @@ -0,0 +1,537 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* constant names */ +#define DEBUGEE_CLASS_NAME "nsk/jvmti/scenarios/sampling/SP05/sp05t003" +#define THREAD_CLASS_NAME "nsk/jvmti/scenarios/sampling/SP05/sp05t003Thread" +#define THREADS_FIELD_NAME "threads" +#define THREADS_FIELD_SIG "[L" THREAD_CLASS_NAME ";" + +/* constants */ +#define TIMEOUT_DELTA 1000 + +/* scaffold objects */ +static JNIEnv* jni = NULL; +static jvmtiEnv *jvmti = NULL; +static jlong timeout = 0; + +/* number of tested threads and events */ +#define THREADS_COUNT 2 +#define EVENTS_COUNT 2 +#define MAX_STACK_DEPTH 64 + +/* tested events */ +static jvmtiEvent eventsList[EVENTS_COUNT] = { + JVMTI_EVENT_THREAD_START, + JVMTI_EVENT_THREAD_END +}; + +/* tested threads names */ +static const char* threadsName[THREADS_COUNT] = { + "threadRunningJava", + "threadRunningNative" +}; + +/* references to tested threads */ +static jthread threadsList[THREADS_COUNT]; + +/* events conunts */ +static volatile int eventsStart = 0; +static volatile int eventsEnd = 0; + +/* ============================================================================= */ + +/* testcase(s) */ +static int prepare(); +static int checkThreads(const char* kind); +static int resumeThreads(const char* kind); +static int clean(); + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { + jni = agentJNI; + + /* wait for initial sync */ + if (!nsk_jvmti_waitForSync(timeout)) + return; + + /* testcase(s) */ + { + /* obtain threads list */ + if (!prepare()) { + nsk_jvmti_setFailStatus(); + return; + } + + /* testcase #1: suspend and check threads on THREAD_START event */ + { + eventsStart = 0; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, + JVMTI_EVENT_THREAD_START, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Let threads to start\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + + NSK_DISPLAY0("Wait for THREAD_START events\n"); + { + int i; + + for (i = 0; i * TIMEOUT_DELTA < timeout; i++) { + if (eventsStart >= THREADS_COUNT) + break; + nsk_jvmti_sleep(TIMEOUT_DELTA); + } + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, + JVMTI_EVENT_THREAD_START, NULL))) { + nsk_jvmti_setFailStatus(); + } + + /* check if all threads suspended on THREAD_START events */ + if (eventsStart != THREADS_COUNT) { + NSK_COMPLAIN2("Unexpected number of THREAD_START events:\n" + "# received: %d\n" + "# expected: %d\n", + eventsStart, THREADS_COUNT); + } + + NSK_DISPLAY0("Testcase #1: check threads on THREAD_START\n"); + if (!NSK_VERIFY(checkThreads("starting"))) + return; + + NSK_DISPLAY0("Resume all threads\n"); + if (!NSK_VERIFY(resumeThreads("starting"))) + return; + + NSK_DISPLAY0("Wait for threads to run\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + } + + /* testcase #2: suspend and check threads on THREAD_END event */ + { + eventsEnd = 0; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE, + JVMTI_EVENT_THREAD_END, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + + NSK_DISPLAY0("Let threads to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; + + NSK_DISPLAY0("Wait for THREAD_END events\n"); + { + int i; + + for (i = 0; i * TIMEOUT_DELTA < timeout; i++) { + if (eventsEnd >= THREADS_COUNT) + break; + nsk_jvmti_sleep(TIMEOUT_DELTA); + } + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE, + JVMTI_EVENT_THREAD_END, NULL))) { + nsk_jvmti_setFailStatus(); + } + + /* check ia all threads suspended on THREAD_END event */ + if (eventsEnd != THREADS_COUNT) { + NSK_COMPLAIN2("Unexpected number of THREAD_END events:\n" + "# received: %d\n" + "# expected: %d\n", + eventsEnd, THREADS_COUNT); + } + + NSK_DISPLAY0("Testcase #2: check threads on THREAD_END\n"); + if (!NSK_VERIFY(checkThreads("finishing"))) + return; + + NSK_DISPLAY0("Resume all threads\n"); + if (!NSK_VERIFY(resumeThreads("finishing"))) + return; + + NSK_DISPLAY0("Wait for threads to finish\n"); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) + return; + } + + /* clean threads references */ + if (!clean()) { + nsk_jvmti_setFailStatus(); + return; + } + } + + /* resume debugee after last sync */ + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ============================================================================= */ + +/** + * Resume all threads in given state. + */ +static int resumeThreads(const char* kind) { + int i; + + for (i = 0; i < THREADS_COUNT; i++) { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(ResumeThread, jvmti, threadsList[i]))) { + nsk_jvmti_setFailStatus(); + } + } + return NSK_TRUE; +} + +/** + * Prepare data: + * - get threads array from static field + * - get each thread from array + * - make global refs + */ +static int prepare() { + jclass debugeeClass = NULL; + jfieldID threadsFieldID = NULL; + jobjectArray threadsArray = NULL; + jsize threadsArrayLength = 0; + jsize i; + + /* find debugee class */ + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) + return NSK_FALSE; + + /* find static field with threads array */ + if (!NSK_JNI_VERIFY(jni, (threadsFieldID = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + THREADS_FIELD_NAME, THREADS_FIELD_SIG)) != NULL)) + return NSK_FALSE; + + /* get threads array from static field */ + if (!NSK_JNI_VERIFY(jni, (threadsArray = (jobjectArray) + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, threadsFieldID)) != NULL)) + return NSK_FALSE; + + /* check array length */ + if (!NSK_JNI_VERIFY(jni, (threadsArrayLength = + NSK_CPP_STUB2(GetArrayLength, jni, threadsArray)) == THREADS_COUNT)) + return NSK_FALSE; + + /* get each thread from array */ + for (i = 0; i < THREADS_COUNT; i++) { + if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread) + NSK_CPP_STUB3(GetObjectArrayElement, jni, threadsArray, i)) != NULL)) + return NSK_FALSE; + } + + /* make global references to threads */ + for (i = 0; i < THREADS_COUNT; i++) { + if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread) + NSK_CPP_STUB2(NewGlobalRef, jni, threadsList[i])) != NULL)) + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/** + * Check thread's stack on event. + * + * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. + */ +static int checkThread(jthread thread, int i, const char* kind) { + jint framesCount = 0; + jint stackDepth = 0; + jvmtiFrameInfo stackFrames[MAX_STACK_DEPTH]; + + NSK_DISPLAY3(" thread #%d (%s): %p\n", i, threadsName[i], (void*)thread); + + /* get frames count */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetFrameCount, jvmti, thread, &framesCount))) { + nsk_jvmti_setFailStatus(); + return NSK_TRUE; + } + NSK_DISPLAY1(" frames count: %d\n", (int)framesCount); + + /* get stack frames */ + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB6(GetStackTrace, jvmti, thread, 0, MAX_STACK_DEPTH, + stackFrames, &stackDepth))) { + nsk_jvmti_setFailStatus(); + return NSK_TRUE; + } + NSK_DISPLAY1(" stack depth: %d\n", (int)stackDepth); + + /* check against emptyness */ + if (framesCount != 0) { + NSK_COMPLAIN5("Unexpected GetFramesCount() for %s thread #%d (%s):\n" + "# got frames: %d\n" + "# expected: %d\n", + kind, i, threadsName[i], + framesCount, 0); + nsk_jvmti_setFailStatus(); + } + if (stackDepth != 0) { + NSK_COMPLAIN5("Unexpected GetStackTrace() for %s thread #%d (%s):\n" + "# got frames: %d\n" + "# expected: %d\n", + kind, i, threadsName[i], + stackDepth, 0); + nsk_jvmti_setFailStatus(); + } + + /* test may continue */ + return NSK_TRUE; +} + +/** + * Testcase: check each thread's stack on event. + * + * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break. + */ +static int checkThreads(const char* kind) { + int i; + + for (i = 0; i < THREADS_COUNT; i++) { + if (!checkThread(threadsList[i], i, kind)) + return NSK_FALSE; + } + return NSK_TRUE; +} + +/** + * Clean data: + * - dispose global references to tested threads + */ +static int clean() { + int i; + + /* dispose global references to threads */ + for (i = 0; i < THREADS_COUNT; i++) { + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, threadsList[i])); + } + + return NSK_TRUE; +} + +/* ============================================================================= */ + +/** + * THREAD_START callback: + * - check thread's stack on THREAD_START + */ +JNIEXPORT void JNICALL +callbackThreadStart(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) { + int i; + + /* check if thread is not NULL */ + if (!NSK_VERIFY(thread != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* check if event is for tested thread */ + for (i = 0; i < THREADS_COUNT; i++) { + if (NSK_CPP_STUB3(IsSameObject, jni, threadsList[i], thread)) { + NSK_DISPLAY0("SUCCESS: expected THREAD_START event\n"); + + /* suspend thread */ + NSK_DISPLAY3(" suspend starting thread #%d (%s): %p\n", + i, threadsName[i], (void*)thread); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(SuspendThread, jvmti, thread))) { + nsk_jvmti_setFailStatus(); + return; + } + eventsStart++; + + break; + } + } +} + +/** + * THREAD_END callback: + * - check thread's stack on THREAD_END + */ +JNIEXPORT void JNICALL +callbackThreadEnd(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) { + int i; + + /* check if thread is not NULL */ + if (!NSK_VERIFY(thread != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* check if event is for tested thread */ + for (i = 0; i < THREADS_COUNT; i++) { + if (NSK_CPP_STUB3(IsSameObject, jni, threadsList[i], thread)) { + NSK_DISPLAY0("SUCCESS: expected THREAD_END event\n"); + + /* suspend thread */ + NSK_DISPLAY3(" suspend finishing thread #%d (%s): %p\n", + i, threadsName[i], (void*)thread); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(SuspendThread, jvmti, thread))) { + nsk_jvmti_setFailStatus(); + return; + } + eventsEnd++; + + break; + } + } +} + +/* ============================================================================= */ + +static volatile int testedThreadRunning = NSK_FALSE; +static volatile int testedThreadShouldFinish = NSK_FALSE; + +/** Native running method in tested thread. */ +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_sampling_SP05_sp05t003ThreadRunningNative_run(JNIEnv* jni, + jobject obj) { + volatile int i = 0, n = 1000; + + /* run in a loop */ + testedThreadRunning = NSK_TRUE; + while (!testedThreadShouldFinish) { + if (n <= 0) + n = 1000; + if (i >= n) + i = 0; + i++; + } + testedThreadRunning = NSK_FALSE; +} + +/** Wait for native method is running. */ +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_scenarios_sampling_SP05_sp05t003ThreadRunningNative_checkStarted(JNIEnv* jni, + jobject obj) { + while (!testedThreadRunning) { + nsk_jvmti_sleep(1000); + } + return testedThreadRunning ? JNI_TRUE : JNI_FALSE; +} + +/** Let native method to finish. */ +JNIEXPORT void JNICALL +Java_nsk_jvmti_scenarios_sampling_SP05_sp05t003ThreadRunningNative_letFinish(JNIEnv* jni, + jobject obj) { + testedThreadShouldFinish = NSK_TRUE; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_sp05t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_sp05t003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_sp05t003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* add capabilities for suspending thread */ + { + jvmtiCapabilities suspendCaps; + memset(&suspendCaps, 0, sizeof(suspendCaps)); + suspendCaps.can_suspend = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti, &suspendCaps))) + return JNI_ERR; + } + + /* set events callbacks */ + { + jvmtiEventCallbacks eventCallbacks; + memset(&eventCallbacks, 0, sizeof(eventCallbacks)); + eventCallbacks.ThreadStart = callbackThreadStart; + eventCallbacks.ThreadEnd = callbackThreadEnd; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti, + &eventCallbacks, sizeof(eventCallbacks)))) + return JNI_ERR; + } + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/libsp06t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/libsp06t001.c deleted file mode 100644 index cd126ed686b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/libsp06t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp06t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/libsp06t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/libsp06t001.cpp new file mode 100644 index 00000000000..88148c9a31f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/libsp06t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp06t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/sp06t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/sp06t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/sp06t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t001/sp06t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/libsp06t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/libsp06t002.c deleted file mode 100644 index f5c9d88eebd..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/libsp06t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp06t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/libsp06t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/libsp06t002.cpp new file mode 100644 index 00000000000..841f30c6ff1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/libsp06t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp06t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/sp06t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/sp06t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/sp06t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t002/sp06t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/libsp06t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/libsp06t003.c deleted file mode 100644 index 017e8f6b2e9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/libsp06t003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp06t003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/libsp06t003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/libsp06t003.cpp new file mode 100644 index 00000000000..4a95c98aeb1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/libsp06t003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp06t003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/sp06t003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/sp06t003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/sp06t003.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/sp06t003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/libsp07t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/libsp07t001.c deleted file mode 100644 index f613fa2c75b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/libsp07t001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp07t001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/libsp07t001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/libsp07t001.cpp new file mode 100644 index 00000000000..47281631f79 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/libsp07t001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp07t001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/sp07t001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/sp07t001.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/sp07t001.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t001/sp07t001.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/libsp07t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/libsp07t002.c deleted file mode 100644 index 2ee0bd48cdf..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/libsp07t002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "sp07t002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/libsp07t002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/libsp07t002.cpp new file mode 100644 index 00000000000..b5d42961ed8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/libsp07t002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "sp07t002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/sp07t002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/sp07t002.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/sp07t002.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/sp07t002.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/followref001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/followref001.c deleted file mode 100644 index c04e3d0d139..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/followref001.c +++ /dev/null @@ -1,885 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -static jlong timeout = 0; - -#define DEBUGEE_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref001" -#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref001RootTestedClass" -#define ROOT_OBJECT_CLASS_SIG "L"ROOT_OBJECT_CLASS_NAME";" -#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref001TestedClass" -#define CHAIN_OBJECT_CLASS_SIG "L"CHAIN_OBJECT_CLASS_NAME";" - -#define OBJECT_FIELD_NAME "rootObject" -#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" -#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" -#define NEXT_FIELD_NAME "next" - - -#define DEFAULT_CHAIN_LENGTH 3 -#define FULL_32_BIT_MASK 0xFFFFFFFF - -typedef struct ObjectDescStruct { - jlong tag; /* Tag of the object */ - jlong exp_class_tag; /* Expected tag of the object class */ - jlong class_tag; /* Reported tag of the object class */ - jint exp_found; /* Expected number of iterations through the object */ - jint found; /* Reported number of iterations through the object */ -} ObjectDesc; - -static int chainLength = 0; -static int objectsCount = 0; -static int fakeUserData = 0; -static int userDataError = 0; - -static ObjectDesc* objectDescList = NULL; - -static const jlong ROOT_CLASS_TAG = 9; -static const jlong CHAIN_CLASS_TAG = 99; -static const jlong ROOT_OBJECT_TAG = 10; -static const jlong CHAIN_OBJECT_TAG = 100; - -static jvmtiHeapCallbacks heapCallbacks = {0}; - -/* This array has to be up-to-date with the jvmtiHeapReferenceKind enum */ -static const char* ref_kind_str[28] = { - "unknown_0", - "JVMTI_HEAP_REFERENCE_CLASS", - "JVMTI_HEAP_REFERENCE_FIELD", - "JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT", - "JVMTI_HEAP_REFERENCE_CLASS_LOADER", - "JVMTI_HEAP_REFERENCE_SIGNERS", - "JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN", - "JVMTI_HEAP_REFERENCE_INTERFACE", - "JVMTI_HEAP_REFERENCE_STATIC_FIELD", - "JVMTI_HEAP_REFERENCE_CONSTANT_POOL", - "JVMTI_HEAP_REFERENCE_SUPERCLASS", - "unknown_11", "unknown_12", "unknown_13", "unknown_14", "unknown_15", - "unknown_16", "unknown_17", "unknown_18", "unknown_19", "unknown_20", - "JVMTI_HEAP_REFERENCE_JNI_GLOBAL", - "JVMTI_HEAP_REFERENCE_SYSTEM_CLASS", - "JVMTI_HEAP_REFERENCE_MONITOR", - "JVMTI_HEAP_REFERENCE_STACK_LOCAL", - "JVMTI_HEAP_REFERENCE_JNI_LOCAL", - "JVMTI_HEAP_REFERENCE_THREAD", - "JVMTI_HEAP_REFERENCE_OTHER" -}; - -#define DEREF(ptr) (((ptr) == NULL ? 0 : *(ptr))) - - -/* ============================================================================= */ - -static int get_reference_index(jvmtiHeapReferenceKind reference_kind, - const jvmtiHeapReferenceInfo* reference_info) -{ - int referrer_index = 0; - - switch (reference_kind) { - case JVMTI_HEAP_REFERENCE_CONSTANT_POOL: - referrer_index = reference_info->constant_pool.index; - break; - case JVMTI_HEAP_REFERENCE_FIELD: - case JVMTI_HEAP_REFERENCE_STATIC_FIELD: - referrer_index = reference_info->field.index; - break; - case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT: - referrer_index = reference_info->array.index; - break; - case JVMTI_HEAP_REFERENCE_STACK_LOCAL: - referrer_index = reference_info->stack_local.slot; - /* Fall through */ - case JVMTI_HEAP_REFERENCE_JNI_LOCAL: - referrer_index |= reference_info->stack_local.depth << 16; - break; - default: - // TODO: check that realy should be done w/ other jvmtiHeapReferenceKind - break; - } - - return referrer_index; -} /* get_reference_index */ - - -/** Initialize objectDescList. */ -static int initObjectDescList(jvmtiEnv* jvmti, - int chainLength, - int* objectsCount, - ObjectDesc** objectDescList) -{ - /* root object + reachable and unreachable object chains */ - *objectsCount = 1 + 2 * chainLength; - - printf("Allocate memory for objects list: %d objects\n", *objectsCount); - fflush(0); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, - (*objectsCount * sizeof(ObjectDesc)), - (unsigned char**) objectDescList))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... allocated array: 0x%p\n", (void*)objectDescList); - fflush(0); - - { - int k; - for (k = 0; k < *objectsCount; k++) { - (*objectDescList)[k].tag = 0; - (*objectDescList)[k].exp_class_tag = CHAIN_CLASS_TAG; - (*objectDescList)[k].exp_found = 0; - (*objectDescList)[k].found = 0; - } - } - (*objectDescList)[0].exp_class_tag = ROOT_CLASS_TAG; - (*objectDescList)[0].tag = ROOT_OBJECT_TAG; - - /* Object with tag=100 must be referenced 2 times */ - (*objectDescList)[chainLength].exp_found = 1; - - - return NSK_TRUE; -} /* initObjectDescList */ - - -/** Find and tag classes. */ -static int getAndTagClasses(jvmtiEnv* jvmti, - JNIEnv* jni, - jclass* debugeeClass, - jclass* rootObjectClass, - jclass* chainObjectClass) -{ - - if (!NSK_JNI_VERIFY(jni, (*debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf("\nFound debugee class: 0x%p\n %s\n", - (void*) *debugeeClass, DEBUGEE_CLASS_NAME); - fflush(0); - - if (!NSK_JNI_VERIFY(jni, (*rootObjectClass = - NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, - *rootObjectClass, - ROOT_CLASS_TAG))) { - nsk_jvmti_setFailStatus(); - } - - printf("\nFound root object class: 0x%p, tag=%ld\n %s\n", - (void*) *rootObjectClass,(long) ROOT_CLASS_TAG, - ROOT_OBJECT_CLASS_NAME); - fflush(0); - - - if (!NSK_JNI_VERIFY(jni, (*chainObjectClass = - NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, - *chainObjectClass, - CHAIN_CLASS_TAG))) { - nsk_jvmti_setFailStatus(); - } - printf("\nFound chain object class: 0x%p, tag=%ld\n %s\n", - (void*) *chainObjectClass, (long) CHAIN_CLASS_TAG, - CHAIN_OBJECT_CLASS_NAME); - fflush(0); - - return NSK_TRUE; -} /* getAndTagClasses */ - - -/** Obtain chain of tested objects and tag them recursively. */ -static int getFieldsAndObjects(jvmtiEnv* jvmti, - JNIEnv* jni, - jclass debugeeClass, - jclass rootObjectClass, - jclass chainObjectClass, - jobject* rootObjectPtr, - jfieldID* reachableChainField, - jfieldID* unreachableChainField, - jfieldID* nextField) -{ - jfieldID rootObjectField = NULL; - - if (!NSK_JNI_VERIFY(jni, (rootObjectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, - debugeeClass, - OBJECT_FIELD_NAME, - ROOT_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf("\nFound fieldID: 0x%p - \'%s\' static field in debugee class\n", - (void*) rootObjectField, OBJECT_FIELD_NAME); - fflush(0); - - if (!NSK_JNI_VERIFY(jni, (*reachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - REACHABLE_CHAIN_FIELD_NAME, - CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf("\nFound fieldID: 0x%p - \'%s\' field in root object class\n", - (void*) reachableChainField, REACHABLE_CHAIN_FIELD_NAME); - fflush(0); - - if (!NSK_JNI_VERIFY(jni, (*unreachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - UNREACHABLE_CHAIN_FIELD_NAME, - CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - printf("\nFound fieldID: 0x%p - \'%s\' field in root object class\n", - (void*) unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME); - fflush(0); - - if (!NSK_JNI_VERIFY(jni, (*nextField = - NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, - NEXT_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf("\nFound fieldID: 0x%p - \'%s\' field in chain object class\n", - (void*) nextField, NEXT_FIELD_NAME); - fflush(0); - - if (!NSK_JNI_VERIFY(jni, (*rootObjectPtr = - NSK_CPP_STUB3(GetStaticObjectField, jni, - debugeeClass, rootObjectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf("\nFound root object: 0x%p\n", (void*) *rootObjectPtr); - fflush(0); - - if (!NSK_JNI_VERIFY(jni, (*rootObjectPtr = - NSK_CPP_STUB2(NewGlobalRef, jni, *rootObjectPtr)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf("Created root object global ref: 0x%p\n", (void*)*rootObjectPtr); - fflush(0); - - return NSK_TRUE; -} /* getFieldsAndObjects */ - - -/** Obtain chain of tested objects and tag them recursively. */ -static int getAndTagChainObjects( - jvmtiEnv* jvmti, - JNIEnv* jni, - jobject currObj, - jfieldID refField, - jfieldID nextField, - int count, - ObjectDesc objectDescList[], - jlong tag, - int reachable) -{ - jobject nextObj = NULL; - jlong objTag = (reachable ? tag : -tag); - - if (count <= 0) { - return NSK_TRUE; - } - - count--; - tag++; - - if (!NSK_JNI_VERIFY(jni, (nextObj = - NSK_CPP_STUB3(GetObjectField, jni, currObj, refField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - objectDescList[count].tag = objTag; - if (reachable) { - objectDescList[count].exp_found++; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, nextObj, objTag))) { - nsk_jvmti_setFailStatus(); - } - printf(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)nextObj); - fflush(0); - - /* To continue traversing objects in the chain */ - if (!getAndTagChainObjects(jvmti, - jni, - nextObj, - nextField, - nextField, - count, - objectDescList, - tag, - reachable) - ) { - return NSK_FALSE; - } - - NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, nextObj)); - - return NSK_TRUE; -} /* getAndTagChainObjects */ - -/** Obtain all tested objects from debugee class and tag them recursively. */ -static int getAndTagTestedObjects( - jvmtiEnv* jvmti, - JNIEnv* jni, - int chainLength, - int* objectsCount, - ObjectDesc** objectDescList, - jobject* rootObjectPtr) -{ - jclass debugeeClass = NULL; - jclass rootObjectClass = NULL; - jclass chainObjectClass = NULL; - - jfieldID reachableChainField = NULL; - jfieldID unreachableChainField = NULL; - jfieldID nextField = NULL; - - if (initObjectDescList(jvmti, - chainLength, - objectsCount, - objectDescList) == NSK_FALSE) { - return NSK_FALSE; - } - - if (getAndTagClasses(jvmti, - jni, - &debugeeClass, - &rootObjectClass, - &chainObjectClass) == NSK_FALSE) { - return NSK_FALSE; - } - - if (getFieldsAndObjects(jvmti, - jni, - debugeeClass, - rootObjectClass, - chainObjectClass, - rootObjectPtr, - &reachableChainField, - &unreachableChainField, - &nextField) == NSK_FALSE) { - return NSK_FALSE; - } - - printf("\nObtain and tag chain objects:\n"); - printf(" root tested object:\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, - *rootObjectPtr, - ROOT_OBJECT_TAG)) - ) { - nsk_jvmti_setFailStatus(); - } - printf(" tag=%-5ld object = 0x%p\n", - (long) ROOT_OBJECT_TAG, (void*) *rootObjectPtr); - - printf(" reachable objects chain: %d objects\n", chainLength); - fflush(0); - - if (!getAndTagChainObjects(jvmti, - jni, - *rootObjectPtr, - reachableChainField, - nextField, - chainLength, - (*objectDescList) + 1, - CHAIN_OBJECT_TAG, - NSK_TRUE) /* reachable objects */ - ) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - printf(" unreachable objects chain: %d objects\n", chainLength); - if (!getAndTagChainObjects(jvmti, - jni, - *rootObjectPtr, - unreachableChainField, - nextField, - chainLength, - (*objectDescList) + 1 + chainLength, - CHAIN_OBJECT_TAG, - NSK_FALSE) /* unreachable objects */ - ) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} /* getAndTagTestedObjects */ - -/** Check if tagged objects were iterated. */ -static int checkTestedObjects(jvmtiEnv* jvmti, - JNIEnv* jni, - int chainLength, - ObjectDesc objectDescList[]) -{ - int success = NSK_TRUE; - int i, idx; - - printf("Following tagged objects were iterated:\n"); - - printf("Root tested object:\n"); - printf(" tag: %ld\n" - " expected to iterate: %d times\n" - " iterated: %d times\n", - (long) objectDescList[0].tag, - objectDescList[0].exp_found, - objectDescList[0].found); - if (objectDescList[0].found != objectDescList[0].exp_found) { - NSK_COMPLAIN1("Root tested object unexpectedly iterated %d times\n", - objectDescList[0].found); - nsk_jvmti_setFailStatus(); - } - - printf("\nReachable objects:\n"); - fflush(0); - for (i = 0; i < chainLength; i++) { - idx = i + 1; - printf("Reachable object:\n" - " tag: %-3ld\n" - " expected to iterate: %d times\n" - " iterated: %d times\n", - (long) objectDescList[idx].tag, - objectDescList[idx].exp_found, - objectDescList[idx].found); - if (objectDescList[i + 1].found <= 0) { - NSK_COMPLAIN0("Reachable object was not iterated\n"); - nsk_jvmti_setFailStatus(); - } - if (objectDescList[idx].found != objectDescList[idx].exp_found) { - NSK_COMPLAIN0("Reachable object was iterated unexpected number of times\n"); - nsk_jvmti_setFailStatus(); - } - } - - printf("\nUnreachable objects:\n"); - for (i = 0; i < chainLength; i++) { - idx = i + 1 + chainLength; - - printf("Unreachable object:\n" - " tag: %ld\n" - " expected to iterate: %d times\n" - " iterated: %d times\n", - (long) objectDescList[idx].tag, - objectDescList[idx].exp_found, - objectDescList[idx].found); - if (objectDescList[idx].found > 0) { - NSK_COMPLAIN0("Unreachable object was iterated\n"); - nsk_jvmti_setFailStatus(); - } - fflush(0); - } - - return NSK_TRUE; -} /* checkTestedObjects */ - - -/** Release references to the tested objects and free allocated memory. */ -static int releaseTestedObjects(jvmtiEnv* jvmti, - JNIEnv* jni, - int chainLength, - ObjectDesc* objectDescList, - jobject rootObject) -{ - if (rootObject != NULL) { - printf("Release object reference to root tested object: 0x%p\n", rootObject); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, rootObject)); - } - - if (objectDescList != NULL) { - printf("Deallocate objects list: 0x%p\n", (void*)objectDescList); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { - nsk_jvmti_setFailStatus(); - } - } - - fflush(0); - return NSK_TRUE; -} /* releaseTestedObjects */ - - -/* ============================================================================= */ - -/** heapReferenceCallback for heap iterator. */ -jint JNICALL heapReferenceCallback( - jvmtiHeapReferenceKind reference_kind, - const jvmtiHeapReferenceInfo* reference_info, - jlong class_tag, - jlong referrer_class_tag, - jlong size, - jlong* tag_ptr, - jlong* referrer_tag_ptr, - jint length, - void* user_data) -{ - jint referrer_index = 0; - jlong tag; - jlong ref_tag; - - printf(" heapReferenceCallback: %s\n", ref_kind_str[reference_kind]); - printf(" reference_info: 0x%p, class_tag: 0x%"LL"d, referrer_class_tag: 0x%"LL"d\n", - reference_info, class_tag, referrer_class_tag); - /* ss45998: class_tag=>referrence_class_tag */ - printf(" size: %"LL"d, tag_ptr: 0x%p, referrer_tag_ptr: 0x%p, length: %-d\n", - size, tag_ptr, referrer_tag_ptr, length); - fflush(0); - - if (((uintptr_t) tag_ptr & FULL_32_BIT_MASK) == FULL_32_BIT_MASK) { - NSK_COMPLAIN1("wrong tag_ptr passed to " - "heapReferenceCallback: %#lx\n", tag_ptr); - nsk_jvmti_setFailStatus(); - tag = 0; - } else { - tag = DEREF(tag_ptr); - } - - if (((uintptr_t) referrer_tag_ptr & FULL_32_BIT_MASK) == FULL_32_BIT_MASK) { - NSK_COMPLAIN1("wrong referrer_tag_ptr passed to " - "heapReferenceCallback: %#lx\n", referrer_tag_ptr); - nsk_jvmti_setFailStatus(); - ref_tag = 0; - } else { - ref_tag = DEREF(referrer_tag_ptr); - } - - referrer_index = get_reference_index(reference_kind, reference_info); - - printf(" class_tag=%"LL"d, tag=%"LL"d, size=%"LL"d," - " ref_tag=%"LL"d, referrer_index=%d\n\n", - class_tag, tag, size, ref_tag, referrer_index); - fflush(0); - - if (length != -1) { - NSK_COMPLAIN1("wrong length passed to heapReferenceCallback: " - "%d; must be: -1\n", length); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr != NULL && *tag_ptr != 0) { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - - if (*tag_ptr < 0) { - NSK_COMPLAIN0("Unreachable tagged object is passed" - " to heapReferenceCallback\n"); - nsk_jvmti_setFailStatus(); - } - break; - } - } - - if (reference_kind != JVMTI_HEAP_REFERENCE_CLASS && found <= 0) { - NSK_COMPLAIN0("Unknown tagged object is passed" - " to heapReferenceCallback\n"); - nsk_jvmti_setFailStatus(); - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed" - " to heapReferenceCallback:\n" - " expected: 0x%p\n" - " actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - switch (reference_kind) { - int i; - case JVMTI_HEAP_REFERENCE_CLASS: { - if (tag == 0) { - return 0; - } - if (tag != ROOT_CLASS_TAG && tag != CHAIN_CLASS_TAG) { - NSK_COMPLAIN0("Unknown tagged class is passed" - " to heapReferenceCallback\n"); - nsk_jvmti_setFailStatus(); - } - for (i = 0; i < objectsCount; i++) { - if (ref_tag == objectDescList[i].tag) { - if (objectDescList[i].exp_class_tag != tag) { - NSK_COMPLAIN2("Wrong tag in heapReferenceCallback" - "/JVMTI_HEAP_REFERENCE_CLASS:\n" - "Expected: %-3ld\n" - "Passed: %-3ld\n", - objectDescList[i].exp_class_tag, - tag); - nsk_jvmti_setFailStatus(); - } - break; - } - } - return 0; - } - case JVMTI_HEAP_REFERENCE_JNI_GLOBAL: - case JVMTI_HEAP_REFERENCE_SYSTEM_CLASS: - case JVMTI_HEAP_REFERENCE_MONITOR: - case JVMTI_HEAP_REFERENCE_STACK_LOCAL: - case JVMTI_HEAP_REFERENCE_JNI_LOCAL: - case JVMTI_HEAP_REFERENCE_THREAD: - case JVMTI_HEAP_REFERENCE_OTHER: { - NSK_COMPLAIN1("This reference kind was not expected: %s\n", - ref_kind_str[reference_kind]); - fflush(0); - nsk_jvmti_setFailStatus(); - return 0; - } - default: - // TODO: check that realy should be done w/ other jvmtiHeapReferenceKind - break; - } - return JVMTI_VISIT_OBJECTS; -} /* heapReferenceCallback */ - - -jint JNICALL primitiveFieldCallback( - jvmtiHeapReferenceKind reference_kind, - const jvmtiHeapReferenceInfo* reference_info, - jlong class_tag, - jlong* tag_ptr, - jvalue value, - jvmtiPrimitiveType value_type, - void* user_data) -{ - printf(" primitiveFieldCallback: ref=%s," - " class_tag=%-3ld, tag=%-3ld, type=%c\n", - ref_kind_str[reference_kind], - (long) class_tag, - (long) DEREF(tag_ptr), - (int ) value_type); - fflush(0); - return 0; -} /* primitiveFieldCallback */ - - -jint JNICALL arrayPrimitiveValueCallback( - jlong class_tag, - jlong size, - jlong* tag_ptr, - jint element_count, - jvmtiPrimitiveType element_type, - const void* elements, - void* user_data) -{ - printf(" arrayPrimitiveValueCallback: class_tag=%-3ld," - " tag=%-3ld, len=%d, type=%c\n", - (long) class_tag, - (long) DEREF(tag_ptr), - (int ) element_count, - (int ) element_type); - fflush(0); - return 0; -} /* arrayPrimitiveValueCallback */ - - -jint JNICALL stringPrimitiveValueCallback( - jlong class_tag, - jlong size, - jlong* tag_ptr, - const jchar* value, - jint value_length, - void* user_data) -{ - printf("stringPrimitiveValueCallback: class_tag=%-3ld, tag=%-3ld, len=%d\n", - (long) class_tag, - (long) DEREF(tag_ptr), - (int ) value_length); - fflush(0); - return 0; -} /* stringPrimitiveValueCallback */ - - - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - jobject rootObject = NULL; - - printf("Wait for tested objects created\n"); - fflush(0); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) { - return; - } - - - printf(">>> Obtain and tag tested objects from debugee class\n"); - fflush(0); - - if (!NSK_VERIFY(getAndTagTestedObjects(jvmti, - jni, - chainLength, - &objectsCount, - &objectDescList, - &rootObject)) - ) { - return; - } - - printf(">>> Let debugee to clean links to unreachable objects\n"); - fflush(0); - - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) { - return; - } - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) { - return; - } - - printf(">>> Start iteration from root tested object: 0x%p\n\n", rootObject); - fflush(0); - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB6(FollowReferences, jvmti, - (jint) 0, /* heap_filter */ - (jclass) NULL, /* class */ - rootObject, /* initial_object */ - &heapCallbacks, - (const void *) &fakeUserData)) - ) { - nsk_jvmti_setFailStatus(); - return; - } - - printf(">>> Check if reachable objects were iterated:\n"); - fflush(0); - - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - - printf(">>> Clean used data\n"); - fflush(0); - - if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, - objectDescList, rootObject))) { - return; - } - - printf(">>> Let debugee to finish\n"); - fflush(0); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) { - return; - } -} /* agentProc */ - - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_followref001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_followref001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_followref001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) { - return JNI_ERR; - } - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); - if (!NSK_VERIFY(chainLength > 0)) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) { - return JNI_ERR; - } - - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - /* Setting Heap Callbacks */ - heapCallbacks.heap_iteration_callback = NULL; - heapCallbacks.heap_reference_callback = heapReferenceCallback; - heapCallbacks.primitive_field_callback = primitiveFieldCallback; - heapCallbacks.array_primitive_value_callback = arrayPrimitiveValueCallback; - heapCallbacks.string_primitive_value_callback = stringPrimitiveValueCallback; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) { - return JNI_ERR; - } - - return JNI_OK; -} /* Agent_OnLoad */ - - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/followref001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/followref001.cpp new file mode 100644 index 00000000000..a771ccbc5fb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/followref001.cpp @@ -0,0 +1,885 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jlong timeout = 0; + +#define DEBUGEE_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref001" +#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref001RootTestedClass" +#define ROOT_OBJECT_CLASS_SIG "L" ROOT_OBJECT_CLASS_NAME ";" +#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref001TestedClass" +#define CHAIN_OBJECT_CLASS_SIG "L" CHAIN_OBJECT_CLASS_NAME ";" + +#define OBJECT_FIELD_NAME "rootObject" +#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" +#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" +#define NEXT_FIELD_NAME "next" + + +#define DEFAULT_CHAIN_LENGTH 3 +#define FULL_32_BIT_MASK 0xFFFFFFFF + +typedef struct ObjectDescStruct { + jlong tag; /* Tag of the object */ + jlong exp_class_tag; /* Expected tag of the object class */ + jlong class_tag; /* Reported tag of the object class */ + jint exp_found; /* Expected number of iterations through the object */ + jint found; /* Reported number of iterations through the object */ +} ObjectDesc; + +static int chainLength = 0; +static int objectsCount = 0; +static int fakeUserData = 0; +static int userDataError = 0; + +static ObjectDesc* objectDescList = NULL; + +static const jlong ROOT_CLASS_TAG = 9; +static const jlong CHAIN_CLASS_TAG = 99; +static const jlong ROOT_OBJECT_TAG = 10; +static const jlong CHAIN_OBJECT_TAG = 100; + +static jvmtiHeapCallbacks heapCallbacks = {}; + +/* This array has to be up-to-date with the jvmtiHeapReferenceKind enum */ +static const char* ref_kind_str[28] = { + "unknown_0", + "JVMTI_HEAP_REFERENCE_CLASS", + "JVMTI_HEAP_REFERENCE_FIELD", + "JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT", + "JVMTI_HEAP_REFERENCE_CLASS_LOADER", + "JVMTI_HEAP_REFERENCE_SIGNERS", + "JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN", + "JVMTI_HEAP_REFERENCE_INTERFACE", + "JVMTI_HEAP_REFERENCE_STATIC_FIELD", + "JVMTI_HEAP_REFERENCE_CONSTANT_POOL", + "JVMTI_HEAP_REFERENCE_SUPERCLASS", + "unknown_11", "unknown_12", "unknown_13", "unknown_14", "unknown_15", + "unknown_16", "unknown_17", "unknown_18", "unknown_19", "unknown_20", + "JVMTI_HEAP_REFERENCE_JNI_GLOBAL", + "JVMTI_HEAP_REFERENCE_SYSTEM_CLASS", + "JVMTI_HEAP_REFERENCE_MONITOR", + "JVMTI_HEAP_REFERENCE_STACK_LOCAL", + "JVMTI_HEAP_REFERENCE_JNI_LOCAL", + "JVMTI_HEAP_REFERENCE_THREAD", + "JVMTI_HEAP_REFERENCE_OTHER" +}; + +#define DEREF(ptr) (((ptr) == NULL ? 0 : *(ptr))) + + +/* ============================================================================= */ + +static int get_reference_index(jvmtiHeapReferenceKind reference_kind, + const jvmtiHeapReferenceInfo* reference_info) +{ + int referrer_index = 0; + + switch (reference_kind) { + case JVMTI_HEAP_REFERENCE_CONSTANT_POOL: + referrer_index = reference_info->constant_pool.index; + break; + case JVMTI_HEAP_REFERENCE_FIELD: + case JVMTI_HEAP_REFERENCE_STATIC_FIELD: + referrer_index = reference_info->field.index; + break; + case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT: + referrer_index = reference_info->array.index; + break; + case JVMTI_HEAP_REFERENCE_STACK_LOCAL: + referrer_index = reference_info->stack_local.slot; + /* Fall through */ + case JVMTI_HEAP_REFERENCE_JNI_LOCAL: + referrer_index |= reference_info->stack_local.depth << 16; + break; + default: + // TODO: check that realy should be done w/ other jvmtiHeapReferenceKind + break; + } + + return referrer_index; +} /* get_reference_index */ + + +/** Initialize objectDescList. */ +static int initObjectDescList(jvmtiEnv* jvmti, + int chainLength, + int* objectsCount, + ObjectDesc** objectDescList) +{ + /* root object + reachable and unreachable object chains */ + *objectsCount = 1 + 2 * chainLength; + + printf("Allocate memory for objects list: %d objects\n", *objectsCount); + fflush(0); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, + (*objectsCount * sizeof(ObjectDesc)), + (unsigned char**) objectDescList))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... allocated array: 0x%p\n", (void*)objectDescList); + fflush(0); + + { + int k; + for (k = 0; k < *objectsCount; k++) { + (*objectDescList)[k].tag = 0; + (*objectDescList)[k].exp_class_tag = CHAIN_CLASS_TAG; + (*objectDescList)[k].exp_found = 0; + (*objectDescList)[k].found = 0; + } + } + (*objectDescList)[0].exp_class_tag = ROOT_CLASS_TAG; + (*objectDescList)[0].tag = ROOT_OBJECT_TAG; + + /* Object with tag=100 must be referenced 2 times */ + (*objectDescList)[chainLength].exp_found = 1; + + + return NSK_TRUE; +} /* initObjectDescList */ + + +/** Find and tag classes. */ +static int getAndTagClasses(jvmtiEnv* jvmti, + JNIEnv* jni, + jclass* debugeeClass, + jclass* rootObjectClass, + jclass* chainObjectClass) +{ + + if (!NSK_JNI_VERIFY(jni, (*debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf("\nFound debugee class: 0x%p\n %s\n", + (void*) *debugeeClass, DEBUGEE_CLASS_NAME); + fflush(0); + + if (!NSK_JNI_VERIFY(jni, (*rootObjectClass = + NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, + *rootObjectClass, + ROOT_CLASS_TAG))) { + nsk_jvmti_setFailStatus(); + } + + printf("\nFound root object class: 0x%p, tag=%ld\n %s\n", + (void*) *rootObjectClass,(long) ROOT_CLASS_TAG, + ROOT_OBJECT_CLASS_NAME); + fflush(0); + + + if (!NSK_JNI_VERIFY(jni, (*chainObjectClass = + NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, + *chainObjectClass, + CHAIN_CLASS_TAG))) { + nsk_jvmti_setFailStatus(); + } + printf("\nFound chain object class: 0x%p, tag=%ld\n %s\n", + (void*) *chainObjectClass, (long) CHAIN_CLASS_TAG, + CHAIN_OBJECT_CLASS_NAME); + fflush(0); + + return NSK_TRUE; +} /* getAndTagClasses */ + + +/** Obtain chain of tested objects and tag them recursively. */ +static int getFieldsAndObjects(jvmtiEnv* jvmti, + JNIEnv* jni, + jclass debugeeClass, + jclass rootObjectClass, + jclass chainObjectClass, + jobject* rootObjectPtr, + jfieldID* reachableChainField, + jfieldID* unreachableChainField, + jfieldID* nextField) +{ + jfieldID rootObjectField = NULL; + + if (!NSK_JNI_VERIFY(jni, (rootObjectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, + debugeeClass, + OBJECT_FIELD_NAME, + ROOT_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf("\nFound fieldID: 0x%p - \'%s\' static field in debugee class\n", + (void*) rootObjectField, OBJECT_FIELD_NAME); + fflush(0); + + if (!NSK_JNI_VERIFY(jni, (*reachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + REACHABLE_CHAIN_FIELD_NAME, + CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf("\nFound fieldID: 0x%p - \'%s\' field in root object class\n", + (void*) reachableChainField, REACHABLE_CHAIN_FIELD_NAME); + fflush(0); + + if (!NSK_JNI_VERIFY(jni, (*unreachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + UNREACHABLE_CHAIN_FIELD_NAME, + CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + printf("\nFound fieldID: 0x%p - \'%s\' field in root object class\n", + (void*) unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME); + fflush(0); + + if (!NSK_JNI_VERIFY(jni, (*nextField = + NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, + NEXT_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf("\nFound fieldID: 0x%p - \'%s\' field in chain object class\n", + (void*) nextField, NEXT_FIELD_NAME); + fflush(0); + + if (!NSK_JNI_VERIFY(jni, (*rootObjectPtr = + NSK_CPP_STUB3(GetStaticObjectField, jni, + debugeeClass, rootObjectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf("\nFound root object: 0x%p\n", (void*) *rootObjectPtr); + fflush(0); + + if (!NSK_JNI_VERIFY(jni, (*rootObjectPtr = + NSK_CPP_STUB2(NewGlobalRef, jni, *rootObjectPtr)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf("Created root object global ref: 0x%p\n", (void*)*rootObjectPtr); + fflush(0); + + return NSK_TRUE; +} /* getFieldsAndObjects */ + + +/** Obtain chain of tested objects and tag them recursively. */ +static int getAndTagChainObjects( + jvmtiEnv* jvmti, + JNIEnv* jni, + jobject currObj, + jfieldID refField, + jfieldID nextField, + int count, + ObjectDesc objectDescList[], + jlong tag, + int reachable) +{ + jobject nextObj = NULL; + jlong objTag = (reachable ? tag : -tag); + + if (count <= 0) { + return NSK_TRUE; + } + + count--; + tag++; + + if (!NSK_JNI_VERIFY(jni, (nextObj = + NSK_CPP_STUB3(GetObjectField, jni, currObj, refField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + objectDescList[count].tag = objTag; + if (reachable) { + objectDescList[count].exp_found++; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, nextObj, objTag))) { + nsk_jvmti_setFailStatus(); + } + printf(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)nextObj); + fflush(0); + + /* To continue traversing objects in the chain */ + if (!getAndTagChainObjects(jvmti, + jni, + nextObj, + nextField, + nextField, + count, + objectDescList, + tag, + reachable) + ) { + return NSK_FALSE; + } + + NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, nextObj)); + + return NSK_TRUE; +} /* getAndTagChainObjects */ + +/** Obtain all tested objects from debugee class and tag them recursively. */ +static int getAndTagTestedObjects( + jvmtiEnv* jvmti, + JNIEnv* jni, + int chainLength, + int* objectsCount, + ObjectDesc** objectDescList, + jobject* rootObjectPtr) +{ + jclass debugeeClass = NULL; + jclass rootObjectClass = NULL; + jclass chainObjectClass = NULL; + + jfieldID reachableChainField = NULL; + jfieldID unreachableChainField = NULL; + jfieldID nextField = NULL; + + if (initObjectDescList(jvmti, + chainLength, + objectsCount, + objectDescList) == NSK_FALSE) { + return NSK_FALSE; + } + + if (getAndTagClasses(jvmti, + jni, + &debugeeClass, + &rootObjectClass, + &chainObjectClass) == NSK_FALSE) { + return NSK_FALSE; + } + + if (getFieldsAndObjects(jvmti, + jni, + debugeeClass, + rootObjectClass, + chainObjectClass, + rootObjectPtr, + &reachableChainField, + &unreachableChainField, + &nextField) == NSK_FALSE) { + return NSK_FALSE; + } + + printf("\nObtain and tag chain objects:\n"); + printf(" root tested object:\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, + *rootObjectPtr, + ROOT_OBJECT_TAG)) + ) { + nsk_jvmti_setFailStatus(); + } + printf(" tag=%-5ld object = 0x%p\n", + (long) ROOT_OBJECT_TAG, (void*) *rootObjectPtr); + + printf(" reachable objects chain: %d objects\n", chainLength); + fflush(0); + + if (!getAndTagChainObjects(jvmti, + jni, + *rootObjectPtr, + reachableChainField, + nextField, + chainLength, + (*objectDescList) + 1, + CHAIN_OBJECT_TAG, + NSK_TRUE) /* reachable objects */ + ) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + printf(" unreachable objects chain: %d objects\n", chainLength); + if (!getAndTagChainObjects(jvmti, + jni, + *rootObjectPtr, + unreachableChainField, + nextField, + chainLength, + (*objectDescList) + 1 + chainLength, + CHAIN_OBJECT_TAG, + NSK_FALSE) /* unreachable objects */ + ) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} /* getAndTagTestedObjects */ + +/** Check if tagged objects were iterated. */ +static int checkTestedObjects(jvmtiEnv* jvmti, + JNIEnv* jni, + int chainLength, + ObjectDesc objectDescList[]) +{ + int success = NSK_TRUE; + int i, idx; + + printf("Following tagged objects were iterated:\n"); + + printf("Root tested object:\n"); + printf(" tag: %ld\n" + " expected to iterate: %d times\n" + " iterated: %d times\n", + (long) objectDescList[0].tag, + objectDescList[0].exp_found, + objectDescList[0].found); + if (objectDescList[0].found != objectDescList[0].exp_found) { + NSK_COMPLAIN1("Root tested object unexpectedly iterated %d times\n", + objectDescList[0].found); + nsk_jvmti_setFailStatus(); + } + + printf("\nReachable objects:\n"); + fflush(0); + for (i = 0; i < chainLength; i++) { + idx = i + 1; + printf("Reachable object:\n" + " tag: %-3ld\n" + " expected to iterate: %d times\n" + " iterated: %d times\n", + (long) objectDescList[idx].tag, + objectDescList[idx].exp_found, + objectDescList[idx].found); + if (objectDescList[i + 1].found <= 0) { + NSK_COMPLAIN0("Reachable object was not iterated\n"); + nsk_jvmti_setFailStatus(); + } + if (objectDescList[idx].found != objectDescList[idx].exp_found) { + NSK_COMPLAIN0("Reachable object was iterated unexpected number of times\n"); + nsk_jvmti_setFailStatus(); + } + } + + printf("\nUnreachable objects:\n"); + for (i = 0; i < chainLength; i++) { + idx = i + 1 + chainLength; + + printf("Unreachable object:\n" + " tag: %ld\n" + " expected to iterate: %d times\n" + " iterated: %d times\n", + (long) objectDescList[idx].tag, + objectDescList[idx].exp_found, + objectDescList[idx].found); + if (objectDescList[idx].found > 0) { + NSK_COMPLAIN0("Unreachable object was iterated\n"); + nsk_jvmti_setFailStatus(); + } + fflush(0); + } + + return NSK_TRUE; +} /* checkTestedObjects */ + + +/** Release references to the tested objects and free allocated memory. */ +static int releaseTestedObjects(jvmtiEnv* jvmti, + JNIEnv* jni, + int chainLength, + ObjectDesc* objectDescList, + jobject rootObject) +{ + if (rootObject != NULL) { + printf("Release object reference to root tested object: 0x%p\n", rootObject); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, rootObject)); + } + + if (objectDescList != NULL) { + printf("Deallocate objects list: 0x%p\n", (void*)objectDescList); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { + nsk_jvmti_setFailStatus(); + } + } + + fflush(0); + return NSK_TRUE; +} /* releaseTestedObjects */ + + +/* ============================================================================= */ + +/** heapReferenceCallback for heap iterator. */ +jint JNICALL heapReferenceCallback( + jvmtiHeapReferenceKind reference_kind, + const jvmtiHeapReferenceInfo* reference_info, + jlong class_tag, + jlong referrer_class_tag, + jlong size, + jlong* tag_ptr, + jlong* referrer_tag_ptr, + jint length, + void* user_data) +{ + jint referrer_index = 0; + jlong tag; + jlong ref_tag; + + printf(" heapReferenceCallback: %s\n", ref_kind_str[reference_kind]); + printf(" reference_info: 0x%p, class_tag: 0x%" LL "d, referrer_class_tag: 0x%" LL "d\n", + reference_info, class_tag, referrer_class_tag); + /* ss45998: class_tag=>referrence_class_tag */ + printf(" size: %" LL "d, tag_ptr: 0x%p, referrer_tag_ptr: 0x%p, length: %-d\n", + size, tag_ptr, referrer_tag_ptr, length); + fflush(0); + + if (((uintptr_t) tag_ptr & FULL_32_BIT_MASK) == FULL_32_BIT_MASK) { + NSK_COMPLAIN1("wrong tag_ptr passed to " + "heapReferenceCallback: %#lx\n", tag_ptr); + nsk_jvmti_setFailStatus(); + tag = 0; + } else { + tag = DEREF(tag_ptr); + } + + if (((uintptr_t) referrer_tag_ptr & FULL_32_BIT_MASK) == FULL_32_BIT_MASK) { + NSK_COMPLAIN1("wrong referrer_tag_ptr passed to " + "heapReferenceCallback: %#lx\n", referrer_tag_ptr); + nsk_jvmti_setFailStatus(); + ref_tag = 0; + } else { + ref_tag = DEREF(referrer_tag_ptr); + } + + referrer_index = get_reference_index(reference_kind, reference_info); + + printf(" class_tag=%" LL "d, tag=%" LL "d, size=%" LL "d," + " ref_tag=%" LL "d, referrer_index=%d\n\n", + class_tag, tag, size, ref_tag, referrer_index); + fflush(0); + + if (length != -1) { + NSK_COMPLAIN1("wrong length passed to heapReferenceCallback: " + "%d; must be: -1\n", length); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr != NULL && *tag_ptr != 0) { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + + if (*tag_ptr < 0) { + NSK_COMPLAIN0("Unreachable tagged object is passed" + " to heapReferenceCallback\n"); + nsk_jvmti_setFailStatus(); + } + break; + } + } + + if (reference_kind != JVMTI_HEAP_REFERENCE_CLASS && found <= 0) { + NSK_COMPLAIN0("Unknown tagged object is passed" + " to heapReferenceCallback\n"); + nsk_jvmti_setFailStatus(); + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed" + " to heapReferenceCallback:\n" + " expected: 0x%p\n" + " actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + switch (reference_kind) { + int i; + case JVMTI_HEAP_REFERENCE_CLASS: { + if (tag == 0) { + return 0; + } + if (tag != ROOT_CLASS_TAG && tag != CHAIN_CLASS_TAG) { + NSK_COMPLAIN0("Unknown tagged class is passed" + " to heapReferenceCallback\n"); + nsk_jvmti_setFailStatus(); + } + for (i = 0; i < objectsCount; i++) { + if (ref_tag == objectDescList[i].tag) { + if (objectDescList[i].exp_class_tag != tag) { + NSK_COMPLAIN2("Wrong tag in heapReferenceCallback" + "/JVMTI_HEAP_REFERENCE_CLASS:\n" + "Expected: %-3ld\n" + "Passed: %-3ld\n", + objectDescList[i].exp_class_tag, + tag); + nsk_jvmti_setFailStatus(); + } + break; + } + } + return 0; + } + case JVMTI_HEAP_REFERENCE_JNI_GLOBAL: + case JVMTI_HEAP_REFERENCE_SYSTEM_CLASS: + case JVMTI_HEAP_REFERENCE_MONITOR: + case JVMTI_HEAP_REFERENCE_STACK_LOCAL: + case JVMTI_HEAP_REFERENCE_JNI_LOCAL: + case JVMTI_HEAP_REFERENCE_THREAD: + case JVMTI_HEAP_REFERENCE_OTHER: { + NSK_COMPLAIN1("This reference kind was not expected: %s\n", + ref_kind_str[reference_kind]); + fflush(0); + nsk_jvmti_setFailStatus(); + return 0; + } + default: + // TODO: check that realy should be done w/ other jvmtiHeapReferenceKind + break; + } + return JVMTI_VISIT_OBJECTS; +} /* heapReferenceCallback */ + + +jint JNICALL primitiveFieldCallback( + jvmtiHeapReferenceKind reference_kind, + const jvmtiHeapReferenceInfo* reference_info, + jlong class_tag, + jlong* tag_ptr, + jvalue value, + jvmtiPrimitiveType value_type, + void* user_data) +{ + printf(" primitiveFieldCallback: ref=%s," + " class_tag=%-3ld, tag=%-3ld, type=%c\n", + ref_kind_str[reference_kind], + (long) class_tag, + (long) DEREF(tag_ptr), + (int ) value_type); + fflush(0); + return 0; +} /* primitiveFieldCallback */ + + +jint JNICALL arrayPrimitiveValueCallback( + jlong class_tag, + jlong size, + jlong* tag_ptr, + jint element_count, + jvmtiPrimitiveType element_type, + const void* elements, + void* user_data) +{ + printf(" arrayPrimitiveValueCallback: class_tag=%-3ld," + " tag=%-3ld, len=%d, type=%c\n", + (long) class_tag, + (long) DEREF(tag_ptr), + (int ) element_count, + (int ) element_type); + fflush(0); + return 0; +} /* arrayPrimitiveValueCallback */ + + +jint JNICALL stringPrimitiveValueCallback( + jlong class_tag, + jlong size, + jlong* tag_ptr, + const jchar* value, + jint value_length, + void* user_data) +{ + printf("stringPrimitiveValueCallback: class_tag=%-3ld, tag=%-3ld, len=%d\n", + (long) class_tag, + (long) DEREF(tag_ptr), + (int ) value_length); + fflush(0); + return 0; +} /* stringPrimitiveValueCallback */ + + + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + jobject rootObject = NULL; + + printf("Wait for tested objects created\n"); + fflush(0); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) { + return; + } + + + printf(">>> Obtain and tag tested objects from debugee class\n"); + fflush(0); + + if (!NSK_VERIFY(getAndTagTestedObjects(jvmti, + jni, + chainLength, + &objectsCount, + &objectDescList, + &rootObject)) + ) { + return; + } + + printf(">>> Let debugee to clean links to unreachable objects\n"); + fflush(0); + + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) { + return; + } + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) { + return; + } + + printf(">>> Start iteration from root tested object: 0x%p\n\n", rootObject); + fflush(0); + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB6(FollowReferences, jvmti, + (jint) 0, /* heap_filter */ + (jclass) NULL, /* class */ + rootObject, /* initial_object */ + &heapCallbacks, + (const void *) &fakeUserData)) + ) { + nsk_jvmti_setFailStatus(); + return; + } + + printf(">>> Check if reachable objects were iterated:\n"); + fflush(0); + + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + + printf(">>> Clean used data\n"); + fflush(0); + + if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, + objectDescList, rootObject))) { + return; + } + + printf(">>> Let debugee to finish\n"); + fflush(0); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) { + return; + } +} /* agentProc */ + + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_followref001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_followref001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_followref001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) { + return JNI_ERR; + } + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); + if (!NSK_VERIFY(chainLength > 0)) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) { + return JNI_ERR; + } + + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + /* Setting Heap Callbacks */ + heapCallbacks.heap_iteration_callback = NULL; + heapCallbacks.heap_reference_callback = heapReferenceCallback; + heapCallbacks.primitive_field_callback = primitiveFieldCallback; + heapCallbacks.array_primitive_value_callback = arrayPrimitiveValueCallback; + heapCallbacks.string_primitive_value_callback = stringPrimitiveValueCallback; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) { + return JNI_ERR; + } + + return JNI_OK; +} /* Agent_OnLoad */ + + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/libfollowref001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/libfollowref001.c deleted file mode 100644 index 8892bc942d9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/libfollowref001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "followref001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/libfollowref001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/libfollowref001.cpp new file mode 100644 index 00000000000..eec1499e722 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref001/libfollowref001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "followref001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/followref002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/followref002.c deleted file mode 100644 index 2855fcd0072..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/followref002.c +++ /dev/null @@ -1,778 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -static jlong timeout = 0; - -#define DEBUGEE_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref002" -#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref002RootTestedClass" -#define ROOT_OBJECT_CLASS_SIG "L"ROOT_OBJECT_CLASS_NAME";" -#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref002TestedClass" -#define CHAIN_OBJECT_CLASS_SIG "L"CHAIN_OBJECT_CLASS_NAME";" - -#define OBJECT_FIELD_NAME "object" -#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" -#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" -#define TAIL_FIELD_NAME "tail" - - -#define DEFAULT_CHAIN_LENGTH 3 - -typedef struct ObjectDescStruct { - jlong tag; /* Tag of the object */ - jlong exp_class_tag; /* Expected tag of the object class */ - jlong class_tag; /* Reported tag of the object class */ - jint exp_found; /* Expected number of iterations through the object */ - jint found; /* Reported number of iterations through the object */ -} ObjectDesc; - -static int chainLength = 0; -static int objectsCount = 0; -static int fakeUserData = 0; -static int userDataError = 0; - -static ObjectDesc* objectDescList = NULL; - -static jlong rootClassTag = 9; -static jlong chainClassTag = 99; -static jlong rootObjectTag = 10; -static jlong chainObjectTag = 100; - -static jvmtiHeapCallbacks heapCallbacks = {0}; - -static const char* ref_kind_str[28] = { - "unknown_0", - "JVMTI_HEAP_REFERENCE_CLASS", - "JVMTI_HEAP_REFERENCE_FIELD", - "JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT", - "JVMTI_HEAP_REFERENCE_CLASS_LOADER", - "JVMTI_HEAP_REFERENCE_SIGNERS", - "JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN", - "JVMTI_HEAP_REFERENCE_INTERFACE", - "JVMTI_HEAP_REFERENCE_STATIC_FIELD", - "JVMTI_HEAP_REFERENCE_CONSTANT_POOL", - "unknown_10", "unknown_11", "unknown_12", - "unknown_13", "unknown_14", "unknown_15", "unknown_16", - "unknown_17", "unknown_18", "unknown_19", "unknown_20", - "JVMTI_HEAP_REFERENCE_JNI_GLOBAL", - "JVMTI_HEAP_REFERENCE_SYSTEM_CLASS", - "JVMTI_HEAP_REFERENCE_MONITOR", - "JVMTI_HEAP_REFERENCE_STACK_LOCAL", - "JVMTI_HEAP_REFERENCE_JNI_LOCAL", - "JVMTI_HEAP_REFERENCE_THREAD", - "JVMTI_HEAP_REFERENCE_OTHER" -}; - -#define DEREF(ptr) (((ptr) == NULL ? 0 : *(ptr))) - -/* ============================================================================= */ - -/** Obtain chain of tested objects and tag them recursively. */ -static int getAndTagChainObjects( - jvmtiEnv* jvmti, - JNIEnv* jni, - jobject firstObject, - jfieldID firstField, - const char firstFieldName[], - jfieldID nextField, - const char nextFieldName[], - int count, - ObjectDesc objectDescList[], - jlong tag, - int reachable) -{ - jobject obj = NULL; - jlong objTag = (reachable ? tag : -tag); - - if (count <= 0) - return NSK_TRUE; - - count--; - tag++; - - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - objectDescList[count].tag = objTag; - if (reachable) { - objectDescList[count].exp_found++; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { - nsk_jvmti_setFailStatus(); - } - printf(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); - fflush(0); - if (!getAndTagChainObjects(jvmti, jni, obj, - nextField, - nextFieldName, - nextField, - nextFieldName, - count, - objectDescList, - tag, - reachable)) { - return NSK_FALSE; - } - - NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); - return NSK_TRUE; -} /* getAndTagChainObjects */ - -/** Obtain all tested objects from debugee class and tag them recursively. */ -static int getAndTagTestedObjects( - jvmtiEnv* jvmti, - JNIEnv* jni, - int chainLength, - int* objectsCount, - ObjectDesc** objectDescList, - jobject* rootObject) -{ - jclass debugeeClass = NULL; - jclass rootObjectClass = NULL; - jclass chainObjectClass = NULL; - - jfieldID objectField = NULL; - jfieldID reachableChainField = NULL; - jfieldID unreachableChainField = NULL; - jfieldID tailField = NULL; - - /* root object + reachable and unreachable object chains */ - *objectsCount = 1 + 2 * chainLength; - - printf("Allocate memory for objects list: %d objects\n", *objectsCount); - fflush(0); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), - (unsigned char**)objectDescList))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... allocated array: 0x%p\n", (void*)objectDescList); - fflush(0); - - { - int k; - for (k = 0; k < *objectsCount; k++) { - (*objectDescList)[k].tag = 0; - (*objectDescList)[k].exp_class_tag = chainClassTag; - (*objectDescList)[k].exp_found = 0; - (*objectDescList)[k].found = 0; - } - } - (*objectDescList)[0].exp_class_tag = rootClassTag; - - printf("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... found class: 0x%p\n", (void*)debugeeClass); - - printf("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (rootObjectClass = - NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... found class: 0x%p\n", (void*)rootObjectClass); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, rootObjectClass, rootClassTag))) { - nsk_jvmti_setFailStatus(); - } - printf(" tag=%-5ld rootClass=0x%p\n", (long)rootClassTag, (void*)rootObjectClass); - - printf("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (chainObjectClass = - NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... found class: 0x%p\n", (void*)chainObjectClass); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, chainObjectClass, chainClassTag))) { - nsk_jvmti_setFailStatus(); - } - printf(" tag=%-5ld chainClass=0x%p\n", (long)chainClassTag, (void*)chainObjectClass); - - printf("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... got fieldID: 0x%p\n", (void*)objectField); - - printf("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (reachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... got fieldID: 0x%p\n", (void*)reachableChainField); - - printf("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (unreachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); - - printf("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (tailField = - NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, - TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... got fieldID: 0x%p\n", (void*)tailField); - - printf("Get root object from static field: %s\n", OBJECT_FIELD_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (*rootObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... got object: 0x%p\n", (void*)*rootObject); - fflush(0); - - if (!NSK_JNI_VERIFY(jni, (*rootObject = - NSK_CPP_STUB2(NewGlobalRef, jni, *rootObject)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... global ref: 0x%p\n", (void*)*rootObject); - - printf("Obtain and tag chain objects:\n"); - - printf(" root tested object:\n"); - fflush(0); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, *rootObject, rootObjectTag))) { - nsk_jvmti_setFailStatus(); - } - printf(" tag=%-5ld object=0x%p\n", (long)rootObjectTag, (void*)*rootObject); - - (*objectDescList)[0].tag = rootObjectTag; - - /* Root object must be referenced 1 time */ - (*objectDescList)[0].exp_found = 1; - - /* Object with tag=101 must be referenced 2 times */ - (*objectDescList)[chainLength].exp_found = 1; - - printf(" reachable objects chain: %d objects\n", chainLength); - fflush(0); - if (!getAndTagChainObjects(jvmti, jni, *rootObject, - reachableChainField, - REACHABLE_CHAIN_FIELD_NAME, - tailField, - TAIL_FIELD_NAME, - chainLength, - (*objectDescList) + 1, - chainObjectTag, - NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - printf(" unreachable objects chain: %d objects\n", chainLength); - if (!getAndTagChainObjects(jvmti, jni, *rootObject, - unreachableChainField, - UNREACHABLE_CHAIN_FIELD_NAME, - tailField, - TAIL_FIELD_NAME, - chainLength, - (*objectDescList) + 1 + chainLength, - chainObjectTag, - NSK_FALSE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} /* getAndTagTestedObjects */ - -/** Check if tagged objects were iterated. */ -static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, - int chainLength, ObjectDesc objectDescList[]) { - int success = NSK_TRUE; - int i, idx; - - printf("Following tagged objects were iterated:\n"); - - printf("Root tested object:\n"); - printf(" tag: %ld\n" - " expected to iterate: %d times\n" - " iterated: %d times\n", - (long) objectDescList[0].tag, - objectDescList[0].exp_found, - objectDescList[0].found); - if (objectDescList[0].found != objectDescList[0].exp_found) { - NSK_COMPLAIN1("Root tested object unexpectedly iterated %d times\n", - objectDescList[0].found); - nsk_jvmti_setFailStatus(); - } - - printf("\nReachable objects:\n"); - fflush(0); - for (i = 0; i < chainLength; i++) { - idx = i + 1; - printf("Reachable object:\n" - " tag: %-3ld\n" - " expected to iterate: %d times\n" - " iterated: %d times\n", - (long) objectDescList[idx].tag, - objectDescList[idx].exp_found, - objectDescList[idx].found); - if (objectDescList[i + 1].found <= 0 && objectDescList[i + 1].exp_found > 0) { - NSK_COMPLAIN0("Reachable object was not iterated\n"); - nsk_jvmti_setFailStatus(); - } - if (objectDescList[idx].found != objectDescList[idx].exp_found) { - NSK_COMPLAIN0("Reachable object was iterated unexpected number of times\n"); - nsk_jvmti_setFailStatus(); - } - } - - printf("\nUnreachable objects:\n"); - for (i = 0; i < chainLength; i++) { - idx = i + 1 + chainLength; - - printf("Unreachable object:\n" - " tag: %ld\n" - " expected to iterate: %d times\n" - " iterated: %d times\n", - (long) objectDescList[idx].tag, - objectDescList[idx].exp_found, - objectDescList[idx].found); - if (objectDescList[idx].found > 0) { - NSK_COMPLAIN0("Unreachable object was iterated\n"); - nsk_jvmti_setFailStatus(); - } - fflush(0); - } - - return NSK_TRUE; -} /* checkTestedObjects */ - -/** Release references to the tested objects and free allocated memory. */ -static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - ObjectDesc* objectDescList, jobject rootObject) { - if (rootObject != NULL) { - printf("Release object reference to root tested object: 0x%p\n", rootObject); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, rootObject)); - } - - if (objectDescList != NULL) { - printf("Deallocate objects list: 0x%p\n", (void*)objectDescList); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { - nsk_jvmti_setFailStatus(); - } - } - - fflush(0); - return NSK_TRUE; -} /* releaseTestedObjects */ - -/* ============================================================================= */ - -/** heapReferenceCallback for heap iterator. */ -jint JNICALL heapReferenceCallback( - jvmtiHeapReferenceKind reference_kind, - const jvmtiHeapReferenceInfo* reference_info, - jlong class_tag, - jlong referrer_class_tag, - jlong size, - jlong* tag_ptr, - jlong* referrer_tag_ptr, - jint length, - void* user_data) -{ - jint referrer_index = 0; - jlong tag = DEREF(tag_ptr); - jlong ref_tag = DEREF(referrer_tag_ptr); - - switch (reference_kind) { - case JVMTI_HEAP_REFERENCE_CONSTANT_POOL: - referrer_index = reference_info->constant_pool.index; - break; - case JVMTI_HEAP_REFERENCE_FIELD: - case JVMTI_HEAP_REFERENCE_STATIC_FIELD: - referrer_index = reference_info->field.index; - break; - case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT: - referrer_index = reference_info->array.index; - break; - case JVMTI_HEAP_REFERENCE_STACK_LOCAL: - referrer_index = reference_info->stack_local.slot; - /* Fall through */ - case JVMTI_HEAP_REFERENCE_JNI_LOCAL: - referrer_index |= reference_info->stack_local.depth << 16; - break; - default: - // TODO: check that realy should be done w/ other jvmtiHeapReferenceKind - break; - } - - printf(" heapReferenceCallback: ref=%s, class_tag=%-3ld, tag=%-3ld," - " size=%-3ld, ref_tag=%-3ld, ref_idx=%#x\n", - ref_kind_str[reference_kind], - (long) class_tag, - (long) tag, - (long) size, - (long) ref_tag, - (int ) referrer_index); - fflush(0); - - if (tag_ptr == NULL) { - NSK_COMPLAIN1("NULL tag_ptr is passed to heapReferenceCallback:" - " tag_ptr=0x%p\n", (void*)tag_ptr); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr != NULL && *tag_ptr != 0) { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - - if (*tag_ptr < 0) { - NSK_COMPLAIN0("Unreachable tagged object is passed to heapReferenceCallback\n"); - nsk_jvmti_setFailStatus(); - } - break; - } - } - - if (reference_kind != JVMTI_HEAP_REFERENCE_CLASS && found <= 0) { - NSK_COMPLAIN0("Unknown tagged object is passed to heapReferenceCallback\n"); - nsk_jvmti_setFailStatus(); - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed to heapReferenceCallback:\n" - " expected: 0x%p\n" - " actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - switch (reference_kind) { - int i; - case JVMTI_HEAP_REFERENCE_CLASS: { - if (tag == 0) { - break; - } - if (tag != rootClassTag && tag != chainClassTag) { - NSK_COMPLAIN0("Unknown tagged class is passed to heapReferenceCallback\n"); - nsk_jvmti_setFailStatus(); - } - for (i = 0; i < objectsCount; i++) { - if (ref_tag == objectDescList[i].tag) { - if (objectDescList[i].exp_class_tag != tag) { - NSK_COMPLAIN2("Wrong tag in heapReferenceCallback/JVMTI_HEAP_REFERENCE_CLASS:\n" - "Expected: %-3ld\n" - "Passed: %-3ld\n", - objectDescList[i].exp_class_tag, - tag); - nsk_jvmti_setFailStatus(); - } - break; - } - } - break; - } - case JVMTI_HEAP_REFERENCE_JNI_GLOBAL: - case JVMTI_HEAP_REFERENCE_SYSTEM_CLASS: - case JVMTI_HEAP_REFERENCE_MONITOR: - case JVMTI_HEAP_REFERENCE_STACK_LOCAL: - case JVMTI_HEAP_REFERENCE_JNI_LOCAL: - case JVMTI_HEAP_REFERENCE_THREAD: - case JVMTI_HEAP_REFERENCE_OTHER: { - NSK_COMPLAIN1("This reference kind was not expected: %s\n", - ref_kind_str[reference_kind]); - fflush(0); - nsk_jvmti_setFailStatus(); - return 0; - } - default: - // TODO: check that realy should be done w/ other jvmtiHeapReferenceKind - break; - } - return JVMTI_VISIT_OBJECTS; -} - -jint JNICALL primitiveFieldCallback( - jvmtiHeapReferenceKind reference_kind, - const jvmtiHeapReferenceInfo* reference_info, - jlong class_tag, - jlong* tag_ptr, - jvalue value, - jvmtiPrimitiveType value_type, - void* user_data) -{ - printf(" primitiveFieldCallback: ref=%s, class_tag=%-3ld, tag=%-3ld, type=%c\n", - ref_kind_str[reference_kind], - (long) class_tag, - (long) DEREF(tag_ptr), - (int ) value_type); - fflush(0); - return 0; -} - -jint JNICALL arrayPrimitiveValueCallback( - jlong class_tag, - jlong size, - jlong* tag_ptr, - jint element_count, - jvmtiPrimitiveType element_type, - const void* elements, - void* user_data) -{ - printf(" arrayPrimitiveValueCallback: class_tag=%-3ld, tag=%-3ld, len=%d, type=%c\n", - (long) class_tag, - (long) DEREF(tag_ptr), - (int ) element_count, - (int ) element_type); - fflush(0); - return 0; -} - -jint JNICALL stringPrimitiveValueCallback( - jlong class_tag, - jlong size, - jlong* tag_ptr, - const jchar* value, - jint value_length, - void* user_data) -{ - printf("stringPrimitiveValueCallback: class_tag=%-3ld, tag=%-3ld, len=%d\n", - (long) class_tag, - (long) DEREF(tag_ptr), - (int ) value_length); - fflush(0); - return 0; -} - -/* ============================================================================= */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - jobject rootObject = NULL; - - printf("Wait for tested objects created\n"); - fflush(0); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) { - return; - } - - printf(">>> Obtain and tag tested objects from debugee class\n"); - fflush(0); - { - if (!NSK_VERIFY(getAndTagTestedObjects(jvmti, jni, - chainLength, &objectsCount, - &objectDescList, &rootObject))) { - return; - } - } - - printf(">>> Let debugee to clean links to unreachable objects\n"); - fflush(0); - { - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) { - return; - } - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) { - return; - } - } - - printf("\n\n>>> Start 1-st iteration for root tested object: 0x%p\n", rootObject); - fflush(0); - { - jint heap_filter = JVMTI_HEAP_FILTER_UNTAGGED | JVMTI_HEAP_FILTER_CLASS_UNTAGGED; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB6(FollowReferences, jvmti, - heap_filter, - (jclass) NULL, /* class */ - rootObject, /* initial_object */ - &heapCallbacks, - (const void *) &fakeUserData))) - { - nsk_jvmti_setFailStatus(); - return; - } - } - - printf(">>> Check if reachable objects were iterated\n"); - fflush(0); - { - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - } - - - { /* Reinstall the expectations */ - int k; - for (k = 0; k < objectsCount; k++) { - (objectDescList)[k].exp_found = 0; - (objectDescList)[k].found = 0; - } - } - - printf("\n\n>>> Start 2-nd iteration for root tested object: 0x%p\n", rootObject); - fflush(0); - { - /* This time everythig is filtered out */ - jint heap_filter = JVMTI_HEAP_FILTER_UNTAGGED | JVMTI_HEAP_FILTER_CLASS_UNTAGGED | - JVMTI_HEAP_FILTER_TAGGED | JVMTI_HEAP_FILTER_CLASS_TAGGED; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB6(FollowReferences, jvmti, - heap_filter, - (jclass) NULL, /* class */ - rootObject, /* initial_object */ - &heapCallbacks, - (const void *) &fakeUserData))) - { - nsk_jvmti_setFailStatus(); - return; - } - } - - printf(">>> Check if reachable objects were not reported this time\n"); - fflush(0); - { - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - } - - printf(">>> Clean used data\n"); - fflush(0); - { - if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, objectDescList, rootObject))) { - return; - } - } - - printf("Let debugee to finish\n"); - fflush(0); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_followref002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_followref002(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_followref002(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); - if (!NSK_VERIFY(chainLength > 0)) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - /* Setting Heap Callbacks */ - heapCallbacks.heap_iteration_callback = NULL; - heapCallbacks.heap_reference_callback = heapReferenceCallback; - heapCallbacks.primitive_field_callback = primitiveFieldCallback; - heapCallbacks.array_primitive_value_callback = arrayPrimitiveValueCallback; - heapCallbacks.string_primitive_value_callback = stringPrimitiveValueCallback; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/followref002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/followref002.cpp new file mode 100644 index 00000000000..684915a5eba --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/followref002.cpp @@ -0,0 +1,778 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jlong timeout = 0; + +#define DEBUGEE_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref002" +#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref002RootTestedClass" +#define ROOT_OBJECT_CLASS_SIG "L" ROOT_OBJECT_CLASS_NAME ";" +#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref002TestedClass" +#define CHAIN_OBJECT_CLASS_SIG "L" CHAIN_OBJECT_CLASS_NAME ";" + +#define OBJECT_FIELD_NAME "object" +#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" +#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" +#define TAIL_FIELD_NAME "tail" + + +#define DEFAULT_CHAIN_LENGTH 3 + +typedef struct ObjectDescStruct { + jlong tag; /* Tag of the object */ + jlong exp_class_tag; /* Expected tag of the object class */ + jlong class_tag; /* Reported tag of the object class */ + jint exp_found; /* Expected number of iterations through the object */ + jint found; /* Reported number of iterations through the object */ +} ObjectDesc; + +static int chainLength = 0; +static int objectsCount = 0; +static int fakeUserData = 0; +static int userDataError = 0; + +static ObjectDesc* objectDescList = NULL; + +static jlong rootClassTag = 9; +static jlong chainClassTag = 99; +static jlong rootObjectTag = 10; +static jlong chainObjectTag = 100; + +static jvmtiHeapCallbacks heapCallbacks = {}; + +static const char* ref_kind_str[28] = { + "unknown_0", + "JVMTI_HEAP_REFERENCE_CLASS", + "JVMTI_HEAP_REFERENCE_FIELD", + "JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT", + "JVMTI_HEAP_REFERENCE_CLASS_LOADER", + "JVMTI_HEAP_REFERENCE_SIGNERS", + "JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN", + "JVMTI_HEAP_REFERENCE_INTERFACE", + "JVMTI_HEAP_REFERENCE_STATIC_FIELD", + "JVMTI_HEAP_REFERENCE_CONSTANT_POOL", + "unknown_10", "unknown_11", "unknown_12", + "unknown_13", "unknown_14", "unknown_15", "unknown_16", + "unknown_17", "unknown_18", "unknown_19", "unknown_20", + "JVMTI_HEAP_REFERENCE_JNI_GLOBAL", + "JVMTI_HEAP_REFERENCE_SYSTEM_CLASS", + "JVMTI_HEAP_REFERENCE_MONITOR", + "JVMTI_HEAP_REFERENCE_STACK_LOCAL", + "JVMTI_HEAP_REFERENCE_JNI_LOCAL", + "JVMTI_HEAP_REFERENCE_THREAD", + "JVMTI_HEAP_REFERENCE_OTHER" +}; + +#define DEREF(ptr) (((ptr) == NULL ? 0 : *(ptr))) + +/* ============================================================================= */ + +/** Obtain chain of tested objects and tag them recursively. */ +static int getAndTagChainObjects( + jvmtiEnv* jvmti, + JNIEnv* jni, + jobject firstObject, + jfieldID firstField, + const char firstFieldName[], + jfieldID nextField, + const char nextFieldName[], + int count, + ObjectDesc objectDescList[], + jlong tag, + int reachable) +{ + jobject obj = NULL; + jlong objTag = (reachable ? tag : -tag); + + if (count <= 0) + return NSK_TRUE; + + count--; + tag++; + + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + objectDescList[count].tag = objTag; + if (reachable) { + objectDescList[count].exp_found++; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { + nsk_jvmti_setFailStatus(); + } + printf(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); + fflush(0); + if (!getAndTagChainObjects(jvmti, jni, obj, + nextField, + nextFieldName, + nextField, + nextFieldName, + count, + objectDescList, + tag, + reachable)) { + return NSK_FALSE; + } + + NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); + return NSK_TRUE; +} /* getAndTagChainObjects */ + +/** Obtain all tested objects from debugee class and tag them recursively. */ +static int getAndTagTestedObjects( + jvmtiEnv* jvmti, + JNIEnv* jni, + int chainLength, + int* objectsCount, + ObjectDesc** objectDescList, + jobject* rootObject) +{ + jclass debugeeClass = NULL; + jclass rootObjectClass = NULL; + jclass chainObjectClass = NULL; + + jfieldID objectField = NULL; + jfieldID reachableChainField = NULL; + jfieldID unreachableChainField = NULL; + jfieldID tailField = NULL; + + /* root object + reachable and unreachable object chains */ + *objectsCount = 1 + 2 * chainLength; + + printf("Allocate memory for objects list: %d objects\n", *objectsCount); + fflush(0); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), + (unsigned char**)objectDescList))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... allocated array: 0x%p\n", (void*)objectDescList); + fflush(0); + + { + int k; + for (k = 0; k < *objectsCount; k++) { + (*objectDescList)[k].tag = 0; + (*objectDescList)[k].exp_class_tag = chainClassTag; + (*objectDescList)[k].exp_found = 0; + (*objectDescList)[k].found = 0; + } + } + (*objectDescList)[0].exp_class_tag = rootClassTag; + + printf("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... found class: 0x%p\n", (void*)debugeeClass); + + printf("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (rootObjectClass = + NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... found class: 0x%p\n", (void*)rootObjectClass); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, rootObjectClass, rootClassTag))) { + nsk_jvmti_setFailStatus(); + } + printf(" tag=%-5ld rootClass=0x%p\n", (long)rootClassTag, (void*)rootObjectClass); + + printf("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (chainObjectClass = + NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... found class: 0x%p\n", (void*)chainObjectClass); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, chainObjectClass, chainClassTag))) { + nsk_jvmti_setFailStatus(); + } + printf(" tag=%-5ld chainClass=0x%p\n", (long)chainClassTag, (void*)chainObjectClass); + + printf("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... got fieldID: 0x%p\n", (void*)objectField); + + printf("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (reachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... got fieldID: 0x%p\n", (void*)reachableChainField); + + printf("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (unreachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); + + printf("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (tailField = + NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, + TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... got fieldID: 0x%p\n", (void*)tailField); + + printf("Get root object from static field: %s\n", OBJECT_FIELD_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (*rootObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... got object: 0x%p\n", (void*)*rootObject); + fflush(0); + + if (!NSK_JNI_VERIFY(jni, (*rootObject = + NSK_CPP_STUB2(NewGlobalRef, jni, *rootObject)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... global ref: 0x%p\n", (void*)*rootObject); + + printf("Obtain and tag chain objects:\n"); + + printf(" root tested object:\n"); + fflush(0); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, *rootObject, rootObjectTag))) { + nsk_jvmti_setFailStatus(); + } + printf(" tag=%-5ld object=0x%p\n", (long)rootObjectTag, (void*)*rootObject); + + (*objectDescList)[0].tag = rootObjectTag; + + /* Root object must be referenced 1 time */ + (*objectDescList)[0].exp_found = 1; + + /* Object with tag=101 must be referenced 2 times */ + (*objectDescList)[chainLength].exp_found = 1; + + printf(" reachable objects chain: %d objects\n", chainLength); + fflush(0); + if (!getAndTagChainObjects(jvmti, jni, *rootObject, + reachableChainField, + REACHABLE_CHAIN_FIELD_NAME, + tailField, + TAIL_FIELD_NAME, + chainLength, + (*objectDescList) + 1, + chainObjectTag, + NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + printf(" unreachable objects chain: %d objects\n", chainLength); + if (!getAndTagChainObjects(jvmti, jni, *rootObject, + unreachableChainField, + UNREACHABLE_CHAIN_FIELD_NAME, + tailField, + TAIL_FIELD_NAME, + chainLength, + (*objectDescList) + 1 + chainLength, + chainObjectTag, + NSK_FALSE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} /* getAndTagTestedObjects */ + +/** Check if tagged objects were iterated. */ +static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, + int chainLength, ObjectDesc objectDescList[]) { + int success = NSK_TRUE; + int i, idx; + + printf("Following tagged objects were iterated:\n"); + + printf("Root tested object:\n"); + printf(" tag: %ld\n" + " expected to iterate: %d times\n" + " iterated: %d times\n", + (long) objectDescList[0].tag, + objectDescList[0].exp_found, + objectDescList[0].found); + if (objectDescList[0].found != objectDescList[0].exp_found) { + NSK_COMPLAIN1("Root tested object unexpectedly iterated %d times\n", + objectDescList[0].found); + nsk_jvmti_setFailStatus(); + } + + printf("\nReachable objects:\n"); + fflush(0); + for (i = 0; i < chainLength; i++) { + idx = i + 1; + printf("Reachable object:\n" + " tag: %-3ld\n" + " expected to iterate: %d times\n" + " iterated: %d times\n", + (long) objectDescList[idx].tag, + objectDescList[idx].exp_found, + objectDescList[idx].found); + if (objectDescList[i + 1].found <= 0 && objectDescList[i + 1].exp_found > 0) { + NSK_COMPLAIN0("Reachable object was not iterated\n"); + nsk_jvmti_setFailStatus(); + } + if (objectDescList[idx].found != objectDescList[idx].exp_found) { + NSK_COMPLAIN0("Reachable object was iterated unexpected number of times\n"); + nsk_jvmti_setFailStatus(); + } + } + + printf("\nUnreachable objects:\n"); + for (i = 0; i < chainLength; i++) { + idx = i + 1 + chainLength; + + printf("Unreachable object:\n" + " tag: %ld\n" + " expected to iterate: %d times\n" + " iterated: %d times\n", + (long) objectDescList[idx].tag, + objectDescList[idx].exp_found, + objectDescList[idx].found); + if (objectDescList[idx].found > 0) { + NSK_COMPLAIN0("Unreachable object was iterated\n"); + nsk_jvmti_setFailStatus(); + } + fflush(0); + } + + return NSK_TRUE; +} /* checkTestedObjects */ + +/** Release references to the tested objects and free allocated memory. */ +static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + ObjectDesc* objectDescList, jobject rootObject) { + if (rootObject != NULL) { + printf("Release object reference to root tested object: 0x%p\n", rootObject); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, rootObject)); + } + + if (objectDescList != NULL) { + printf("Deallocate objects list: 0x%p\n", (void*)objectDescList); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { + nsk_jvmti_setFailStatus(); + } + } + + fflush(0); + return NSK_TRUE; +} /* releaseTestedObjects */ + +/* ============================================================================= */ + +/** heapReferenceCallback for heap iterator. */ +jint JNICALL heapReferenceCallback( + jvmtiHeapReferenceKind reference_kind, + const jvmtiHeapReferenceInfo* reference_info, + jlong class_tag, + jlong referrer_class_tag, + jlong size, + jlong* tag_ptr, + jlong* referrer_tag_ptr, + jint length, + void* user_data) +{ + jint referrer_index = 0; + jlong tag = DEREF(tag_ptr); + jlong ref_tag = DEREF(referrer_tag_ptr); + + switch (reference_kind) { + case JVMTI_HEAP_REFERENCE_CONSTANT_POOL: + referrer_index = reference_info->constant_pool.index; + break; + case JVMTI_HEAP_REFERENCE_FIELD: + case JVMTI_HEAP_REFERENCE_STATIC_FIELD: + referrer_index = reference_info->field.index; + break; + case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT: + referrer_index = reference_info->array.index; + break; + case JVMTI_HEAP_REFERENCE_STACK_LOCAL: + referrer_index = reference_info->stack_local.slot; + /* Fall through */ + case JVMTI_HEAP_REFERENCE_JNI_LOCAL: + referrer_index |= reference_info->stack_local.depth << 16; + break; + default: + // TODO: check that realy should be done w/ other jvmtiHeapReferenceKind + break; + } + + printf(" heapReferenceCallback: ref=%s, class_tag=%-3ld, tag=%-3ld," + " size=%-3ld, ref_tag=%-3ld, ref_idx=%#x\n", + ref_kind_str[reference_kind], + (long) class_tag, + (long) tag, + (long) size, + (long) ref_tag, + (int ) referrer_index); + fflush(0); + + if (tag_ptr == NULL) { + NSK_COMPLAIN1("NULL tag_ptr is passed to heapReferenceCallback:" + " tag_ptr=0x%p\n", (void*)tag_ptr); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr != NULL && *tag_ptr != 0) { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + + if (*tag_ptr < 0) { + NSK_COMPLAIN0("Unreachable tagged object is passed to heapReferenceCallback\n"); + nsk_jvmti_setFailStatus(); + } + break; + } + } + + if (reference_kind != JVMTI_HEAP_REFERENCE_CLASS && found <= 0) { + NSK_COMPLAIN0("Unknown tagged object is passed to heapReferenceCallback\n"); + nsk_jvmti_setFailStatus(); + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed to heapReferenceCallback:\n" + " expected: 0x%p\n" + " actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + switch (reference_kind) { + int i; + case JVMTI_HEAP_REFERENCE_CLASS: { + if (tag == 0) { + break; + } + if (tag != rootClassTag && tag != chainClassTag) { + NSK_COMPLAIN0("Unknown tagged class is passed to heapReferenceCallback\n"); + nsk_jvmti_setFailStatus(); + } + for (i = 0; i < objectsCount; i++) { + if (ref_tag == objectDescList[i].tag) { + if (objectDescList[i].exp_class_tag != tag) { + NSK_COMPLAIN2("Wrong tag in heapReferenceCallback/JVMTI_HEAP_REFERENCE_CLASS:\n" + "Expected: %-3ld\n" + "Passed: %-3ld\n", + objectDescList[i].exp_class_tag, + tag); + nsk_jvmti_setFailStatus(); + } + break; + } + } + break; + } + case JVMTI_HEAP_REFERENCE_JNI_GLOBAL: + case JVMTI_HEAP_REFERENCE_SYSTEM_CLASS: + case JVMTI_HEAP_REFERENCE_MONITOR: + case JVMTI_HEAP_REFERENCE_STACK_LOCAL: + case JVMTI_HEAP_REFERENCE_JNI_LOCAL: + case JVMTI_HEAP_REFERENCE_THREAD: + case JVMTI_HEAP_REFERENCE_OTHER: { + NSK_COMPLAIN1("This reference kind was not expected: %s\n", + ref_kind_str[reference_kind]); + fflush(0); + nsk_jvmti_setFailStatus(); + return 0; + } + default: + // TODO: check that realy should be done w/ other jvmtiHeapReferenceKind + break; + } + return JVMTI_VISIT_OBJECTS; +} + +jint JNICALL primitiveFieldCallback( + jvmtiHeapReferenceKind reference_kind, + const jvmtiHeapReferenceInfo* reference_info, + jlong class_tag, + jlong* tag_ptr, + jvalue value, + jvmtiPrimitiveType value_type, + void* user_data) +{ + printf(" primitiveFieldCallback: ref=%s, class_tag=%-3ld, tag=%-3ld, type=%c\n", + ref_kind_str[reference_kind], + (long) class_tag, + (long) DEREF(tag_ptr), + (int ) value_type); + fflush(0); + return 0; +} + +jint JNICALL arrayPrimitiveValueCallback( + jlong class_tag, + jlong size, + jlong* tag_ptr, + jint element_count, + jvmtiPrimitiveType element_type, + const void* elements, + void* user_data) +{ + printf(" arrayPrimitiveValueCallback: class_tag=%-3ld, tag=%-3ld, len=%d, type=%c\n", + (long) class_tag, + (long) DEREF(tag_ptr), + (int ) element_count, + (int ) element_type); + fflush(0); + return 0; +} + +jint JNICALL stringPrimitiveValueCallback( + jlong class_tag, + jlong size, + jlong* tag_ptr, + const jchar* value, + jint value_length, + void* user_data) +{ + printf("stringPrimitiveValueCallback: class_tag=%-3ld, tag=%-3ld, len=%d\n", + (long) class_tag, + (long) DEREF(tag_ptr), + (int ) value_length); + fflush(0); + return 0; +} + +/* ============================================================================= */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + jobject rootObject = NULL; + + printf("Wait for tested objects created\n"); + fflush(0); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) { + return; + } + + printf(">>> Obtain and tag tested objects from debugee class\n"); + fflush(0); + { + if (!NSK_VERIFY(getAndTagTestedObjects(jvmti, jni, + chainLength, &objectsCount, + &objectDescList, &rootObject))) { + return; + } + } + + printf(">>> Let debugee to clean links to unreachable objects\n"); + fflush(0); + { + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) { + return; + } + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) { + return; + } + } + + printf("\n\n>>> Start 1-st iteration for root tested object: 0x%p\n", rootObject); + fflush(0); + { + jint heap_filter = JVMTI_HEAP_FILTER_UNTAGGED | JVMTI_HEAP_FILTER_CLASS_UNTAGGED; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB6(FollowReferences, jvmti, + heap_filter, + (jclass) NULL, /* class */ + rootObject, /* initial_object */ + &heapCallbacks, + (const void *) &fakeUserData))) + { + nsk_jvmti_setFailStatus(); + return; + } + } + + printf(">>> Check if reachable objects were iterated\n"); + fflush(0); + { + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + } + + + { /* Reinstall the expectations */ + int k; + for (k = 0; k < objectsCount; k++) { + (objectDescList)[k].exp_found = 0; + (objectDescList)[k].found = 0; + } + } + + printf("\n\n>>> Start 2-nd iteration for root tested object: 0x%p\n", rootObject); + fflush(0); + { + /* This time everythig is filtered out */ + jint heap_filter = JVMTI_HEAP_FILTER_UNTAGGED | JVMTI_HEAP_FILTER_CLASS_UNTAGGED | + JVMTI_HEAP_FILTER_TAGGED | JVMTI_HEAP_FILTER_CLASS_TAGGED; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB6(FollowReferences, jvmti, + heap_filter, + (jclass) NULL, /* class */ + rootObject, /* initial_object */ + &heapCallbacks, + (const void *) &fakeUserData))) + { + nsk_jvmti_setFailStatus(); + return; + } + } + + printf(">>> Check if reachable objects were not reported this time\n"); + fflush(0); + { + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + } + + printf(">>> Clean used data\n"); + fflush(0); + { + if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, objectDescList, rootObject))) { + return; + } + } + + printf("Let debugee to finish\n"); + fflush(0); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_followref002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_followref002(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_followref002(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); + if (!NSK_VERIFY(chainLength > 0)) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + /* Setting Heap Callbacks */ + heapCallbacks.heap_iteration_callback = NULL; + heapCallbacks.heap_reference_callback = heapReferenceCallback; + heapCallbacks.primitive_field_callback = primitiveFieldCallback; + heapCallbacks.array_primitive_value_callback = arrayPrimitiveValueCallback; + heapCallbacks.string_primitive_value_callback = stringPrimitiveValueCallback; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/libfollowref002.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/libfollowref002.c deleted file mode 100644 index 59bb333edf7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/libfollowref002.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "followref002.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/libfollowref002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/libfollowref002.cpp new file mode 100644 index 00000000000..f8d0aca908c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref002/libfollowref002.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "followref002.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/followref003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/followref003.c deleted file mode 100644 index 284408a3b58..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/followref003.c +++ /dev/null @@ -1,1113 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvmti.h" -#include "agent_common.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -static jlong timeout = 0; - -#define INFO_NONE 0x00 -#define INFO_ALL 0xFF -#define INFO_OBJREF 0x01 -#define INFO_STACKREF 0x02 -#define INFO_HEAPROOT 0x04 -#define INFO_HEAPOBJ 0x08 - -static unsigned int info = INFO_ALL; - -#define DEBUGEE_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref003" -#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref003RootTestedClass" -#define ROOT_OBJECT_CLASS_SIG "L"ROOT_OBJECT_CLASS_NAME";" -#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref003TestedClass" -#define CHAIN_OBJECT_CLASS_SIG "L"CHAIN_OBJECT_CLASS_NAME";" - -#define OBJECT_FIELD_NAME "object" -#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" -#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" -#define TAIL_FIELD_NAME "tail" - - -#define DEFAULT_CHAIN_LENGTH 3 -#define MAXDEPTH 50 -#define MAXSLOT 16 - -typedef struct ObjectDescStruct { - jlong tag; - jlong class_tag; - jlong exp_class_tag; - jint exp_found; - jint found; -} ObjectDesc; - -static int chainLength = 0; -static int objectsCount = 0; -static int fakeUserData = 0; -static int userDataError = 0; - -static ObjectDesc* objectDescList = NULL; - -#define TARG_THREAD_TAG 11 -#define FIRST_THREAD_TAG (TARG_THREAD_TAG + 1) - -#define TARG_FRAME_DEPTH 1 - -static jlong rootClassTag = 9; -static jlong chainClassTag = 99; -static jlong thrObjectTag = FIRST_THREAD_TAG; -static jlong rootObjectTag = 55; -static jlong chainObjectTag = 100; - - -/* Java method frame slots interesting to check */ -#define ARGV_STRING_ARR_SLOT 1 -#define FIRST_PRIM_ARR_SLOT 3 -#define LAST_PRIM_ARR_SLOT 10 -#define DUMMY_STRING_ARR_SLOT 11 - - -static jvmtiHeapCallbacks heapCallbacks = {0}; - -static const char* ref_kind_str[28] = { - "unknown_0", - "REFERENCE_CLASS", - "REFERENCE_FIELD", - "REFERENCE_ARRAY_ELEMENT", - "REFERENCE_CLASS_LOADER", - "REFERENCE_SIGNERS", - "REFERENCE_PROTECTION_DOMAIN", - "REFERENCE_INTERFACE", - "REFERENCE_STATIC_FIELD", - "REFERENCE_CONSTANT_POOL", - "unknown_10", "unknown_11", "unknown_12", - "unknown_13", "unknown_14", "unknown_15", "unknown_16", - "unknown_17", "unknown_18", "unknown_19", "unknown_20", - "REFERENCE_JNI_GLOBAL", - "REFERENCE_SYSTEM_CLASS", - "REFERENCE_MONITOR", - "REFERENCE_STACK_LOCAL", - "REFERENCE_JNI_LOCAL", - "REFERENCE_THREAD", - "REFERENCE_OTHER" -}; - - -#define DEREF(ptr) (((ptr) == NULL ? 0 : *(ptr))) - - -/* ============================================================================= */ - -/** Obtain chain of tested objects and tag them recursively. */ -static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, - jfieldID firstField, const char firstFieldName[], - jfieldID nextField, const char nextFieldName[], - int count, ObjectDesc objectDescList[], - jlong tag, int reachable) { - jobject obj = NULL; - jlong objTag = (reachable ? tag : -tag); - - if (count <= 0) - return NSK_TRUE; - - count--; - tag++; - - if (!NSK_JNI_VERIFY(jni, (obj = - NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - objectDescList[count].tag = objTag; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { - nsk_jvmti_setFailStatus(); - } - printf(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); - fflush(0); - if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, - nextField, nextFieldName, - count, objectDescList, tag, reachable)) { - return NSK_FALSE; - } - - NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); - return NSK_TRUE; -} - -/** Obtain all tested objects from debugee class and tag them recursively. */ -static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - int *objectsCount, ObjectDesc* *objectDescList, - jobject* rootObject) { - jclass debugeeClass = NULL; - jclass rootObjectClass = NULL; - jclass chainObjectClass = NULL; - - jfieldID objectField = NULL; - jfieldID reachableChainField = NULL; - jfieldID unreachableChainField = NULL; - jfieldID tailField = NULL; - - *objectsCount = 1 + 2 * chainLength; - - printf("Allocate memory for objects list: %d objects\n", *objectsCount); - fflush(0); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), - (unsigned char**)objectDescList))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... allocated array: 0x%p\n", (void*)objectDescList); - fflush(0); - - { - int k; - for (k = 0; k < *objectsCount; k++) { - (*objectDescList)[k].tag = 0; - (*objectDescList)[k].exp_class_tag = chainClassTag; - (*objectDescList)[k].exp_found = 0; - (*objectDescList)[k].found = 0; - } - } - (*objectDescList)[0].exp_class_tag = rootClassTag; - - printf("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (debugeeClass = - NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... found class: 0x%p\n", (void*)debugeeClass); - - printf("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (rootObjectClass = - NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... found class: 0x%p\n", (void*)rootObjectClass); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, rootObjectClass, rootClassTag))) { - nsk_jvmti_setFailStatus(); - } - printf(" tag=%-5ld rootClass=0x%p\n", - (long)rootClassTag, (void*)rootObjectClass); - - printf("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (chainObjectClass = - NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... found class: 0x%p\n", - (void*)chainObjectClass); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, chainObjectClass, chainClassTag))) { - nsk_jvmti_setFailStatus(); - } - printf(" tag=%-5ld chainClass=0x%p\n", - (long)chainClassTag, (void*)chainObjectClass); - - printf("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (objectField = - NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, - OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... got fieldID: 0x%p\n", (void*)objectField); - - printf("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (reachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... got fieldID: 0x%p\n", (void*)reachableChainField); - - printf("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (unreachableChainField = - NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, - UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); - - printf("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (tailField = - NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, - TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... got fieldID: 0x%p\n", (void*)tailField); - - printf("Get root object from static field: %s\n", OBJECT_FIELD_NAME); - fflush(0); - if (!NSK_JNI_VERIFY(jni, (*rootObject = - NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, - objectField)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... got object: 0x%p\n", (void*)*rootObject); - fflush(0); - - if (!NSK_JNI_VERIFY(jni, (*rootObject = - NSK_CPP_STUB2(NewGlobalRef, jni, *rootObject)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - printf(" ... global ref: 0x%p\n", (void*)*rootObject); - - printf("Obtain and tag chain objects:\n"); - - printf(" root tested object\n"); - fflush(0); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, *rootObject, rootObjectTag))) { - nsk_jvmti_setFailStatus(); - } - printf(" tag=%-5ld object=0x%p\n", - (long)rootObjectTag, (void*)*rootObject); - - /* Root object must be reported 1 time */ - (*objectDescList)[0].exp_found = 1; - (*objectDescList)[0].tag = rootObjectTag; - - printf(" reachable objects chain: %d objects\n", chainLength); - fflush(0); - if (!getChainObjects(jvmti, jni, *rootObject, - reachableChainField, REACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, (*objectDescList) + 1, - chainObjectTag, NSK_TRUE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - /* First unreachable object must be reported once - * as JVMTI_HEAP_REFERENCE_STACK_LOCAL */ - (*objectDescList)[2 * chainLength].exp_found = 1; - - printf(" unreachable objects chain: %d objects\n", chainLength); - if (!getChainObjects(jvmti, jni, *rootObject, - unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, - tailField, TAIL_FIELD_NAME, - chainLength, (*objectDescList) + 1 + chainLength, - chainObjectTag, NSK_FALSE)) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/** Check if tagged objects were iterated. */ -static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, - int chainLength, ObjectDesc objectDescList[]) { - int success = NSK_TRUE; - int i, idx; - - printf("Following tagged objects were iterated:\n"); - - printf("Root tested object:\n"); - printf(" tag: %ld\n" - " expected to iterate: %d times\n" - " iterated: %d times\n", - (long) objectDescList[0].tag, - objectDescList[0].exp_found, - objectDescList[0].found); - if (objectDescList[0].found != objectDescList[0].exp_found) { - NSK_COMPLAIN1("Root tested object unexpectedly iterated %d times\n", - objectDescList[0].found); - nsk_jvmti_setFailStatus(); - } - - printf("\nReachable objects:\n"); - fflush(0); - for (i = 0; i < chainLength; i++) { - idx = i + 1; - printf("Reachable object:\n" - " tag: %-3ld\n" - " expected to iterate: %d times\n" - " iterated: %d times\n", - (long) objectDescList[idx].tag, - objectDescList[idx].exp_found, - objectDescList[idx].found); - if (objectDescList[i + 1].found <= 0 && objectDescList[i + 1].exp_found > 0) { - NSK_COMPLAIN0("Reachable object was not iterated\n"); - nsk_jvmti_setFailStatus(); - } - if (objectDescList[idx].found != objectDescList[idx].exp_found) { - NSK_COMPLAIN0("Reachable object was iterated unexpected number of times\n"); - nsk_jvmti_setFailStatus(); - } - } - - printf("\nUnreachable objects:\n"); - for (i = 0; i < chainLength; i++) { - idx = i + 1 + chainLength; - - printf("Unreachable object:\n" - " tag: %ld\n" - " expected to iterate: %d times\n" - " iterated: %d times\n", - (long) objectDescList[idx].tag, - objectDescList[idx].exp_found, - objectDescList[idx].found); - if (objectDescList[idx].found > 0 && objectDescList[idx].exp_found == 0) { - NSK_COMPLAIN0("Unreachable object was iterated\n"); - nsk_jvmti_setFailStatus(); - } - fflush(0); - } - - return NSK_TRUE; -} - -/** Release references to the tested objects and free allocated memory. */ -static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, - ObjectDesc* objectDescList, jobject rootObject) { - if (rootObject != NULL) { - printf("Release object reference to root tested object: 0x%p\n", rootObject); - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, rootObject)); - } - - if (objectDescList != NULL) { - printf("Deallocate objects list: 0x%p\n", (void*)objectDescList); - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { - nsk_jvmti_setFailStatus(); - } - } - - fflush(0); - return NSK_TRUE; -} - -/* ============================================================================= */ - -/* Some diagnostics happen in the first FollowReferences call only */ -static int first_followref = 1; - -typedef struct ThreadDescStruct { - jlong tag; - jlong id; -} ThreadDesc; - -#define MAX_THREADS 1024 -static ThreadDesc thrDesc [MAX_THREADS] = {{0}}; - -static jlong registerThread(jlong thr_id, jlong thr_tag) { - if (thr_id <= 0 || thr_id >= MAX_THREADS) { - NSK_COMPLAIN1("Unexpected thread ID: %ld\n", thr_id); - nsk_jvmti_setFailStatus(); - return 0; - } - if (thrDesc[thr_id].id == 0) { - /* need to set the first occurence info */ - thrDesc[thr_id].id = thr_id; - thrDesc[thr_id].tag = thr_tag; - } else if (thr_tag != thrDesc[thr_id].tag) { - NSK_COMPLAIN3("Thread tag doesn't match the first occurence: thr_id= %ld\n" - "\t first thr_tag=%#lx, curr thr_tag=%#lx\n", - thr_id, thrDesc[thr_id].tag, thr_tag); - nsk_jvmti_setFailStatus(); - return 0; - } - return thr_id; -} /* registerThread */ - -typedef struct FrameDescStruct { - jlong thr_id; - jint depth; - jmethodID method; -} FrameDesc; - -#define MAX_FRAMES 256 -static FrameDesc frameDesc[MAX_FRAMES] = {{0}}; -static int curr_frame_id = 0; /* Index 0 should not be used */ - -/* returns frame slot number in the table of frames */ -static int registerFrame(jlong thr_id, jint depth, jmethodID method, - jvmtiHeapReferenceKind ref_kind) -{ - int idx; - int failed = 0; - - FrameDesc *fr; - if (depth < 0 || depth > MAXDEPTH) { - NSK_COMPLAIN1("Incorrect frame depth: %ld\n", depth); - failed = 1; - } - /* JNI_LOCAL references from native methods may not have a jmethodID. - * (Do we have to clarify this in the JVMTI spec?) - * Do not consider the test as failing in such a case. - */ - if (method == NULL && ref_kind != JVMTI_HEAP_REFERENCE_JNI_LOCAL) { - NSK_COMPLAIN0("methodID must not be NULL\n"); - failed = 1; - } - if (failed) { - nsk_jvmti_setFailStatus(); - return 0; - } - - /* Check if this frame was registered */ - for (idx = 1; idx <= curr_frame_id; idx++) { - fr = &frameDesc[idx]; - if (fr->thr_id == thr_id && fr->depth == depth && fr->method == method) { - return idx; - } - } - if (++curr_frame_id >= MAX_FRAMES) { - NSK_COMPLAIN1("Internal: Insufficient frames table size: %ld\n", MAX_FRAMES); - return 0; - } - fr = &frameDesc[curr_frame_id]; - fr->thr_id = thr_id; - fr->depth = depth; - fr->method = method; - - return curr_frame_id; -} /* registerFrame */ - - -typedef struct LocalDescStruct { - jint frame_id; - jlocation location; - jint slot; - jlong tag; -} LocalDesc; - -#define MAX_LOCALS 100 -static LocalDesc locDesc [MAX_LOCALS] = {{0}}; -static int curr_local_idx = 0; /* Index 0 should not be used */ - -/* returns frame slot number in the table of frames */ -static int registerLocal(jint frame_id, jlocation location, jint slot, jlong tag) { - int idx; - LocalDesc *loc; - int failed = 0; - - if (slot < 0 || slot > MAXSLOT) { - NSK_COMPLAIN1("Incorrect stack local slot#: %ld\n", slot); - failed = 1; - } - if ((jlong) location == -1L) { - NSK_COMPLAIN0("Location must not be -1\n"); - failed = 1; - } - - if (failed) { - nsk_jvmti_setFailStatus(); - return 0; - } - - /* Check if this local was registered */ - for (idx = 1; idx <= curr_local_idx; idx++) { - loc = &locDesc[idx]; - if (loc->frame_id == frame_id && - loc->slot == slot) { - if (first_followref) { - /* Do this check on the first FollowReferences call only */ - FrameDesc *fr = &frameDesc[frame_id]; - printf("Second report of the local: " - "loc_idx=%d, frame_id=%d, slot=%d\n", - idx, frame_id, slot); - printf("\t thr_id=%"LL"d, depth=%d, meth=0x%p\n", - fr->thr_id, fr->depth, fr->method); - failed = 1; - } - if (loc->tag != tag) { - NSK_COMPLAIN2("Tag mismatch: expected %#lx, passed: %#lx\n", - loc->tag, tag); - failed = 1; - } - if (loc->location != location) { - NSK_COMPLAIN2("Location mismatch: expected %ld, passed: %ld\n", - (long) loc->location, (long) location); - failed = 1; - } - if (failed) { - nsk_jvmti_setFailStatus(); - return 0; - } - return idx; - } - } - if (++curr_local_idx >= MAX_LOCALS) { - printf("Internal: Insufficient locals table size: %d\n", MAX_FRAMES); - return 0; - } - loc = &locDesc[curr_local_idx]; - loc->frame_id = frame_id; - loc->location = location; - loc->slot = slot; - loc->tag = tag; - - return curr_local_idx; -} /* registerLocal */ - - -/** heapReferenceCallback for heap iterator. */ -jint JNICALL heapReferenceCallback( - jvmtiHeapReferenceKind ref_kind, - const jvmtiHeapReferenceInfo* reference_info, - jlong class_tag, - jlong referrer_class_tag, - jlong size, - jlong* tag_ptr, - jlong* referrer_tag_ptr, - jint length, - void* user_data) -{ - jint depth = -1; - jint slot = -1; - jint index = -1; - jmethodID method = (jmethodID) NULL; - jlocation location = (jlocation)(-1); - jlong tag = DEREF(tag_ptr); - jlong ref_tag = DEREF(referrer_tag_ptr); - jlong thr_tag = -1; - jlong thr_id = -1; - jlong thr_idx = -1; - int res = -1; - int meth_idx = -1; - - switch (ref_kind) { - case JVMTI_HEAP_REFERENCE_CONSTANT_POOL: - index = reference_info->constant_pool.index; - break; - case JVMTI_HEAP_REFERENCE_FIELD: - case JVMTI_HEAP_REFERENCE_STATIC_FIELD: - index = reference_info->field.index; - break; - case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT: - index = reference_info->array.index; - break; - case JVMTI_HEAP_REFERENCE_STACK_LOCAL: - thr_tag = reference_info->stack_local.thread_tag; - thr_id = reference_info->stack_local.thread_id; - depth = reference_info->stack_local.depth; - method = reference_info->stack_local.method; - location = reference_info->stack_local.location; - slot = reference_info->stack_local.slot; - index = slot | depth << 16; - break; - case JVMTI_HEAP_REFERENCE_JNI_LOCAL: - thr_tag = reference_info->jni_local.thread_tag; - thr_id = reference_info->jni_local.thread_id; - depth = reference_info->jni_local.depth; - method = reference_info->jni_local.method; - index = depth; - break; - default: - // TODO: check that realy should be done w/ other jvmtiHeapReferenceKind - break; - } - - if (ref_kind == JVMTI_HEAP_REFERENCE_OTHER || - ref_kind == JVMTI_HEAP_REFERENCE_JNI_GLOBAL || - ref_kind == JVMTI_HEAP_REFERENCE_SYSTEM_CLASS) { - return 0; /* Skip it as there is a plan to test it differently */ - } - - if (ref_kind == JVMTI_HEAP_REFERENCE_THREAD) { - /* Target thread has been tagged already */ - if (tag == 0) { - tag = *tag_ptr = thrObjectTag++; - /* Just want to report new tag for thread object */ - printf(" heapReferenceCallback: ref=%s, tag=%-3ld, size=%-3ld\n", - ref_kind_str[ref_kind], - (long) *tag_ptr, - (long) size); - } - - fflush(0); - return 0; - } - - printf(" heapReferenceCallback: ref=%s, class_tag=%-3ld, tag=%-3ld," - " size=%-3ld, len=%-2d\n" - "\t\t ref_tag=%-"LL"d, thr_tag=%-3ld, thr_id=%"LL"d, " - "meth=0x%p, loc=%ld, idx=%#x\n", - ref_kind_str[ref_kind], - (long) class_tag, - (long) tag, - (long) size, - (int ) length, - ref_tag, - (long) thr_tag, - thr_id, - method, - (long) location, - (int ) index); - fflush(0); - - if (tag_ptr == NULL) { - NSK_COMPLAIN1("NULL tag_ptr is passed to heapReferenceCallback:" - " tag_ptr=0x%p\n", (void*)tag_ptr); - nsk_jvmti_setFailStatus(); - } - - if (tag_ptr != NULL && tag != 0) { - int found = 0; - int i; - - for (i = 0; i < objectsCount; i++) { - if (*tag_ptr == objectDescList[i].tag) { - found++; - objectDescList[i].found++; - - if (*tag_ptr < 0 && *tag_ptr != -chainObjectTag && - ref_kind != JVMTI_HEAP_REFERENCE_STACK_LOCAL) - { - NSK_COMPLAIN0("Unreachable tagged object is " - "passed to heapReferenceCallback\n"); - nsk_jvmti_setFailStatus(); - break; - } - break; - } - } - - if (ref_kind != JVMTI_HEAP_REFERENCE_CLASS && - ref_kind != JVMTI_HEAP_REFERENCE_JNI_LOCAL && found <= 0 && - tag < FIRST_THREAD_TAG && tag > (thrObjectTag - 1)) - { - NSK_COMPLAIN0("Unknown tagged object is passed " - "to heapReferenceCallback\n"); - nsk_jvmti_setFailStatus(); - } - } - - if (user_data != &fakeUserData && !userDataError) { - NSK_COMPLAIN2("Unexpected user_data is passed " - "to heapReferenceCallback:\n" - " expected: 0x%p\n" - " actual: 0x%p\n", - user_data, - &fakeUserData); - nsk_jvmti_setFailStatus(); - userDataError++; - } - - switch (ref_kind) { - case JVMTI_HEAP_REFERENCE_CLASS: { - int i; - if (tag == 0) { - return 0; - } - if (tag != rootClassTag && tag != chainClassTag) { - NSK_COMPLAIN0("Unknown tagged class is passed " - "to heapReferenceCallback\n"); - nsk_jvmti_setFailStatus(); - break; - } - for (i = 0; i < objectsCount; i++) { - if (ref_tag == objectDescList[i].tag) { - if (objectDescList[i].exp_class_tag != tag) { - NSK_COMPLAIN2("Wrong tag in heapReferenceCallback" - "/JVMTI_HEAP_REFERENCE_CLASS:\n" - "Expected: %-3ld\n" - "Passed: %-3ld\n", - objectDescList[i].exp_class_tag, - tag); - nsk_jvmti_setFailStatus(); - } - break; - } - } - break; - } - - case JVMTI_HEAP_REFERENCE_STATIC_FIELD: - if (tag != rootObjectTag || class_tag != rootClassTag) { - NSK_COMPLAIN1("This reference kind was not expected: %s\n", - ref_kind_str[ref_kind]); - fflush(0); - nsk_jvmti_setFailStatus(); - } - break; - - case JVMTI_HEAP_REFERENCE_STACK_LOCAL: - // Skip local references from non-main (e.g. compiler) threads. - if (thr_tag == TARG_THREAD_TAG) { - thr_idx = registerThread(thr_id, thr_tag); - meth_idx = registerFrame(thr_id, depth, method, ref_kind); - if (meth_idx > 0) { - jint loc_idx = registerLocal(meth_idx, location, slot, tag); - } - } - /* This part is kind of hack. It has some expectations about stack layout */ - if (thr_tag == TARG_THREAD_TAG && - reference_info->stack_local.depth == TARG_FRAME_DEPTH) { - if (length != -1) { - jint exp_len = length; - - if (reference_info->stack_local.slot == ARGV_STRING_ARR_SLOT) { - exp_len = 0; - } - else if (reference_info->stack_local.slot >= FIRST_PRIM_ARR_SLOT && - reference_info->stack_local.slot <= LAST_PRIM_ARR_SLOT) { - exp_len = 2; - } - else if (reference_info->stack_local.slot == DUMMY_STRING_ARR_SLOT) { - exp_len = 3; - } - if (length != exp_len) { - NSK_COMPLAIN2("Wrong length of the local array:" - " expected: %-d, found: %-d\n\n", exp_len, length); - } - } else { /* length == -1 */ - if ((reference_info->stack_local.slot >= FIRST_PRIM_ARR_SLOT && - reference_info->stack_local.slot <= DUMMY_STRING_ARR_SLOT) || - reference_info->stack_local.slot == ARGV_STRING_ARR_SLOT) { - NSK_COMPLAIN0("Length of array must not be -1\n"); - } - } - if (length == 0 - && reference_info->stack_local.slot != ARGV_STRING_ARR_SLOT - && reference_info->stack_local.slot < FIRST_PRIM_ARR_SLOT - && reference_info->stack_local.slot > DUMMY_STRING_ARR_SLOT) { - NSK_COMPLAIN1("Wrong length of the local variable:" - " expected: -1, found: %-d\n\n", length); - nsk_jvmti_setFailStatus(); - } - } - break; - case JVMTI_HEAP_REFERENCE_JNI_LOCAL: - // Skip JNI local references from non-main (e.g. compiler) threads. - if (thr_tag == TARG_THREAD_TAG) { - thr_idx = registerThread(thr_id, thr_tag); - meth_idx = registerFrame(thr_id, depth, method, ref_kind); - } - break; - - case JVMTI_REFERENCE_ARRAY_ELEMENT: - case JVMTI_HEAP_REFERENCE_JNI_GLOBAL: - case JVMTI_HEAP_REFERENCE_SYSTEM_CLASS: - case JVMTI_HEAP_REFERENCE_MONITOR: - case JVMTI_HEAP_REFERENCE_OTHER: - /* These reference kinds are expected */ - break; - - default: { - NSK_COMPLAIN1("This reference kind was not expected: %s\n\n", - ref_kind_str[ref_kind]); - fflush(0); - nsk_jvmti_setFailStatus(); - break; - } - } - return 0; -} - -jint JNICALL primitiveFieldCallback - (jvmtiHeapReferenceKind ref_kind, - const jvmtiHeapReferenceInfo* reference_info, - jlong class_tag, - jlong* tag_ptr, - jvalue value, - jvmtiPrimitiveType value_type, - void* user_data) -{ - printf(" primitiveFieldCallback: ref=%s, class_tag=%-3ld, tag=%-3ld, type=%c\n", - ref_kind_str[ref_kind], - (long) class_tag, - (long) DEREF(tag_ptr), - (int ) value_type); - fflush(0); - return 0; -} - -jint JNICALL arrayPrimitiveValueCallback - (jlong class_tag, jlong size, jlong* tag_ptr, jint element_count, - jvmtiPrimitiveType element_type, const void* elements, void* user_data) -{ - printf(" arrayPrimitiveValueCallback: class_tag=%-3ld, tag=%-3ld, len=%d, type=%c\n", - (long) class_tag, - (long) DEREF(tag_ptr), - (int ) element_count, - (int ) element_type); - fflush(0); - return 0; -} - -jint JNICALL stringPrimitiveValueCallback - (jlong class_tag, jlong size, jlong* tag_ptr, const jchar* value, - jint value_length, void* user_data) -{ - printf("stringPrimitiveValueCallback: class_tag=%-3ld, tag=%-3ld, len=%d\n", - (long) class_tag, - (long) DEREF(tag_ptr), - (int ) value_length); - fflush(0); - return 0; -} - - -/* ============================================================================= */ -static jthread getTargetThread(jvmtiEnv *jvmti) { - static const char *target_thread_name = "main"; - jint i; - jint thread_count = -1; - jthread *threads = NULL; - - (*jvmti)->GetAllThreads(jvmti, &thread_count, &threads); - - for (i = 0; i < thread_count; i++) { - jvmtiThreadInfo thread_info; - (*jvmti)->GetThreadInfo(jvmti, threads[i], &thread_info); - - if (strcmp(thread_info.name, target_thread_name) == 0) { - return threads[i]; - } - } - - return NULL; -} - -static jvmtiError setTagForTargetThread(jvmtiEnv *jvmti, jlong tag) { - jthread target_thread = getTargetThread(jvmti); - return (*jvmti)->SetTag(jvmti, target_thread, tag); -} - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - jobject rootObject = NULL; - - printf("Wait for tested objects created\n"); - fflush(0); - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) { - return; - } - - printf(">>> Obtain and tag tested objects from debugee class\n"); - fflush(0); - { - if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, &objectsCount, - &objectDescList, &rootObject))) { - return; - } - } - - printf(">>> Let debugee to clean links to unreachable objects\n"); - fflush(0); - { - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) { - return; - } - if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) { - return; - } - } - - if (!NSK_JVMTI_VERIFY(setTagForTargetThread(jvmti, TARG_THREAD_TAG))) { - nsk_jvmti_setFailStatus(); - return; - } - - printf("\n\n>>> Start 1-st iteration starting from the heap root\n"); - fflush(0); - { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB6(FollowReferences, jvmti, - (jint) 0, /* heap_filter */ - (jclass) NULL, /* class */ - (jobject) NULL, /* initial_object */ - &heapCallbacks, - (const void *) &fakeUserData))) - { - nsk_jvmti_setFailStatus(); - return; - } - } - - printf(">>> Check if reachable objects were iterated\n"); - fflush(0); - { - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - } - - { /* Reinstall the expectations */ - int k; - for (k = 0; k < objectsCount; k++) { - (objectDescList)[k].exp_found = 0; - (objectDescList)[k].found = 0; - } - /* Heap root object must be reported 2 times */ - objectDescList[0].exp_found = 2; - - /* First unreachable object must be reported once - * as JVMTI_HEAP_REFERENCE_STACK_LOCAL */ - objectDescList[2 * chainLength].exp_found = 1; - } - - printf("\n\n>>> Start 2-nd iteration starting from the heap root\n"); - fflush(0); - first_followref = 0; - { - jint heap_filter = JVMTI_HEAP_FILTER_UNTAGGED - | JVMTI_HEAP_FILTER_CLASS_UNTAGGED; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB6(FollowReferences, jvmti, - heap_filter, - (jclass) NULL, /* class */ - (jobject) NULL, /* initial_object */ - &heapCallbacks, - (const void *) &fakeUserData))) - { - nsk_jvmti_setFailStatus(); - return; - } - } - - printf(">>> Check that both reachable and unreachable " - "objects were not iterated\n"); - fflush(0); - { - if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { - nsk_jvmti_setFailStatus(); - } - } - - - printf(">>> Clean used data\n"); - fflush(0); - { - if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, - objectDescList, rootObject))) { - return; - } - } - - printf("Let debugee to finish\n"); - fflush(0); - if (!NSK_VERIFY(nsk_jvmti_resumeSync())) - return; -} - -/* ============================================================================= */ - -/** Agent library initialization. */ -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_followref003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_followref003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_followref003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - { - const char* infoOpt = nsk_jvmti_findOptionValue("info"); - if (infoOpt != NULL) { - if (strcmp(infoOpt, "none") == 0) - info = INFO_NONE; - else if (strcmp(infoOpt, "all") == 0) - info = INFO_ALL; - else if (strcmp(infoOpt, "objref") == 0) - info = INFO_OBJREF; - else if (strcmp(infoOpt, "stackref") == 0) - info = INFO_STACKREF; - else if (strcmp(infoOpt, "heaproot") == 0) - info = INFO_HEAPROOT; - else if (strcmp(infoOpt, "heapobj") == 0) - info = INFO_HEAPOBJ; - else { - printf("Unknown option value: info=%s\n", infoOpt); - fflush(0); - return JNI_ERR; - } - } - } - - chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); - if (!NSK_VERIFY(chainLength > 0)) - return JNI_ERR; - - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_tag_objects = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { - return JNI_ERR; - } - } - - /* Setting Heap Callbacks */ - heapCallbacks.heap_iteration_callback = NULL; - heapCallbacks.heap_reference_callback = heapReferenceCallback; - heapCallbacks.primitive_field_callback = primitiveFieldCallback; - heapCallbacks.array_primitive_value_callback = arrayPrimitiveValueCallback; - heapCallbacks.string_primitive_value_callback = stringPrimitiveValueCallback; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/followref003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/followref003.cpp new file mode 100644 index 00000000000..2a21d891681 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/followref003.cpp @@ -0,0 +1,1113 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "jvmti.h" +#include "agent_common.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +static jlong timeout = 0; + +#define INFO_NONE 0x00 +#define INFO_ALL 0xFF +#define INFO_OBJREF 0x01 +#define INFO_STACKREF 0x02 +#define INFO_HEAPROOT 0x04 +#define INFO_HEAPOBJ 0x08 + +static unsigned int info = INFO_ALL; + +#define DEBUGEE_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref003" +#define ROOT_OBJECT_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref003RootTestedClass" +#define ROOT_OBJECT_CLASS_SIG "L" ROOT_OBJECT_CLASS_NAME ";" +#define CHAIN_OBJECT_CLASS_NAME "nsk/jvmti/unit/FollowReferences/followref003TestedClass" +#define CHAIN_OBJECT_CLASS_SIG "L" CHAIN_OBJECT_CLASS_NAME ";" + +#define OBJECT_FIELD_NAME "object" +#define REACHABLE_CHAIN_FIELD_NAME "reachableChain" +#define UNREACHABLE_CHAIN_FIELD_NAME "unreachableChain" +#define TAIL_FIELD_NAME "tail" + + +#define DEFAULT_CHAIN_LENGTH 3 +#define MAXDEPTH 50 +#define MAXSLOT 16 + +typedef struct ObjectDescStruct { + jlong tag; + jlong class_tag; + jlong exp_class_tag; + jint exp_found; + jint found; +} ObjectDesc; + +static int chainLength = 0; +static int objectsCount = 0; +static int fakeUserData = 0; +static int userDataError = 0; + +static ObjectDesc* objectDescList = NULL; + +#define TARG_THREAD_TAG 11 +#define FIRST_THREAD_TAG (TARG_THREAD_TAG + 1) + +#define TARG_FRAME_DEPTH 1 + +static jlong rootClassTag = 9; +static jlong chainClassTag = 99; +static jlong thrObjectTag = FIRST_THREAD_TAG; +static jlong rootObjectTag = 55; +static jlong chainObjectTag = 100; + + +/* Java method frame slots interesting to check */ +#define ARGV_STRING_ARR_SLOT 1 +#define FIRST_PRIM_ARR_SLOT 3 +#define LAST_PRIM_ARR_SLOT 10 +#define DUMMY_STRING_ARR_SLOT 11 + + +static jvmtiHeapCallbacks heapCallbacks = {}; + +static const char* ref_kind_str[28] = { + "unknown_0", + "REFERENCE_CLASS", + "REFERENCE_FIELD", + "REFERENCE_ARRAY_ELEMENT", + "REFERENCE_CLASS_LOADER", + "REFERENCE_SIGNERS", + "REFERENCE_PROTECTION_DOMAIN", + "REFERENCE_INTERFACE", + "REFERENCE_STATIC_FIELD", + "REFERENCE_CONSTANT_POOL", + "unknown_10", "unknown_11", "unknown_12", + "unknown_13", "unknown_14", "unknown_15", "unknown_16", + "unknown_17", "unknown_18", "unknown_19", "unknown_20", + "REFERENCE_JNI_GLOBAL", + "REFERENCE_SYSTEM_CLASS", + "REFERENCE_MONITOR", + "REFERENCE_STACK_LOCAL", + "REFERENCE_JNI_LOCAL", + "REFERENCE_THREAD", + "REFERENCE_OTHER" +}; + + +#define DEREF(ptr) (((ptr) == NULL ? 0 : *(ptr))) + + +/* ============================================================================= */ + +/** Obtain chain of tested objects and tag them recursively. */ +static int getChainObjects(jvmtiEnv* jvmti, JNIEnv* jni, jobject firstObject, + jfieldID firstField, const char firstFieldName[], + jfieldID nextField, const char nextFieldName[], + int count, ObjectDesc objectDescList[], + jlong tag, int reachable) { + jobject obj = NULL; + jlong objTag = (reachable ? tag : -tag); + + if (count <= 0) + return NSK_TRUE; + + count--; + tag++; + + if (!NSK_JNI_VERIFY(jni, (obj = + NSK_CPP_STUB3(GetObjectField, jni, firstObject, firstField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + objectDescList[count].tag = objTag; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, obj, objTag))) { + nsk_jvmti_setFailStatus(); + } + printf(" tag=%-5ld object=0x%p\n", (long)objTag, (void*)obj); + fflush(0); + if (!getChainObjects(jvmti, jni, obj, nextField, nextFieldName, + nextField, nextFieldName, + count, objectDescList, tag, reachable)) { + return NSK_FALSE; + } + + NSK_TRACE(NSK_CPP_STUB2(DeleteLocalRef, jni, obj)); + return NSK_TRUE; +} + +/** Obtain all tested objects from debugee class and tag them recursively. */ +static int getTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + int *objectsCount, ObjectDesc* *objectDescList, + jobject* rootObject) { + jclass debugeeClass = NULL; + jclass rootObjectClass = NULL; + jclass chainObjectClass = NULL; + + jfieldID objectField = NULL; + jfieldID reachableChainField = NULL; + jfieldID unreachableChainField = NULL; + jfieldID tailField = NULL; + + *objectsCount = 1 + 2 * chainLength; + + printf("Allocate memory for objects list: %d objects\n", *objectsCount); + fflush(0); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(Allocate, jvmti, (*objectsCount * sizeof(ObjectDesc)), + (unsigned char**)objectDescList))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... allocated array: 0x%p\n", (void*)objectDescList); + fflush(0); + + { + int k; + for (k = 0; k < *objectsCount; k++) { + (*objectDescList)[k].tag = 0; + (*objectDescList)[k].exp_class_tag = chainClassTag; + (*objectDescList)[k].exp_found = 0; + (*objectDescList)[k].found = 0; + } + } + (*objectDescList)[0].exp_class_tag = rootClassTag; + + printf("Find debugee class: %s\n", DEBUGEE_CLASS_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (debugeeClass = + NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... found class: 0x%p\n", (void*)debugeeClass); + + printf("Find root object class: %s\n", ROOT_OBJECT_CLASS_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (rootObjectClass = + NSK_CPP_STUB2(FindClass, jni, ROOT_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... found class: 0x%p\n", (void*)rootObjectClass); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, rootObjectClass, rootClassTag))) { + nsk_jvmti_setFailStatus(); + } + printf(" tag=%-5ld rootClass=0x%p\n", + (long)rootClassTag, (void*)rootObjectClass); + + printf("Find chain object class: %s\n", CHAIN_OBJECT_CLASS_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (chainObjectClass = + NSK_CPP_STUB2(FindClass, jni, CHAIN_OBJECT_CLASS_NAME)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... found class: 0x%p\n", + (void*)chainObjectClass); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, chainObjectClass, chainClassTag))) { + nsk_jvmti_setFailStatus(); + } + printf(" tag=%-5ld chainClass=0x%p\n", + (long)chainClassTag, (void*)chainObjectClass); + + printf("Find static field in debugee class: %s\n", OBJECT_FIELD_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (objectField = + NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass, + OBJECT_FIELD_NAME, ROOT_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... got fieldID: 0x%p\n", (void*)objectField); + + printf("Find instance field in root object class: %s\n", REACHABLE_CHAIN_FIELD_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (reachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + REACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... got fieldID: 0x%p\n", (void*)reachableChainField); + + printf("Find instance field in root object class: %s\n", UNREACHABLE_CHAIN_FIELD_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (unreachableChainField = + NSK_CPP_STUB4(GetFieldID, jni, rootObjectClass, + UNREACHABLE_CHAIN_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... got fieldID: 0x%p\n", (void*)unreachableChainField); + + printf("Find instance field in chain object class: %s\n", TAIL_FIELD_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (tailField = + NSK_CPP_STUB4(GetFieldID, jni, chainObjectClass, + TAIL_FIELD_NAME, CHAIN_OBJECT_CLASS_SIG)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... got fieldID: 0x%p\n", (void*)tailField); + + printf("Get root object from static field: %s\n", OBJECT_FIELD_NAME); + fflush(0); + if (!NSK_JNI_VERIFY(jni, (*rootObject = + NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, + objectField)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... got object: 0x%p\n", (void*)*rootObject); + fflush(0); + + if (!NSK_JNI_VERIFY(jni, (*rootObject = + NSK_CPP_STUB2(NewGlobalRef, jni, *rootObject)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + printf(" ... global ref: 0x%p\n", (void*)*rootObject); + + printf("Obtain and tag chain objects:\n"); + + printf(" root tested object\n"); + fflush(0); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, *rootObject, rootObjectTag))) { + nsk_jvmti_setFailStatus(); + } + printf(" tag=%-5ld object=0x%p\n", + (long)rootObjectTag, (void*)*rootObject); + + /* Root object must be reported 1 time */ + (*objectDescList)[0].exp_found = 1; + (*objectDescList)[0].tag = rootObjectTag; + + printf(" reachable objects chain: %d objects\n", chainLength); + fflush(0); + if (!getChainObjects(jvmti, jni, *rootObject, + reachableChainField, REACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, (*objectDescList) + 1, + chainObjectTag, NSK_TRUE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + /* First unreachable object must be reported once + * as JVMTI_HEAP_REFERENCE_STACK_LOCAL */ + (*objectDescList)[2 * chainLength].exp_found = 1; + + printf(" unreachable objects chain: %d objects\n", chainLength); + if (!getChainObjects(jvmti, jni, *rootObject, + unreachableChainField, UNREACHABLE_CHAIN_FIELD_NAME, + tailField, TAIL_FIELD_NAME, + chainLength, (*objectDescList) + 1 + chainLength, + chainObjectTag, NSK_FALSE)) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/** Check if tagged objects were iterated. */ +static int checkTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, + int chainLength, ObjectDesc objectDescList[]) { + int success = NSK_TRUE; + int i, idx; + + printf("Following tagged objects were iterated:\n"); + + printf("Root tested object:\n"); + printf(" tag: %ld\n" + " expected to iterate: %d times\n" + " iterated: %d times\n", + (long) objectDescList[0].tag, + objectDescList[0].exp_found, + objectDescList[0].found); + if (objectDescList[0].found != objectDescList[0].exp_found) { + NSK_COMPLAIN1("Root tested object unexpectedly iterated %d times\n", + objectDescList[0].found); + nsk_jvmti_setFailStatus(); + } + + printf("\nReachable objects:\n"); + fflush(0); + for (i = 0; i < chainLength; i++) { + idx = i + 1; + printf("Reachable object:\n" + " tag: %-3ld\n" + " expected to iterate: %d times\n" + " iterated: %d times\n", + (long) objectDescList[idx].tag, + objectDescList[idx].exp_found, + objectDescList[idx].found); + if (objectDescList[i + 1].found <= 0 && objectDescList[i + 1].exp_found > 0) { + NSK_COMPLAIN0("Reachable object was not iterated\n"); + nsk_jvmti_setFailStatus(); + } + if (objectDescList[idx].found != objectDescList[idx].exp_found) { + NSK_COMPLAIN0("Reachable object was iterated unexpected number of times\n"); + nsk_jvmti_setFailStatus(); + } + } + + printf("\nUnreachable objects:\n"); + for (i = 0; i < chainLength; i++) { + idx = i + 1 + chainLength; + + printf("Unreachable object:\n" + " tag: %ld\n" + " expected to iterate: %d times\n" + " iterated: %d times\n", + (long) objectDescList[idx].tag, + objectDescList[idx].exp_found, + objectDescList[idx].found); + if (objectDescList[idx].found > 0 && objectDescList[idx].exp_found == 0) { + NSK_COMPLAIN0("Unreachable object was iterated\n"); + nsk_jvmti_setFailStatus(); + } + fflush(0); + } + + return NSK_TRUE; +} + +/** Release references to the tested objects and free allocated memory. */ +static int releaseTestedObjects(jvmtiEnv* jvmti, JNIEnv* jni, int chainLength, + ObjectDesc* objectDescList, jobject rootObject) { + if (rootObject != NULL) { + printf("Release object reference to root tested object: 0x%p\n", rootObject); + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, rootObject)); + } + + if (objectDescList != NULL) { + printf("Deallocate objects list: 0x%p\n", (void*)objectDescList); + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)objectDescList))) { + nsk_jvmti_setFailStatus(); + } + } + + fflush(0); + return NSK_TRUE; +} + +/* ============================================================================= */ + +/* Some diagnostics happen in the first FollowReferences call only */ +static int first_followref = 1; + +typedef struct ThreadDescStruct { + jlong tag; + jlong id; +} ThreadDesc; + +#define MAX_THREADS 1024 +static ThreadDesc thrDesc [MAX_THREADS] = {}; + +static jlong registerThread(jlong thr_id, jlong thr_tag) { + if (thr_id <= 0 || thr_id >= MAX_THREADS) { + NSK_COMPLAIN1("Unexpected thread ID: %ld\n", thr_id); + nsk_jvmti_setFailStatus(); + return 0; + } + if (thrDesc[thr_id].id == 0) { + /* need to set the first occurence info */ + thrDesc[thr_id].id = thr_id; + thrDesc[thr_id].tag = thr_tag; + } else if (thr_tag != thrDesc[thr_id].tag) { + NSK_COMPLAIN3("Thread tag doesn't match the first occurence: thr_id= %ld\n" + "\t first thr_tag=%#lx, curr thr_tag=%#lx\n", + thr_id, thrDesc[thr_id].tag, thr_tag); + nsk_jvmti_setFailStatus(); + return 0; + } + return thr_id; +} /* registerThread */ + +typedef struct FrameDescStruct { + jlong thr_id; + jint depth; + jmethodID method; +} FrameDesc; + +#define MAX_FRAMES 256 +static FrameDesc frameDesc[MAX_FRAMES] = {}; +static int curr_frame_id = 0; /* Index 0 should not be used */ + +/* returns frame slot number in the table of frames */ +static int registerFrame(jlong thr_id, jint depth, jmethodID method, + jvmtiHeapReferenceKind ref_kind) +{ + int idx; + int failed = 0; + + FrameDesc *fr; + if (depth < 0 || depth > MAXDEPTH) { + NSK_COMPLAIN1("Incorrect frame depth: %ld\n", depth); + failed = 1; + } + /* JNI_LOCAL references from native methods may not have a jmethodID. + * (Do we have to clarify this in the JVMTI spec?) + * Do not consider the test as failing in such a case. + */ + if (method == NULL && ref_kind != JVMTI_HEAP_REFERENCE_JNI_LOCAL) { + NSK_COMPLAIN0("methodID must not be NULL\n"); + failed = 1; + } + if (failed) { + nsk_jvmti_setFailStatus(); + return 0; + } + + /* Check if this frame was registered */ + for (idx = 1; idx <= curr_frame_id; idx++) { + fr = &frameDesc[idx]; + if (fr->thr_id == thr_id && fr->depth == depth && fr->method == method) { + return idx; + } + } + if (++curr_frame_id >= MAX_FRAMES) { + NSK_COMPLAIN1("Internal: Insufficient frames table size: %ld\n", MAX_FRAMES); + return 0; + } + fr = &frameDesc[curr_frame_id]; + fr->thr_id = thr_id; + fr->depth = depth; + fr->method = method; + + return curr_frame_id; +} /* registerFrame */ + + +typedef struct LocalDescStruct { + jint frame_id; + jlocation location; + jint slot; + jlong tag; +} LocalDesc; + +#define MAX_LOCALS 100 +static LocalDesc locDesc [MAX_LOCALS] = {}; +static int curr_local_idx = 0; /* Index 0 should not be used */ + +/* returns frame slot number in the table of frames */ +static int registerLocal(jint frame_id, jlocation location, jint slot, jlong tag) { + int idx; + LocalDesc *loc; + int failed = 0; + + if (slot < 0 || slot > MAXSLOT) { + NSK_COMPLAIN1("Incorrect stack local slot#: %ld\n", slot); + failed = 1; + } + if ((jlong) location == -1L) { + NSK_COMPLAIN0("Location must not be -1\n"); + failed = 1; + } + + if (failed) { + nsk_jvmti_setFailStatus(); + return 0; + } + + /* Check if this local was registered */ + for (idx = 1; idx <= curr_local_idx; idx++) { + loc = &locDesc[idx]; + if (loc->frame_id == frame_id && + loc->slot == slot) { + if (first_followref) { + /* Do this check on the first FollowReferences call only */ + FrameDesc *fr = &frameDesc[frame_id]; + printf("Second report of the local: " + "loc_idx=%d, frame_id=%d, slot=%d\n", + idx, frame_id, slot); + printf("\t thr_id=%" LL "d, depth=%d, meth=0x%p\n", + fr->thr_id, fr->depth, fr->method); + failed = 1; + } + if (loc->tag != tag) { + NSK_COMPLAIN2("Tag mismatch: expected %#lx, passed: %#lx\n", + loc->tag, tag); + failed = 1; + } + if (loc->location != location) { + NSK_COMPLAIN2("Location mismatch: expected %ld, passed: %ld\n", + (long) loc->location, (long) location); + failed = 1; + } + if (failed) { + nsk_jvmti_setFailStatus(); + return 0; + } + return idx; + } + } + if (++curr_local_idx >= MAX_LOCALS) { + printf("Internal: Insufficient locals table size: %d\n", MAX_FRAMES); + return 0; + } + loc = &locDesc[curr_local_idx]; + loc->frame_id = frame_id; + loc->location = location; + loc->slot = slot; + loc->tag = tag; + + return curr_local_idx; +} /* registerLocal */ + + +/** heapReferenceCallback for heap iterator. */ +jint JNICALL heapReferenceCallback( + jvmtiHeapReferenceKind ref_kind, + const jvmtiHeapReferenceInfo* reference_info, + jlong class_tag, + jlong referrer_class_tag, + jlong size, + jlong* tag_ptr, + jlong* referrer_tag_ptr, + jint length, + void* user_data) +{ + jint depth = -1; + jint slot = -1; + jint index = -1; + jmethodID method = (jmethodID) NULL; + jlocation location = (jlocation)(-1); + jlong tag = DEREF(tag_ptr); + jlong ref_tag = DEREF(referrer_tag_ptr); + jlong thr_tag = -1; + jlong thr_id = -1; + jlong thr_idx = -1; + int res = -1; + int meth_idx = -1; + + switch (ref_kind) { + case JVMTI_HEAP_REFERENCE_CONSTANT_POOL: + index = reference_info->constant_pool.index; + break; + case JVMTI_HEAP_REFERENCE_FIELD: + case JVMTI_HEAP_REFERENCE_STATIC_FIELD: + index = reference_info->field.index; + break; + case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT: + index = reference_info->array.index; + break; + case JVMTI_HEAP_REFERENCE_STACK_LOCAL: + thr_tag = reference_info->stack_local.thread_tag; + thr_id = reference_info->stack_local.thread_id; + depth = reference_info->stack_local.depth; + method = reference_info->stack_local.method; + location = reference_info->stack_local.location; + slot = reference_info->stack_local.slot; + index = slot | depth << 16; + break; + case JVMTI_HEAP_REFERENCE_JNI_LOCAL: + thr_tag = reference_info->jni_local.thread_tag; + thr_id = reference_info->jni_local.thread_id; + depth = reference_info->jni_local.depth; + method = reference_info->jni_local.method; + index = depth; + break; + default: + // TODO: check that realy should be done w/ other jvmtiHeapReferenceKind + break; + } + + if (ref_kind == JVMTI_HEAP_REFERENCE_OTHER || + ref_kind == JVMTI_HEAP_REFERENCE_JNI_GLOBAL || + ref_kind == JVMTI_HEAP_REFERENCE_SYSTEM_CLASS) { + return 0; /* Skip it as there is a plan to test it differently */ + } + + if (ref_kind == JVMTI_HEAP_REFERENCE_THREAD) { + /* Target thread has been tagged already */ + if (tag == 0) { + tag = *tag_ptr = thrObjectTag++; + /* Just want to report new tag for thread object */ + printf(" heapReferenceCallback: ref=%s, tag=%-3ld, size=%-3ld\n", + ref_kind_str[ref_kind], + (long) *tag_ptr, + (long) size); + } + + fflush(0); + return 0; + } + + printf(" heapReferenceCallback: ref=%s, class_tag=%-3ld, tag=%-3ld," + " size=%-3ld, len=%-2d\n" + "\t\t ref_tag=%-" LL "d, thr_tag=%-3ld, thr_id=%" LL "d, " + "meth=0x%p, loc=%ld, idx=%#x\n", + ref_kind_str[ref_kind], + (long) class_tag, + (long) tag, + (long) size, + (int ) length, + ref_tag, + (long) thr_tag, + thr_id, + method, + (long) location, + (int ) index); + fflush(0); + + if (tag_ptr == NULL) { + NSK_COMPLAIN1("NULL tag_ptr is passed to heapReferenceCallback:" + " tag_ptr=0x%p\n", (void*)tag_ptr); + nsk_jvmti_setFailStatus(); + } + + if (tag_ptr != NULL && tag != 0) { + int found = 0; + int i; + + for (i = 0; i < objectsCount; i++) { + if (*tag_ptr == objectDescList[i].tag) { + found++; + objectDescList[i].found++; + + if (*tag_ptr < 0 && *tag_ptr != -chainObjectTag && + ref_kind != JVMTI_HEAP_REFERENCE_STACK_LOCAL) + { + NSK_COMPLAIN0("Unreachable tagged object is " + "passed to heapReferenceCallback\n"); + nsk_jvmti_setFailStatus(); + break; + } + break; + } + } + + if (ref_kind != JVMTI_HEAP_REFERENCE_CLASS && + ref_kind != JVMTI_HEAP_REFERENCE_JNI_LOCAL && found <= 0 && + tag < FIRST_THREAD_TAG && tag > (thrObjectTag - 1)) + { + NSK_COMPLAIN0("Unknown tagged object is passed " + "to heapReferenceCallback\n"); + nsk_jvmti_setFailStatus(); + } + } + + if (user_data != &fakeUserData && !userDataError) { + NSK_COMPLAIN2("Unexpected user_data is passed " + "to heapReferenceCallback:\n" + " expected: 0x%p\n" + " actual: 0x%p\n", + user_data, + &fakeUserData); + nsk_jvmti_setFailStatus(); + userDataError++; + } + + switch (ref_kind) { + case JVMTI_HEAP_REFERENCE_CLASS: { + int i; + if (tag == 0) { + return 0; + } + if (tag != rootClassTag && tag != chainClassTag) { + NSK_COMPLAIN0("Unknown tagged class is passed " + "to heapReferenceCallback\n"); + nsk_jvmti_setFailStatus(); + break; + } + for (i = 0; i < objectsCount; i++) { + if (ref_tag == objectDescList[i].tag) { + if (objectDescList[i].exp_class_tag != tag) { + NSK_COMPLAIN2("Wrong tag in heapReferenceCallback" + "/JVMTI_HEAP_REFERENCE_CLASS:\n" + "Expected: %-3ld\n" + "Passed: %-3ld\n", + objectDescList[i].exp_class_tag, + tag); + nsk_jvmti_setFailStatus(); + } + break; + } + } + break; + } + + case JVMTI_HEAP_REFERENCE_STATIC_FIELD: + if (tag != rootObjectTag || class_tag != rootClassTag) { + NSK_COMPLAIN1("This reference kind was not expected: %s\n", + ref_kind_str[ref_kind]); + fflush(0); + nsk_jvmti_setFailStatus(); + } + break; + + case JVMTI_HEAP_REFERENCE_STACK_LOCAL: + // Skip local references from non-main (e.g. compiler) threads. + if (thr_tag == TARG_THREAD_TAG) { + thr_idx = registerThread(thr_id, thr_tag); + meth_idx = registerFrame(thr_id, depth, method, ref_kind); + if (meth_idx > 0) { + jint loc_idx = registerLocal(meth_idx, location, slot, tag); + } + } + /* This part is kind of hack. It has some expectations about stack layout */ + if (thr_tag == TARG_THREAD_TAG && + reference_info->stack_local.depth == TARG_FRAME_DEPTH) { + if (length != -1) { + jint exp_len = length; + + if (reference_info->stack_local.slot == ARGV_STRING_ARR_SLOT) { + exp_len = 0; + } + else if (reference_info->stack_local.slot >= FIRST_PRIM_ARR_SLOT && + reference_info->stack_local.slot <= LAST_PRIM_ARR_SLOT) { + exp_len = 2; + } + else if (reference_info->stack_local.slot == DUMMY_STRING_ARR_SLOT) { + exp_len = 3; + } + if (length != exp_len) { + NSK_COMPLAIN2("Wrong length of the local array:" + " expected: %-d, found: %-d\n\n", exp_len, length); + } + } else { /* length == -1 */ + if ((reference_info->stack_local.slot >= FIRST_PRIM_ARR_SLOT && + reference_info->stack_local.slot <= DUMMY_STRING_ARR_SLOT) || + reference_info->stack_local.slot == ARGV_STRING_ARR_SLOT) { + NSK_COMPLAIN0("Length of array must not be -1\n"); + } + } + if (length == 0 + && reference_info->stack_local.slot != ARGV_STRING_ARR_SLOT + && reference_info->stack_local.slot < FIRST_PRIM_ARR_SLOT + && reference_info->stack_local.slot > DUMMY_STRING_ARR_SLOT) { + NSK_COMPLAIN1("Wrong length of the local variable:" + " expected: -1, found: %-d\n\n", length); + nsk_jvmti_setFailStatus(); + } + } + break; + case JVMTI_HEAP_REFERENCE_JNI_LOCAL: + // Skip JNI local references from non-main (e.g. compiler) threads. + if (thr_tag == TARG_THREAD_TAG) { + thr_idx = registerThread(thr_id, thr_tag); + meth_idx = registerFrame(thr_id, depth, method, ref_kind); + } + break; + + case JVMTI_REFERENCE_ARRAY_ELEMENT: + case JVMTI_HEAP_REFERENCE_JNI_GLOBAL: + case JVMTI_HEAP_REFERENCE_SYSTEM_CLASS: + case JVMTI_HEAP_REFERENCE_MONITOR: + case JVMTI_HEAP_REFERENCE_OTHER: + /* These reference kinds are expected */ + break; + + default: { + NSK_COMPLAIN1("This reference kind was not expected: %s\n\n", + ref_kind_str[ref_kind]); + fflush(0); + nsk_jvmti_setFailStatus(); + break; + } + } + return 0; +} + +jint JNICALL primitiveFieldCallback + (jvmtiHeapReferenceKind ref_kind, + const jvmtiHeapReferenceInfo* reference_info, + jlong class_tag, + jlong* tag_ptr, + jvalue value, + jvmtiPrimitiveType value_type, + void* user_data) +{ + printf(" primitiveFieldCallback: ref=%s, class_tag=%-3ld, tag=%-3ld, type=%c\n", + ref_kind_str[ref_kind], + (long) class_tag, + (long) DEREF(tag_ptr), + (int ) value_type); + fflush(0); + return 0; +} + +jint JNICALL arrayPrimitiveValueCallback + (jlong class_tag, jlong size, jlong* tag_ptr, jint element_count, + jvmtiPrimitiveType element_type, const void* elements, void* user_data) +{ + printf(" arrayPrimitiveValueCallback: class_tag=%-3ld, tag=%-3ld, len=%d, type=%c\n", + (long) class_tag, + (long) DEREF(tag_ptr), + (int ) element_count, + (int ) element_type); + fflush(0); + return 0; +} + +jint JNICALL stringPrimitiveValueCallback + (jlong class_tag, jlong size, jlong* tag_ptr, const jchar* value, + jint value_length, void* user_data) +{ + printf("stringPrimitiveValueCallback: class_tag=%-3ld, tag=%-3ld, len=%d\n", + (long) class_tag, + (long) DEREF(tag_ptr), + (int ) value_length); + fflush(0); + return 0; +} + + +/* ============================================================================= */ +static jthread getTargetThread(jvmtiEnv *jvmti) { + static const char *target_thread_name = "main"; + jint i; + jint thread_count = -1; + jthread *threads = NULL; + + jvmti->GetAllThreads(&thread_count, &threads); + + for (i = 0; i < thread_count; i++) { + jvmtiThreadInfo thread_info; + jvmti->GetThreadInfo(threads[i], &thread_info); + + if (strcmp(thread_info.name, target_thread_name) == 0) { + return threads[i]; + } + } + + return NULL; +} + +static jvmtiError setTagForTargetThread(jvmtiEnv *jvmti, jlong tag) { + jthread target_thread = getTargetThread(jvmti); + return jvmti->SetTag(target_thread, tag); +} + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + jobject rootObject = NULL; + + printf("Wait for tested objects created\n"); + fflush(0); + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) { + return; + } + + printf(">>> Obtain and tag tested objects from debugee class\n"); + fflush(0); + { + if (!NSK_VERIFY(getTestedObjects(jvmti, jni, chainLength, &objectsCount, + &objectDescList, &rootObject))) { + return; + } + } + + printf(">>> Let debugee to clean links to unreachable objects\n"); + fflush(0); + { + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) { + return; + } + if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) { + return; + } + } + + if (!NSK_JVMTI_VERIFY(setTagForTargetThread(jvmti, TARG_THREAD_TAG))) { + nsk_jvmti_setFailStatus(); + return; + } + + printf("\n\n>>> Start 1-st iteration starting from the heap root\n"); + fflush(0); + { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB6(FollowReferences, jvmti, + (jint) 0, /* heap_filter */ + (jclass) NULL, /* class */ + (jobject) NULL, /* initial_object */ + &heapCallbacks, + (const void *) &fakeUserData))) + { + nsk_jvmti_setFailStatus(); + return; + } + } + + printf(">>> Check if reachable objects were iterated\n"); + fflush(0); + { + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + } + + { /* Reinstall the expectations */ + int k; + for (k = 0; k < objectsCount; k++) { + (objectDescList)[k].exp_found = 0; + (objectDescList)[k].found = 0; + } + /* Heap root object must be reported 2 times */ + objectDescList[0].exp_found = 2; + + /* First unreachable object must be reported once + * as JVMTI_HEAP_REFERENCE_STACK_LOCAL */ + objectDescList[2 * chainLength].exp_found = 1; + } + + printf("\n\n>>> Start 2-nd iteration starting from the heap root\n"); + fflush(0); + first_followref = 0; + { + jint heap_filter = JVMTI_HEAP_FILTER_UNTAGGED + | JVMTI_HEAP_FILTER_CLASS_UNTAGGED; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB6(FollowReferences, jvmti, + heap_filter, + (jclass) NULL, /* class */ + (jobject) NULL, /* initial_object */ + &heapCallbacks, + (const void *) &fakeUserData))) + { + nsk_jvmti_setFailStatus(); + return; + } + } + + printf(">>> Check that both reachable and unreachable " + "objects were not iterated\n"); + fflush(0); + { + if (!checkTestedObjects(jvmti, jni, chainLength, objectDescList)) { + nsk_jvmti_setFailStatus(); + } + } + + + printf(">>> Clean used data\n"); + fflush(0); + { + if (!NSK_VERIFY(releaseTestedObjects(jvmti, jni, chainLength, + objectDescList, rootObject))) { + return; + } + } + + printf("Let debugee to finish\n"); + fflush(0); + if (!NSK_VERIFY(nsk_jvmti_resumeSync())) + return; +} + +/* ============================================================================= */ + +/** Agent library initialization. */ +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_followref003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_followref003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_followref003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + { + const char* infoOpt = nsk_jvmti_findOptionValue("info"); + if (infoOpt != NULL) { + if (strcmp(infoOpt, "none") == 0) + info = INFO_NONE; + else if (strcmp(infoOpt, "all") == 0) + info = INFO_ALL; + else if (strcmp(infoOpt, "objref") == 0) + info = INFO_OBJREF; + else if (strcmp(infoOpt, "stackref") == 0) + info = INFO_STACKREF; + else if (strcmp(infoOpt, "heaproot") == 0) + info = INFO_HEAPROOT; + else if (strcmp(infoOpt, "heapobj") == 0) + info = INFO_HEAPOBJ; + else { + printf("Unknown option value: info=%s\n", infoOpt); + fflush(0); + return JNI_ERR; + } + } + } + + chainLength = nsk_jvmti_findOptionIntValue("objects", DEFAULT_CHAIN_LENGTH); + if (!NSK_VERIFY(chainLength > 0)) + return JNI_ERR; + + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_tag_objects = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) { + return JNI_ERR; + } + } + + /* Setting Heap Callbacks */ + heapCallbacks.heap_iteration_callback = NULL; + heapCallbacks.heap_reference_callback = heapReferenceCallback; + heapCallbacks.primitive_field_callback = primitiveFieldCallback; + heapCallbacks.array_primitive_value_callback = arrayPrimitiveValueCallback; + heapCallbacks.string_primitive_value_callback = stringPrimitiveValueCallback; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/libfollowref003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/libfollowref003.c deleted file mode 100644 index ec66b4dc18b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/libfollowref003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "followref003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/libfollowref003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/libfollowref003.cpp new file mode 100644 index 00000000000..2be3724074b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/libfollowref003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "followref003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/followref004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/followref004.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/followref004.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/followref004.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/libfollowref004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/libfollowref004.c deleted file mode 100644 index 7a764dcba65..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/libfollowref004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "followref004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/libfollowref004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/libfollowref004.cpp new file mode 100644 index 00000000000..eb313320753 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref004/libfollowref004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "followref004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/followref005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/followref005.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/followref005.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/followref005.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/libfollowref005.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/libfollowref005.c deleted file mode 100644 index 8b7ca7588d9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/libfollowref005.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "followref005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/libfollowref005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/libfollowref005.cpp new file mode 100644 index 00000000000..af96d9e4af7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref005/libfollowref005.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "followref005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/followref006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/followref006.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/followref006.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/followref006.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/libfollowref006.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/libfollowref006.c deleted file mode 100644 index 92d08a10405..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/libfollowref006.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "followref006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/libfollowref006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/libfollowref006.cpp new file mode 100644 index 00000000000..7d532b513de --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref006/libfollowref006.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "followref006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/earlyretbase.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/earlyretbase.c deleted file mode 100644 index 538734e58aa..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/earlyretbase.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return errCode - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; - -/* MethodExit and PopFrame events expected */ -static int meth_exit_exp_events = 0; -static int pop_frame_exp_events = 0; - -/* MethodExit and PopFrame events generated */ -static int meth_exit_gen_events = 0; -static int pop_frame_gen_events = 0; - -static int errCode = PASSED; - -static const char *sig_exp = "()J"; -static const char *name_exp = "activeMethod"; -static jmethodID midActiveMethod = NULL; - -void JNICALL -MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, - jmethodID method, jboolean was_poped_by_exc, jvalue return_value) { - - if (method == midActiveMethod) { - printf("#### MethodExit event occurred ####\n"); - fflush(0); - meth_exit_gen_events++; - } -} - -void JNICALL -FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean wasPopedByException) { - - if (method == midActiveMethod) { - printf("#### FramePop event occurred ####\n"); - fflush(0); - pop_frame_gen_events++; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretbase_suspThread(JNIEnv *env, - jclass cls, jobject earlyretThr) { - jvmtiError err; - - if (!caps.can_force_early_return || !caps.can_suspend) { - return PASSED; - } - - printf(">>>>>>>> Invoke SuspendThread()\n"); - if ((err = ((*jvmti)->SuspendThread(jvmti, earlyretThr))) - != JVMTI_ERROR_NONE) { - printf("%s: Failed to call SuspendThread(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - return JNI_ERR; - } - printf("<<<<<<<< SuspendThread() is successfully done\n"); - fflush(0); - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretbase_resThread(JNIEnv *env, - jclass cls, jobject earlyretThr) { - jvmtiError err; - - if (!caps.can_force_early_return || !caps.can_suspend) { - return PASSED; - } - - printf(">>>>>>>> Invoke ResumeThread()\n"); - if ((err = ((*jvmti)->ResumeThread(jvmti, earlyretThr))) - != JVMTI_ERROR_NONE) { - printf("%s: Failed to call ResumeThread(): error=%d: %s\n", - __FILE__, err, TranslateError(err)); - return JNI_ERR; - } - printf("<<<<<<<< ResumeThread() is successfully done\n"); - fflush(0); - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretbase_doForceEarlyReturn(JNIEnv *env, - jclass cls, jclass targCls, jthread earlyretThr, jlong valToRet) { - jvmtiError err; - - if (!caps.can_force_early_return || !caps.can_suspend) { - return PASSED; - } - - /* Turn on the JVMTI MetodExit and PopFrame events to check - * that ForceEarlyReturn correctly generates them */ - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable METHOD_EXIT event: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } else { - meth_exit_exp_events++; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_FRAME_POP, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable FRAME_POP event: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti)->NotifyFramePop(jvmti, earlyretThr, 0); - if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && - !caps.can_generate_frame_pop_events) { - /* Ok, it's expected */ - } else if (err != JVMTI_ERROR_NONE) { - printf("(NotifyFramePop) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } else { - pop_frame_exp_events++; - } - printf(">>>>>>>> Invoke ForceEarlyReturn()\n"); - - printf("Before call to GetMethodID(%s, %s)\n", name_exp, sig_exp); - midActiveMethod = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, targCls), - name_exp, sig_exp); - if (midActiveMethod == NULL) { - printf("Cannot find Method ID for method %s\n", name_exp); - RETURN_FAILED; - } - printf("After call to GetMethodID(%s, %s)\n", name_exp, sig_exp); - - if ((err = ((*jvmti)->ForceEarlyReturnLong(jvmti, earlyretThr, valToRet))) - != JVMTI_ERROR_NONE) { - printf("TEST FAILED: the function ForceEarlyReturn()" - " returned the error %d: %s\n", - err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - RETURN_FAILED; - } - printf("Check #1 PASSED: ForceEarlyReturn() is successfully done\n"); - fflush(0); - - return(errCode); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_earlyretbase(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_earlyretbase(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_earlyretbase(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong error code from a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_force_early_return) { - printf("Warning: ForceEarlyReturn is not implemented\n"); - return JNI_OK; - } - - if (!caps.can_suspend) { - printf("Warning: suspend/resume is not implemented\n"); - return JNI_OK; - } - - if (caps.can_generate_frame_pop_events && caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - callbacks.FramePop = &FramePop; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: FramePop or MethodExit event is not implemented\n"); - } - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretbase_check(JNIEnv *env, jclass cls) { - - printf("JVMTI PopFrame events: expected: %d, generated: %d\n", - meth_exit_exp_events, meth_exit_gen_events); - - printf("JVMTI MethodExit events: expected: %d, generated: %d\n", - pop_frame_exp_events, pop_frame_gen_events); - - /* Check if the JVMTI events were generated correctly by ForceEarlyReturn */ - if (meth_exit_exp_events != meth_exit_gen_events || - pop_frame_exp_events != pop_frame_gen_events) { - printf("TEST FAILED: JVMTI MethodExit or PopFrame events " - "generated incorrectly\n"); - errCode = STATUS_FAILED; - } else { - printf("Check #2 PASSED: JVMTI MethodExit and PopFrame " - "events generated correctly\n"); - errCode = PASSED; - } - fflush(0); - return errCode; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/earlyretbase.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/earlyretbase.cpp new file mode 100644 index 00000000000..5c8bc58c184 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/earlyretbase.cpp @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return errCode + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; + +/* MethodExit and PopFrame events expected */ +static int meth_exit_exp_events = 0; +static int pop_frame_exp_events = 0; + +/* MethodExit and PopFrame events generated */ +static int meth_exit_gen_events = 0; +static int pop_frame_gen_events = 0; + +static int errCode = PASSED; + +static const char *sig_exp = "()J"; +static const char *name_exp = "activeMethod"; +static jmethodID midActiveMethod = NULL; + +void JNICALL +MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, + jmethodID method, jboolean was_poped_by_exc, jvalue return_value) { + + if (method == midActiveMethod) { + printf("#### MethodExit event occurred ####\n"); + fflush(0); + meth_exit_gen_events++; + } +} + +void JNICALL +FramePop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean wasPopedByException) { + + if (method == midActiveMethod) { + printf("#### FramePop event occurred ####\n"); + fflush(0); + pop_frame_gen_events++; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretbase_suspThread(JNIEnv *env, + jclass cls, jobject earlyretThr) { + jvmtiError err; + + if (!caps.can_force_early_return || !caps.can_suspend) { + return PASSED; + } + + printf(">>>>>>>> Invoke SuspendThread()\n"); + if ((err = (jvmti->SuspendThread(earlyretThr))) + != JVMTI_ERROR_NONE) { + printf("%s: Failed to call SuspendThread(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + return JNI_ERR; + } + printf("<<<<<<<< SuspendThread() is successfully done\n"); + fflush(0); + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretbase_resThread(JNIEnv *env, + jclass cls, jobject earlyretThr) { + jvmtiError err; + + if (!caps.can_force_early_return || !caps.can_suspend) { + return PASSED; + } + + printf(">>>>>>>> Invoke ResumeThread()\n"); + if ((err = (jvmti->ResumeThread(earlyretThr))) + != JVMTI_ERROR_NONE) { + printf("%s: Failed to call ResumeThread(): error=%d: %s\n", + __FILE__, err, TranslateError(err)); + return JNI_ERR; + } + printf("<<<<<<<< ResumeThread() is successfully done\n"); + fflush(0); + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretbase_doForceEarlyReturn(JNIEnv *env, + jclass cls, jclass targCls, jthread earlyretThr, jlong valToRet) { + jvmtiError err; + + if (!caps.can_force_early_return || !caps.can_suspend) { + return PASSED; + } + + /* Turn on the JVMTI MetodExit and PopFrame events to check + * that ForceEarlyReturn correctly generates them */ + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable METHOD_EXIT event: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } else { + meth_exit_exp_events++; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_FRAME_POP, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable FRAME_POP event: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti->NotifyFramePop(earlyretThr, 0); + if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && + !caps.can_generate_frame_pop_events) { + /* Ok, it's expected */ + } else if (err != JVMTI_ERROR_NONE) { + printf("(NotifyFramePop) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } else { + pop_frame_exp_events++; + } + printf(">>>>>>>> Invoke ForceEarlyReturn()\n"); + + printf("Before call to GetMethodID(%s, %s)\n", name_exp, sig_exp); + midActiveMethod = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, targCls), + name_exp, sig_exp); + if (midActiveMethod == NULL) { + printf("Cannot find Method ID for method %s\n", name_exp); + RETURN_FAILED; + } + printf("After call to GetMethodID(%s, %s)\n", name_exp, sig_exp); + + if ((err = (jvmti->ForceEarlyReturnLong(earlyretThr, valToRet))) + != JVMTI_ERROR_NONE) { + printf("TEST FAILED: the function ForceEarlyReturn()" + " returned the error %d: %s\n", + err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + RETURN_FAILED; + } + printf("Check #1 PASSED: ForceEarlyReturn() is successfully done\n"); + fflush(0); + + return(errCode); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_earlyretbase(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_earlyretbase(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_earlyretbase(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong error code from a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_force_early_return) { + printf("Warning: ForceEarlyReturn is not implemented\n"); + return JNI_OK; + } + + if (!caps.can_suspend) { + printf("Warning: suspend/resume is not implemented\n"); + return JNI_OK; + } + + if (caps.can_generate_frame_pop_events && caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + callbacks.FramePop = &FramePop; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: FramePop or MethodExit event is not implemented\n"); + } + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretbase_check(JNIEnv *env, jclass cls) { + + printf("JVMTI PopFrame events: expected: %d, generated: %d\n", + meth_exit_exp_events, meth_exit_gen_events); + + printf("JVMTI MethodExit events: expected: %d, generated: %d\n", + pop_frame_exp_events, pop_frame_gen_events); + + /* Check if the JVMTI events were generated correctly by ForceEarlyReturn */ + if (meth_exit_exp_events != meth_exit_gen_events || + pop_frame_exp_events != pop_frame_gen_events) { + printf("TEST FAILED: JVMTI MethodExit or PopFrame events " + "generated incorrectly\n"); + errCode = STATUS_FAILED; + } else { + printf("Check #2 PASSED: JVMTI MethodExit and PopFrame " + "events generated correctly\n"); + errCode = PASSED; + } + fflush(0); + return errCode; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/libearlyretbase.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/libearlyretbase.c deleted file mode 100644 index ce523e51c97..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/libearlyretbase.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "earlyretbase.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/libearlyretbase.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/libearlyretbase.cpp new file mode 100644 index 00000000000..e6010ece156 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretbase/libearlyretbase.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "earlyretbase.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/earlyretfp.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/earlyretfp.c deleted file mode 100644 index 133dc9a2e43..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/earlyretfp.c +++ /dev/null @@ -1,478 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return - -#define METHCNT 2 -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint errCode = PASSED; -static jboolean printdump = JNI_TRUE; -static jmethodID midCheckPoint = NULL; -static jmethodID midRun = NULL; -static jmethodID midCountDownFloat = NULL; -static jmethodID midCountDownDouble = NULL; - -/* There is no synchronization for the counters because - * they are incremented in single threaded mode. - */ -static jint methodExitEventCount = 0; -static jint framesExpected = 0; -static jint framesCount = 0; - -static jint methidx = 0; -static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretfp$earlyretThread;"; -static const char *sig_exp [METHCNT] = { "(I)D", "(I)F" }; -static const char *name_exp[METHCNT] = { "countDownDouble", "countDownFloat" }; - -/* These are really initialized in getReady() */ -static float ret_val_f = 0.0; -static double ret_val_d = 0.0; - -static const char *argName = "nestingCount"; - -void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, - jlocation loc, jint i) { - jvmtiError err; - jclass cls; - jlocation loc_exp = (i == 0) ? 0x16 : 0xd; - char *sigClass, *name, *sig, *generic; - jvmtiLocalVariableEntry *table = NULL; - jint entryCount = 0; - jint argValue; - jint j; - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, mid, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - RETURN_FAILED; - } - - /* Get Local Variable Table to be able to get the argument value - * from current method frame and compare it with the expected value - */ - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - RETURN_FAILED; - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - if (strcmp(table[j].name, argName) == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, 0, - table[j].slot, &argValue); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - RETURN_FAILED; - } - } - } - } - - if (printdump == JNI_TRUE) { - printf("\n>>> step %d: \"%s.%s%s\"\n", i, sigClass, name, sig); - printf(">>> location: 0x%x%08x", (jint)(loc >> 32), (jint)loc); - printf(", arg value: %d\n", argValue); - } - - if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { - printf("(step %d) wrong class sig: \"%s\",\n", i, sigClass); - printf(" expected: \"%s\"\n", cls_exp); - RETURN_FAILED; - } - if (name == NULL || strcmp(name, name_exp[methidx]) != 0) { - printf("(step %d) wrong method name: \"%s\",", i, name); - printf(" expected: \"%s\"\n", name_exp[methidx]); - RETURN_FAILED; - } - if (sig == NULL || strcmp(sig, sig_exp[methidx]) != 0) { - printf("(step %d) wrong method sig: \"%s\",", i, sig); - printf(" expected: \"%s\"\n", sig_exp[methidx]); - RETURN_FAILED; - } - methidx = (methidx + 1) % METHCNT; - if (loc != loc_exp) { - printf("(step %d) wrong location: 0x%x%08x,", - i, (jint)(loc >> 32), (jint)loc); - printf(" expected: 0x%x\n", (jint)loc_exp); - RETURN_FAILED; - } - if (argValue != i) { - printf("(step %d) wrong argument value: %d,", i, argValue); - printf(" expected: %d\n", i); - RETURN_FAILED; - } - - if (sigClass != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sigClass); - } - if (name != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)name); - } - if (sig != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sig); - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].name)); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].signature)); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table); - } - if (methodExitEventCount != framesCount + 1) { - printf("(step %d) Wrong methodExitEventCount: %d,", - i, methodExitEventCount); - printf(" expected: %d\n", framesCount + 1); - RETURN_FAILED; - } - fflush(0); -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (midCheckPoint != method) { - printf("bp: don't know where we get called from"); - RETURN_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> breakpoint in checkPoint\n"); - } - - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable single step: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable method exit events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->ForceEarlyReturnVoid(jvmti_env, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - fflush(0); -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err = JVMTI_ERROR_NONE; - - if (method == midRun) { - if (printdump == JNI_TRUE) { - printf(">>> returned early %d frames till method \"run()\"\n", - framesCount); - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable single step: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - } else { - check(jvmti_env, thread, method, location, framesCount); - framesCount++; - - if (method == midCountDownFloat) { - err = (*jvmti_env)->ForceEarlyReturnFloat(jvmti_env, thread, ret_val_f); - } - if (method == midCountDownDouble) { - err = (*jvmti_env)->ForceEarlyReturnDouble(jvmti_env, thread, ret_val_d); - } - if (err != JVMTI_ERROR_NONE) { - printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - } - fflush(0); -} - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, jvalue value) { - - jboolean bad_exception = was_popped_by_exception; - methodExitEventCount++; - if (method == midRun || method == midCheckPoint) { - // ignore - } else if (method == midCountDownFloat) { - printf(">>> ForceEarlyReturnFloat value: %8.4f, expected %8.4f\n", - value.f, ret_val_f); - if (value.f != ret_val_f) { - printf("Wrong ForceEarlyReturnFloat return value: %8.4f\n", value.f); - errCode = STATUS_FAILED; - } - } else if (method == midCountDownDouble) { - printf(">>> ForceEarlyReturnDouble value: %8.4f, expected %8.4f\n", - value.d, ret_val_d); - if (value.d != ret_val_d) { - printf("Wrong ForceEarlyReturnDouble return value: %8.4f\n", value.d); - errCode = STATUS_FAILED; - } - } else { - // Exceptions are ok for non test methods. Sometimes the VM invokes java - // and throws exceptions, and we don't want to complain about these. - bad_exception = JNI_FALSE; - } - if (bad_exception) { - printf("Method was_popped_by_exception unexpectedly\n"); - errCode = STATUS_FAILED; - } - fflush(0); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_earlyretfp(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_earlyretfp(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_earlyretfp(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printf("Printdump is turned on!\n"); - - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong error code from a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_force_early_return) { - printf("Warning: ForceEarlyReturn is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_method_exit_events && - caps.can_generate_single_step_events) - { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - callbacks.MethodExit = &MethodExit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or SingleStep event are not implemented\n"); - } - - fflush(0); - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_getReady( - JNIEnv *env, jclass c, jclass cls, jint depth, jdouble retval) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - RETURN_FAILED; - } - - if (!caps.can_force_early_return || - !caps.can_generate_breakpoint_events || - !caps.can_generate_method_exit_events || - !caps.can_generate_single_step_events) { - return; - } - - midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "run", "()V"); - if (midRun == NULL) { - printf("Cannot find Method ID for method run\n"); - RETURN_FAILED; - } - - midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (midCheckPoint == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - RETURN_FAILED; - } - - midCountDownFloat = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "countDownFloat", "(I)F"); - if (midCountDownFloat == NULL) { - printf("Cannot find Method ID for method countDownFloat\n"); - RETURN_FAILED; - } - - midCountDownDouble = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "countDownDouble", "(I)D"); - if (midCountDownDouble == NULL) { - printf("Cannot find Method ID for method countDownDouble\n"); - RETURN_FAILED; - } - - err = (*jvmti)->SetBreakpoint(jvmti, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } else { - framesExpected = depth; - ret_val_d = retval; - ret_val_f = (float) (retval - 1.0); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_printFloat( - JNIEnv *env, jclass cls, jfloat val) { - - printf("\n>>> Returned value is %8.4f, hex: %#a\n", val, val); - fflush(0); - return; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_printDouble( - JNIEnv *env, jclass cls, jdouble val) { - - printf("\n>>> Returned value is %8.4f, hex: %#a\n", val, val); - fflush(0); - return; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_check(JNIEnv *env, jclass cls) { - if (framesCount != framesExpected) { - printf("Wrong number of returned early frames: %d, expected: %d\n", - framesCount, framesExpected); - errCode = STATUS_FAILED; - } - fflush(0); - return errCode; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/earlyretfp.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/earlyretfp.cpp new file mode 100644 index 00000000000..bd91c08eaa1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/earlyretfp.cpp @@ -0,0 +1,478 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return + +#define METHCNT 2 +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint errCode = PASSED; +static jboolean printdump = JNI_TRUE; +static jmethodID midCheckPoint = NULL; +static jmethodID midRun = NULL; +static jmethodID midCountDownFloat = NULL; +static jmethodID midCountDownDouble = NULL; + +/* There is no synchronization for the counters because + * they are incremented in single threaded mode. + */ +static jint methodExitEventCount = 0; +static jint framesExpected = 0; +static jint framesCount = 0; + +static jint methidx = 0; +static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretfp$earlyretThread;"; +static const char *sig_exp [METHCNT] = { "(I)D", "(I)F" }; +static const char *name_exp[METHCNT] = { "countDownDouble", "countDownFloat" }; + +/* These are really initialized in getReady() */ +static float ret_val_f = 0.0; +static double ret_val_d = 0.0; + +static const char *argName = "nestingCount"; + +void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, + jlocation loc, jint i) { + jvmtiError err; + jclass cls; + jlocation loc_exp = (i == 0) ? 0x16 : 0xd; + char *sigClass, *name, *sig, *generic; + jvmtiLocalVariableEntry *table = NULL; + jint entryCount = 0; + jint argValue; + jint j; + + err = jvmti_env->GetMethodDeclaringClass(mid, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->GetClassSignature(cls, &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + RETURN_FAILED; + } + + /* Get Local Variable Table to be able to get the argument value + * from current method frame and compare it with the expected value + */ + err = jvmti_env->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + RETURN_FAILED; + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + if (strcmp(table[j].name, argName) == 0) { + err = jvmti_env->GetLocalInt(thr, 0, + table[j].slot, &argValue); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + RETURN_FAILED; + } + } + } + } + + if (printdump == JNI_TRUE) { + printf("\n>>> step %d: \"%s.%s%s\"\n", i, sigClass, name, sig); + printf(">>> location: 0x%x%08x", (jint)(loc >> 32), (jint)loc); + printf(", arg value: %d\n", argValue); + } + + if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { + printf("(step %d) wrong class sig: \"%s\",\n", i, sigClass); + printf(" expected: \"%s\"\n", cls_exp); + RETURN_FAILED; + } + if (name == NULL || strcmp(name, name_exp[methidx]) != 0) { + printf("(step %d) wrong method name: \"%s\",", i, name); + printf(" expected: \"%s\"\n", name_exp[methidx]); + RETURN_FAILED; + } + if (sig == NULL || strcmp(sig, sig_exp[methidx]) != 0) { + printf("(step %d) wrong method sig: \"%s\",", i, sig); + printf(" expected: \"%s\"\n", sig_exp[methidx]); + RETURN_FAILED; + } + methidx = (methidx + 1) % METHCNT; + if (loc != loc_exp) { + printf("(step %d) wrong location: 0x%x%08x,", + i, (jint)(loc >> 32), (jint)loc); + printf(" expected: 0x%x\n", (jint)loc_exp); + RETURN_FAILED; + } + if (argValue != i) { + printf("(step %d) wrong argument value: %d,", i, argValue); + printf(" expected: %d\n", i); + RETURN_FAILED; + } + + if (sigClass != NULL) { + jvmti_env->Deallocate((unsigned char*)sigClass); + } + if (name != NULL) { + jvmti_env->Deallocate((unsigned char*)name); + } + if (sig != NULL) { + jvmti_env->Deallocate((unsigned char*)sig); + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + jvmti_env->Deallocate((unsigned char*)(table[j].name)); + jvmti_env->Deallocate((unsigned char*)(table[j].signature)); + } + jvmti_env->Deallocate((unsigned char*)table); + } + if (methodExitEventCount != framesCount + 1) { + printf("(step %d) Wrong methodExitEventCount: %d,", + i, methodExitEventCount); + printf(" expected: %d\n", framesCount + 1); + RETURN_FAILED; + } + fflush(0); +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (midCheckPoint != method) { + printf("bp: don't know where we get called from"); + RETURN_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> breakpoint in checkPoint\n"); + } + + err = jvmti_env->ClearBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable single step: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable method exit events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->ForceEarlyReturnVoid(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + fflush(0); +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err = JVMTI_ERROR_NONE; + + if (method == midRun) { + if (printdump == JNI_TRUE) { + printf(">>> returned early %d frames till method \"run()\"\n", + framesCount); + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable single step: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + } else { + check(jvmti_env, thread, method, location, framesCount); + framesCount++; + + if (method == midCountDownFloat) { + err = jvmti_env->ForceEarlyReturnFloat(thread, ret_val_f); + } + if (method == midCountDownDouble) { + err = jvmti_env->ForceEarlyReturnDouble(thread, ret_val_d); + } + if (err != JVMTI_ERROR_NONE) { + printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + } + fflush(0); +} + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, jvalue value) { + + jboolean bad_exception = was_popped_by_exception; + methodExitEventCount++; + if (method == midRun || method == midCheckPoint) { + // ignore + } else if (method == midCountDownFloat) { + printf(">>> ForceEarlyReturnFloat value: %8.4f, expected %8.4f\n", + value.f, ret_val_f); + if (value.f != ret_val_f) { + printf("Wrong ForceEarlyReturnFloat return value: %8.4f\n", value.f); + errCode = STATUS_FAILED; + } + } else if (method == midCountDownDouble) { + printf(">>> ForceEarlyReturnDouble value: %8.4f, expected %8.4f\n", + value.d, ret_val_d); + if (value.d != ret_val_d) { + printf("Wrong ForceEarlyReturnDouble return value: %8.4f\n", value.d); + errCode = STATUS_FAILED; + } + } else { + // Exceptions are ok for non test methods. Sometimes the VM invokes java + // and throws exceptions, and we don't want to complain about these. + bad_exception = JNI_FALSE; + } + if (bad_exception) { + printf("Method was_popped_by_exception unexpectedly\n"); + errCode = STATUS_FAILED; + } + fflush(0); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_earlyretfp(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_earlyretfp(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_earlyretfp(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printf("Printdump is turned on!\n"); + + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong error code from a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_force_early_return) { + printf("Warning: ForceEarlyReturn is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_method_exit_events && + caps.can_generate_single_step_events) + { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + callbacks.MethodExit = &MethodExit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or SingleStep event are not implemented\n"); + } + + fflush(0); + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_getReady( + JNIEnv *env, jclass c, jclass cls, jint depth, jdouble retval) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + RETURN_FAILED; + } + + if (!caps.can_force_early_return || + !caps.can_generate_breakpoint_events || + !caps.can_generate_method_exit_events || + !caps.can_generate_single_step_events) { + return; + } + + midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "run", "()V"); + if (midRun == NULL) { + printf("Cannot find Method ID for method run\n"); + RETURN_FAILED; + } + + midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (midCheckPoint == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + RETURN_FAILED; + } + + midCountDownFloat = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "countDownFloat", "(I)F"); + if (midCountDownFloat == NULL) { + printf("Cannot find Method ID for method countDownFloat\n"); + RETURN_FAILED; + } + + midCountDownDouble = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "countDownDouble", "(I)D"); + if (midCountDownDouble == NULL) { + printf("Cannot find Method ID for method countDownDouble\n"); + RETURN_FAILED; + } + + err = jvmti->SetBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } else { + framesExpected = depth; + ret_val_d = retval; + ret_val_f = (float) (retval - 1.0); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_printFloat( + JNIEnv *env, jclass cls, jfloat val) { + + printf("\n>>> Returned value is %8.4f, hex: %#a\n", val, val); + fflush(0); + return; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_printDouble( + JNIEnv *env, jclass cls, jdouble val) { + + printf("\n>>> Returned value is %8.4f, hex: %#a\n", val, val); + fflush(0); + return; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_check(JNIEnv *env, jclass cls) { + if (framesCount != framesExpected) { + printf("Wrong number of returned early frames: %d, expected: %d\n", + framesCount, framesExpected); + errCode = STATUS_FAILED; + } + fflush(0); + return errCode; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/libearlyretfp.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/libearlyretfp.c deleted file mode 100644 index 4af1e038b3d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/libearlyretfp.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "earlyretfp.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/libearlyretfp.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/libearlyretfp.cpp new file mode 100644 index 00000000000..b0008946496 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/libearlyretfp.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "earlyretfp.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/earlyretint.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/earlyretint.c deleted file mode 100644 index 220c6a18391..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/earlyretint.c +++ /dev/null @@ -1,493 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint errCode = PASSED; -static jboolean printdump = JNI_TRUE; - -static jmethodID midCheckPoint = NULL; -static jmethodID midRun = NULL; - -static jmethodID midCountDownInt = NULL; -static jmethodID midCountDownShort = NULL; -static jmethodID midCountDownChar = NULL; -static jmethodID midCountDownByte = NULL; -static jmethodID midCountDownBoolean = NULL; - -static jint framesExpected = 0; -static jint framesCount = 0; -static jint methodExitEventCount = 0; - -static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretint$earlyretThread;"; - -#define METHCNT 5 -static jint methidx = -1; -static const char *sign_exp[METHCNT] = { "(I)Z", "(I)B", "(I)C", - "(I)S", "(I)I" }; -static const char *name_exp[METHCNT] = { "countDownBoolean", - "countDownByte", - "countDownChar", - "countDownShort", - "countDownInt" }; - -static const int val_exp [METHCNT] = { 1, 101, 202, 303, 404 }; -static int val_ret [METHCNT] = { 0, 0, 0, 0, 0 }; - - -static const char *argName = "nestingCount"; - -void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, - jlocation loc, jint i) { - jvmtiError err; - jclass cls; - jlocation loc_exp = (i == 0) ? 0x21 : 0xd; - char *sigClass, *name, *sig, *generic; - jvmtiLocalVariableEntry *table = NULL; - jint entryCount = 0; - jint argValue = -i; - jint j; - - methidx = (methidx + 1) % METHCNT; - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, mid, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - RETURN_FAILED; - } - - if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { - printf("(step %d) Wrong class sig: \"%s\",\n", i, sigClass); - printf(" expected: \"%s\"\n", cls_exp); - RETURN_FAILED; - } - if (name == NULL || strcmp(name, name_exp[methidx]) != 0) { - printf("(step %d) wrong method name: \"%s\",", i, name); - printf(" expected: \"%s\"\n", name_exp[methidx]); - RETURN_FAILED; - } - if (sig == NULL || strcmp(sig, sign_exp[methidx]) != 0) { - printf("(step %d) wrong method sig: \"%s\",", i, sig); - printf(" expected: \"%s\"\n", sign_exp[methidx]); - RETURN_FAILED; - } - - if (printdump == JNI_TRUE) { - printf("\n>>> step %d: \"%s.%s%s\"\n", i, sigClass, name, sig); - printf(">>> location: 0x%x%08x\n", (jint)(loc >> 32), (jint)loc); - } - - /* Get Local Variable Table to be able to get the argument value - * from current method frame and compare it with the expected value - */ - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - RETURN_FAILED; - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - if (strcmp(table[j].name, argName) == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, 0, - table[j].slot, &argValue); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - RETURN_FAILED; - } - } - } - } - - if (loc != loc_exp) { - printf("(step %d) wrong location: 0x%x%08x,", - i, (jint)(loc >> 32), (jint)loc); - printf(" expected: 0x%x\n", (jint)loc_exp); - RETURN_FAILED; - } - if (argValue != i) { - printf("(step %d) wrong argument value: %d,", i, argValue); - printf(" expected: %d\n", i); - RETURN_FAILED; - } - - if (sigClass != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sigClass); - } - if (name != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)name); - } - if (sig != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sig); - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].name)); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].signature)); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table); - } - if (methodExitEventCount != (framesCount + 1)) { - printf("(step %d) wrong methodExitEventCount: %d,", - i, methodExitEventCount); - printf(" expected: %d\n", framesCount + 1); - RETURN_FAILED; - } - fflush(0); -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (midCheckPoint != method) { - printf("bp: don't know where we get called from"); - RETURN_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> breakpoint in checkPoint\n"); - } - - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable single step events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable method exit events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->ForceEarlyReturnVoid(jvmti_env, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - fflush(0); -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (method == midRun) { - if (printdump == JNI_TRUE) { - printf(">>> returned early %d frames till method \"run()\"\n", - framesCount); - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable single step events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_EXIT, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable method exit events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - } else if (method == midCountDownInt || method == midCountDownShort - || method == midCountDownChar || method == midCountDownByte - || method == midCountDownBoolean) { - check(jvmti_env, thread, method, location, framesCount); - framesCount++; - - err = (*jvmti_env)->ForceEarlyReturnInt(jvmti_env, thread, - val_exp[methidx]); - if (err != JVMTI_ERROR_NONE) { - printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - } - fflush(0); -} - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, jvalue value) { - val_ret[0] = value.z; - val_ret[1] = value.b; - val_ret[2] = value.c; - val_ret[3] = value.s; - val_ret[4] = value.i; - methodExitEventCount++; - if (method == midRun || method == midCheckPoint) { - return; - } - printf(">>> ForceEarlyReturnInt value: %d, expected %d\n", - val_ret[methidx], val_exp[methidx]); - - if (val_ret[methidx] != val_exp[methidx]) { - printf("Wrong ForceEarlyReturnInt return value: %d\n", val_ret[methidx]); - errCode = STATUS_FAILED; - } - if (was_popped_by_exception) { - printf("Method was_popped_by_exception unexpectedly\n"); - errCode = STATUS_FAILED; - } - fflush(0); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_earlyretint(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_earlyretint(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_earlyretint(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printf("Printdump is turned on!\n"); - - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong error code from a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_force_early_return) { - printf("Warning: ForceEarlyReturn is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_method_exit_events && - caps.can_generate_single_step_events) - { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - callbacks.MethodExit = &MethodExit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or SingleStep event are not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretint_getReady( - JNIEnv *env, jclass c, jclass cls, jint depth) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - RETURN_FAILED; - } - - if (!caps.can_force_early_return || - !caps.can_generate_breakpoint_events || - !caps.can_generate_method_exit_events || - !caps.can_generate_single_step_events) { - return; - } - - midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "run", "()V"); - if (midRun == NULL) { - printf("Cannot find Method ID for method run\n"); - RETURN_FAILED; - } - - midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (midCheckPoint == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - RETURN_FAILED; - } - - midCountDownInt = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "countDownInt", "(I)I"); - if (midCheckPoint == NULL) { - printf("Cannot find Method ID for method countDownInt\n"); - RETURN_FAILED; - } - - midCountDownShort = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "countDownShort", "(I)S"); - if (midCountDownShort == NULL) { - printf("Cannot find Method ID for method countDownShort\n"); - RETURN_FAILED; - } - - midCountDownChar = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "countDownChar", "(I)C"); - if (midCountDownChar == NULL) { - printf("Cannot find Method ID for method countDownChar\n"); - RETURN_FAILED; - } - - midCountDownByte = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "countDownByte", "(I)B"); - if (midCountDownByte == NULL) { - printf("Cannot find Method ID for method countDownByte\n"); - RETURN_FAILED; - } - - midCountDownBoolean = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "countDownBoolean", "(I)Z"); - if (midCountDownBoolean == NULL) { - printf("Cannot find Method ID for method countDownBoolean\n"); - RETURN_FAILED; - } - - err = (*jvmti)->SetBreakpoint(jvmti, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } else { - framesExpected = depth; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretint_printInt( - JNIEnv *env, jclass cls, jint val) { - - printf("\n>>> Returned value: dec %d, hex: %#x\n", val, val); - fflush(0); - return; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretint_check(JNIEnv *env, jclass cls) { - if (framesCount != framesExpected) { - printf("Wrong number of returned early frames: %d, expected: %d\n", - framesCount, framesExpected); - errCode = STATUS_FAILED; - } - fflush(0); - return errCode; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/earlyretint.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/earlyretint.cpp new file mode 100644 index 00000000000..f635cec9b1b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/earlyretint.cpp @@ -0,0 +1,493 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint errCode = PASSED; +static jboolean printdump = JNI_TRUE; + +static jmethodID midCheckPoint = NULL; +static jmethodID midRun = NULL; + +static jmethodID midCountDownInt = NULL; +static jmethodID midCountDownShort = NULL; +static jmethodID midCountDownChar = NULL; +static jmethodID midCountDownByte = NULL; +static jmethodID midCountDownBoolean = NULL; + +static jint framesExpected = 0; +static jint framesCount = 0; +static jint methodExitEventCount = 0; + +static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretint$earlyretThread;"; + +#define METHCNT 5 +static jint methidx = -1; +static const char *sign_exp[METHCNT] = { "(I)Z", "(I)B", "(I)C", + "(I)S", "(I)I" }; +static const char *name_exp[METHCNT] = { "countDownBoolean", + "countDownByte", + "countDownChar", + "countDownShort", + "countDownInt" }; + +static const int val_exp [METHCNT] = { 1, 101, 202, 303, 404 }; +static int val_ret [METHCNT] = { 0, 0, 0, 0, 0 }; + + +static const char *argName = "nestingCount"; + +void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, + jlocation loc, jint i) { + jvmtiError err; + jclass cls; + jlocation loc_exp = (i == 0) ? 0x21 : 0xd; + char *sigClass, *name, *sig, *generic; + jvmtiLocalVariableEntry *table = NULL; + jint entryCount = 0; + jint argValue = -i; + jint j; + + methidx = (methidx + 1) % METHCNT; + + err = jvmti_env->GetMethodDeclaringClass(mid, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->GetClassSignature(cls, &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + RETURN_FAILED; + } + + if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { + printf("(step %d) Wrong class sig: \"%s\",\n", i, sigClass); + printf(" expected: \"%s\"\n", cls_exp); + RETURN_FAILED; + } + if (name == NULL || strcmp(name, name_exp[methidx]) != 0) { + printf("(step %d) wrong method name: \"%s\",", i, name); + printf(" expected: \"%s\"\n", name_exp[methidx]); + RETURN_FAILED; + } + if (sig == NULL || strcmp(sig, sign_exp[methidx]) != 0) { + printf("(step %d) wrong method sig: \"%s\",", i, sig); + printf(" expected: \"%s\"\n", sign_exp[methidx]); + RETURN_FAILED; + } + + if (printdump == JNI_TRUE) { + printf("\n>>> step %d: \"%s.%s%s\"\n", i, sigClass, name, sig); + printf(">>> location: 0x%x%08x\n", (jint)(loc >> 32), (jint)loc); + } + + /* Get Local Variable Table to be able to get the argument value + * from current method frame and compare it with the expected value + */ + err = jvmti_env->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + RETURN_FAILED; + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + if (strcmp(table[j].name, argName) == 0) { + err = jvmti_env->GetLocalInt(thr, 0, + table[j].slot, &argValue); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + RETURN_FAILED; + } + } + } + } + + if (loc != loc_exp) { + printf("(step %d) wrong location: 0x%x%08x,", + i, (jint)(loc >> 32), (jint)loc); + printf(" expected: 0x%x\n", (jint)loc_exp); + RETURN_FAILED; + } + if (argValue != i) { + printf("(step %d) wrong argument value: %d,", i, argValue); + printf(" expected: %d\n", i); + RETURN_FAILED; + } + + if (sigClass != NULL) { + jvmti_env->Deallocate((unsigned char*)sigClass); + } + if (name != NULL) { + jvmti_env->Deallocate((unsigned char*)name); + } + if (sig != NULL) { + jvmti_env->Deallocate((unsigned char*)sig); + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + jvmti_env->Deallocate((unsigned char*)(table[j].name)); + jvmti_env->Deallocate((unsigned char*)(table[j].signature)); + } + jvmti_env->Deallocate((unsigned char*)table); + } + if (methodExitEventCount != (framesCount + 1)) { + printf("(step %d) wrong methodExitEventCount: %d,", + i, methodExitEventCount); + printf(" expected: %d\n", framesCount + 1); + RETURN_FAILED; + } + fflush(0); +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (midCheckPoint != method) { + printf("bp: don't know where we get called from"); + RETURN_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> breakpoint in checkPoint\n"); + } + + err = jvmti_env->ClearBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable single step events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable method exit events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->ForceEarlyReturnVoid(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + fflush(0); +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (method == midRun) { + if (printdump == JNI_TRUE) { + printf(">>> returned early %d frames till method \"run()\"\n", + framesCount); + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable single step events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_EXIT, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable method exit events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + } else if (method == midCountDownInt || method == midCountDownShort + || method == midCountDownChar || method == midCountDownByte + || method == midCountDownBoolean) { + check(jvmti_env, thread, method, location, framesCount); + framesCount++; + + err = jvmti_env->ForceEarlyReturnInt(thread, + val_exp[methidx]); + if (err != JVMTI_ERROR_NONE) { + printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + } + fflush(0); +} + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, jvalue value) { + val_ret[0] = value.z; + val_ret[1] = value.b; + val_ret[2] = value.c; + val_ret[3] = value.s; + val_ret[4] = value.i; + methodExitEventCount++; + if (method == midRun || method == midCheckPoint) { + return; + } + printf(">>> ForceEarlyReturnInt value: %d, expected %d\n", + val_ret[methidx], val_exp[methidx]); + + if (val_ret[methidx] != val_exp[methidx]) { + printf("Wrong ForceEarlyReturnInt return value: %d\n", val_ret[methidx]); + errCode = STATUS_FAILED; + } + if (was_popped_by_exception) { + printf("Method was_popped_by_exception unexpectedly\n"); + errCode = STATUS_FAILED; + } + fflush(0); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_earlyretint(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_earlyretint(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_earlyretint(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printf("Printdump is turned on!\n"); + + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong error code from a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_force_early_return) { + printf("Warning: ForceEarlyReturn is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_method_exit_events && + caps.can_generate_single_step_events) + { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + callbacks.MethodExit = &MethodExit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or SingleStep event are not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretint_getReady( + JNIEnv *env, jclass c, jclass cls, jint depth) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + RETURN_FAILED; + } + + if (!caps.can_force_early_return || + !caps.can_generate_breakpoint_events || + !caps.can_generate_method_exit_events || + !caps.can_generate_single_step_events) { + return; + } + + midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "run", "()V"); + if (midRun == NULL) { + printf("Cannot find Method ID for method run\n"); + RETURN_FAILED; + } + + midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (midCheckPoint == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + RETURN_FAILED; + } + + midCountDownInt = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "countDownInt", "(I)I"); + if (midCheckPoint == NULL) { + printf("Cannot find Method ID for method countDownInt\n"); + RETURN_FAILED; + } + + midCountDownShort = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "countDownShort", "(I)S"); + if (midCountDownShort == NULL) { + printf("Cannot find Method ID for method countDownShort\n"); + RETURN_FAILED; + } + + midCountDownChar = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "countDownChar", "(I)C"); + if (midCountDownChar == NULL) { + printf("Cannot find Method ID for method countDownChar\n"); + RETURN_FAILED; + } + + midCountDownByte = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "countDownByte", "(I)B"); + if (midCountDownByte == NULL) { + printf("Cannot find Method ID for method countDownByte\n"); + RETURN_FAILED; + } + + midCountDownBoolean = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "countDownBoolean", "(I)Z"); + if (midCountDownBoolean == NULL) { + printf("Cannot find Method ID for method countDownBoolean\n"); + RETURN_FAILED; + } + + err = jvmti->SetBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } else { + framesExpected = depth; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretint_printInt( + JNIEnv *env, jclass cls, jint val) { + + printf("\n>>> Returned value: dec %d, hex: %#x\n", val, val); + fflush(0); + return; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretint_check(JNIEnv *env, jclass cls) { + if (framesCount != framesExpected) { + printf("Wrong number of returned early frames: %d, expected: %d\n", + framesCount, framesExpected); + errCode = STATUS_FAILED; + } + fflush(0); + return errCode; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/libearlyretint.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/libearlyretint.c deleted file mode 100644 index cce87deb8ff..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/libearlyretint.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "earlyretint.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/libearlyretint.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/libearlyretint.cpp new file mode 100644 index 00000000000..4c2ab567c8a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretint/libearlyretint.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "earlyretint.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/earlyretlong.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/earlyretlong.c deleted file mode 100644 index a425c4494ed..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/earlyretlong.c +++ /dev/null @@ -1,449 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "jni_tools.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint errCode = PASSED; -static jboolean printdump = JNI_TRUE; - -static jmethodID midRun = NULL; -static jmethodID midCountDownLong = NULL; -static jmethodID midCheckPoint = NULL; - -static jint framesExpected = 0; -static jint framesCount = 0; -static jint methodExitEventCount = 0; - -static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretlong$earlyretThread;"; - -static jlong val_exp = 0L; -static const char *sig_exp = "(I)J"; -static const char *name_exp = "countDownLong"; - -static const char *argName = "nestingCount"; - -void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, - jlocation loc, jint frame_no) { - jvmtiError err; - jclass cls; - jlocation loc_exp = (frame_no == 0) ? 0x15 : 0xd; - char *sigClass, *name, *sig, *generic; - jvmtiLocalVariableEntry *table = NULL; - jint entryCount = 0; - jint argValue; - jint j; - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, mid, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - - /* Get Local Variable Table to be able to get the argument value - * from current method frame and compare it with the expected value - */ - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - if (strcmp(table[j].name, argName) == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, 0, - table[j].slot, &argValue); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - } - } - } - - if (printdump == JNI_TRUE) { - printf("\n>>> step %d: \"%s.%s%s\"\n", frame_no, sigClass, name, sig); - printf(">>> location: %#x%08x", (jint)(loc >> 32), (jint)loc); - printf(", arg value: %d\n", argValue); - } - - if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { - printf("(step %d) Wrong class sig: \"%s\",\n", frame_no, sigClass); - printf(" expected: \"%s\"\n", cls_exp); - RETURN_FAILED; - } - if (name == NULL || strcmp(name, name_exp) != 0) { - printf("(step %d) wrong method name: \"%s\",", frame_no, name); - printf(" expected: \"%s\"\n", name_exp); - RETURN_FAILED; - } - if (sig == NULL || strcmp(sig, sig_exp) != 0) { - printf("(step %d) wrong method sig: \"%s\",", frame_no, sig); - printf(" expected: \"%s\"\n", sig_exp); - RETURN_FAILED; - } - if (loc != loc_exp) { - printf("(step %d) wrong location: %#x%08x,", - frame_no, (jint)(loc >> 32), (jint)loc); - printf(" expected: %#x\n", (jint)loc_exp); - RETURN_FAILED; - } - if (argValue != frame_no) { - printf("(step %d) wrong argument value: %d,", frame_no, argValue); - printf(" expected: %d\n", frame_no); - RETURN_FAILED; - } - - if (sigClass != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sigClass); - } - if (name != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)name); - } - if (sig != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sig); - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].name)); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].signature)); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table); - } - if (methodExitEventCount != (framesCount + 1)) { - printf("(step %d) wrong methodExitEventCount: %d,", - frame_no, methodExitEventCount); - printf(" expected: %d\n", framesCount + 1); - RETURN_FAILED; - } - fflush(0); -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (midCheckPoint != method) { - printf("bp: don't know where we get called from"); - RETURN_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> breakpoint in checkPoint\n"); - } - - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable single step events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable method exit events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->ForceEarlyReturnVoid(jvmti_env, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - fflush(0); -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (method == midRun) { - if (printdump == JNI_TRUE) { - printf(">>> returned early %d frames till method \"run()\"\n", - framesCount); - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable single step events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_EXIT, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable method exit events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - } else if (method == midCountDownLong) { - check(jvmti_env, thread, method, location, framesCount); - framesCount++; - - err = (*jvmti_env)->ForceEarlyReturnLong(jvmti_env, thread, ++val_exp); - if (err != JVMTI_ERROR_NONE) { - printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - } - fflush(0); -} - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, jvalue value) { - jlong ret_val = value.j; - int * val_ptr = (int *) &ret_val; - int * exp_ptr = (int *) &val_exp; - - methodExitEventCount++; - if (method == midCountDownLong) { - printf(">>> ForceEarlyReturnLong value: dec: %"LL"d, hex: %#x %#x\n", - ret_val, val_ptr[0], val_ptr[1]); - printf(">>> expected return value: dec: %"LL"d, hex: %#x %#x\n", - val_exp, exp_ptr[0], exp_ptr[1]); - - if (ret_val != val_exp) { - printf("Wrong ForceEarlyReturnLong return value: %"LL"d\n", ret_val); - errCode = STATUS_FAILED; - } - if (was_popped_by_exception) { - printf("Method was_popped_by_exception unexpectedly\n"); - errCode = STATUS_FAILED; - } - } - fflush(0); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_earlyretlong(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_earlyretlong(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_earlyretlong(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printf("Printdump is turned on!\n"); - - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong error code from a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_force_early_return) { - printf("Warning: ForceEarlyReturn is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_method_exit_events && - caps.can_generate_single_step_events) - { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - callbacks.MethodExit = &MethodExit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or SingleStep event are not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretlong_getReady( - JNIEnv *env, jclass c, jclass cls, jint depth, jlong retval_base) { - jvmtiError err; - - val_exp = retval_base; - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - RETURN_FAILED; - } - - if (!caps.can_force_early_return || - !caps.can_generate_breakpoint_events || - !caps.can_generate_method_exit_events || - !caps.can_generate_single_step_events) { - return; - } - - midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "run", "()V"); - if (midRun == NULL) { - printf("Cannot find Method ID for method run\n"); - RETURN_FAILED; - } - - midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (midCheckPoint == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - RETURN_FAILED; - } - - midCountDownLong = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "countDownLong", "(I)J"); - if (midCountDownLong == NULL) { - printf("Cannot find Method ID for method countDownLong\n"); - RETURN_FAILED; - } - - err = (*jvmti)->SetBreakpoint(jvmti, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } else { - framesExpected = depth; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretlong_printLong( - JNIEnv *env, jclass cls, jlong val) { - jint *iptr = (int *) &val; - - printf("\n>>> Returned value: dec: %"LL"d, hex: %#x %#x\n", - val, iptr[0], iptr[1]); - fflush(0); - return; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretlong_check(JNIEnv *env, jclass cls) { - if (framesCount != framesExpected) { - printf("Wrong number of returned early frames: %d, expected: %d\n", - framesCount, framesExpected); - errCode = STATUS_FAILED; - } - fflush(0); - return errCode; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/earlyretlong.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/earlyretlong.cpp new file mode 100644 index 00000000000..dde756e15a0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/earlyretlong.cpp @@ -0,0 +1,449 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "jni_tools.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint errCode = PASSED; +static jboolean printdump = JNI_TRUE; + +static jmethodID midRun = NULL; +static jmethodID midCountDownLong = NULL; +static jmethodID midCheckPoint = NULL; + +static jint framesExpected = 0; +static jint framesCount = 0; +static jint methodExitEventCount = 0; + +static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretlong$earlyretThread;"; + +static jlong val_exp = 0L; +static const char *sig_exp = "(I)J"; +static const char *name_exp = "countDownLong"; + +static const char *argName = "nestingCount"; + +void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, + jlocation loc, jint frame_no) { + jvmtiError err; + jclass cls; + jlocation loc_exp = (frame_no == 0) ? 0x15 : 0xd; + char *sigClass, *name, *sig, *generic; + jvmtiLocalVariableEntry *table = NULL; + jint entryCount = 0; + jint argValue; + jint j; + + err = jvmti_env->GetMethodDeclaringClass(mid, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->GetClassSignature(cls, &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + + /* Get Local Variable Table to be able to get the argument value + * from current method frame and compare it with the expected value + */ + err = jvmti_env->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + if (strcmp(table[j].name, argName) == 0) { + err = jvmti_env->GetLocalInt(thr, 0, + table[j].slot, &argValue); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + } + } + } + + if (printdump == JNI_TRUE) { + printf("\n>>> step %d: \"%s.%s%s\"\n", frame_no, sigClass, name, sig); + printf(">>> location: %#x%08x", (jint)(loc >> 32), (jint)loc); + printf(", arg value: %d\n", argValue); + } + + if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { + printf("(step %d) Wrong class sig: \"%s\",\n", frame_no, sigClass); + printf(" expected: \"%s\"\n", cls_exp); + RETURN_FAILED; + } + if (name == NULL || strcmp(name, name_exp) != 0) { + printf("(step %d) wrong method name: \"%s\",", frame_no, name); + printf(" expected: \"%s\"\n", name_exp); + RETURN_FAILED; + } + if (sig == NULL || strcmp(sig, sig_exp) != 0) { + printf("(step %d) wrong method sig: \"%s\",", frame_no, sig); + printf(" expected: \"%s\"\n", sig_exp); + RETURN_FAILED; + } + if (loc != loc_exp) { + printf("(step %d) wrong location: %#x%08x,", + frame_no, (jint)(loc >> 32), (jint)loc); + printf(" expected: %#x\n", (jint)loc_exp); + RETURN_FAILED; + } + if (argValue != frame_no) { + printf("(step %d) wrong argument value: %d,", frame_no, argValue); + printf(" expected: %d\n", frame_no); + RETURN_FAILED; + } + + if (sigClass != NULL) { + jvmti_env->Deallocate((unsigned char*)sigClass); + } + if (name != NULL) { + jvmti_env->Deallocate((unsigned char*)name); + } + if (sig != NULL) { + jvmti_env->Deallocate((unsigned char*)sig); + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + jvmti_env->Deallocate((unsigned char*)(table[j].name)); + jvmti_env->Deallocate((unsigned char*)(table[j].signature)); + } + jvmti_env->Deallocate((unsigned char*)table); + } + if (methodExitEventCount != (framesCount + 1)) { + printf("(step %d) wrong methodExitEventCount: %d,", + frame_no, methodExitEventCount); + printf(" expected: %d\n", framesCount + 1); + RETURN_FAILED; + } + fflush(0); +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (midCheckPoint != method) { + printf("bp: don't know where we get called from"); + RETURN_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> breakpoint in checkPoint\n"); + } + + err = jvmti_env->ClearBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable single step events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable method exit events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->ForceEarlyReturnVoid(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + fflush(0); +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (method == midRun) { + if (printdump == JNI_TRUE) { + printf(">>> returned early %d frames till method \"run()\"\n", + framesCount); + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable single step events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_EXIT, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable method exit events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + } else if (method == midCountDownLong) { + check(jvmti_env, thread, method, location, framesCount); + framesCount++; + + err = jvmti_env->ForceEarlyReturnLong(thread, ++val_exp); + if (err != JVMTI_ERROR_NONE) { + printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + } + fflush(0); +} + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, jvalue value) { + jlong ret_val = value.j; + int * val_ptr = (int *) &ret_val; + int * exp_ptr = (int *) &val_exp; + + methodExitEventCount++; + if (method == midCountDownLong) { + printf(">>> ForceEarlyReturnLong value: dec: %" LL "d, hex: %#x %#x\n", + ret_val, val_ptr[0], val_ptr[1]); + printf(">>> expected return value: dec: %" LL "d, hex: %#x %#x\n", + val_exp, exp_ptr[0], exp_ptr[1]); + + if (ret_val != val_exp) { + printf("Wrong ForceEarlyReturnLong return value: %" LL "d\n", ret_val); + errCode = STATUS_FAILED; + } + if (was_popped_by_exception) { + printf("Method was_popped_by_exception unexpectedly\n"); + errCode = STATUS_FAILED; + } + } + fflush(0); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_earlyretlong(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_earlyretlong(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_earlyretlong(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printf("Printdump is turned on!\n"); + + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong error code from a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_force_early_return) { + printf("Warning: ForceEarlyReturn is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_method_exit_events && + caps.can_generate_single_step_events) + { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + callbacks.MethodExit = &MethodExit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or SingleStep event are not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretlong_getReady( + JNIEnv *env, jclass c, jclass cls, jint depth, jlong retval_base) { + jvmtiError err; + + val_exp = retval_base; + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + RETURN_FAILED; + } + + if (!caps.can_force_early_return || + !caps.can_generate_breakpoint_events || + !caps.can_generate_method_exit_events || + !caps.can_generate_single_step_events) { + return; + } + + midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "run", "()V"); + if (midRun == NULL) { + printf("Cannot find Method ID for method run\n"); + RETURN_FAILED; + } + + midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (midCheckPoint == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + RETURN_FAILED; + } + + midCountDownLong = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "countDownLong", "(I)J"); + if (midCountDownLong == NULL) { + printf("Cannot find Method ID for method countDownLong\n"); + RETURN_FAILED; + } + + err = jvmti->SetBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } else { + framesExpected = depth; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretlong_printLong( + JNIEnv *env, jclass cls, jlong val) { + jint *iptr = (jint *) &val; + + printf("\n>>> Returned value: dec: %" LL "d, hex: %#x %#x\n", + val, iptr[0], iptr[1]); + fflush(0); + return; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretlong_check(JNIEnv *env, jclass cls) { + if (framesCount != framesExpected) { + printf("Wrong number of returned early frames: %d, expected: %d\n", + framesCount, framesExpected); + errCode = STATUS_FAILED; + } + fflush(0); + return errCode; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/libearlyretlong.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/libearlyretlong.c deleted file mode 100644 index eca038abf55..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/libearlyretlong.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "earlyretlong.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/libearlyretlong.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/libearlyretlong.cpp new file mode 100644 index 00000000000..5d31bcf102d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretlong/libearlyretlong.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "earlyretlong.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/earlyretobj.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/earlyretobj.c deleted file mode 100644 index 9b27d7750c6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/earlyretobj.c +++ /dev/null @@ -1,445 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint errCode = PASSED; -static jboolean printdump = JNI_TRUE; - -static jmethodID midRun = NULL; -static jmethodID midCountDownObject = NULL; -static jmethodID midCheckPoint = NULL; - -static jint framesExpected = 0; -static jint framesCount = 0; -static jint methodExitEventCount = 0; - -static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretobj$earlyretThread;"; - -static jobject val_exp = NULL; -static const char *sig_exp = "(I)Lnsk/jvmti/unit/ForceEarlyReturn/earlyretobj$RetObj;"; -static const char *name_exp = "countDownObject"; - -static const char *argName = "nestingCount"; - -void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, - jlocation loc, jint frame_no) { - jvmtiError err; - jclass cls; - jlocation loc_exp = (frame_no == 0) ? 0x15 : 0xd; - char *sigClass, *name, *sig, *generic; - jvmtiLocalVariableEntry *table = NULL; - jint entryCount = 0; - jint argValue; - jint j; - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, mid, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - - /* Get Local Variable Table to be able to get the argument value - * from current method frame and compare it with the expected value - */ - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - if (strcmp(table[j].name, argName) == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, 0, - table[j].slot, &argValue); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - } - } - } - - if (printdump == JNI_TRUE) { - printf("\n>>> step %d: \"%s.%s%s\"\n", frame_no, sigClass, name, sig); - printf(">>> location: %#x%08x", (jint)(loc >> 32), (jint)loc); - printf(", arg value: %d\n", argValue); - } - - if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { - printf("(step %d) Wrong class sig: \"%s\",\n", frame_no, sigClass); - printf(" expected: \"%s\"\n", cls_exp); - RETURN_FAILED; - } - if (name == NULL || strcmp(name, name_exp) != 0) { - printf("(step %d) wrong method name: \"%s\",", frame_no, name); - printf(" expected: \"%s\"\n", name_exp); - RETURN_FAILED; - } - if (sig == NULL || strcmp(sig, sig_exp) != 0) { - printf("(step %d) wrong method sig: \"%s\",", frame_no, sig); - printf(" expected: \"%s\"\n", sig_exp); - RETURN_FAILED; - } - if (loc != loc_exp) { - printf("(step %d) wrong location: %#x%08x,", - frame_no, (jint)(loc >> 32), (jint)loc); - printf(" expected: %#x\n", (jint)loc_exp); - RETURN_FAILED; - } - if (argValue != frame_no) { - printf("(step %d) wrong argument value: %d,", frame_no, argValue); - printf(" expected: %d\n", frame_no); - RETURN_FAILED; - } - - if (sigClass != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sigClass); - } - if (name != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)name); - } - if (sig != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sig); - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].name)); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].signature)); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table); - } - if (methodExitEventCount != (framesCount + 1)) { - printf("(step %d) wrong methodExitEventCount: %d,", - frame_no, methodExitEventCount); - printf(" expected: %d\n", framesCount + 1); - RETURN_FAILED; - } - fflush(0); -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (midCheckPoint != method) { - printf("bp: don't know where we get called from"); - RETURN_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> breakpoint in checkPoint\n"); - } - - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable single step events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable method exit events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->ForceEarlyReturnVoid(jvmti_env, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(ForceEarlyReturnVoid) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - fflush(0); -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (method == midRun) { - if (printdump == JNI_TRUE) { - printf(">>> returned early %d frames till method \"run()\"\n", - framesCount); - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable single step events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_EXIT, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable method exit events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - } else { - check(jvmti_env, thread, method, location, framesCount); - framesCount++; - err = (*jvmti_env)->ForceEarlyReturnObject(jvmti_env, thread, - val_exp); - if (err != JVMTI_ERROR_NONE) { - printf("(ForceEarlyReturnObject) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - } - fflush(0); -} - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, jvalue value) { - jobject ret_val = value.l; - - methodExitEventCount++; - printf("MethodExit event: methodExitEventCount=%d\n", methodExitEventCount); - if (method == midRun || method == midCheckPoint) { - return; - } - if (method == midCountDownObject) { - if (!JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, ret_val), val_exp)) { - printf("Wrong ForceEarlyReturnObject return value: 0x%p\n", ret_val); - printf("expected: 0x%p\n", val_exp); - errCode = STATUS_FAILED; - } - if (was_popped_by_exception) { - printf("Method was_popped_by_exception unexpectedly\n"); - errCode = STATUS_FAILED; - } - } - fflush(0); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_earlyretobj(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_earlyretobj(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_earlyretobj(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printf("Printdump is turned on!\n"); - - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong error code from a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_force_early_return) { - printf("Warning: ForceEarlyReturn is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_method_exit_events && - caps.can_generate_single_step_events) - { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - callbacks.MethodExit = &MethodExit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or SingleStep event are not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretobj_getReady( - JNIEnv *env, jclass c, jclass cls, jint depth, jobject ret_obj) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - RETURN_FAILED; - } - - if (!caps.can_force_early_return || - !caps.can_generate_breakpoint_events || - !caps.can_generate_method_exit_events || - !caps.can_generate_single_step_events) { - return; - } - - midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "run", "()V"); - if (midRun == NULL) { - printf("Cannot find Method ID for method run\n"); - RETURN_FAILED; - } - - midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (midCheckPoint == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - RETURN_FAILED; - } - - midCountDownObject = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "countDownObject", sig_exp); - if (midCountDownObject == NULL) { - printf("Cannot find Method ID for method countDownObject\n"); - RETURN_FAILED; - } - - err = (*jvmti)->SetBreakpoint(jvmti, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } else { - val_exp = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, ret_obj)); - framesExpected = depth; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretobj_check(JNIEnv *env, jclass cls) { - if (framesCount != framesExpected) { - printf("Wrong number of returned early frames: %d, expected: %d\n", - framesCount, framesExpected); - errCode = STATUS_FAILED; - } - fflush(0); - return errCode; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretobj_printObject( - JNIEnv *env, jclass cls, jobject obj) { - - printf("\nReturned jobject: %#" PRIxPTR "\n", (uintptr_t)obj); - fflush(0); - return; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/earlyretobj.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/earlyretobj.cpp new file mode 100644 index 00000000000..ca4958da7c3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/earlyretobj.cpp @@ -0,0 +1,445 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint errCode = PASSED; +static jboolean printdump = JNI_TRUE; + +static jmethodID midRun = NULL; +static jmethodID midCountDownObject = NULL; +static jmethodID midCheckPoint = NULL; + +static jint framesExpected = 0; +static jint framesCount = 0; +static jint methodExitEventCount = 0; + +static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretobj$earlyretThread;"; + +static jobject val_exp = NULL; +static const char *sig_exp = "(I)Lnsk/jvmti/unit/ForceEarlyReturn/earlyretobj$RetObj;"; +static const char *name_exp = "countDownObject"; + +static const char *argName = "nestingCount"; + +void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, + jlocation loc, jint frame_no) { + jvmtiError err; + jclass cls; + jlocation loc_exp = (frame_no == 0) ? 0x15 : 0xd; + char *sigClass, *name, *sig, *generic; + jvmtiLocalVariableEntry *table = NULL; + jint entryCount = 0; + jint argValue; + jint j; + + err = jvmti_env->GetMethodDeclaringClass(mid, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->GetClassSignature(cls, &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + + /* Get Local Variable Table to be able to get the argument value + * from current method frame and compare it with the expected value + */ + err = jvmti_env->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + if (strcmp(table[j].name, argName) == 0) { + err = jvmti_env->GetLocalInt(thr, 0, + table[j].slot, &argValue); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + } + } + } + + if (printdump == JNI_TRUE) { + printf("\n>>> step %d: \"%s.%s%s\"\n", frame_no, sigClass, name, sig); + printf(">>> location: %#x%08x", (jint)(loc >> 32), (jint)loc); + printf(", arg value: %d\n", argValue); + } + + if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { + printf("(step %d) Wrong class sig: \"%s\",\n", frame_no, sigClass); + printf(" expected: \"%s\"\n", cls_exp); + RETURN_FAILED; + } + if (name == NULL || strcmp(name, name_exp) != 0) { + printf("(step %d) wrong method name: \"%s\",", frame_no, name); + printf(" expected: \"%s\"\n", name_exp); + RETURN_FAILED; + } + if (sig == NULL || strcmp(sig, sig_exp) != 0) { + printf("(step %d) wrong method sig: \"%s\",", frame_no, sig); + printf(" expected: \"%s\"\n", sig_exp); + RETURN_FAILED; + } + if (loc != loc_exp) { + printf("(step %d) wrong location: %#x%08x,", + frame_no, (jint)(loc >> 32), (jint)loc); + printf(" expected: %#x\n", (jint)loc_exp); + RETURN_FAILED; + } + if (argValue != frame_no) { + printf("(step %d) wrong argument value: %d,", frame_no, argValue); + printf(" expected: %d\n", frame_no); + RETURN_FAILED; + } + + if (sigClass != NULL) { + jvmti_env->Deallocate((unsigned char*)sigClass); + } + if (name != NULL) { + jvmti_env->Deallocate((unsigned char*)name); + } + if (sig != NULL) { + jvmti_env->Deallocate((unsigned char*)sig); + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + jvmti_env->Deallocate((unsigned char*)(table[j].name)); + jvmti_env->Deallocate((unsigned char*)(table[j].signature)); + } + jvmti_env->Deallocate((unsigned char*)table); + } + if (methodExitEventCount != (framesCount + 1)) { + printf("(step %d) wrong methodExitEventCount: %d,", + frame_no, methodExitEventCount); + printf(" expected: %d\n", framesCount + 1); + RETURN_FAILED; + } + fflush(0); +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (midCheckPoint != method) { + printf("bp: don't know where we get called from"); + RETURN_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> breakpoint in checkPoint\n"); + } + + err = jvmti_env->ClearBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable single step events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable method exit events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->ForceEarlyReturnVoid(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(ForceEarlyReturnVoid) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + fflush(0); +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (method == midRun) { + if (printdump == JNI_TRUE) { + printf(">>> returned early %d frames till method \"run()\"\n", + framesCount); + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable single step events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_EXIT, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable method exit events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + } else { + check(jvmti_env, thread, method, location, framesCount); + framesCount++; + err = jvmti_env->ForceEarlyReturnObject(thread, + val_exp); + if (err != JVMTI_ERROR_NONE) { + printf("(ForceEarlyReturnObject) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + } + fflush(0); +} + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, jvalue value) { + jobject ret_val = value.l; + + methodExitEventCount++; + printf("MethodExit event: methodExitEventCount=%d\n", methodExitEventCount); + if (method == midRun || method == midCheckPoint) { + return; + } + if (method == midCountDownObject) { + if (!JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, ret_val), val_exp)) { + printf("Wrong ForceEarlyReturnObject return value: 0x%p\n", ret_val); + printf("expected: 0x%p\n", val_exp); + errCode = STATUS_FAILED; + } + if (was_popped_by_exception) { + printf("Method was_popped_by_exception unexpectedly\n"); + errCode = STATUS_FAILED; + } + } + fflush(0); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_earlyretobj(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_earlyretobj(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_earlyretobj(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printf("Printdump is turned on!\n"); + + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong error code from a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_force_early_return) { + printf("Warning: ForceEarlyReturn is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_method_exit_events && + caps.can_generate_single_step_events) + { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + callbacks.MethodExit = &MethodExit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or SingleStep event are not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretobj_getReady( + JNIEnv *env, jclass c, jclass cls, jint depth, jobject ret_obj) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + RETURN_FAILED; + } + + if (!caps.can_force_early_return || + !caps.can_generate_breakpoint_events || + !caps.can_generate_method_exit_events || + !caps.can_generate_single_step_events) { + return; + } + + midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "run", "()V"); + if (midRun == NULL) { + printf("Cannot find Method ID for method run\n"); + RETURN_FAILED; + } + + midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (midCheckPoint == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + RETURN_FAILED; + } + + midCountDownObject = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "countDownObject", sig_exp); + if (midCountDownObject == NULL) { + printf("Cannot find Method ID for method countDownObject\n"); + RETURN_FAILED; + } + + err = jvmti->SetBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } else { + val_exp = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, ret_obj)); + framesExpected = depth; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretobj_check(JNIEnv *env, jclass cls) { + if (framesCount != framesExpected) { + printf("Wrong number of returned early frames: %d, expected: %d\n", + framesCount, framesExpected); + errCode = STATUS_FAILED; + } + fflush(0); + return errCode; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretobj_printObject( + JNIEnv *env, jclass cls, jobject obj) { + + printf("\nReturned jobject: %#" PRIxPTR "\n", (uintptr_t)obj); + fflush(0); + return; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/libearlyretobj.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/libearlyretobj.c deleted file mode 100644 index 32b667effe6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/libearlyretobj.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "earlyretobj.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/libearlyretobj.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/libearlyretobj.cpp new file mode 100644 index 00000000000..80722854613 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretobj/libearlyretobj.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "earlyretobj.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/earlyretstr.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/earlyretstr.c deleted file mode 100644 index 596692fbd71..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/earlyretstr.c +++ /dev/null @@ -1,435 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint errCode = PASSED; -static jboolean printdump = JNI_TRUE; - -static jmethodID midRun = NULL; -static jmethodID midCountDownString = NULL; -static jmethodID midCheckPoint = NULL; - -static jint framesExpected = 0; -static jint framesCount = 0; -static jint methodExitEventCount = 0; - -static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretstr$earlyretThread;"; - -static jstring str_exp = NULL; -static const char *sig_exp = "(I)Ljava/lang/String;"; -static const char *name_exp = "countDownString"; - -static const char *argName = "nestingCount"; - -void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, - jlocation loc, jint frame_no) { - jvmtiError err; - jclass cls; - jlocation loc_exp = (frame_no == 0) ? 0x15 : 0xd; - char *sigClass, *name, *sig, *generic; - jvmtiLocalVariableEntry *table = NULL; - jint entryCount = 0; - jint argValue; - jint j; - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, mid, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - - /* Get Local Variable Table to be able to get the argument value - * from current method frame and compare it with the expected value - */ - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - if (strcmp(table[j].name, argName) == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, 0, - table[j].slot, &argValue); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - } - } - } - - if (printdump == JNI_TRUE) { - printf("\n>>> step %d: \"%s.%s%s\"\n", frame_no, sigClass, name, sig); - printf(">>> location: 0x%x%08x", (jint)(loc >> 32), (jint)loc); - printf(", arg value: %d\n", argValue); - } - - if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { - printf("(step %d) Wrong class sig: \"%s\",\n", frame_no, sigClass); - printf(" expected: \"%s\"\n", cls_exp); - RETURN_FAILED; - } - if (name == NULL || strcmp(name, name_exp) != 0) { - printf("(step %d) wrong method name: \"%s\",", frame_no, name); - printf(" expected: \"%s\"\n", name_exp); - RETURN_FAILED; - } - if (sig == NULL || strcmp(sig, sig_exp) != 0) { - printf("(step %d) wrong method sig: \"%s\",", frame_no, sig); - printf(" expected: \"%s\"\n", sig_exp); - RETURN_FAILED; - } - if (loc != loc_exp) { - printf("(step %d) wrong location: 0x%x%08x,", - frame_no, (jint)(loc >> 32), (jint)loc); - printf(" expected: 0x%x\n", (jint)loc_exp); - RETURN_FAILED; - } - if (argValue != frame_no) { - printf("(step %d) wrong argument value: %d,", frame_no, argValue); - printf(" expected: %d\n", frame_no); - RETURN_FAILED; - } - - if (sigClass != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sigClass); - } - if (name != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)name); - } - if (sig != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sig); - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].name)); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].signature)); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table); - } - if (methodExitEventCount != (framesCount + 1)) { - printf("(step %d) wrong methodExitEventCount: %d,", - frame_no, methodExitEventCount); - printf(" expected: %d\n", framesCount + 1); - RETURN_FAILED; - } - fflush(0); -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (midCheckPoint != method) { - printf("bp: don't know where we get called from"); - RETURN_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> breakpoint in checkPoint\n"); - } - - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable single step events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable method exit events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->ForceEarlyReturnVoid(jvmti_env, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(ForceEarlyReturnVoid) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - fflush(0); -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (method == midRun) { - if (printdump == JNI_TRUE) { - printf(">>> returned early %d frames till method \"run()\"\n", - framesCount); - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable single step events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_METHOD_EXIT, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable method exit events: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - } else { - check(jvmti_env, thread, method, location, framesCount); - framesCount++; - err = (*jvmti_env)->ForceEarlyReturnObject(jvmti_env, thread, str_exp); - if (err != JVMTI_ERROR_NONE) { - printf("(ForceEarlyReturnObject) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - } - fflush(0); -} - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, - jmethodID method, jboolean was_popped_by_exception, jvalue value) { - const char* ret_str; - const char* exp_str; - jstring ret_val = value.l; - - methodExitEventCount++; - printf("MethodExit event: methodExitEventCount=%d\n", methodExitEventCount); - if (method == midRun || method == midCheckPoint) { - return; - } - if (method == midCountDownString) { - ret_str = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, ret_val), 0); - exp_str = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, str_exp), 0); - printf("Expected string: \"%s\"\n", exp_str); - printf("Returned string: \"%s\"\n", ret_str); - if (was_popped_by_exception) { - printf("Method was_popped_by_exception unexpectedly\n"); - errCode = STATUS_FAILED; - } - } - fflush(0); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_earlyretstr(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_earlyretstr(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_earlyretstr(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printf("Printdump is turned on!\n"); - - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong error code of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_force_early_return) { - printf("Warning: ForceEarlyReturn is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_method_exit_events && - caps.can_generate_single_step_events) - { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - callbacks.MethodExit = &MethodExit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or SingleStep event are not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretstr_getReady( - JNIEnv *env, jclass c, jclass cls, jint depth, jstring expected_str) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - RETURN_FAILED; - } - - if (!caps.can_force_early_return || - !caps.can_generate_breakpoint_events || - !caps.can_generate_method_exit_events || - !caps.can_generate_single_step_events) { - return; - } - - midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "run", "()V"); - if (midRun == NULL) { - printf("Cannot find Method ID for method run\n"); - RETURN_FAILED; - } - - midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (midCheckPoint == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - RETURN_FAILED; - } - - midCountDownString = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "countDownString", sig_exp); - if (midCountDownString == NULL) { - printf("Cannot find Method ID for method countDownString\n"); - RETURN_FAILED; - } - - err = (*jvmti)->SetBreakpoint(jvmti, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } else { - str_exp = JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, expected_str)); - framesExpected = depth; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretstr_check(JNIEnv *env, jclass cls) { - if (framesCount != framesExpected) { - printf("Wrong number of returned early frames: %d, expected: %d\n", - framesCount, framesExpected); - errCode = STATUS_FAILED; - } - fflush(0); - return errCode; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/earlyretstr.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/earlyretstr.cpp new file mode 100644 index 00000000000..12886ca2520 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/earlyretstr.cpp @@ -0,0 +1,435 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint errCode = PASSED; +static jboolean printdump = JNI_TRUE; + +static jmethodID midRun = NULL; +static jmethodID midCountDownString = NULL; +static jmethodID midCheckPoint = NULL; + +static jint framesExpected = 0; +static jint framesCount = 0; +static jint methodExitEventCount = 0; + +static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretstr$earlyretThread;"; + +static jstring str_exp = NULL; +static const char *sig_exp = "(I)Ljava/lang/String;"; +static const char *name_exp = "countDownString"; + +static const char *argName = "nestingCount"; + +void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, + jlocation loc, jint frame_no) { + jvmtiError err; + jclass cls; + jlocation loc_exp = (frame_no == 0) ? 0x15 : 0xd; + char *sigClass, *name, *sig, *generic; + jvmtiLocalVariableEntry *table = NULL; + jint entryCount = 0; + jint argValue; + jint j; + + err = jvmti_env->GetMethodDeclaringClass(mid, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->GetClassSignature(cls, &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + + /* Get Local Variable Table to be able to get the argument value + * from current method frame and compare it with the expected value + */ + err = jvmti_env->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + if (strcmp(table[j].name, argName) == 0) { + err = jvmti_env->GetLocalInt(thr, 0, + table[j].slot, &argValue); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + } + } + } + + if (printdump == JNI_TRUE) { + printf("\n>>> step %d: \"%s.%s%s\"\n", frame_no, sigClass, name, sig); + printf(">>> location: 0x%x%08x", (jint)(loc >> 32), (jint)loc); + printf(", arg value: %d\n", argValue); + } + + if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { + printf("(step %d) Wrong class sig: \"%s\",\n", frame_no, sigClass); + printf(" expected: \"%s\"\n", cls_exp); + RETURN_FAILED; + } + if (name == NULL || strcmp(name, name_exp) != 0) { + printf("(step %d) wrong method name: \"%s\",", frame_no, name); + printf(" expected: \"%s\"\n", name_exp); + RETURN_FAILED; + } + if (sig == NULL || strcmp(sig, sig_exp) != 0) { + printf("(step %d) wrong method sig: \"%s\",", frame_no, sig); + printf(" expected: \"%s\"\n", sig_exp); + RETURN_FAILED; + } + if (loc != loc_exp) { + printf("(step %d) wrong location: 0x%x%08x,", + frame_no, (jint)(loc >> 32), (jint)loc); + printf(" expected: 0x%x\n", (jint)loc_exp); + RETURN_FAILED; + } + if (argValue != frame_no) { + printf("(step %d) wrong argument value: %d,", frame_no, argValue); + printf(" expected: %d\n", frame_no); + RETURN_FAILED; + } + + if (sigClass != NULL) { + jvmti_env->Deallocate((unsigned char*)sigClass); + } + if (name != NULL) { + jvmti_env->Deallocate((unsigned char*)name); + } + if (sig != NULL) { + jvmti_env->Deallocate((unsigned char*)sig); + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + jvmti_env->Deallocate((unsigned char*)(table[j].name)); + jvmti_env->Deallocate((unsigned char*)(table[j].signature)); + } + jvmti_env->Deallocate((unsigned char*)table); + } + if (methodExitEventCount != (framesCount + 1)) { + printf("(step %d) wrong methodExitEventCount: %d,", + frame_no, methodExitEventCount); + printf(" expected: %d\n", framesCount + 1); + RETURN_FAILED; + } + fflush(0); +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (midCheckPoint != method) { + printf("bp: don't know where we get called from"); + RETURN_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> breakpoint in checkPoint\n"); + } + + err = jvmti_env->ClearBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable single step events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable method exit events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->ForceEarlyReturnVoid(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(ForceEarlyReturnVoid) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + fflush(0); +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (method == midRun) { + if (printdump == JNI_TRUE) { + printf(">>> returned early %d frames till method \"run()\"\n", + framesCount); + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable single step events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_METHOD_EXIT, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable method exit events: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + } else { + check(jvmti_env, thread, method, location, framesCount); + framesCount++; + err = jvmti_env->ForceEarlyReturnObject(thread, str_exp); + if (err != JVMTI_ERROR_NONE) { + printf("(ForceEarlyReturnObject) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + } + fflush(0); +} + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, + jmethodID method, jboolean was_popped_by_exception, jvalue value) { + const char* ret_str; + const char* exp_str; + jstring ret_val = (jstring) value.l; + + methodExitEventCount++; + printf("MethodExit event: methodExitEventCount=%d\n", methodExitEventCount); + if (method == midRun || method == midCheckPoint) { + return; + } + if (method == midCountDownString) { + ret_str = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, ret_val), 0); + exp_str = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, str_exp), 0); + printf("Expected string: \"%s\"\n", exp_str); + printf("Returned string: \"%s\"\n", ret_str); + if (was_popped_by_exception) { + printf("Method was_popped_by_exception unexpectedly\n"); + errCode = STATUS_FAILED; + } + } + fflush(0); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_earlyretstr(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_earlyretstr(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_earlyretstr(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printf("Printdump is turned on!\n"); + + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong error code of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_force_early_return) { + printf("Warning: ForceEarlyReturn is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_method_exit_events && + caps.can_generate_single_step_events) + { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + callbacks.MethodExit = &MethodExit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or SingleStep event are not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretstr_getReady( + JNIEnv *env, jclass c, jclass cls, jint depth, jstring expected_str) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + RETURN_FAILED; + } + + if (!caps.can_force_early_return || + !caps.can_generate_breakpoint_events || + !caps.can_generate_method_exit_events || + !caps.can_generate_single_step_events) { + return; + } + + midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "run", "()V"); + if (midRun == NULL) { + printf("Cannot find Method ID for method run\n"); + RETURN_FAILED; + } + + midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (midCheckPoint == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + RETURN_FAILED; + } + + midCountDownString = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "countDownString", sig_exp); + if (midCountDownString == NULL) { + printf("Cannot find Method ID for method countDownString\n"); + RETURN_FAILED; + } + + err = jvmti->SetBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } else { + str_exp = (jstring) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, expected_str)); + framesExpected = depth; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretstr_check(JNIEnv *env, jclass cls) { + if (framesCount != framesExpected) { + printf("Wrong number of returned early frames: %d, expected: %d\n", + framesCount, framesExpected); + errCode = STATUS_FAILED; + } + fflush(0); + return errCode; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/libearlyretstr.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/libearlyretstr.c deleted file mode 100644 index 31c83980169..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/libearlyretstr.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "earlyretstr.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/libearlyretstr.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/libearlyretstr.cpp new file mode 100644 index 00000000000..bbdced0568c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretstr/libearlyretstr.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "earlyretstr.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/earlyretvoid.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/earlyretvoid.c deleted file mode 100644 index b38922d736b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/earlyretvoid.c +++ /dev/null @@ -1,374 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint errCode = PASSED; -static jboolean printdump = JNI_TRUE; -static jmethodID midCheckPoint = NULL; -static jmethodID midRun = NULL; - -static jint framesExpected = 0; -static jint framesCount = 0; - -static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretvoid$earlyretThread;"; -static const char *name_exp = "countDown"; -static const char *sig_exp = "(I)V"; -static const char *argName = "nestingCount"; - -void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, - jlocation loc, jint frame_no) { - jvmtiError err; - jclass cls; - jlocation loc_exp = (frame_no == 0) ? 25 : 11; - char *sigClass, *name, *sig, *generic; - jvmtiLocalVariableEntry *table = NULL; - jint entryCount = 0; - jint argValue; - jint j; - - err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, mid, &cls); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &sigClass, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->GetMethodName(jvmti_env, mid, &name, &sig, &generic); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - - /* Get Local Variable Table to be able to get the argument value - * from current method frame and compare it with the expected value - */ - err = (*jvmti_env)->GetLocalVariableTable(jvmti_env, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - if (strcmp(table[j].name, argName) == 0) { - err = (*jvmti_env)->GetLocalInt(jvmti_env, thr, 0, - table[j].slot, &argValue); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", - frame_no, TranslateError(err), err); - RETURN_FAILED; - } - } - } - } - - if (printdump == JNI_TRUE) { - printf(">>> step %d: \"%s.%s%s\"\n", frame_no, sigClass, name, sig); - printf(">>> location: %#x%08x", (jint)(loc >> 32), (jint)loc); - printf(", arg value: %d\n", argValue); - } - - if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { - printf("(step %d) wrong class sig: \"%s\",\n", frame_no, sigClass); - printf(" expected: \"%s\"\n", cls_exp); - RETURN_FAILED; - } - if (name == NULL || strcmp(name, name_exp) != 0) { - printf("(step %d) wrong method name: \"%s\",", frame_no, name); - printf(" expected: \"%s\"\n", name_exp); - RETURN_FAILED; - } - if (sig == NULL || strcmp(sig, sig_exp) != 0) { - printf("(step %d) wrong method sig: \"%s\",", frame_no, sig); - printf(" expected: \"%s\"\n", sig_exp); - RETURN_FAILED; - } - if (loc != loc_exp) { - printf("(step %d) wrong location: %#x%08x,", - frame_no, (jint)(loc >> 32), (jint)loc); - printf(" expected: %#x\n", (jint)loc_exp); - RETURN_FAILED; - } - if (argValue != frame_no) { - printf("(step %d) wrong argument value: %d,", frame_no, argValue); - printf(" expected: %d\n", frame_no); - RETURN_FAILED; - } - - if (sigClass != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sigClass); - } - if (name != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)name); - } - if (sig != NULL) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)sig); - } - if (table != NULL) { - for (j = 0; j < entryCount; j++) { - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].name)); - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)(table[j].signature)); - } - (*jvmti_env)->Deallocate(jvmti_env, (unsigned char*)table); - } - fflush(0); -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (midCheckPoint != method) { - printf("bp: don't know where we get called from"); - RETURN_FAILED; - } - - if (printdump == JNI_TRUE) { - printf(">>> breakpoint in checkPoint\n"); - } - - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot enable single step: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti_env)->ForceEarlyReturnVoid(jvmti_env, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - fflush(0); -} - -void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (method == midRun) { - if (printdump == JNI_TRUE) { - printf(">>> returned early %d frames till method \"run()\"\n", - framesCount); - } - - err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_DISABLE, - JVMTI_EVENT_SINGLE_STEP, thread); - if (err != JVMTI_ERROR_NONE) { - printf("Cannot disable single step: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - } else { - check(jvmti_env, thread, method, location, framesCount); - framesCount++; - - err = (*jvmti_env)->ForceEarlyReturnVoid(jvmti_env, thread); - if (err != JVMTI_ERROR_NONE) { - printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - } - fflush(0); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_earlyretvoid(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_earlyretvoid(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_earlyretvoid(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printf("Printdump is turned on!\n"); - - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong error code from a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_force_early_return) { - printf("Warning: ForceEarlyReturn is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_single_step_events) { - callbacks.Breakpoint = &Breakpoint; - callbacks.SingleStep = &SingleStep; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: Breakpoint or SingleStep event are not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretvoid_getReady( - JNIEnv *env, jclass c, jclass cls, jint depth) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - RETURN_FAILED; - } - - if (!caps.can_force_early_return || - !caps.can_generate_breakpoint_events || - !caps.can_generate_single_step_events) { - return; - } - - midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "run", "()V"); - if (midRun == NULL) { - printf("Cannot find Method ID for method run\n"); - RETURN_FAILED; - } - - midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (midCheckPoint == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - RETURN_FAILED; - } - - err = (*jvmti)->SetBreakpoint(jvmti, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } else { - framesExpected = depth; - } - fflush(0); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretvoid_check(JNIEnv *env, jclass cls) { - if (framesCount != framesExpected) { - printf("Wrong number of returned early frames: %d, expected: %d\n", - framesCount, framesExpected); - errCode = STATUS_FAILED; - } - fflush(0); - return errCode; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/earlyretvoid.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/earlyretvoid.cpp new file mode 100644 index 00000000000..5eb01efe13c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/earlyretvoid.cpp @@ -0,0 +1,374 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint errCode = PASSED; +static jboolean printdump = JNI_TRUE; +static jmethodID midCheckPoint = NULL; +static jmethodID midRun = NULL; + +static jint framesExpected = 0; +static jint framesCount = 0; + +static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretvoid$earlyretThread;"; +static const char *name_exp = "countDown"; +static const char *sig_exp = "(I)V"; +static const char *argName = "nestingCount"; + +void check(jvmtiEnv *jvmti_env, jthread thr, jmethodID mid, + jlocation loc, jint frame_no) { + jvmtiError err; + jclass cls; + jlocation loc_exp = (frame_no == 0) ? 25 : 11; + char *sigClass, *name, *sig, *generic; + jvmtiLocalVariableEntry *table = NULL; + jint entryCount = 0; + jint argValue; + jint j; + + err = jvmti_env->GetMethodDeclaringClass(mid, &cls); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->GetClassSignature(cls, &sigClass, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->GetMethodName(mid, &name, &sig, &generic); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + + /* Get Local Variable Table to be able to get the argument value + * from current method frame and compare it with the expected value + */ + err = jvmti_env->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + if (strcmp(table[j].name, argName) == 0) { + err = jvmti_env->GetLocalInt(thr, 0, + table[j].slot, &argValue); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalInt#%d) unexpected error: %s (%d)\n", + frame_no, TranslateError(err), err); + RETURN_FAILED; + } + } + } + } + + if (printdump == JNI_TRUE) { + printf(">>> step %d: \"%s.%s%s\"\n", frame_no, sigClass, name, sig); + printf(">>> location: %#x%08x", (jint)(loc >> 32), (jint)loc); + printf(", arg value: %d\n", argValue); + } + + if (sigClass == NULL || strcmp(sigClass, cls_exp) != 0) { + printf("(step %d) wrong class sig: \"%s\",\n", frame_no, sigClass); + printf(" expected: \"%s\"\n", cls_exp); + RETURN_FAILED; + } + if (name == NULL || strcmp(name, name_exp) != 0) { + printf("(step %d) wrong method name: \"%s\",", frame_no, name); + printf(" expected: \"%s\"\n", name_exp); + RETURN_FAILED; + } + if (sig == NULL || strcmp(sig, sig_exp) != 0) { + printf("(step %d) wrong method sig: \"%s\",", frame_no, sig); + printf(" expected: \"%s\"\n", sig_exp); + RETURN_FAILED; + } + if (loc != loc_exp) { + printf("(step %d) wrong location: %#x%08x,", + frame_no, (jint)(loc >> 32), (jint)loc); + printf(" expected: %#x\n", (jint)loc_exp); + RETURN_FAILED; + } + if (argValue != frame_no) { + printf("(step %d) wrong argument value: %d,", frame_no, argValue); + printf(" expected: %d\n", frame_no); + RETURN_FAILED; + } + + if (sigClass != NULL) { + jvmti_env->Deallocate((unsigned char*)sigClass); + } + if (name != NULL) { + jvmti_env->Deallocate((unsigned char*)name); + } + if (sig != NULL) { + jvmti_env->Deallocate((unsigned char*)sig); + } + if (table != NULL) { + for (j = 0; j < entryCount; j++) { + jvmti_env->Deallocate((unsigned char*)(table[j].name)); + jvmti_env->Deallocate((unsigned char*)(table[j].signature)); + } + jvmti_env->Deallocate((unsigned char*)table); + } + fflush(0); +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (midCheckPoint != method) { + printf("bp: don't know where we get called from"); + RETURN_FAILED; + } + + if (printdump == JNI_TRUE) { + printf(">>> breakpoint in checkPoint\n"); + } + + err = jvmti_env->ClearBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot enable single step: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti_env->ForceEarlyReturnVoid(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + fflush(0); +} + +void JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (method == midRun) { + if (printdump == JNI_TRUE) { + printf(">>> returned early %d frames till method \"run()\"\n", + framesCount); + } + + err = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, + JVMTI_EVENT_SINGLE_STEP, thread); + if (err != JVMTI_ERROR_NONE) { + printf("Cannot disable single step: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + } else { + check(jvmti_env, thread, method, location, framesCount); + framesCount++; + + err = jvmti_env->ForceEarlyReturnVoid(thread); + if (err != JVMTI_ERROR_NONE) { + printf("(ForceEarlyReturn) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + } + fflush(0); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_earlyretvoid(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_earlyretvoid(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_earlyretvoid(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printf("Printdump is turned on!\n"); + + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong error code from a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_force_early_return) { + printf("Warning: ForceEarlyReturn is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_single_step_events) { + callbacks.Breakpoint = &Breakpoint; + callbacks.SingleStep = &SingleStep; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: Breakpoint or SingleStep event are not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretvoid_getReady( + JNIEnv *env, jclass c, jclass cls, jint depth) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + RETURN_FAILED; + } + + if (!caps.can_force_early_return || + !caps.can_generate_breakpoint_events || + !caps.can_generate_single_step_events) { + return; + } + + midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "run", "()V"); + if (midRun == NULL) { + printf("Cannot find Method ID for method run\n"); + RETURN_FAILED; + } + + midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (midCheckPoint == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + RETURN_FAILED; + } + + err = jvmti->SetBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } else { + framesExpected = depth; + } + fflush(0); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretvoid_check(JNIEnv *env, jclass cls) { + if (framesCount != framesExpected) { + printf("Wrong number of returned early frames: %d, expected: %d\n", + framesCount, framesExpected); + errCode = STATUS_FAILED; + } + fflush(0); + return errCode; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/libearlyretvoid.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/libearlyretvoid.c deleted file mode 100644 index e487a2a7b7f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/libearlyretvoid.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "earlyretvoid.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/libearlyretvoid.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/libearlyretvoid.cpp new file mode 100644 index 00000000000..2edbbf0753c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/libearlyretvoid.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "earlyretvoid.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/getallstktr001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/getallstktr001.c deleted file mode 100644 index e90ad6e9376..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/getallstktr001.c +++ /dev/null @@ -1,405 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "jni_tools.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_ARG1(x) -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_ARG1(x) x -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define JVMTI_ENV_ARG JNI_ENV_ARG -#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 -#define JVMTI_ENV_PTR JNI_ENV_PTR - -#define STATUS_FAILED 2 -#define PASSED 0 - -#define JVMTI_ERROR_CHECK(str,res) \ - if ( res != JVMTI_ERROR_NONE) { \ - printf("%s %d\n" ,str, res); \ - return res; \ - } - -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) \ - if ( res != err) { \ - printf("%s unexpected error %d\n", str, res); \ - return res; \ - } - -#define JVMTI_ERROR_CHECK_VOID(str,res) \ - if (res != JVMTI_ERROR_NONE) { \ - printf("%s %d\n" ,str, res); \ - iGlobalStatus = STATUS_FAILED; \ - } - -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) \ - if (res != err) { \ - printf("%s unexpected error %d\n",str, res); \ - iGlobalStatus = STATUS_FAILED; \ - } - - -static jvmtiEnv *jvmti; -static jint iGlobalStatus = PASSED; -static jvmtiCapabilities jvmti_caps; -static jrawMonitorID jraw_monitor; - - -#define MAX_FRAMES_CNT 30 -static jvmtiStackInfo *stack_buf1 = NULL; -static jvmtiStackInfo *stack_buf2 = NULL; -static jthread *thread_list = NULL; -static jvmtiThreadInfo *thread_info = NULL; -static jint threads_count = 0; - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getallstktr001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getallstktr001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getallstktr001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { - jint res; - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res < 0) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - /* Add capabilities */ - res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - return JNI_OK; -} - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_GetResult( - JNIEnv * env, jclass cls) -{ - return iGlobalStatus; -} - - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_CreateRawMonitor( - JNIEnv * env, jclass cls) -{ - jvmtiError ret; - char sz[128]; - - sprintf(sz, "Raw-monitor"); - ret = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG1(jvmti), - sz, &jraw_monitor); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Raw monitor create %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_RawMonitorEnter( - JNIEnv * env, jclass cls) -{ - jvmtiError ret; - - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti), - jraw_monitor); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Raw monitor enter %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_RawMonitorExit( - JNIEnv * env, jclass cls) -{ - jvmtiError ret; - - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti), - jraw_monitor); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorExit %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } -} - -void compare_all_frames(int ti, int frames_count, - jvmtiFrameInfo *fr_buf1, - jvmtiFrameInfo *fr_buf2) -{ - int fi; - jvmtiFrameInfo *fr1, *fr2; - - for (fi = 0; fi < frames_count; fi++) { - fr1 = &fr_buf1[fi]; - fr2 = &fr_buf2[fi]; - if (fr1->method != fr2->method) { - printf("FAILED: compare frame: thread %d: frame %d: " - "different methods", ti, fi); - iGlobalStatus = STATUS_FAILED; - return; - } - if (fr1->location != fr2->location) { - printf("FAILED: compare frame: thread %d: frame %d: " - "different locations", ti, fi); - iGlobalStatus = STATUS_FAILED; - return; - } - printf("thr #%d: compare frame #%d: fields are the same: " - " method: 0x%p, location: %#"LL"x\n", - ti, fi, fr1->method, fr1->location); - fflush(0); - } -} - -void compare_one_stack_trace(int ti, - jvmtiStackInfo *stk1, - jvmtiStackInfo *stk2, - jvmtiThreadInfo *thr_info) -{ - static const char* TEST_THREAD_NAME_PREFIX = "getallstktr001-"; - size_t PFX_LEN = strlen(TEST_THREAD_NAME_PREFIX); - - if (thr_info->name != NULL) { - printf("compare stack #%d: thread: %s\n", ti, thr_info->name); - } else { - printf("compare stack #%d: thread is NULL\n", ti); - return; - } - - if (strlen(thr_info->name) < PFX_LEN || - strncmp(thr_info->name, TEST_THREAD_NAME_PREFIX, PFX_LEN) != 0) - { - printf("compare stack #%d: %s isn't tested thread - skip it\n", - ti, thr_info->name); - return; - } - - if (stk1->state != stk2->state) { - printf("FAILED: compare stack #%d: different states: " - "st1: %d, st2: %d\n", - ti, stk1->state, stk2->state); - iGlobalStatus = STATUS_FAILED; - return; - } - if (stk1->frame_count != stk2->frame_count) { - printf("FAILED: compare stack #%d: different frame_count: " - "cnt1: %d, cnt2: %d\n", - ti, stk1->frame_count, stk2->frame_count); - iGlobalStatus = STATUS_FAILED; - return; - } - - printf("compare stack #%d: fields are the same: " - " jthread: 0x%p, state: %d, frame_count: %d\n", - ti, stk1->thread, stk1->state, stk1->frame_count); - - fflush(0); - compare_all_frames(ti, - stk1->frame_count, - stk1->frame_buffer, - stk2->frame_buffer); -} - -void compare_all_stack_traces(int thr_count, - jvmtiStackInfo *stk_buf1, - jvmtiStackInfo *stk_buf2, - jvmtiThreadInfo *thr_info) -{ - int ti; - for (ti = 0; ti < thr_count; ti++) { - compare_one_stack_trace(ti, &stk_buf1[ti], &stk_buf2[ti], &thr_info[ti]); - } -} - - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_GetAllStackTraces( - JNIEnv * env, jclass cls) -{ - jvmtiError ret; - int ti; - - ret = JVMTI_ENV_PTR(jvmti)->GetAllStackTraces(JVMTI_ENV_ARG1(jvmti), - MAX_FRAMES_CNT, - &stack_buf1, - &threads_count); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetAllStackTraces %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } - - ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG1(jvmti), - sizeof(jthread) * threads_count, - (unsigned char**)&thread_list); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Allocate failed with %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } - - for (ti = 0; ti < threads_count; ti++) { - thread_list[ti] = - (jthread)JNI_ENV_PTR(env)->NewGlobalRef( - JNI_ENV_ARG(env, stack_buf1[ti].thread)); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_GetThreadsInfo( - JNIEnv * env, jclass cls) -{ - jvmtiError ret; - int ti; - - ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG1(jvmti), - sizeof(jvmtiThreadInfo) * threads_count, - (unsigned char**)&thread_info); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Allocate failed with %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } - - for (ti = 0; ti < threads_count; ti++) { - ret = JVMTI_ENV_PTR(jvmti)->GetThreadInfo(JVMTI_ENV_ARG1(jvmti), - thread_list[ti], - &thread_info[ti]); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetThreadInfo %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } - printf("GetThreadInfo %d: thread: %s\n", ti, thread_info[ti].name); - fflush(0); - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_GetThreadListStackTraces( - JNIEnv * env, jclass cls) -{ - jvmtiError ret; - - ret = JVMTI_ENV_PTR(jvmti)->GetThreadListStackTraces( - JVMTI_ENV_ARG1(jvmti), - threads_count, - thread_list, - MAX_FRAMES_CNT, - &stack_buf2); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetThreadListStackTraces %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } - -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_ForceGC( - JNIEnv * env, jclass cls) -{ - jvmtiError ret; - ret = JVMTI_ENV_PTR(jvmti)->ForceGarbageCollection(JVMTI_ENV_ARG1(jvmti)); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: ForceGarbageCollection %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_CompareStackTraces( - JNIEnv * env, jclass cls) -{ - compare_all_stack_traces(threads_count, stack_buf1, stack_buf2, thread_info); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_DeallocateBuffers( - JNIEnv * env, jclass cls) -{ - jvmtiError ret; - - ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG1(jvmti), - (unsigned char *)stack_buf1); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Deallocate stack_buf1 failed with %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } - - ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG1(jvmti), - (unsigned char *)stack_buf2); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Deallocate stack_buf2 failed with %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } - - ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG1(jvmti), - (unsigned char *)thread_info); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Deallocate thread_info failed with %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } - ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG1(jvmti), - (unsigned char *)thread_list); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Deallocate thread_list failed with %d \n", ret); - iGlobalStatus = STATUS_FAILED; - } -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/getallstktr001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/getallstktr001.cpp new file mode 100644 index 00000000000..cdeb4ebed90 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/getallstktr001.cpp @@ -0,0 +1,394 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "jni_tools.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_ARG1(x) +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_ARG1(x) x +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define JVMTI_ENV_ARG JNI_ENV_ARG +#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 +#define JVMTI_ENV_PTR JNI_ENV_PTR + +#define STATUS_FAILED 2 +#define PASSED 0 + +#define JVMTI_ERROR_CHECK(str,res) \ + if ( res != JVMTI_ERROR_NONE) { \ + printf("%s %d\n" ,str, res); \ + return res; \ + } + +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) \ + if ( res != err) { \ + printf("%s unexpected error %d\n", str, res); \ + return res; \ + } + +#define JVMTI_ERROR_CHECK_VOID(str,res) \ + if (res != JVMTI_ERROR_NONE) { \ + printf("%s %d\n" ,str, res); \ + iGlobalStatus = STATUS_FAILED; \ + } + +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) \ + if (res != err) { \ + printf("%s unexpected error %d\n",str, res); \ + iGlobalStatus = STATUS_FAILED; \ + } + + +static jvmtiEnv *jvmti; +static jint iGlobalStatus = PASSED; +static jvmtiCapabilities jvmti_caps; +static jrawMonitorID jraw_monitor; + + +#define MAX_FRAMES_CNT 30 +static jvmtiStackInfo *stack_buf1 = NULL; +static jvmtiStackInfo *stack_buf2 = NULL; +static jthread *thread_list = NULL; +static jvmtiThreadInfo *thread_info = NULL; +static jint threads_count = 0; + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getallstktr001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getallstktr001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getallstktr001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { + jint res; + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res < 0) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + /* Add capabilities */ + res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + return JNI_OK; +} + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_GetResult( + JNIEnv * env, jclass cls) +{ + return iGlobalStatus; +} + + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_CreateRawMonitor( + JNIEnv * env, jclass cls) +{ + jvmtiError ret; + char sz[128]; + + sprintf(sz, "Raw-monitor"); + ret = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti, sz), + &jraw_monitor); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Raw monitor create %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_RawMonitorEnter( + JNIEnv * env, jclass cls) +{ + jvmtiError ret; + + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, jraw_monitor)); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Raw monitor enter %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_RawMonitorExit( + JNIEnv * env, jclass cls) +{ + jvmtiError ret; + + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti, jraw_monitor)); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorExit %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } +} + +void compare_all_frames(int ti, int frames_count, + jvmtiFrameInfo *fr_buf1, + jvmtiFrameInfo *fr_buf2) +{ + int fi; + jvmtiFrameInfo *fr1, *fr2; + + for (fi = 0; fi < frames_count; fi++) { + fr1 = &fr_buf1[fi]; + fr2 = &fr_buf2[fi]; + if (fr1->method != fr2->method) { + printf("FAILED: compare frame: thread %d: frame %d: " + "different methods", ti, fi); + iGlobalStatus = STATUS_FAILED; + return; + } + if (fr1->location != fr2->location) { + printf("FAILED: compare frame: thread %d: frame %d: " + "different locations", ti, fi); + iGlobalStatus = STATUS_FAILED; + return; + } + printf("thr #%d: compare frame #%d: fields are the same: " + " method: 0x%p, location: %#" LL "x\n", + ti, fi, fr1->method, fr1->location); + fflush(0); + } +} + +void compare_one_stack_trace(int ti, + jvmtiStackInfo *stk1, + jvmtiStackInfo *stk2, + jvmtiThreadInfo *thr_info) +{ + static const char* TEST_THREAD_NAME_PREFIX = "getallstktr001-"; + size_t PFX_LEN = strlen(TEST_THREAD_NAME_PREFIX); + + if (thr_info->name != NULL) { + printf("compare stack #%d: thread: %s\n", ti, thr_info->name); + } else { + printf("compare stack #%d: thread is NULL\n", ti); + return; + } + + if (strlen(thr_info->name) < PFX_LEN || + strncmp(thr_info->name, TEST_THREAD_NAME_PREFIX, PFX_LEN) != 0) + { + printf("compare stack #%d: %s isn't tested thread - skip it\n", + ti, thr_info->name); + return; + } + + if (stk1->state != stk2->state) { + printf("FAILED: compare stack #%d: different states: " + "st1: %d, st2: %d\n", + ti, stk1->state, stk2->state); + iGlobalStatus = STATUS_FAILED; + return; + } + if (stk1->frame_count != stk2->frame_count) { + printf("FAILED: compare stack #%d: different frame_count: " + "cnt1: %d, cnt2: %d\n", + ti, stk1->frame_count, stk2->frame_count); + iGlobalStatus = STATUS_FAILED; + return; + } + + printf("compare stack #%d: fields are the same: " + " jthread: 0x%p, state: %d, frame_count: %d\n", + ti, stk1->thread, stk1->state, stk1->frame_count); + + fflush(0); + compare_all_frames(ti, + stk1->frame_count, + stk1->frame_buffer, + stk2->frame_buffer); +} + +void compare_all_stack_traces(int thr_count, + jvmtiStackInfo *stk_buf1, + jvmtiStackInfo *stk_buf2, + jvmtiThreadInfo *thr_info) +{ + int ti; + for (ti = 0; ti < thr_count; ti++) { + compare_one_stack_trace(ti, &stk_buf1[ti], &stk_buf2[ti], &thr_info[ti]); + } +} + + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_GetAllStackTraces( + JNIEnv * env, jclass cls) +{ + jvmtiError ret; + int ti; + + ret = JVMTI_ENV_PTR(jvmti)->GetAllStackTraces(JVMTI_ENV_ARG(jvmti, MAX_FRAMES_CNT), + &stack_buf1, + &threads_count); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetAllStackTraces %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } + + ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG(jvmti, sizeof(jthread) * threads_count), + (unsigned char**)&thread_list); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Allocate failed with %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } + + for (ti = 0; ti < threads_count; ti++) { + thread_list[ti] = + (jthread)JNI_ENV_PTR(env)->NewGlobalRef( + JNI_ENV_ARG(env, stack_buf1[ti].thread)); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_GetThreadsInfo( + JNIEnv * env, jclass cls) +{ + jvmtiError ret; + int ti; + + ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG(jvmti, sizeof(jvmtiThreadInfo) * threads_count), + (unsigned char**)&thread_info); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Allocate failed with %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } + + for (ti = 0; ti < threads_count; ti++) { + ret = JVMTI_ENV_PTR(jvmti)->GetThreadInfo(JVMTI_ENV_ARG(jvmti, thread_list[ti]), + &thread_info[ti]); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetThreadInfo %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } + printf("GetThreadInfo %d: thread: %s\n", ti, thread_info[ti].name); + fflush(0); + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_GetThreadListStackTraces( + JNIEnv * env, jclass cls) +{ + jvmtiError ret; + + ret = JVMTI_ENV_PTR(jvmti)->GetThreadListStackTraces( + JVMTI_ENV_ARG(jvmti, threads_count), + thread_list, + MAX_FRAMES_CNT, + &stack_buf2); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetThreadListStackTraces %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } + +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_ForceGC( + JNIEnv * env, jclass cls) +{ + jvmtiError ret; + ret = JVMTI_ENV_PTR(jvmti)->ForceGarbageCollection(JVMTI_ENV_ARG1(jvmti)); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: ForceGarbageCollection %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_CompareStackTraces( + JNIEnv * env, jclass cls) +{ + compare_all_stack_traces(threads_count, stack_buf1, stack_buf2, thread_info); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_DeallocateBuffers( + JNIEnv * env, jclass cls) +{ + jvmtiError ret; + + ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG(jvmti, (unsigned char *)stack_buf1)); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Deallocate stack_buf1 failed with %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } + + ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG(jvmti, (unsigned char *)stack_buf2)); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Deallocate stack_buf2 failed with %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } + + ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG(jvmti, (unsigned char *)thread_info)); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Deallocate thread_info failed with %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } + ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG(jvmti, (unsigned char *)thread_list)); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Deallocate thread_list failed with %d \n", ret); + iGlobalStatus = STATUS_FAILED; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/libgetallstktr001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/libgetallstktr001.c deleted file mode 100644 index 3eaa1e28f48..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/libgetallstktr001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getallstktr001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/libgetallstktr001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/libgetallstktr001.cpp new file mode 100644 index 00000000000..42ea27b0ff8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/libgetallstktr001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getallstktr001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/getcpool001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/getcpool001.c deleted file mode 100644 index 0999fb8bcfe..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/getcpool001.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; - -#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return - -static jint errCode = PASSED; -static jvmtiEnv *jvmti = NULL; -static jmethodID midCheckPoint = NULL; - - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetConstantPool_getcpool001_getCP( - JNIEnv *env, jclass c, jint id, jclass cls) { - jvmtiError err; - int idx = 0; - int rep = 0; - jint cp_cnt = 0; - jint cp_bytes_cnt = 0; - unsigned char *cp_bytes = NULL; - - err = (*jvmti)->GetConstantPool(jvmti, cls, &cp_cnt, &cp_bytes_cnt, &cp_bytes); - if (err != JVMTI_ERROR_NONE) { - printf("(GetConstantPool) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - /* Print Constant Pool attrs*/ - printf("getCP: id = %d, cnt = %03d, bytes_cnt = %04d\n", - id, cp_cnt, cp_bytes_cnt); - fflush(0); -} - -void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thread, jmethodID method, jlocation location) { - jvmtiError err; - - if (midCheckPoint != method) { - printf("bp: don't know where we get called from"); - RETURN_FAILED; - } - - printf(">>> breakpoint in checkPoint\n"); - - err = (*jvmti_env)->ClearBreakpoint(jvmti_env, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(ClearBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - fflush(0); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getcpool001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getcpool001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getcpool001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_force_early_return) { - printf("Warning: GetConstantPool is not implemented\n"); - } - - if (caps.can_generate_breakpoint_events && - caps.can_generate_single_step_events) { - callbacks.Breakpoint = &Breakpoint; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetConstantPool_getcpool001_getReady( - JNIEnv *env, jclass c, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - RETURN_FAILED; - } - - if (!caps.can_force_early_return || - !caps.can_generate_breakpoint_events || - !caps.can_generate_single_step_events) { - return; - } - - midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "checkPoint", "()V"); - if (midCheckPoint == NULL) { - printf("Cannot find Method ID for method checkPoint\n"); - RETURN_FAILED; - } - - err = (*jvmti)->SetBreakpoint(jvmti, midCheckPoint, 0); - if (err != JVMTI_ERROR_NONE) { - printf("(SetBreakpoint) unexpected error: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_BREAKPOINT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable BREAKPOINT event: %s (%d)\n", - TranslateError(err), err); - RETURN_FAILED; - } - -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_GetConstantPool_getcpool001_check(JNIEnv *env, jclass cls) { - return errCode; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/getcpool001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/getcpool001.cpp new file mode 100644 index 00000000000..7973f71d44a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/getcpool001.cpp @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; + +#define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return + +static jint errCode = PASSED; +static jvmtiEnv *jvmti = NULL; +static jmethodID midCheckPoint = NULL; + + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetConstantPool_getcpool001_getCP( + JNIEnv *env, jclass c, jint id, jclass cls) { + jvmtiError err; + int idx = 0; + int rep = 0; + jint cp_cnt = 0; + jint cp_bytes_cnt = 0; + unsigned char *cp_bytes = NULL; + + err = jvmti->GetConstantPool(cls, &cp_cnt, &cp_bytes_cnt, &cp_bytes); + if (err != JVMTI_ERROR_NONE) { + printf("(GetConstantPool) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + /* Print Constant Pool attrs*/ + printf("getCP: id = %d, cnt = %03d, bytes_cnt = %04d\n", + id, cp_cnt, cp_bytes_cnt); + fflush(0); +} + +void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thread, jmethodID method, jlocation location) { + jvmtiError err; + + if (midCheckPoint != method) { + printf("bp: don't know where we get called from"); + RETURN_FAILED; + } + + printf(">>> breakpoint in checkPoint\n"); + + err = jvmti_env->ClearBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(ClearBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + fflush(0); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getcpool001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getcpool001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getcpool001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_force_early_return) { + printf("Warning: GetConstantPool is not implemented\n"); + } + + if (caps.can_generate_breakpoint_events && + caps.can_generate_single_step_events) { + callbacks.Breakpoint = &Breakpoint; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetConstantPool_getcpool001_getReady( + JNIEnv *env, jclass c, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + RETURN_FAILED; + } + + if (!caps.can_force_early_return || + !caps.can_generate_breakpoint_events || + !caps.can_generate_single_step_events) { + return; + } + + midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "checkPoint", "()V"); + if (midCheckPoint == NULL) { + printf("Cannot find Method ID for method checkPoint\n"); + RETURN_FAILED; + } + + err = jvmti->SetBreakpoint(midCheckPoint, 0); + if (err != JVMTI_ERROR_NONE) { + printf("(SetBreakpoint) unexpected error: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_BREAKPOINT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable BREAKPOINT event: %s (%d)\n", + TranslateError(err), err); + RETURN_FAILED; + } + +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_GetConstantPool_getcpool001_check(JNIEnv *env, jclass cls) { + return errCode; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/libgetcpool001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/libgetcpool001.c deleted file mode 100644 index 7d46add1a4a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/libgetcpool001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getcpool001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/libgetcpool001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/libgetcpool001.cpp new file mode 100644 index 00000000000..77b74f710e8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/libgetcpool001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getcpool001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/liblinetab004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/liblinetab004.c deleted file mode 100644 index 3e7cb0c34b0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/liblinetab004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "linetab004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/liblinetab004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/liblinetab004.cpp new file mode 100644 index 00000000000..68044688505 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/liblinetab004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "linetab004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/linetab004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/linetab004.c deleted file mode 100644 index a91afb915a7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/linetab004.c +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_linetab004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_linetab004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_linetab004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_line_numbers) { - printf("Warning: GetLineNumberTable is not implemented\n"); - } - - return JNI_OK; -} - -void checkGetLineNumberTable(jmethodID mid, const char *methName, - int abstract, jvmtiError exp) { - jint entryCount = -1; - jvmtiLineNumberEntry *table = NULL; - jvmtiError err; - int i; - - err = (*jvmti)->GetLineNumberTable(jvmti, mid, &entryCount, &table); - if (printdump == JNI_TRUE) { - printf("\n Method: %s%s\n", methName, - (abstract==0) ? "" : " (abstract)"); - } - if (err != exp) { - result = STATUS_FAILED; - printf(" Error expected: %s (%d),\n", TranslateError(exp), exp); - printf(" actual: %s (%d)\n", TranslateError(err), err); - if (err == JVMTI_ERROR_NONE) { - printf(" %s%s line number table (%d entries):%s\n", - methName, (abstract==0) ? "" : " (abstract)", - entryCount, (entryCount==0 ? " empty" : "")); - for (i = 0; i < entryCount; i++) { - printf(" start_location = 0x%x%08x,", - (jint)(table[i].start_location >> 32), - (jint)table[i].start_location); - printf(" line_number = %d\n", table[i].line_number); - } - } - } else if (printdump == JNI_TRUE) { - printf(" Error code: %s (%d),\n", TranslateError(err), err); - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_GetLineNumberTable_linetab004_check(JNIEnv *env, jclass cls) { - jmethodID mid; - jclass abstr; - jclass interf; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_get_line_numbers) { - return result; - } - - if (printdump == JNI_TRUE) { - printf("\n Check methods of interface:\n"); - } - interf = JNI_ENV_PTR(env)->FindClass(env, - "nsk/jvmti/unit/GetLineNumberTable/Interface004"); - if (interf == NULL) { - printf("Cannot get Interface class!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "instanceMeth0", "()I"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - checkGetLineNumberTable(mid, "instanceMeth0", 1, - JVMTI_ERROR_ABSENT_INFORMATION); - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "instanceMeth1", "()I"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - checkGetLineNumberTable(mid, "instanceMeth1", 1, - JVMTI_ERROR_ABSENT_INFORMATION); - - if (printdump == JNI_TRUE) { - printf("\n Check methods of abstract class:\n"); - } - abstr = JNI_ENV_PTR(env)->GetSuperclass(JNI_ENV_ARG(env, cls)); - if (abstr == NULL) { - printf("Cannot get super class!\n"); - return STATUS_FAILED; - } - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, abstr), - "instanceMeth0", "()I"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - checkGetLineNumberTable(mid, "instanceMeth0", 1, - JVMTI_ERROR_ABSENT_INFORMATION); - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, abstr), - "instanceMeth1", "()I"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - checkGetLineNumberTable(mid, "instanceMeth1", 0, - JVMTI_ERROR_ABSENT_INFORMATION); - - if (printdump == JNI_TRUE) { - printf("\n Check methods of regular class:\n"); - } - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "instanceMeth0", "()I"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - checkGetLineNumberTable(mid, "instanceMeth0", 0, - JVMTI_ERROR_ABSENT_INFORMATION); - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "instanceMeth1", "()I"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - checkGetLineNumberTable(mid, "instanceMeth1", 0, - JVMTI_ERROR_ABSENT_INFORMATION); - - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "instanceMeth2", "()I"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - checkGetLineNumberTable(mid, "instanceMeth2", 0, - JVMTI_ERROR_ABSENT_INFORMATION); - - if (printdump == JNI_TRUE) { - printf("\n Check native methods of regular class:\n"); - } - mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), - "instanceNativeMeth", "()I"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - checkGetLineNumberTable(mid, "instanceNativeMeth", 1, - JVMTI_ERROR_NATIVE_METHOD); - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "staticNativeMeth", "()I"); - if (mid == NULL) { - printf("Cannot get method ID!\n"); - return STATUS_FAILED; - } - checkGetLineNumberTable(mid, "staticNativeMeth", 1, - JVMTI_ERROR_NATIVE_METHOD); - - if (printdump == JNI_TRUE) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/linetab004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/linetab004.cpp new file mode 100644 index 00000000000..f5da828dec5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/linetab004.cpp @@ -0,0 +1,273 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_linetab004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_linetab004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_linetab004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_line_numbers) { + printf("Warning: GetLineNumberTable is not implemented\n"); + } + + return JNI_OK; +} + +void checkGetLineNumberTable(jmethodID mid, const char *methName, + int abstract, jvmtiError exp) { + jint entryCount = -1; + jvmtiLineNumberEntry *table = NULL; + jvmtiError err; + int i; + + err = jvmti->GetLineNumberTable(mid, &entryCount, &table); + if (printdump == JNI_TRUE) { + printf("\n Method: %s%s\n", methName, + (abstract==0) ? "" : " (abstract)"); + } + if (err != exp) { + result = STATUS_FAILED; + printf(" Error expected: %s (%d),\n", TranslateError(exp), exp); + printf(" actual: %s (%d)\n", TranslateError(err), err); + if (err == JVMTI_ERROR_NONE) { + printf(" %s%s line number table (%d entries):%s\n", + methName, (abstract==0) ? "" : " (abstract)", + entryCount, (entryCount==0 ? " empty" : "")); + for (i = 0; i < entryCount; i++) { + printf(" start_location = 0x%x%08x,", + (jint)(table[i].start_location >> 32), + (jint)table[i].start_location); + printf(" line_number = %d\n", table[i].line_number); + } + } + } else if (printdump == JNI_TRUE) { + printf(" Error code: %s (%d),\n", TranslateError(err), err); + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_GetLineNumberTable_linetab004_check(JNIEnv *env, jclass cls) { + jmethodID mid; + jclass abstr; + jclass interf; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_get_line_numbers) { + return result; + } + + if (printdump == JNI_TRUE) { + printf("\n Check methods of interface:\n"); + } + interf = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, + "nsk/jvmti/unit/GetLineNumberTable/Interface004")); + if (interf == NULL) { + printf("Cannot get Interface class!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "instanceMeth0", "()I"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + checkGetLineNumberTable(mid, "instanceMeth0", 1, + JVMTI_ERROR_ABSENT_INFORMATION); + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "instanceMeth1", "()I"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + checkGetLineNumberTable(mid, "instanceMeth1", 1, + JVMTI_ERROR_ABSENT_INFORMATION); + + if (printdump == JNI_TRUE) { + printf("\n Check methods of abstract class:\n"); + } + abstr = JNI_ENV_PTR(env)->GetSuperclass(JNI_ENV_ARG(env, cls)); + if (abstr == NULL) { + printf("Cannot get super class!\n"); + return STATUS_FAILED; + } + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, abstr), + "instanceMeth0", "()I"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + checkGetLineNumberTable(mid, "instanceMeth0", 1, + JVMTI_ERROR_ABSENT_INFORMATION); + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, abstr), + "instanceMeth1", "()I"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + checkGetLineNumberTable(mid, "instanceMeth1", 0, + JVMTI_ERROR_ABSENT_INFORMATION); + + if (printdump == JNI_TRUE) { + printf("\n Check methods of regular class:\n"); + } + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "instanceMeth0", "()I"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + checkGetLineNumberTable(mid, "instanceMeth0", 0, + JVMTI_ERROR_ABSENT_INFORMATION); + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "instanceMeth1", "()I"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + checkGetLineNumberTable(mid, "instanceMeth1", 0, + JVMTI_ERROR_ABSENT_INFORMATION); + + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "instanceMeth2", "()I"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + checkGetLineNumberTable(mid, "instanceMeth2", 0, + JVMTI_ERROR_ABSENT_INFORMATION); + + if (printdump == JNI_TRUE) { + printf("\n Check native methods of regular class:\n"); + } + mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls), + "instanceNativeMeth", "()I"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + checkGetLineNumberTable(mid, "instanceNativeMeth", 1, + JVMTI_ERROR_NATIVE_METHOD); + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "staticNativeMeth", "()I"); + if (mid == NULL) { + printf("Cannot get method ID!\n"); + return STATUS_FAILED; + } + checkGetLineNumberTable(mid, "staticNativeMeth", 1, + JVMTI_ERROR_NATIVE_METHOD); + + if (printdump == JNI_TRUE) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/getlocal003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/getlocal003.c deleted file mode 100644 index 14cbfda1d3e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/getlocal003.c +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - */ - -#include -#include -#include "jvmti.h" -#include "jni_tools.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID mid = NULL; -static jvmtiLocalVariableEntry *table = NULL; -static jint entryCount = 0; -static jint methodExitCnt = -1; - -void print_LocalVariableEntry(jvmtiLocalVariableEntry *lvt_elem) { - printf("\n Var name: %s, slot: %d", lvt_elem->name, lvt_elem->slot); - printf(", start_bci: %"LL"d", lvt_elem->start_location); - printf(", end_bci: %"LL"d", lvt_elem->start_location + lvt_elem->length); - printf(", signature: %s\n", lvt_elem->signature); -} - -void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, - jthread thr, jmethodID method, - jboolean was_poped_by_exception, jvalue return_value) { - jvmtiError err; - jint i; - jmethodID frame_method; - jlocation location; - jint intVal; - jfloat floatVal; - jdouble doubleVal; - jobject obj; - - if (mid == method) { - - err = (*jvmti_env)->GetFrameLocation(jvmti_env, thr, 0, - &frame_method, &location); - if (err != JVMTI_ERROR_NONE) { - printf("\t failure: %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - return; - } - if (frame_method != method) { - printf("\t failure: GetFrameLocation returned wrong jmethodID\n"); - result = STATUS_FAILED; - return; - } - - printf("\n MethodExit: BEGIN %d, Current frame bci: %"LL"d\n\n", - ++methodExitCnt, location); - for (i = 0; i < entryCount; i++) { - if (table[i].start_location > location || - table[i].start_location + table[i].length < location) { - continue; /* The local variable is not visible */ - } - print_LocalVariableEntry(&table[i]); - - err = (*jvmti)->GetLocalInt(jvmti, thr, 0, table[i].slot, &intVal); - printf(" GetLocalInt: %s (%d)\n", TranslateError(err), err); - if (err != JVMTI_ERROR_NONE && table[i].signature[0] == 'I') { - result = STATUS_FAILED; - } - - err = (*jvmti)->GetLocalFloat(jvmti, thr, 0, table[i].slot, &floatVal); - printf(" GetLocalFloat: %s (%d)\n", TranslateError(err), err); - if (err != JVMTI_ERROR_NONE && table[i].signature[0] == 'F') { - result = STATUS_FAILED; - } - - err = (*jvmti)->GetLocalDouble(jvmti, thr, 0, table[i].slot, &doubleVal); - printf(" GetLocalDouble: %s (%d)\n", TranslateError(err), err); - if (err != JVMTI_ERROR_NONE && table[i].signature[0] == 'D') { - result = STATUS_FAILED; - } - - err = (*jvmti)->GetLocalObject(jvmti, thr, 0, table[i].slot, &obj); - printf(" GetLocalObject: %s (%d)\n", TranslateError(err), err); - if (err != JVMTI_ERROR_NONE && table[i].signature[0] == 'L') { - result = STATUS_FAILED; - } - } - printf("\n MethodExit: END %d\n\n", methodExitCnt); - fflush(stdout); - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getlocal003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getlocal003(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getlocal003(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_access_local_variables) { - printf("Warning: Access to local variables is not implemented\n"); - } else if (caps.can_generate_method_exit_events) { - callbacks.MethodExit = &MethodExit; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - } else { - printf("Warning: MethodExit event is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetLocalVariable_getlocal003_getMeth(JNIEnv *env, jclass cls) { - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_access_local_variables || - !caps.can_generate_method_exit_events) return; - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "staticMeth", "(I)I"); - if (mid == NULL) { - printf("Cannot find Method ID for staticMeth\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetLocalVariableTable(jvmti, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_METHOD_EXIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable metod exit event: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - fflush(stdout); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetLocalVariable_getlocal003_checkLoc(JNIEnv *env, - jclass cls, jthread thr) { - jvmtiError err; - jvmtiLocalVariableEntry *table; - jint entryCount; - jmethodID mid; - jint locVar; - jint i, j; - int overlap = 0; - - if (jvmti == NULL) { - return; - } - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "staticMeth", "(I)I"); - if (mid == NULL) { - printf("Cannot find Method ID for staticMeth\n"); - result = STATUS_FAILED; - return; - } - - err = (*jvmti)->GetLocalVariableTable(jvmti, mid, &entryCount, &table); - if (err != JVMTI_ERROR_NONE) { - printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return; - } - - for (i = 0; i < entryCount; i++) { - print_LocalVariableEntry(&table[i]); - - err = (*jvmti)->GetLocalInt(jvmti, thr, 1, table[i].slot, &locVar); - - printf(" GetLocalInt: %s (%d)\n", TranslateError(err), err); - if (strcmp(table[i].name, "intArg") == 0) { - if (err != JVMTI_ERROR_NONE) { - printf(" failure: JVMTI_ERROR_NONE is expected\n"); - result = STATUS_FAILED; - } - } - else if (strcmp(table[i].name, "pi") == 0) { - if (err != JVMTI_ERROR_TYPE_MISMATCH) { - printf(" failure: JVMTI_ERROR_TYPE_MISMATCH is expected\n"); - result = STATUS_FAILED; - } - } else { - if (err != JVMTI_ERROR_INVALID_SLOT) { - printf(" failure: JVMTI_ERROR_INVALID_SLOT is expected\n"); - result = STATUS_FAILED; - } - } - if (table[i].slot != 2) { - continue; - } - - for (j = 0; j < entryCount; j++) { - /* We do cross checks between all variables having slot #2. - * No overlapping between location ranges are allowed. - */ - if (table[j].slot != 2 || i == j) { - continue; - } - if (table[i].start_location > table[j].start_location + table[j].length || - table[j].start_location > table[i].start_location + table[i].length - ) { - continue; /* Everything is Ok */ - } - - printf(" failure: locations of vars with slot #2 are overlaped:\n"); - print_LocalVariableEntry(&table[i]); - print_LocalVariableEntry(&table[j]); - overlap++; - result = STATUS_FAILED; - } - } - if (!overlap) { - printf("\n Succes: locations of vars with slot #2 are NOT overlaped\n\n"); - } - fflush(stdout); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_GetLocalVariable_getlocal003_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/getlocal003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/getlocal003.cpp new file mode 100644 index 00000000000..5b8c4b27770 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/getlocal003.cpp @@ -0,0 +1,329 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + */ + +#include +#include +#include "jvmti.h" +#include "jni_tools.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID mid = NULL; +static jvmtiLocalVariableEntry *table = NULL; +static jint entryCount = 0; +static jint methodExitCnt = -1; + +void print_LocalVariableEntry(jvmtiLocalVariableEntry *lvt_elem) { + printf("\n Var name: %s, slot: %d", lvt_elem->name, lvt_elem->slot); + printf(", start_bci: %" LL "d", lvt_elem->start_location); + printf(", end_bci: %" LL "d", lvt_elem->start_location + lvt_elem->length); + printf(", signature: %s\n", lvt_elem->signature); +} + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv *env, + jthread thr, jmethodID method, + jboolean was_poped_by_exception, jvalue return_value) { + jvmtiError err; + jint i; + jmethodID frame_method; + jlocation location; + jint intVal; + jfloat floatVal; + jdouble doubleVal; + jobject obj; + + if (mid == method) { + + err = jvmti_env->GetFrameLocation(thr, 0, + &frame_method, &location); + if (err != JVMTI_ERROR_NONE) { + printf("\t failure: %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + return; + } + if (frame_method != method) { + printf("\t failure: GetFrameLocation returned wrong jmethodID\n"); + result = STATUS_FAILED; + return; + } + + printf("\n MethodExit: BEGIN %d, Current frame bci: %" LL "d\n\n", + ++methodExitCnt, location); + for (i = 0; i < entryCount; i++) { + if (table[i].start_location > location || + table[i].start_location + table[i].length < location) { + continue; /* The local variable is not visible */ + } + print_LocalVariableEntry(&table[i]); + + err = jvmti->GetLocalInt(thr, 0, table[i].slot, &intVal); + printf(" GetLocalInt: %s (%d)\n", TranslateError(err), err); + if (err != JVMTI_ERROR_NONE && table[i].signature[0] == 'I') { + result = STATUS_FAILED; + } + + err = jvmti->GetLocalFloat(thr, 0, table[i].slot, &floatVal); + printf(" GetLocalFloat: %s (%d)\n", TranslateError(err), err); + if (err != JVMTI_ERROR_NONE && table[i].signature[0] == 'F') { + result = STATUS_FAILED; + } + + err = jvmti->GetLocalDouble(thr, 0, table[i].slot, &doubleVal); + printf(" GetLocalDouble: %s (%d)\n", TranslateError(err), err); + if (err != JVMTI_ERROR_NONE && table[i].signature[0] == 'D') { + result = STATUS_FAILED; + } + + err = jvmti->GetLocalObject(thr, 0, table[i].slot, &obj); + printf(" GetLocalObject: %s (%d)\n", TranslateError(err), err); + if (err != JVMTI_ERROR_NONE && table[i].signature[0] == 'L') { + result = STATUS_FAILED; + } + } + printf("\n MethodExit: END %d\n\n", methodExitCnt); + fflush(stdout); + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getlocal003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getlocal003(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getlocal003(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_access_local_variables) { + printf("Warning: Access to local variables is not implemented\n"); + } else if (caps.can_generate_method_exit_events) { + callbacks.MethodExit = &MethodExit; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + } else { + printf("Warning: MethodExit event is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetLocalVariable_getlocal003_getMeth(JNIEnv *env, jclass cls) { + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_access_local_variables || + !caps.can_generate_method_exit_events) return; + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "staticMeth", "(I)I"); + if (mid == NULL) { + printf("Cannot find Method ID for staticMeth\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_METHOD_EXIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable metod exit event: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + fflush(stdout); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetLocalVariable_getlocal003_checkLoc(JNIEnv *env, + jclass cls, jthread thr) { + jvmtiError err; + jvmtiLocalVariableEntry *table; + jint entryCount; + jmethodID mid; + jint locVar; + jint i, j; + int overlap = 0; + + if (jvmti == NULL) { + return; + } + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "staticMeth", "(I)I"); + if (mid == NULL) { + printf("Cannot find Method ID for staticMeth\n"); + result = STATUS_FAILED; + return; + } + + err = jvmti->GetLocalVariableTable(mid, &entryCount, &table); + if (err != JVMTI_ERROR_NONE) { + printf("(GetLocalVariableTable) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return; + } + + for (i = 0; i < entryCount; i++) { + print_LocalVariableEntry(&table[i]); + + err = jvmti->GetLocalInt(thr, 1, table[i].slot, &locVar); + + printf(" GetLocalInt: %s (%d)\n", TranslateError(err), err); + if (strcmp(table[i].name, "intArg") == 0) { + if (err != JVMTI_ERROR_NONE) { + printf(" failure: JVMTI_ERROR_NONE is expected\n"); + result = STATUS_FAILED; + } + } + else if (strcmp(table[i].name, "pi") == 0) { + if (err != JVMTI_ERROR_TYPE_MISMATCH) { + printf(" failure: JVMTI_ERROR_TYPE_MISMATCH is expected\n"); + result = STATUS_FAILED; + } + } else { + if (err != JVMTI_ERROR_INVALID_SLOT) { + printf(" failure: JVMTI_ERROR_INVALID_SLOT is expected\n"); + result = STATUS_FAILED; + } + } + if (table[i].slot != 2) { + continue; + } + + for (j = 0; j < entryCount; j++) { + /* We do cross checks between all variables having slot #2. + * No overlapping between location ranges are allowed. + */ + if (table[j].slot != 2 || i == j) { + continue; + } + if (table[i].start_location > table[j].start_location + table[j].length || + table[j].start_location > table[i].start_location + table[i].length + ) { + continue; /* Everything is Ok */ + } + + printf(" failure: locations of vars with slot #2 are overlaped:\n"); + print_LocalVariableEntry(&table[i]); + print_LocalVariableEntry(&table[j]); + overlap++; + result = STATUS_FAILED; + } + } + if (!overlap) { + printf("\n Succes: locations of vars with slot #2 are NOT overlaped\n\n"); + } + fflush(stdout); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_GetLocalVariable_getlocal003_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/libgetlocal003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/libgetlocal003.c deleted file mode 100644 index 9d1ac62d097..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/libgetlocal003.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getlocal003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/libgetlocal003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/libgetlocal003.cpp new file mode 100644 index 00000000000..bd7ca89a1f4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/libgetlocal003.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getlocal003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/getlocal004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/getlocal004.c deleted file mode 100644 index 185105f81e9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/getlocal004.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - */ - -#include -#include -#include "jvmti.h" -#include "jni_tools.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jmethodID mid = NULL; - -void print_LocalVariableEntry(jvmtiLocalVariableEntry *lvt_elem) { - printf("\n Var name: %s, slot: %d", lvt_elem->name, lvt_elem->slot); - printf(", start_bci: %"LL"d", lvt_elem->start_location); - printf(", end_bci: %"LL"d", lvt_elem->start_location + lvt_elem->length); - printf(", signature: %s\n", lvt_elem->signature); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_getlocal004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_getlocal004(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_getlocal004(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_access_local_variables) { - printf("Warning: Access to local variables is not implemented\n"); - } - - return JNI_OK; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetLocalVariable_getlocal004_getMeth(JNIEnv *env, jclass cls) { - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - result = STATUS_FAILED; - return; - } - - if (!caps.can_access_local_variables || - !caps.can_generate_method_exit_events) return; - - mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), - "staticMeth", "(I)I"); - if (mid == NULL) { - printf("Cannot find Method ID for staticMeth\n"); - result = STATUS_FAILED; - return; - } - - fflush(stdout); -} - -void checkErrorCodeIn(jvmtiError err, jint slot) { - if (err != JVMTI_ERROR_NONE) { - printf(" FAILURE: JVMTI_ERROR_NONE is expected, slot: %d\n\n", slot); - result = STATUS_FAILED; - } else { - printf(" success: JVMTI_ERROR_NONE as expected, slot: %d\n\n", slot); - } -} - -void checkErrorCodeOut(jvmtiError err, jint slot) { - if (err != JVMTI_ERROR_INVALID_SLOT) { - printf(" FAILURE: JVMTI_ERROR_INVALID_SLOT is expected, slot: %d\n\n", slot); - result = STATUS_FAILED; - } else { - printf(" success: JVMTI_ERROR_INVALID_SLOT as expected, slot: %d\n\n", slot); - } -} - -#define CHECK_ERROR_CODE(scope_no, err, slot) \ - if (scope_no == 1) { \ - checkErrorCodeOut(err, slot); \ - } else { \ - checkErrorCodeIn(err, slot); \ - } - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_GetLocalVariable_getlocal004_checkLoc(JNIEnv *env, - jclass cls, jthread thr, jint scope_no) { - jvmtiError err = JVMTI_ERROR_NONE; - jint slot = 0; - jint locInt = 0; - jlong locLong = 0L; - jdouble locDouble = 0.0f; - - if (jvmti == NULL) { - return; - } - printf("\n ----------------- checkLoc: %d -----------------\n\n", scope_no); - - /* Check for slots which has to be available in general */ - for (slot = 3; slot < 5; slot++) { - err = (*jvmti)->GetLocalInt(jvmti, thr, 1, slot, &locInt); - printf(" GetLocalInt: %s (%d)\n", TranslateError(err), err); - CHECK_ERROR_CODE(scope_no, err, slot); - - if (err == JVMTI_ERROR_NONE) { - printf(" slot%d: %d\n", slot, locInt); - } - - err = (*jvmti)->GetLocalLong(jvmti, thr, 1, slot, &locLong); - printf(" GetLocalLong: %s (%d)\n", TranslateError(err), err); - CHECK_ERROR_CODE(scope_no, err, slot); - - err = (*jvmti)->GetLocalDouble(jvmti, thr, 1, slot, &locDouble); - printf(" GetLocalDouble: %s (%d)\n", TranslateError(err), err); - CHECK_ERROR_CODE(scope_no, err, slot); - } - - /* Slot 5 is special: it's not for 64 bit values! */ - slot = 5; { - err = (*jvmti)->GetLocalInt(jvmti, thr, 1, slot, &locInt); - printf(" GetLocalInt: %s (%d)\n", TranslateError(err), err); - CHECK_ERROR_CODE(scope_no, err, slot); - - if (err == JVMTI_ERROR_NONE) { - printf(" slot%d: %d\n", slot, locInt); - } - - err = (*jvmti)->GetLocalLong(jvmti, thr, 1, slot, &locLong); - printf(" GetLocalLong: %s (%d)\n", TranslateError(err), err); - checkErrorCodeOut(err, slot); - - err = (*jvmti)->GetLocalDouble(jvmti, thr, 1, slot, &locDouble); - printf(" GetLocalDouble: %s (%d)\n", TranslateError(err), err); - checkErrorCodeOut(err, slot); - } - - /* Check for slots which has to be unavailable in general */ - for (slot = 6; slot < 8; slot++) { - err = (*jvmti)->GetLocalInt(jvmti, thr, 1, slot, &locInt); - printf(" GetLocalInt: %s (%d)\n", TranslateError(err), err); - checkErrorCodeOut(err, slot); - - if (err == JVMTI_ERROR_NONE) { - printf(" slot%d: %d\n", slot, locInt); - } - - err = (*jvmti)->GetLocalLong(jvmti, thr, 1, slot, &locLong); - printf(" GetLocalLong: %s (%d)\n", TranslateError(err), err); - checkErrorCodeOut(err, slot); - - err = (*jvmti)->GetLocalDouble(jvmti, thr, 1, slot, &locDouble); - printf(" GetLocalDouble: %s (%d)\n", TranslateError(err), err); - checkErrorCodeOut(err, slot); - } - - fflush(stdout); -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_GetLocalVariable_getlocal004_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/getlocal004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/getlocal004.cpp new file mode 100644 index 00000000000..366a9b5a34d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/getlocal004.cpp @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + */ + +#include +#include +#include "jvmti.h" +#include "jni_tools.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jmethodID mid = NULL; + +void print_LocalVariableEntry(jvmtiLocalVariableEntry *lvt_elem) { + printf("\n Var name: %s, slot: %d", lvt_elem->name, lvt_elem->slot); + printf(", start_bci: %" LL "d", lvt_elem->start_location); + printf(", end_bci: %" LL "d", lvt_elem->start_location + lvt_elem->length); + printf(", signature: %s\n", lvt_elem->signature); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_getlocal004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_getlocal004(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_getlocal004(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_access_local_variables) { + printf("Warning: Access to local variables is not implemented\n"); + } + + return JNI_OK; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetLocalVariable_getlocal004_getMeth(JNIEnv *env, jclass cls) { + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + result = STATUS_FAILED; + return; + } + + if (!caps.can_access_local_variables || + !caps.can_generate_method_exit_events) return; + + mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls), + "staticMeth", "(I)I"); + if (mid == NULL) { + printf("Cannot find Method ID for staticMeth\n"); + result = STATUS_FAILED; + return; + } + + fflush(stdout); +} + +void checkErrorCodeIn(jvmtiError err, jint slot) { + if (err != JVMTI_ERROR_NONE) { + printf(" FAILURE: JVMTI_ERROR_NONE is expected, slot: %d\n\n", slot); + result = STATUS_FAILED; + } else { + printf(" success: JVMTI_ERROR_NONE as expected, slot: %d\n\n", slot); + } +} + +void checkErrorCodeOut(jvmtiError err, jint slot) { + if (err != JVMTI_ERROR_INVALID_SLOT) { + printf(" FAILURE: JVMTI_ERROR_INVALID_SLOT is expected, slot: %d\n\n", slot); + result = STATUS_FAILED; + } else { + printf(" success: JVMTI_ERROR_INVALID_SLOT as expected, slot: %d\n\n", slot); + } +} + +#define CHECK_ERROR_CODE(scope_no, err, slot) \ + if (scope_no == 1) { \ + checkErrorCodeOut(err, slot); \ + } else { \ + checkErrorCodeIn(err, slot); \ + } + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_GetLocalVariable_getlocal004_checkLoc(JNIEnv *env, + jclass cls, jthread thr, jint scope_no) { + jvmtiError err = JVMTI_ERROR_NONE; + jint slot = 0; + jint locInt = 0; + jlong locLong = 0L; + jdouble locDouble = 0.0f; + + if (jvmti == NULL) { + return; + } + printf("\n ----------------- checkLoc: %d -----------------\n\n", scope_no); + + /* Check for slots which has to be available in general */ + for (slot = 3; slot < 5; slot++) { + err = jvmti->GetLocalInt(thr, 1, slot, &locInt); + printf(" GetLocalInt: %s (%d)\n", TranslateError(err), err); + CHECK_ERROR_CODE(scope_no, err, slot); + + if (err == JVMTI_ERROR_NONE) { + printf(" slot%d: %d\n", slot, locInt); + } + + err = jvmti->GetLocalLong(thr, 1, slot, &locLong); + printf(" GetLocalLong: %s (%d)\n", TranslateError(err), err); + CHECK_ERROR_CODE(scope_no, err, slot); + + err = jvmti->GetLocalDouble(thr, 1, slot, &locDouble); + printf(" GetLocalDouble: %s (%d)\n", TranslateError(err), err); + CHECK_ERROR_CODE(scope_no, err, slot); + } + + /* Slot 5 is special: it's not for 64 bit values! */ + slot = 5; { + err = jvmti->GetLocalInt(thr, 1, slot, &locInt); + printf(" GetLocalInt: %s (%d)\n", TranslateError(err), err); + CHECK_ERROR_CODE(scope_no, err, slot); + + if (err == JVMTI_ERROR_NONE) { + printf(" slot%d: %d\n", slot, locInt); + } + + err = jvmti->GetLocalLong(thr, 1, slot, &locLong); + printf(" GetLocalLong: %s (%d)\n", TranslateError(err), err); + checkErrorCodeOut(err, slot); + + err = jvmti->GetLocalDouble(thr, 1, slot, &locDouble); + printf(" GetLocalDouble: %s (%d)\n", TranslateError(err), err); + checkErrorCodeOut(err, slot); + } + + /* Check for slots which has to be unavailable in general */ + for (slot = 6; slot < 8; slot++) { + err = jvmti->GetLocalInt(thr, 1, slot, &locInt); + printf(" GetLocalInt: %s (%d)\n", TranslateError(err), err); + checkErrorCodeOut(err, slot); + + if (err == JVMTI_ERROR_NONE) { + printf(" slot%d: %d\n", slot, locInt); + } + + err = jvmti->GetLocalLong(thr, 1, slot, &locLong); + printf(" GetLocalLong: %s (%d)\n", TranslateError(err), err); + checkErrorCodeOut(err, slot); + + err = jvmti->GetLocalDouble(thr, 1, slot, &locDouble); + printf(" GetLocalDouble: %s (%d)\n", TranslateError(err), err); + checkErrorCodeOut(err, slot); + } + + fflush(stdout); +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_GetLocalVariable_getlocal004_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/libgetlocal004.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/libgetlocal004.c deleted file mode 100644 index e4f068971d8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/libgetlocal004.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "getlocal004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/libgetlocal004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/libgetlocal004.cpp new file mode 100644 index 00000000000..9c92fda4184 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/libgetlocal004.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "getlocal004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/issynth001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/issynth001.c deleted file mode 100644 index 6f404397fa1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/issynth001.c +++ /dev/null @@ -1,299 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 -#define JVM_ACC_SYNTHETIC 0x1000 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_issynth001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_issynth001(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_issynth001(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_get_synthetic_attribute) { - printf("Warning: IsMethodSynthetic is not implemented\n"); - } - - return JNI_OK; -} - -char const *jbooleanToString(jboolean flag) { - return ((flag == JNI_TRUE) ? "true" : "false"); -} - -JNIEXPORT jint JNICALL -checkClassMethods(jclass klass) { - jvmtiError err; - jmethodID mid; - jboolean isSynthetic; - jint meth_cnt = 0; - jmethodID* methods_ptr = NULL; - char* name_ptr = NULL; - char* sign_ptr = NULL; - int i; - - err = (*jvmti)->GetClassMethods(jvmti, klass, &meth_cnt, &methods_ptr); - if (err != JVMTI_ERROR_NONE) { - printf("GetClassMethods unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - for (i = 0; i < meth_cnt; i++) { - jint mods; - mid = methods_ptr[i]; - err = (*jvmti)->GetMethodName(jvmti, mid, &name_ptr, - &sign_ptr, (char **) NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - return STATUS_FAILED; - } - - printf("Method # %d; name: %s, signature: %s\n", i, name_ptr, sign_ptr); - err = (*jvmti)->IsMethodSynthetic(jvmti, mid, &isSynthetic); - if (err != JVMTI_ERROR_NONE) { - printf("(IsMethodSynthetic#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - - err = (*jvmti)->GetMethodModifiers(jvmti, mid, &mods); - if (err != JVMTI_ERROR_NONE) { - printf("(GetMethodModifiers#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - printf("\tACC_SYNTHETIC bit: %d\n", ((mods & JVM_ACC_SYNTHETIC) != 0)); - if ((mods & JVM_ACC_SYNTHETIC) && isSynthetic) { - printf("\tIsMethodSynthetic result and ACC_SYNTHETIC bit are matched\n"); - } else if ((mods & JVM_ACC_SYNTHETIC) || isSynthetic) { - printf("Failure: IsMethodSynthetic result and ACC_SYNTHETIC bit don't match\n"); - result = STATUS_FAILED; - continue; - } - } - printf("\n"); - return result; -} - -JNIEXPORT jint JNICALL -checkClassFields(jclass klass) { - jvmtiError err; - jfieldID fid; - jboolean isSynthetic; - jint fld_cnt = 0; - jfieldID* fields_ptr = NULL; - char* name_ptr = NULL; - char* sign_ptr = NULL; - int i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->GetClassFields(jvmti, klass, &fld_cnt, &fields_ptr); - if (err != JVMTI_ERROR_NONE) { - printf("GetClassFields unexpected error: %s (%d)\n", - TranslateError(err), err); - return STATUS_FAILED; - } - - for (i = 0; i < fld_cnt; i++) { - jint mods; - fid = fields_ptr[i]; - err = (*jvmti)->GetFieldName(jvmti, klass, fid, &name_ptr, - &sign_ptr, (char **) NULL); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldName#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - return STATUS_FAILED; - } - - printf("Field # %d; name: %s, signature: %s\n", i, name_ptr, sign_ptr); - err = (*jvmti)->IsFieldSynthetic(jvmti, klass, fid, &isSynthetic); - if (err != JVMTI_ERROR_NONE) { - printf("(IsFieldSynthetic#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - - err = (*jvmti)->GetFieldModifiers(jvmti, klass, fid, &mods); - if (err != JVMTI_ERROR_NONE) { - printf("(GetFieldModifiers#%d) unexpected error: %s (%d)\n", - i, TranslateError(err), err); - result = STATUS_FAILED; - continue; - } - printf("\tACC_SYNTHETIC bit: %d\n", ((mods & JVM_ACC_SYNTHETIC) != 0)); - if ((mods & JVM_ACC_SYNTHETIC) && isSynthetic) { - printf("\tIsFieldSynthetic result and ACC_SYNTHETIC bit are matched\n"); - } else if ((mods & JVM_ACC_SYNTHETIC) || isSynthetic) { - printf("Failure: IsFieldSynthetic result and ACC_SYNTHETIC bit don't match\n"); - result = STATUS_FAILED; - continue; - } - } - - return result; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_IsSynthetic_issynth001_check(JNIEnv *env, - jclass cls, jclass klass) { - - jvmtiError err; - char* class_sign = NULL; - - if (!caps.can_get_synthetic_attribute) { - return result; - } - - err = (*jvmti)->GetClassSignature(jvmti, cls, &class_sign, (char **) NULL); - if (err != JVMTI_ERROR_NONE) { - printf("GetSourceFileName unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return result; - } else { - printf("Class signature: %s\n", class_sign); - } - - /* - * The following synthetic methods are expected: - * Name: class$, Signature: (Ljava/lang/String;)Ljava/lang/Class; - * Name: access$000, Signature: (Lnsk/jvmti/unit/IsMethodSynthetic/issynth001;)I - */ - - result = checkClassMethods(cls); - if (result != PASSED) { - return result; - } - - err = (*jvmti)->GetClassSignature(jvmti, klass, &class_sign, (char **) NULL); - if (err != JVMTI_ERROR_NONE) { - printf("GetSourceFileName unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - return result; - } else { - printf("Class signature: %s\n", class_sign); - } - - /* Just a sanity check of methods of Inner class. - * No synthetic methods are expected here. - */ - result = checkClassMethods(klass); - if (result != PASSED) { - return result; - } - - /* Check of fields of Inner class. - * Just one synthetic field is expected here: - * Name: this$0, Signature: Lnsk/jvmti/unit/IsSynthetic/issynth001; - */ - result = checkClassFields(klass); - - return result; -} - -JNIEXPORT jint JNICALL Java_issynth001_getRes(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/issynth001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/issynth001.cpp new file mode 100644 index 00000000000..fd84f02d532 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/issynth001.cpp @@ -0,0 +1,299 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 +#define JVM_ACC_SYNTHETIC 0x1000 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_issynth001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_issynth001(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_issynth001(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_get_synthetic_attribute) { + printf("Warning: IsMethodSynthetic is not implemented\n"); + } + + return JNI_OK; +} + +char const *jbooleanToString(jboolean flag) { + return ((flag == JNI_TRUE) ? "true" : "false"); +} + +JNIEXPORT jint JNICALL +checkClassMethods(jclass klass) { + jvmtiError err; + jmethodID mid; + jboolean isSynthetic; + jint meth_cnt = 0; + jmethodID* methods_ptr = NULL; + char* name_ptr = NULL; + char* sign_ptr = NULL; + int i; + + err = jvmti->GetClassMethods(klass, &meth_cnt, &methods_ptr); + if (err != JVMTI_ERROR_NONE) { + printf("GetClassMethods unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + for (i = 0; i < meth_cnt; i++) { + jint mods; + mid = methods_ptr[i]; + err = jvmti->GetMethodName(mid, &name_ptr, + &sign_ptr, (char **) NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + return STATUS_FAILED; + } + + printf("Method # %d; name: %s, signature: %s\n", i, name_ptr, sign_ptr); + err = jvmti->IsMethodSynthetic(mid, &isSynthetic); + if (err != JVMTI_ERROR_NONE) { + printf("(IsMethodSynthetic#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + + err = jvmti->GetMethodModifiers(mid, &mods); + if (err != JVMTI_ERROR_NONE) { + printf("(GetMethodModifiers#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + printf("\tACC_SYNTHETIC bit: %d\n", ((mods & JVM_ACC_SYNTHETIC) != 0)); + if ((mods & JVM_ACC_SYNTHETIC) && isSynthetic) { + printf("\tIsMethodSynthetic result and ACC_SYNTHETIC bit are matched\n"); + } else if ((mods & JVM_ACC_SYNTHETIC) || isSynthetic) { + printf("Failure: IsMethodSynthetic result and ACC_SYNTHETIC bit don't match\n"); + result = STATUS_FAILED; + continue; + } + } + printf("\n"); + return result; +} + +JNIEXPORT jint JNICALL +checkClassFields(jclass klass) { + jvmtiError err; + jfieldID fid; + jboolean isSynthetic; + jint fld_cnt = 0; + jfieldID* fields_ptr = NULL; + char* name_ptr = NULL; + char* sign_ptr = NULL; + int i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->GetClassFields(klass, &fld_cnt, &fields_ptr); + if (err != JVMTI_ERROR_NONE) { + printf("GetClassFields unexpected error: %s (%d)\n", + TranslateError(err), err); + return STATUS_FAILED; + } + + for (i = 0; i < fld_cnt; i++) { + jint mods; + fid = fields_ptr[i]; + err = jvmti->GetFieldName(klass, fid, &name_ptr, + &sign_ptr, (char **) NULL); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldName#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + return STATUS_FAILED; + } + + printf("Field # %d; name: %s, signature: %s\n", i, name_ptr, sign_ptr); + err = jvmti->IsFieldSynthetic(klass, fid, &isSynthetic); + if (err != JVMTI_ERROR_NONE) { + printf("(IsFieldSynthetic#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + + err = jvmti->GetFieldModifiers(klass, fid, &mods); + if (err != JVMTI_ERROR_NONE) { + printf("(GetFieldModifiers#%d) unexpected error: %s (%d)\n", + i, TranslateError(err), err); + result = STATUS_FAILED; + continue; + } + printf("\tACC_SYNTHETIC bit: %d\n", ((mods & JVM_ACC_SYNTHETIC) != 0)); + if ((mods & JVM_ACC_SYNTHETIC) && isSynthetic) { + printf("\tIsFieldSynthetic result and ACC_SYNTHETIC bit are matched\n"); + } else if ((mods & JVM_ACC_SYNTHETIC) || isSynthetic) { + printf("Failure: IsFieldSynthetic result and ACC_SYNTHETIC bit don't match\n"); + result = STATUS_FAILED; + continue; + } + } + + return result; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_IsSynthetic_issynth001_check(JNIEnv *env, + jclass cls, jclass klass) { + + jvmtiError err; + char* class_sign = NULL; + + if (!caps.can_get_synthetic_attribute) { + return result; + } + + err = jvmti->GetClassSignature(cls, &class_sign, (char **) NULL); + if (err != JVMTI_ERROR_NONE) { + printf("GetSourceFileName unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return result; + } else { + printf("Class signature: %s\n", class_sign); + } + + /* + * The following synthetic methods are expected: + * Name: class$, Signature: (Ljava/lang/String;)Ljava/lang/Class; + * Name: access$000, Signature: (Lnsk/jvmti/unit/IsMethodSynthetic/issynth001;)I + */ + + result = checkClassMethods(cls); + if (result != PASSED) { + return result; + } + + err = jvmti->GetClassSignature(klass, &class_sign, (char **) NULL); + if (err != JVMTI_ERROR_NONE) { + printf("GetSourceFileName unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + return result; + } else { + printf("Class signature: %s\n", class_sign); + } + + /* Just a sanity check of methods of Inner class. + * No synthetic methods are expected here. + */ + result = checkClassMethods(klass); + if (result != PASSED) { + return result; + } + + /* Check of fields of Inner class. + * Just one synthetic field is expected here: + * Name: this$0, Signature: Lnsk/jvmti/unit/IsSynthetic/issynth001; + */ + result = checkClassFields(klass); + + return result; +} + +JNIEXPORT jint JNICALL Java_issynth001_getRes(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/libIsSyntheticIssynth001.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/libIsSyntheticIssynth001.c deleted file mode 100644 index 5f9835f19ec..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/libIsSyntheticIssynth001.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "issynth001.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/libIsSyntheticIssynth001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/libIsSyntheticIssynth001.cpp new file mode 100644 index 00000000000..f98c51e27da --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/IsSynthetic/issynth001/libIsSyntheticIssynth001.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "issynth001.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/JvmtiTest.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/JvmtiTest.c deleted file mode 100644 index 3c91d3ab185..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/JvmtiTest.c +++ /dev/null @@ -1,352 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_ARG1(x) -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_ARG1(x) x -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define JVMTI_ENV_ARG JNI_ENV_ARG -#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 -#define JVMTI_ENV_PTR JNI_ENV_PTR - -#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} - -#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } - -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } - -#define THREADS_LIMIT 2000 - - -jvmtiEnv *jvmti; -jint iGlobalStatus = 0; -jthread susp_thrd[THREADS_LIMIT]; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities jvmti_caps; -jrawMonitorID jraw_monitor[20]; -int process_once = 0; - -/* forward decl */ -void print_method_name(jmethodID mid); - -int printdump = 0; - - -void debug_printf(char *fmt, ...) { - va_list args; - - va_start(args, fmt); - if (printdump) { - vprintf(fmt, args); - } - va_end(args); -} - -void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - debug_printf("VMInit event\n"); -} - -void JNICALL vmExit(jvmtiEnv *jvmti_env, JNIEnv *env) { - debug_printf("VMDeath event\n"); -} - -typedef jclass (*findLoadClass_type) (JNIEnv *env, jobject loader, jstring name); - -findLoadClass_type findLoadedClass_func; - -JNIEXPORT jclass JNICALL -my_findLoadedClass(JNIEnv *env, jobject loader, jstring name) { - const char* sname = (*env)->GetStringUTFChars(env, name, NULL); - debug_printf("Intercepted findLoadedClass, name = %s\n", sname); - return (*findLoadedClass_func)(env, loader, name); -} - -void JNICALL testNativeMethodBind(jvmtiEnv* jvmti_env, JNIEnv *jni_env, - jthread thread, jmethodID mid, void* func, void** func_ptr) { - jvmtiPhase phase; - char *mname; - char *signature; - jint ret; - - ret = (*jvmti_env)->GetPhase(jvmti_env, &phase); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetPhase %d\n", ret); - iGlobalStatus = 2; - return; - } - - if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE) - return; - - debug_printf("bind event: \n"); - print_method_name(mid); - - ret = (*jvmti_env)->GetMethodName(jvmti_env, mid, &mname, &signature, NULL); - if (ret == JVMTI_ERROR_NONE) { - if (strcmp(mname, "findLoadedClass") == 0) { - findLoadedClass_func = (findLoadClass_type)func; - *func_ptr = (void*)my_findLoadedClass; - debug_printf("REDIRECTED findLoadedClass\n"); - } - } -} - - - -void init_callbacks() { - memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); - callbacks.VMInit = vmInit; - callbacks.VMDeath = vmExit; - callbacks.NativeMethodBind = testNativeMethodBind; -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { - jint res; - - if (options && strlen(options) > 0) { - if (strstr(options, "printdump")) { - printdump = 1; - } - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res < 0) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - - /* Add capabilities */ - res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("AddCapabilities returned error", res); - - /* Enable events */ - init_callbacks(); - res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); - JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_NATIVE_METHOD_BIND,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for native method bind event returned error", res); - - return JNI_OK; -} - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_MethodBind_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { - return iGlobalStatus; -} - - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_MethodBind_JvmtiTest_CreateRawMonitor(JNIEnv * env, jclass class, jint i) { - jvmtiError ret; - char sz[128]; - - sprintf(sz, "Rawmonitor-%d",i); - debug_printf("jvmti create raw monitor \n"); - ret = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG1(jvmti),sz, &jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: ForceGarbageCollection %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_MethodBind_JvmtiTest_RawMonitorEnter(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti Raw monitor enter \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Raw monitor enter %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_MethodBind_JvmtiTest_RawMonitorExit(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti raw monitor exit \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti), jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorExit %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_MethodBind_JvmtiTest_RawMonitorWait(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti RawMonitorWait \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorWait(JVMTI_ENV_ARG1(jvmti),jraw_monitor[i],-1); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorWait %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_MethodBind_JvmtiTest_RawMonitorNotify(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti RawMonitorNotify \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorNotifyAll(JVMTI_ENV_ARG1(jvmti),jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorNotify %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT int JNICALL -Java_nsk_jvmti_unit_MethodBind_JvmtiTest_GetFrameCount(JNIEnv * env, jclass cls, jobject thr) { - jvmtiError ret; - jint count; - - debug_printf("jvmti GetFrameCount \n"); - ret = JVMTI_ENV_PTR(jvmti)->GetFrameCount(JVMTI_ENV_ARG1(jvmti), (jthread)thr, &count); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetFrameCount returned %d \n", ret); - iGlobalStatus = 2; - } - return count; -} - -void -print_method_name(jmethodID mid) { - jvmtiError ret; - jclass class; - char *mname; - char *signature; - char *clname = "unknown"; - ret = JVMTI_ENV_PTR(jvmti)->GetMethodDeclaringClass(JVMTI_ENV_ARG1(jvmti), mid, &class); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetMethodDeclaringClass %d \n", ret); - iGlobalStatus = 2; - return; - } - - ret = JVMTI_ENV_PTR(jvmti)->GetClassSignature(JVMTI_ENV_ARG1(jvmti), class, &clname, NULL); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetClassSignature %d \n", ret); - iGlobalStatus = 2; - return; - } - - ret = JVMTI_ENV_PTR(jvmti)->GetMethodName(JVMTI_ENV_ARG1(jvmti), mid, &mname, &signature, NULL); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetMethodName %d \n", ret); - iGlobalStatus = 2; - return; - } - - debug_printf("%s::%s(%s)\n", clname, mname, signature); -} - - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_MethodBind_JvmtiTest_GetStackTrace(JNIEnv * env, jclass cls, jobject thr) { - jvmtiError ret; - jvmtiFrameInfo *stack_buffer = NULL; - jint max_count = 20; - jint count; - - - ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG1(jvmti), sizeof(jvmtiFrameInfo) * max_count, (unsigned char**)&stack_buffer); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Allocate failed with %d \n", ret); - iGlobalStatus = 2; - } - - ret = JVMTI_ENV_PTR(jvmti)->GetStackTrace(JVMTI_ENV_ARG1(jvmti), thr, 0, max_count , stack_buffer, &count); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetStackTrace %d \n", ret); - iGlobalStatus = 2; - } - - ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG1(jvmti), (unsigned char *)stack_buffer); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Deallocate failed with %d \n", ret); - iGlobalStatus = 2; - } - - -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_MethodBind_JvmtiTest_SaveThreadInfo(JNIEnv * env, jclass cls, jobject oobj) { - -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/JvmtiTest.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/JvmtiTest.cpp new file mode 100644 index 00000000000..f98d7819813 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/JvmtiTest.cpp @@ -0,0 +1,352 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_ARG1(x) +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_ARG1(x) x +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define JVMTI_ENV_ARG JNI_ENV_ARG +#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 +#define JVMTI_ENV_PTR JNI_ENV_PTR + +#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} + +#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } + +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } + +#define THREADS_LIMIT 2000 + + +jvmtiEnv *jvmti; +jint iGlobalStatus = 0; +jthread susp_thrd[THREADS_LIMIT]; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities jvmti_caps; +jrawMonitorID jraw_monitor[20]; +int process_once = 0; + +/* forward decl */ +void print_method_name(jmethodID mid); + +int printdump = 0; + + +void debug_printf(const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + if (printdump) { + vprintf(fmt, args); + } + va_end(args); +} + +void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + debug_printf("VMInit event\n"); +} + +void JNICALL vmExit(jvmtiEnv *jvmti_env, JNIEnv *env) { + debug_printf("VMDeath event\n"); +} + +typedef jclass (*findLoadClass_type) (JNIEnv *env, jobject loader, jstring name); + +findLoadClass_type findLoadedClass_func; + +JNIEXPORT jclass JNICALL +my_findLoadedClass(JNIEnv *env, jobject loader, jstring name) { + const char* sname = env->GetStringUTFChars(name, NULL); + debug_printf("Intercepted findLoadedClass, name = %s\n", sname); + return (*findLoadedClass_func)(env, loader, name); +} + +void JNICALL testNativeMethodBind(jvmtiEnv* jvmti_env, JNIEnv *jni_env, + jthread thread, jmethodID mid, void* func, void** func_ptr) { + jvmtiPhase phase; + char *mname; + char *signature; + jint ret; + + ret = jvmti_env->GetPhase(&phase); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetPhase %d\n", ret); + iGlobalStatus = 2; + return; + } + + if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE) + return; + + debug_printf("bind event: \n"); + print_method_name(mid); + + ret = jvmti_env->GetMethodName(mid, &mname, &signature, NULL); + if (ret == JVMTI_ERROR_NONE) { + if (strcmp(mname, "findLoadedClass") == 0) { + findLoadedClass_func = (findLoadClass_type)func; + *func_ptr = (void*)my_findLoadedClass; + debug_printf("REDIRECTED findLoadedClass\n"); + } + } +} + + + +void init_callbacks() { + memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); + callbacks.VMInit = vmInit; + callbacks.VMDeath = vmExit; + callbacks.NativeMethodBind = testNativeMethodBind; +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { + jint res; + + if (options && strlen(options) > 0) { + if (strstr(options, "printdump")) { + printdump = 1; + } + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res < 0) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + + /* Add capabilities */ + res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("AddCapabilities returned error", res); + + /* Enable events */ + init_callbacks(); + res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); + JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_NATIVE_METHOD_BIND,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for native method bind event returned error", res); + + return JNI_OK; +} + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_MethodBind_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { + return iGlobalStatus; +} + + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_MethodBind_JvmtiTest_CreateRawMonitor(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + char sz[128]; + + sprintf(sz, "Rawmonitor-%d",i); + debug_printf("jvmti create raw monitor \n"); + ret = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti, sz), &jraw_monitor[i]); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: ForceGarbageCollection %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_MethodBind_JvmtiTest_RawMonitorEnter(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti Raw monitor enter \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, jraw_monitor[i])); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Raw monitor enter %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_MethodBind_JvmtiTest_RawMonitorExit(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti raw monitor exit \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti, jraw_monitor[i])); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorExit %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_MethodBind_JvmtiTest_RawMonitorWait(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti RawMonitorWait \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorWait(JVMTI_ENV_ARG(jvmti, jraw_monitor[i]), -1); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorWait %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_MethodBind_JvmtiTest_RawMonitorNotify(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti RawMonitorNotify \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorNotifyAll(JVMTI_ENV_ARG(jvmti, jraw_monitor[i])); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorNotify %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT int JNICALL +Java_nsk_jvmti_unit_MethodBind_JvmtiTest_GetFrameCount(JNIEnv * env, jclass cls, jobject thr) { + jvmtiError ret; + jint count; + + debug_printf("jvmti GetFrameCount \n"); + ret = JVMTI_ENV_PTR(jvmti)->GetFrameCount(JVMTI_ENV_ARG(jvmti, (jthread)thr), &count); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetFrameCount returned %d \n", ret); + iGlobalStatus = 2; + } + return count; +} + +void +print_method_name(jmethodID mid) { + jvmtiError ret; + jclass klass; + char *mname; + char *signature; + char *clname = (char*) "unknown"; + ret = JVMTI_ENV_PTR(jvmti)->GetMethodDeclaringClass(JVMTI_ENV_ARG(jvmti, mid), &klass); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetMethodDeclaringClass %d \n", ret); + iGlobalStatus = 2; + return; + } + + ret = JVMTI_ENV_PTR(jvmti)->GetClassSignature(JVMTI_ENV_ARG(jvmti, klass), &clname, NULL); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetClassSignature %d \n", ret); + iGlobalStatus = 2; + return; + } + + ret = JVMTI_ENV_PTR(jvmti)->GetMethodName(JVMTI_ENV_ARG(jvmti, mid), &mname, &signature, NULL); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetMethodName %d \n", ret); + iGlobalStatus = 2; + return; + } + + debug_printf("%s::%s(%s)\n", clname, mname, signature); +} + + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_MethodBind_JvmtiTest_GetStackTrace(JNIEnv * env, jclass cls, jobject thr) { + jvmtiError ret; + jvmtiFrameInfo *stack_buffer = NULL; + jint max_count = 20; + jint count; + + + ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG(jvmti, sizeof(jvmtiFrameInfo) * max_count), (unsigned char**)&stack_buffer); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Allocate failed with %d \n", ret); + iGlobalStatus = 2; + } + + ret = JVMTI_ENV_PTR(jvmti)->GetStackTrace(JVMTI_ENV_ARG(jvmti, thr), 0, max_count , stack_buffer, &count); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetStackTrace %d \n", ret); + iGlobalStatus = 2; + } + + ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG(jvmti, (unsigned char *)stack_buffer)); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Deallocate failed with %d \n", ret); + iGlobalStatus = 2; + } + + +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_MethodBind_JvmtiTest_SaveThreadInfo(JNIEnv * env, jclass cls, jobject oobj) { + +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/libMethodBind.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/libMethodBind.c deleted file mode 100644 index fcef2030c0e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/libMethodBind.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "JvmtiTest.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/libMethodBind.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/libMethodBind.cpp new file mode 100644 index 00000000000..fea00132b93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/MethodBind/JvmtiTest/libMethodBind.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "JvmtiTest.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/JvmtiTest.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/JvmtiTest.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/JvmtiTest.c rename to test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/JvmtiTest.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/libOnUnload.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/libOnUnload.c deleted file mode 100644 index fcef2030c0e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/libOnUnload.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "JvmtiTest.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/libOnUnload.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/libOnUnload.cpp new file mode 100644 index 00000000000..fea00132b93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/OnUnload/JvmtiTest/libOnUnload.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "JvmtiTest.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/JvmtiTest.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/JvmtiTest.c deleted file mode 100644 index 305af13b46c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/JvmtiTest.c +++ /dev/null @@ -1,351 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* This test case to test the following: - * StackTrace esp. new args - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_ARG1(x) -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_ARG1(x) x -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define JVMTI_ENV_ARG JNI_ENV_ARG -#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 -#define JVMTI_ENV_PTR JNI_ENV_PTR - -#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} - -#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } - -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } - -#define THREADS_LIMIT 2000 - - -jvmtiEnv *jvmti; -jint iGlobalStatus = 0; -jthread susp_thrd[THREADS_LIMIT]; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities jvmti_caps; -jrawMonitorID jraw_monitor[20]; - -int process_once = 0; - - - -int printdump = 0; - - -void debug_printf(char *fmt, ...) { - va_list args; - - va_start(args, fmt); - if (printdump) { - vprintf(fmt, args); - } - va_end(args); -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { - jint res; - - if (options && strlen(options) > 0) { - if (strstr(options, "printdump")) { - printdump = 1; - } - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res < 0) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - - /* Add capabilities */ - res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - return JNI_OK; -} - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_StackTrace_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { - return iGlobalStatus; -} - - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_StackTrace_JvmtiTest_CreateRawMonitor(JNIEnv * env, jclass class, jint i) { - jvmtiError ret; - char sz[128]; - - sprintf(sz, "Rawmonitor-%d",i); - debug_printf("jvmti create raw monitor \n"); - ret = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG1(jvmti),sz, &jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: ForceGarbageCollection %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_StackTrace_JvmtiTest_RawMonitorEnter(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti Raw monitor enter \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Raw monitor enter %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_StackTrace_JvmtiTest_RawMonitorExit(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti raw monitor exit \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti), jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorExit %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_StackTrace_JvmtiTest_RawMonitorWait(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti RawMonitorWait \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorWait(JVMTI_ENV_ARG1(jvmti),jraw_monitor[i],-1); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorWait %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_StackTrace_JvmtiTest_RawMonitorNotify(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti RawMonitorNotify \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorNotifyAll(JVMTI_ENV_ARG1(jvmti),jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorNotify %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT int JNICALL -Java_nsk_jvmti_unit_StackTrace_JvmtiTest_GetFrameCount(JNIEnv * env, jclass cls, jobject thr) { - jvmtiError ret; - jint count; - - debug_printf("jvmti GetFrameCount \n"); - ret = JVMTI_ENV_PTR(jvmti)->GetFrameCount(JVMTI_ENV_ARG1(jvmti), (jthread)thr, &count); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetFrameCount returned %d \n", ret); - iGlobalStatus = 2; - } - return count; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_StackTrace_JvmtiTest_GetStackTrace(JNIEnv * env, jclass cls, jobject thr) { - jvmtiError ret; - jvmtiFrameInfo *stack_buffer = NULL; - jvmtiFrameInfo *compare_buffer = NULL; - jint max_count = 20; - jint count; - jclass class; - char *mname; - char *signature; - char *clname; - int i; - int j; - - - debug_printf("jvmti GetStackTrace \n"); - - ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG1(jvmti), sizeof(jvmtiFrameInfo) * max_count, (unsigned char**)&stack_buffer); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Allocate failed with %d \n", ret); - iGlobalStatus = 2; - } - - ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG1(jvmti), sizeof(jvmtiFrameInfo) * max_count, (unsigned char**)&compare_buffer); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Allocate failed with %d \n", ret); - iGlobalStatus = 2; - } - - - ret = JVMTI_ENV_PTR(jvmti)->SuspendThread(JVMTI_ENV_ARG1(jvmti), thr); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: SuspendThread failed with %d \n", ret); - iGlobalStatus = 2; - } - - ret = JVMTI_ENV_PTR(jvmti)->GetStackTrace(JVMTI_ENV_ARG1(jvmti), thr, 0, max_count , stack_buffer, &count); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetStackTrace %d \n", ret); - iGlobalStatus = 2; - } - - for (i = 1; i < count; ++i) { - int res_count = 48343; - ret = JVMTI_ENV_PTR(jvmti)->GetStackTrace(JVMTI_ENV_ARG1(jvmti), thr, i, max_count , compare_buffer, &res_count); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetStackTrace2 %d \n", ret); - iGlobalStatus = 2; - } - if (res_count != count - i) { - printf("Error: mismatch res_count = %d, count = %d, i = %d\n", res_count, count, i); - iGlobalStatus = 2; - } - for (j = 0; j < res_count; j++) { - if (compare_buffer[j].method != stack_buffer[j+i].method) { - printf("Error: wrong method\n"); - iGlobalStatus = 2; - } - } - } - - for (i = 1; i < count; ++i) { - int res_count = 48343; - ret = JVMTI_ENV_PTR(jvmti)->GetStackTrace(JVMTI_ENV_ARG1(jvmti), thr, -i, max_count , compare_buffer, &res_count); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetStackTrace2 %d \n", ret); - iGlobalStatus = 2; - } - if (res_count != i) { - printf("Error: mismatch res_count = %d, i = %d\n", res_count, i); - iGlobalStatus = 2; - } - for (j = 0; j < res_count; j++) { - if (compare_buffer[j].method != stack_buffer[j+count-i].method) { - printf("Error: wrong neg method\n"); - iGlobalStatus = 2; - } - } - } - - debug_printf("Count = %d\n", count); - - - ret = JVMTI_ENV_PTR(jvmti)->ResumeThread(JVMTI_ENV_ARG1(jvmti), thr); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: ResumeThread failed with %d \n", ret); - iGlobalStatus = 2; - } - - debug_printf(" Java Stack trace ---\n"); - - for (i = 0; i < count; i++) { - ret = JVMTI_ENV_PTR(jvmti)->GetMethodDeclaringClass(JVMTI_ENV_ARG1(jvmti), stack_buffer[i].method, &class); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetMethodDeclaringClass %d \n", ret); - iGlobalStatus = 2; - return; - } - - ret = JVMTI_ENV_PTR(jvmti)->GetClassSignature(JVMTI_ENV_ARG1(jvmti), class, &clname, NULL); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetClassSignature %d \n", ret); - iGlobalStatus = 2; - return; - } - - ret = JVMTI_ENV_PTR(jvmti)->GetMethodName(JVMTI_ENV_ARG1(jvmti), stack_buffer[i].method, &mname, &signature, NULL); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetMethodName %d \n", ret); - iGlobalStatus = 2; - return; - } - - debug_printf("[%d] %s::%s(%s) at %lld \n",i,clname, mname, signature, stack_buffer[i].location); - - - } - - - ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG1(jvmti), (unsigned char *)stack_buffer); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Deallocate failed with %d \n", ret); - iGlobalStatus = 2; - } - - -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_StackTrace_JvmtiTest_SaveThreadInfo(JNIEnv * env, jclass cls, jobject oobj) { - -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/JvmtiTest.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/JvmtiTest.cpp new file mode 100644 index 00000000000..60158728bc1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/JvmtiTest.cpp @@ -0,0 +1,351 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* This test case to test the following: + * StackTrace esp. new args + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_ARG1(x) +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_ARG1(x) x +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define JVMTI_ENV_ARG JNI_ENV_ARG +#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 +#define JVMTI_ENV_PTR JNI_ENV_PTR + +#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} + +#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } + +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } + +#define THREADS_LIMIT 2000 + + +jvmtiEnv *jvmti; +jint iGlobalStatus = 0; +jthread susp_thrd[THREADS_LIMIT]; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities jvmti_caps; +jrawMonitorID jraw_monitor[20]; + +int process_once = 0; + + + +int printdump = 0; + + +void debug_printf(const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + if (printdump) { + vprintf(fmt, args); + } + va_end(args); +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { + jint res; + + if (options && strlen(options) > 0) { + if (strstr(options, "printdump")) { + printdump = 1; + } + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res < 0) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + + /* Add capabilities */ + res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + return JNI_OK; +} + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_StackTrace_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { + return iGlobalStatus; +} + + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_StackTrace_JvmtiTest_CreateRawMonitor(JNIEnv * env, jclass klass, jint i) { + jvmtiError ret; + char sz[128]; + + sprintf(sz, "Rawmonitor-%d",i); + debug_printf("jvmti create raw monitor \n"); + ret = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti, sz), &jraw_monitor[i]); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: ForceGarbageCollection %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_StackTrace_JvmtiTest_RawMonitorEnter(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti Raw monitor enter \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, jraw_monitor[i])); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Raw monitor enter %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_StackTrace_JvmtiTest_RawMonitorExit(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti raw monitor exit \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti, jraw_monitor[i])); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorExit %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_StackTrace_JvmtiTest_RawMonitorWait(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti RawMonitorWait \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorWait(JVMTI_ENV_ARG(jvmti, jraw_monitor[i]), -1); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorWait %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_StackTrace_JvmtiTest_RawMonitorNotify(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti RawMonitorNotify \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorNotifyAll(JVMTI_ENV_ARG(jvmti, jraw_monitor[i])); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorNotify %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT int JNICALL +Java_nsk_jvmti_unit_StackTrace_JvmtiTest_GetFrameCount(JNIEnv * env, jclass cls, jobject thr) { + jvmtiError ret; + jint count; + + debug_printf("jvmti GetFrameCount \n"); + ret = JVMTI_ENV_PTR(jvmti)->GetFrameCount(JVMTI_ENV_ARG(jvmti, (jthread)thr), &count); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetFrameCount returned %d \n", ret); + iGlobalStatus = 2; + } + return count; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_StackTrace_JvmtiTest_GetStackTrace(JNIEnv * env, jclass cls, jobject thr) { + jvmtiError ret; + jvmtiFrameInfo *stack_buffer = NULL; + jvmtiFrameInfo *compare_buffer = NULL; + jint max_count = 20; + jint count; + jclass klass; + char *mname; + char *signature; + char *clname; + int i; + int j; + + + debug_printf("jvmti GetStackTrace \n"); + + ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG(jvmti, sizeof(jvmtiFrameInfo) * max_count), (unsigned char**)&stack_buffer); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Allocate failed with %d \n", ret); + iGlobalStatus = 2; + } + + ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG(jvmti, sizeof(jvmtiFrameInfo) * max_count), (unsigned char**)&compare_buffer); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Allocate failed with %d \n", ret); + iGlobalStatus = 2; + } + + + ret = JVMTI_ENV_PTR(jvmti)->SuspendThread(JVMTI_ENV_ARG(jvmti, thr)); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: SuspendThread failed with %d \n", ret); + iGlobalStatus = 2; + } + + ret = JVMTI_ENV_PTR(jvmti)->GetStackTrace(JVMTI_ENV_ARG(jvmti, thr), 0, max_count , stack_buffer, &count); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetStackTrace %d \n", ret); + iGlobalStatus = 2; + } + + for (i = 1; i < count; ++i) { + jint res_count = 48343; + ret = JVMTI_ENV_PTR(jvmti)->GetStackTrace(JVMTI_ENV_ARG(jvmti, thr), i, max_count , compare_buffer, &res_count); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetStackTrace2 %d \n", ret); + iGlobalStatus = 2; + } + if (res_count != count - i) { + printf("Error: mismatch res_count = %d, count = %d, i = %d\n", res_count, count, i); + iGlobalStatus = 2; + } + for (j = 0; j < res_count; j++) { + if (compare_buffer[j].method != stack_buffer[j+i].method) { + printf("Error: wrong method\n"); + iGlobalStatus = 2; + } + } + } + + for (i = 1; i < count; ++i) { + jint res_count = 48343; + ret = JVMTI_ENV_PTR(jvmti)->GetStackTrace(JVMTI_ENV_ARG(jvmti, thr), -i, max_count , compare_buffer, &res_count); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetStackTrace2 %d \n", ret); + iGlobalStatus = 2; + } + if (res_count != i) { + printf("Error: mismatch res_count = %d, i = %d\n", res_count, i); + iGlobalStatus = 2; + } + for (j = 0; j < res_count; j++) { + if (compare_buffer[j].method != stack_buffer[j+count-i].method) { + printf("Error: wrong neg method\n"); + iGlobalStatus = 2; + } + } + } + + debug_printf("Count = %d\n", count); + + + ret = JVMTI_ENV_PTR(jvmti)->ResumeThread(JVMTI_ENV_ARG(jvmti, thr)); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: ResumeThread failed with %d \n", ret); + iGlobalStatus = 2; + } + + debug_printf(" Java Stack trace ---\n"); + + for (i = 0; i < count; i++) { + ret = JVMTI_ENV_PTR(jvmti)->GetMethodDeclaringClass(JVMTI_ENV_ARG(jvmti, stack_buffer[i].method), &klass); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetMethodDeclaringClass %d \n", ret); + iGlobalStatus = 2; + return; + } + + ret = JVMTI_ENV_PTR(jvmti)->GetClassSignature(JVMTI_ENV_ARG(jvmti, klass), &clname, NULL); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetClassSignature %d \n", ret); + iGlobalStatus = 2; + return; + } + + ret = JVMTI_ENV_PTR(jvmti)->GetMethodName(JVMTI_ENV_ARG(jvmti, stack_buffer[i].method), &mname, &signature, NULL); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetMethodName %d \n", ret); + iGlobalStatus = 2; + return; + } + + debug_printf("[%d] %s::%s(%s) at %lld \n",i,clname, mname, signature, stack_buffer[i].location); + + + } + + + ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG(jvmti, (unsigned char *)stack_buffer)); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Deallocate failed with %d \n", ret); + iGlobalStatus = 2; + } + + +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_StackTrace_JvmtiTest_SaveThreadInfo(JNIEnv * env, jclass cls, jobject oobj) { + +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/libStackTrace.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/libStackTrace.c deleted file mode 100644 index fcef2030c0e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/libStackTrace.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "JvmtiTest.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/libStackTrace.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/libStackTrace.cpp new file mode 100644 index 00000000000..fea00132b93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/StackTrace/JvmtiTest/libStackTrace.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "JvmtiTest.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/agentthr.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/agentthr.c deleted file mode 100644 index 8d8a097f7e3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/agentthr.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static JavaVM *jvm_ins; -static jvmtiEnv *jvmti = NULL; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jboolean agent_was_started = JNI_FALSE; -static jboolean done = JNI_FALSE; - - -jthread jthr(JNIEnv *env) { - jclass thrClass; - jmethodID cid; - jthread res; - - thrClass = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, "java/lang/Thread")); - cid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, thrClass), "", "()V"); - res = JNI_ENV_PTR(env)->NewObject(JNI_ENV_ARG(env, thrClass), cid); - return res; -} - -void JNICALL agent_start(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void *p) { - JNIEnv *env; - - if (jvmti_env != jvmti) { - printf("(agent_start) JVMTI envs don't match\n"); - result = STATUS_FAILED; - } - - JNI_ENV_PTR(jvm_ins)->GetEnv(JNI_ENV_ARG(jvm_ins, (void **) &env), - JNI_VERSION_1_2); - if (jni_env != env) { - printf("(agent_start) JNI envs don't match\n"); - result = STATUS_FAILED; - } - - if ((size_t)p != 12345) { - printf("(agent_start) args don't match\n"); - result = STATUS_FAILED; - } - done = JNI_TRUE; -} - - - -void JNICALL vm_init(jvmtiEnv* jvmti_env, JNIEnv *env, jthread thread) { - jvmtiError err; - - if (!agent_was_started) { - agent_was_started = JNI_TRUE; - - err = (*jvmti)->RunAgentThread(jvmti, jthr(env), agent_start, - (void *)999, JVMTI_THREAD_MAX_PRIORITY+1); - if (err != JVMTI_ERROR_INVALID_PRIORITY) { - printf("(RunAgentThread#1) expected JVMTI_ERROR_INVALID_PRIORITY got error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RunAgentThread(jvmti, jthr(env), agent_start, - (void *)999, JVMTI_THREAD_MIN_PRIORITY-1); - if (err != JVMTI_ERROR_INVALID_PRIORITY) { - printf("(RunAgentThread#1) expected JVMTI_ERROR_INVALID_PRIORITY got error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - err = (*jvmti)->RunAgentThread(jvmti, jthr(env), agent_start, - (void *)12345, JVMTI_THREAD_NORM_PRIORITY); - if (err != JVMTI_ERROR_NONE) { - printf("(RunAgentThread#2) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_agentthr(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_agentthr(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_agentthr(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiError err; - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - jvm_ins = jvm; - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - callbacks.VMInit = &vm_init; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Failed to enable JVMTI_EVENT_THREAD_START: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_unit_agentthr_isOver(JNIEnv *env, jclass cls) { - return done; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_agentthr_getRes(JNIEnv *env, jclass cls) { - if (!done) { - printf("agent thread has not completed\n"); - result = STATUS_FAILED; - } - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/agentthr.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/agentthr.cpp new file mode 100644 index 00000000000..936fd9269d5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/agentthr.cpp @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static JavaVM *jvm_ins; +static jvmtiEnv *jvmti = NULL; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jboolean agent_was_started = JNI_FALSE; +static jboolean done = JNI_FALSE; + + +jthread jthr(JNIEnv *env) { + jclass thrClass; + jmethodID cid; + jthread res; + + thrClass = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, "java/lang/Thread")); + cid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, thrClass), "", "()V"); + res = JNI_ENV_PTR(env)->NewObject(JNI_ENV_ARG(env, thrClass), cid); + return res; +} + +void JNICALL agent_start(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void *p) { + JNIEnv *env; + + if (jvmti_env != jvmti) { + printf("(agent_start) JVMTI envs don't match\n"); + result = STATUS_FAILED; + } + + JNI_ENV_PTR(jvm_ins)->GetEnv(JNI_ENV_ARG(jvm_ins, (void **) &env), + JNI_VERSION_1_2); + if (jni_env != env) { + printf("(agent_start) JNI envs don't match\n"); + result = STATUS_FAILED; + } + + if ((size_t)p != 12345) { + printf("(agent_start) args don't match\n"); + result = STATUS_FAILED; + } + done = JNI_TRUE; +} + + + +void JNICALL vm_init(jvmtiEnv* jvmti_env, JNIEnv *env, jthread thread) { + jvmtiError err; + + if (!agent_was_started) { + agent_was_started = JNI_TRUE; + + err = jvmti->RunAgentThread(jthr(env), agent_start, + (void *)999, JVMTI_THREAD_MAX_PRIORITY+1); + if (err != JVMTI_ERROR_INVALID_PRIORITY) { + printf("(RunAgentThread#1) expected JVMTI_ERROR_INVALID_PRIORITY got error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RunAgentThread(jthr(env), agent_start, + (void *)999, JVMTI_THREAD_MIN_PRIORITY-1); + if (err != JVMTI_ERROR_INVALID_PRIORITY) { + printf("(RunAgentThread#1) expected JVMTI_ERROR_INVALID_PRIORITY got error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + err = jvmti->RunAgentThread(jthr(env), agent_start, + (void *)12345, JVMTI_THREAD_NORM_PRIORITY); + if (err != JVMTI_ERROR_NONE) { + printf("(RunAgentThread#2) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_agentthr(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_agentthr(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_agentthr(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiError err; + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + jvm_ins = jvm; + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + callbacks.VMInit = &vm_init; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Failed to enable JVMTI_EVENT_THREAD_START: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_unit_agentthr_isOver(JNIEnv *env, jclass cls) { + return done; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_agentthr_getRes(JNIEnv *env, jclass cls) { + if (!done) { + printf("agent thread has not completed\n"); + result = STATUS_FAILED; + } + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/libagentthr.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/libagentthr.c deleted file mode 100644 index c12ae95425a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/libagentthr.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "agentthr.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/libagentthr.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/libagentthr.cpp new file mode 100644 index 00000000000..9dfcc2c7e24 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/agentthr/libagentthr.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "agentthr.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/clsldrclss00x.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/clsldrclss00x.c deleted file mode 100644 index 156efe18530..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/clsldrclss00x.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_clsldrclss00x(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_clsldrclss00x(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_clsldrclss00x(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_clsldrclss00x_check(JNIEnv *env, jclass appCls, jclass objCls) { - jvmtiError err; - jobject appClassloader; - jobject objClassloader; - jclass *classes; - jint classCount; - jboolean found; - jint i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - err = (*jvmti)->GetClassLoader(jvmti, appCls, &appClassloader); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassLoader app) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (appClassloader == NULL) { - printf("(GetClassLoader app) unexpected loader - NULL\n"); - result = STATUS_FAILED; - } - - err = (*jvmti)->GetClassLoader(jvmti, objCls, &objClassloader); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassLoader obj) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } - if (objClassloader != NULL) { - printf("(GetClassLoader obj) unexpected loader - !NULL\n"); - result = STATUS_FAILED; - } - - err = (*jvmti)->GetClassLoaderClasses(jvmti, appClassloader, &classCount, &classes); - if (err != JVMTI_ERROR_NONE) { - printf("Error (GetClassLoaderClasses app): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump) { - printf(">>> number of classes in app class loader: %d\n", classCount); - if (JNI_FALSE) { - for (i = 0; i < classCount; ++i) { - char *classSig; - jclass k = classes[i]; - err = (*jvmti)->GetClassSignature(jvmti, k, &classSig, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Error (getClassSignature): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } else { - printf(" %s\n", classSig); - err = (*jvmti)->Deallocate(jvmti, (unsigned char*)classSig); - if (err != JVMTI_ERROR_NONE) { - printf("Error (Deallocate): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - } - } - } - } - found = JNI_FALSE; - for (i = 0; i < classCount; ++i) { - jclass k = classes[i]; - if ( (*env)->IsSameObject(env, k, appCls) ) { - if (printdump) { - printf(">>> found app class in app class loader\n"); - } - found = JNI_TRUE; - break; - } - } - if (!found) { - printf("Error: didn't find app class in app class loader\n"); - result = STATUS_FAILED; - } - - err = (*jvmti)->GetClassLoaderClasses(jvmti, objClassloader, &classCount, &classes); - if (err != JVMTI_ERROR_NONE) { - printf("Error (GetClassLoaderClasses obj): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - if (printdump) { - printf(">>> number of classes in bootstrap class loader: %d\n", classCount); - } - found = JNI_FALSE; - for (i = 0; i < classCount; ++i) { - jclass k = classes[i]; - if ( (*env)->IsSameObject(env, k, objCls) ) { - if (printdump) { - printf(">>> found Object class in bootstrap class loader\n"); - } - found = JNI_TRUE; - break; - } - } - if (!found) { - printf("Error: didn't find Object class in bootstrap class loader\n"); - result = STATUS_FAILED; - } - - if (printdump) { - printf(">>> ... done\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/clsldrclss00x.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/clsldrclss00x.cpp new file mode 100644 index 00000000000..bcaafe4467a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/clsldrclss00x.cpp @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_clsldrclss00x(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_clsldrclss00x(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_clsldrclss00x(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_clsldrclss00x_check(JNIEnv *env, jclass appCls, jclass objCls) { + jvmtiError err; + jobject appClassloader; + jobject objClassloader; + jclass *classes; + jint classCount; + jboolean found; + jint i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + err = jvmti->GetClassLoader(appCls, &appClassloader); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassLoader app) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (appClassloader == NULL) { + printf("(GetClassLoader app) unexpected loader - NULL\n"); + result = STATUS_FAILED; + } + + err = jvmti->GetClassLoader(objCls, &objClassloader); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassLoader obj) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } + if (objClassloader != NULL) { + printf("(GetClassLoader obj) unexpected loader - !NULL\n"); + result = STATUS_FAILED; + } + + err = jvmti->GetClassLoaderClasses(appClassloader, &classCount, &classes); + if (err != JVMTI_ERROR_NONE) { + printf("Error (GetClassLoaderClasses app): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump) { + printf(">>> number of classes in app class loader: %d\n", classCount); + if (JNI_FALSE) { + for (i = 0; i < classCount; ++i) { + char *classSig; + jclass k = classes[i]; + err = jvmti->GetClassSignature(k, &classSig, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Error (getClassSignature): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } else { + printf(" %s\n", classSig); + err = jvmti->Deallocate((unsigned char*)classSig); + if (err != JVMTI_ERROR_NONE) { + printf("Error (Deallocate): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + } + } + } + } + found = JNI_FALSE; + for (i = 0; i < classCount; ++i) { + jclass k = classes[i]; + if ( env->IsSameObject(k, appCls) ) { + if (printdump) { + printf(">>> found app class in app class loader\n"); + } + found = JNI_TRUE; + break; + } + } + if (!found) { + printf("Error: didn't find app class in app class loader\n"); + result = STATUS_FAILED; + } + + err = jvmti->GetClassLoaderClasses(objClassloader, &classCount, &classes); + if (err != JVMTI_ERROR_NONE) { + printf("Error (GetClassLoaderClasses obj): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + if (printdump) { + printf(">>> number of classes in bootstrap class loader: %d\n", classCount); + } + found = JNI_FALSE; + for (i = 0; i < classCount; ++i) { + jclass k = classes[i]; + if ( env->IsSameObject(k, objCls) ) { + if (printdump) { + printf(">>> found Object class in bootstrap class loader\n"); + } + found = JNI_TRUE; + break; + } + } + if (!found) { + printf("Error: didn't find Object class in bootstrap class loader\n"); + result = STATUS_FAILED; + } + + if (printdump) { + printf(">>> ... done\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/libclsldrclss00x.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/libclsldrclss00x.c deleted file mode 100644 index 8f032454b2b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/libclsldrclss00x.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "clsldrclss00x.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/libclsldrclss00x.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/libclsldrclss00x.cpp new file mode 100644 index 00000000000..766281bc325 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/clsldrclss00x/libclsldrclss00x.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "clsldrclss00x.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/JvmtiTest.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/JvmtiTest.c deleted file mode 100644 index 991864054bb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/JvmtiTest.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define STATUS_FAILED 2 -#define PASSED 0 - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; -static jvmtiEventCallbacks callbacks; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; - -const char* CLASS_NAME = "nsk/jvmti/unit/events/redefineCFLH/JvmtiTestr"; - -void JNICALL -VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - if (printdump == JNI_TRUE) { - printf("VMInit event received\n"); - } -} - -void JNICALL -ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *env, - jclass redefined_class, - jobject loader, const char* name, - jobject protection_domain, - jint class_data_len, - const unsigned char* class_data, - jint* new_class_data_len, - unsigned char** new_class_data) { - - jvmtiError err; - int len = sizeof(jint); - char *sig; - char *gen; - - if (name != NULL && (strcmp(name, CLASS_NAME) == 0)) { - if (printdump == JNI_TRUE) { - printf("Received class file load hook event for class %s\n", name); - } - - if (redefined_class != NULL) { - err = (*jvmti)->GetClassSignature(jvmti, redefined_class, &sig, &gen); - if (err != JVMTI_ERROR_NONE) { - printf("(GetClassSignature) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else if (printdump == JNI_TRUE) { - printf("redefined class name signature is %s\n", sig); - } - } - - err = (*jvmti)->Allocate(jvmti, class_data_len, new_class_data); - if (err != JVMTI_ERROR_NONE) { - printf("(Allocate) unexpected error: %s (%d)\n", - TranslateError(err), err); - result = STATUS_FAILED; - } else { - *new_class_data_len = class_data_len; - memcpy(*new_class_data, class_data, class_data_len); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), - JVMTI_VERSION_1_1)) != JNI_OK) { - printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); - return JNI_ERR; - } - - err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->AddCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(AddCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - err = (*jvmti)->GetCapabilities(jvmti, &caps); - if (err != JVMTI_ERROR_NONE) { - printf("(GetCapabilities) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if (!caps.can_redefine_classes) { - printf("Warning: RedefineClasses is not implemented\n"); - } - - callbacks.VMInit = &VMInit; - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - printf("(SetEventCallbacks) unexpected error: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if ((err = ((*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_VM_INIT, NULL))) != JVMTI_ERROR_NONE) { - printf("Failed to enable event JVMTI_EVENT_VM_INIT: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - if ((err = ((*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, - JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) != JVMTI_ERROR_NONE) { - printf("Failed to enable event JVMTI_EVENT_CLASS_FILE_LOAD_HOOK: %s (%d)\n", - TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_events_redefineCFLH_JvmtiTest_makeRedefinition(JNIEnv *env, - jclass cls, jint fl, jclass redefCls, jbyteArray classBytes) { - jvmtiClassDefinition classDef; - jvmtiError err; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - if (!caps.can_redefine_classes) { - return PASSED; - } - -/* filling the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = - JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); - classDef.class_bytes = (unsigned char *) - JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), - NULL); - - if (fl == 2) { - printf(">>>>>>>> Invoke RedefineClasses():\n"); - printf("\tnew class byte count=%d\n", classDef.class_byte_count); - } - err = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if (err != JVMTI_ERROR_NONE) { - printf("%s: Failed to call RedefineClasses():\n", __FILE__); - printf("\tthe function returned error %d: %s\n", - err, TranslateError(err)); - printf("\tFor more info about this error see the JVMTI spec.\n"); - return STATUS_FAILED; - } - if (fl == 2) - printf("<<<<<<<< RedefineClasses() is successfully done\n"); - - return PASSED; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_events_redefineCFLH_JvmtiTest_GetResult(JNIEnv *env, jclass cls) { - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/JvmtiTest.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/JvmtiTest.cpp new file mode 100644 index 00000000000..43ac017898f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/JvmtiTest.cpp @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define STATUS_FAILED 2 +#define PASSED 0 + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; +static jvmtiEventCallbacks callbacks; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; + +const char* CLASS_NAME = "nsk/jvmti/unit/events/redefineCFLH/JvmtiTestr"; + +void JNICALL +VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + if (printdump == JNI_TRUE) { + printf("VMInit event received\n"); + } +} + +void JNICALL +ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *env, + jclass redefined_class, + jobject loader, const char* name, + jobject protection_domain, + jint class_data_len, + const unsigned char* class_data, + jint* new_class_data_len, + unsigned char** new_class_data) { + + jvmtiError err; + int len = sizeof(jint); + char *sig; + char *gen; + + if (name != NULL && (strcmp(name, CLASS_NAME) == 0)) { + if (printdump == JNI_TRUE) { + printf("Received class file load hook event for class %s\n", name); + } + + if (redefined_class != NULL) { + err = jvmti->GetClassSignature(redefined_class, &sig, &gen); + if (err != JVMTI_ERROR_NONE) { + printf("(GetClassSignature) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else if (printdump == JNI_TRUE) { + printf("redefined class name signature is %s\n", sig); + } + } + + err = jvmti->Allocate(class_data_len, new_class_data); + if (err != JVMTI_ERROR_NONE) { + printf("(Allocate) unexpected error: %s (%d)\n", + TranslateError(err), err); + result = STATUS_FAILED; + } else { + *new_class_data_len = class_data_len; + memcpy(*new_class_data, class_data, class_data_len); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti), + JVMTI_VERSION_1_1)) != JNI_OK) { + printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); + return JNI_ERR; + } + + err = jvmti->GetPotentialCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->AddCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(AddCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + err = jvmti->GetCapabilities(&caps); + if (err != JVMTI_ERROR_NONE) { + printf("(GetCapabilities) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if (!caps.can_redefine_classes) { + printf("Warning: RedefineClasses is not implemented\n"); + } + + callbacks.VMInit = &VMInit; + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + printf("(SetEventCallbacks) unexpected error: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if ((err = (jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_VM_INIT, NULL))) != JVMTI_ERROR_NONE) { + printf("Failed to enable event JVMTI_EVENT_VM_INIT: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + if ((err = (jvmti->SetEventNotificationMode(JVMTI_ENABLE, + JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) != JVMTI_ERROR_NONE) { + printf("Failed to enable event JVMTI_EVENT_CLASS_FILE_LOAD_HOOK: %s (%d)\n", + TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_events_redefineCFLH_JvmtiTest_makeRedefinition(JNIEnv *env, + jclass cls, jint fl, jclass redefCls, jbyteArray classBytes) { + jvmtiClassDefinition classDef; + jvmtiError err; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + if (!caps.can_redefine_classes) { + return PASSED; + } + +/* filling the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = + JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes)); + classDef.class_bytes = (unsigned char *) + JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes), + NULL); + + if (fl == 2) { + printf(">>>>>>>> Invoke RedefineClasses():\n"); + printf("\tnew class byte count=%d\n", classDef.class_byte_count); + } + err = jvmti->RedefineClasses(1, &classDef); + if (err != JVMTI_ERROR_NONE) { + printf("%s: Failed to call RedefineClasses():\n", __FILE__); + printf("\tthe function returned error %d: %s\n", + err, TranslateError(err)); + printf("\tFor more info about this error see the JVMTI spec.\n"); + return STATUS_FAILED; + } + if (fl == 2) + printf("<<<<<<<< RedefineClasses() is successfully done\n"); + + return PASSED; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_events_redefineCFLH_JvmtiTest_GetResult(JNIEnv *env, jclass cls) { + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/libredefineCFLH.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/libredefineCFLH.c deleted file mode 100644 index fcef2030c0e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/libredefineCFLH.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "JvmtiTest.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/libredefineCFLH.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/libredefineCFLH.cpp new file mode 100644 index 00000000000..fea00132b93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/events/redefineCFLH/JvmtiTest/libredefineCFLH.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "JvmtiTest.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/extmech.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/extmech.c deleted file mode 100644 index 8b303105377..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/extmech.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti; -static jint result = PASSED; - -/* - * Class: nsk.jvmti.unit.extmech - * Method: isClassUnloadingEnabled - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL -Java_nsk_jvmti_unit_extmech_isClassUnloadingEnabled - (JNIEnv *env, jclass cls) -{ - jint count, i; - jvmtiExtensionFunctionInfo* ext_funcs; - jvmtiError err; - - err = (*jvmti)->GetExtensionFunctions(jvmti, &count, &ext_funcs); - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "GetExtensionFunctions failed: %d\n", err); - result = STATUS_FAILED; - return JNI_FALSE; - } - - for (i=0; iGetExtensionEvents(jvmti, &count, &ext_events); - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "GetExtensionEvents failed: %d\n", err); - result = STATUS_FAILED; - return; - } - - for (i=0; iSetExtensionEventCallback(jvmti, ext_events[i].extension_event_index, - enable ? (jvmtiExtensionEvent)ClassUnload : NULL); - - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "SetExtenionEventCallback failed: %d\n", err); - result = STATUS_FAILED; - } else { - char* id = ext_events[i].id; - if (enable) { - fprintf(stderr, "%s callback enabled\n", id); - } else { - fprintf(stderr, "%s callback disabled\n", id); - } - } - return; - } - } -} - -/* - * Class: nsk.jvmti.unit.extmech - * Method: dumpExtensions - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_extmech_dumpExtensions - (JNIEnv *env, jclass cls) -{ - jint count, i, j; - jvmtiExtensionFunctionInfo* ext_funcs; - jvmtiExtensionEventInfo* ext_events; - jvmtiError err; - - err = (*jvmti)->GetExtensionFunctions(jvmti, &count, &ext_funcs); - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "GetExtensionFunctions failed: %d\n", err); - result = STATUS_FAILED; - return; - } - - fprintf(stderr, "Extension functions:\n"); - for (i=0; iGetExtensionEvents(jvmti, &count, &ext_events); - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "GetExtensionEvents failed: %d\n", err); - result = STATUS_FAILED; - return; - } - - fprintf(stderr, "Extension events:\n"); - for (i=0; iGetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_1); - if (rc != JNI_OK) { - fprintf(stderr, "Unable to create jvmtiEnv, GetEnv failed, error=%d\n", rc); - return JNI_ERR; - } - - return JNI_OK; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/extmech.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/extmech.cpp new file mode 100644 index 00000000000..65c88630131 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/extmech.cpp @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti; +static jint result = PASSED; + +/* + * Class: nsk.jvmti.unit.extmech + * Method: isClassUnloadingEnabled + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL +Java_nsk_jvmti_unit_extmech_isClassUnloadingEnabled + (JNIEnv *env, jclass cls) +{ + jint count, i; + jvmtiExtensionFunctionInfo* ext_funcs; + jvmtiError err; + + err = jvmti->GetExtensionFunctions(&count, &ext_funcs); + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "GetExtensionFunctions failed: %d\n", err); + result = STATUS_FAILED; + return JNI_FALSE; + } + + for (i=0; iGetExtensionEvents(&count, &ext_events); + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "GetExtensionEvents failed: %d\n", err); + result = STATUS_FAILED; + return; + } + + for (i=0; iSetExtensionEventCallback(ext_events[i].extension_event_index, + enable ? (jvmtiExtensionEvent)ClassUnload : NULL); + + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "SetExtenionEventCallback failed: %d\n", err); + result = STATUS_FAILED; + } else { + char* id = ext_events[i].id; + if (enable) { + fprintf(stderr, "%s callback enabled\n", id); + } else { + fprintf(stderr, "%s callback disabled\n", id); + } + } + return; + } + } +} + +/* + * Class: nsk.jvmti.unit.extmech + * Method: dumpExtensions + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_extmech_dumpExtensions + (JNIEnv *env, jclass cls) +{ + jint count, i, j; + jvmtiExtensionFunctionInfo* ext_funcs; + jvmtiExtensionEventInfo* ext_events; + jvmtiError err; + + err = jvmti->GetExtensionFunctions(&count, &ext_funcs); + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "GetExtensionFunctions failed: %d\n", err); + result = STATUS_FAILED; + return; + } + + fprintf(stderr, "Extension functions:\n"); + for (i=0; iGetExtensionEvents(&count, &ext_events); + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "GetExtensionEvents failed: %d\n", err); + result = STATUS_FAILED; + return; + } + + fprintf(stderr, "Extension events:\n"); + for (i=0; iGetEnv((void **)&jvmti, JVMTI_VERSION_1_1); + if (rc != JNI_OK) { + fprintf(stderr, "Unable to create jvmtiEnv, GetEnv failed, error=%d\n", rc); + return JNI_ERR; + } + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/libextmech.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/libextmech.c deleted file mode 100644 index 8c9ec8d983c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/libextmech.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "extmech.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/libextmech.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/libextmech.cpp new file mode 100644 index 00000000000..bdbf6808d3c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extmech/libextmech.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "extmech.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/JvmtiTest.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/JvmtiTest.c deleted file mode 100644 index 73c99eb789e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/JvmtiTest.c +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_ARG1(x) -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_ARG1(x) x -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define JVMTI_ENV_ARG JNI_ENV_ARG -#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 -#define JVMTI_ENV_PTR JNI_ENV_PTR - -#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} - -#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } - -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } - -static jvmtiEnv *jvmti; -static jint iGlobalStatus = 0; -static jvmtiCapabilities jvmti_caps; -static jvmtiEventCallbacks callbacks; -static int boot_class_count = 0; - -static const char* BOOT_CLASS = - "nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/Boot"; - -static const char* CLASSPATH = "java.class.path"; - -static char segment[3000] = "."; - -int printdump = 0; - - -void debug_printf(char *fmt, ...) { - va_list args; - - va_start(args, fmt); - if (printdump) { - vprintf(fmt, args); - } - va_end(args); -} - - -/* - * Check that it is not possible to add to the boot class path during the Start phase - */ -void JNICALL -vmStart(jvmtiEnv *jvmti, JNIEnv* jni) { - jvmtiError res; - - debug_printf("VMStart event done\n"); - - res = JVMTI_ENV_PTR(jvmti)->AddToBootstrapClassLoaderSearch(JVMTI_ENV_ARG(jvmti, segment)); - JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID("VMStart: AddToBootstrapClassLoaderSearch returned error ", - res, JVMTI_ERROR_WRONG_PHASE); -} - -/* - * Check that it is possible to add to the boot class path before VMDeath event return. - */ -void JNICALL -vmDeath(jvmtiEnv *jvmti, JNIEnv* jni) { - jvmtiError res; - - debug_printf("VMDeath event done\n"); - - res = JVMTI_ENV_PTR(jvmti)->AddToBootstrapClassLoaderSearch(JVMTI_ENV_ARG(jvmti, segment)); - /* In the live phase, anything other than an existing JAR file is an invalid path. - So, check that JVMTI_ERROR_ILLEGAL_ARGUMENT error is thrown. - */ - JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID("VMDeath: AddToBootstrapClassLoaderSearch returned error ", - res, JVMTI_ERROR_ILLEGAL_ARGUMENT); -} - -/* - * Check that it is possible to add to the boot class path during the Live phase - */ -void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - jvmtiError res; - - debug_printf("VMInit event done\n"); - - res = JVMTI_ENV_PTR(jvmti)->AddToBootstrapClassLoaderSearch(JVMTI_ENV_ARG(jvmti, segment)); - /* In the live phase, anything other than an existing JAR file is an invalid path. - So, check that JVMTI_ERROR_ILLEGAL_ARGUMENT error is thrown. - */ - JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID("VMInit: AddToBootstrapClassLoaderSearch returned error ", - res, JVMTI_ERROR_ILLEGAL_ARGUMENT); -} - -/* - * Check that it is not possible to add to the boot class path during the Primordial phase - */ -void JNICALL -NativeMethodBind(jvmtiEnv* jvmti, JNIEnv *jni, - jthread thread, jmethodID method, - void* address, void** new_address_ptr) { - jvmtiPhase phase; - jvmtiError res; - - res = JVMTI_ENV_PTR(jvmti)->GetPhase(JVMTI_ENV_ARG(jvmti, &phase)); - JVMTI_ERROR_CHECK_VOID("GetPhase returned error", res); - - if (phase == JVMTI_PHASE_PRIMORDIAL) { - debug_printf("Primordial phase\n"); - - res = JVMTI_ENV_PTR(jvmti)->AddToBootstrapClassLoaderSearch(JVMTI_ENV_ARG(jvmti, segment)); - JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID("Primordial: AddToBootstrapClassLoaderSearch returned error ", - res, JVMTI_ERROR_WRONG_PHASE); - } -} - - -void JNICALL -classFileLoadEvent(jvmtiEnv *jvmti_env, JNIEnv *env, - jclass redefined_class, - jobject loader,const char* name, - jobject protection_domain, - jint class_data_len, - const unsigned char* class_data, - jint* new_class_data_len, - unsigned char** new_class_data) { - - if (name != NULL && (strcmp(name, BOOT_CLASS) == 0)) { - debug_printf("Received class file load hook event for class: \n\t%s\n", - name); - debug_printf("Received class loader: 0x%p \n", loader); - /* Check to make sure Boot class got loaded from bootstrap class path.*/ - - if (loader == NULL) { - boot_class_count++; - } - } -} - - -void init_callbacks() { - memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); - - callbacks.VMInit = vmInit; - callbacks.VMStart = vmStart; - callbacks.VMDeath = vmDeath; - callbacks.NativeMethodBind = NativeMethodBind; - callbacks.ClassFileLoadHook = classFileLoadEvent; -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { - jint res; - char *idx; - - debug_printf("Agent_OnLoad event done\n"); - - if (options && strlen(options) > 0) { - if (strstr(options, "printdump")) { - printdump = 1; - } - - strncpy(segment, options, (size_t) sizeof(segment)/sizeof(char)); - segment[(size_t) sizeof(segment)/sizeof(char) - 1] = 0; - idx = strchr(segment, ','); - if (idx != NULL) *idx = 0; - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res < 0) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - /* Add capabilities */ - res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetAddCapabilities returned error", res); - - - /* Enable events */ - init_callbacks(); - res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); - JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_START,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_START returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_NATIVE_METHOD_BIND,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for NATIVE_METHOD_BIND returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_DEATH returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode CLASS_FILE_LOAD_HOOK returned error", res); - - strcat(segment, "/newclass"); - debug_printf("segment=%s\n", segment); - res = JVMTI_ENV_PTR(jvmti)->AddToBootstrapClassLoaderSearch(JVMTI_ENV_ARG(jvmti, segment)); - JVMTI_ERROR_CHECK("AddToBootStrapClassLoaderSearch returned error", res); - - return JNI_OK; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_functions_AddToBootstrapClassLoaderSearch_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { - - if (boot_class_count != 1) { - printf("Error: no ClassFileLoadHook event for Boot class loaded from bootstrap class path\n"); - iGlobalStatus = 2; - } - return iGlobalStatus; -} - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/JvmtiTest.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/JvmtiTest.cpp new file mode 100644 index 00000000000..7048a9644e7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/JvmtiTest.cpp @@ -0,0 +1,274 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_ARG1(x) +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_ARG1(x) x +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define JVMTI_ENV_ARG JNI_ENV_ARG +#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 +#define JVMTI_ENV_PTR JNI_ENV_PTR + +#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} + +#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } + +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } + +static jvmtiEnv *jvmti; +static jint iGlobalStatus = 0; +static jvmtiCapabilities jvmti_caps; +static jvmtiEventCallbacks callbacks; +static int boot_class_count = 0; + +static const char* BOOT_CLASS = + "nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/Boot"; + +static const char* CLASSPATH = "java.class.path"; + +static char segment[3000] = "."; + +int printdump = 0; + + +void debug_printf(const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + if (printdump) { + vprintf(fmt, args); + } + va_end(args); +} + + +/* + * Check that it is not possible to add to the boot class path during the Start phase + */ +void JNICALL +vmStart(jvmtiEnv *jvmti, JNIEnv* jni) { + jvmtiError res; + + debug_printf("VMStart event done\n"); + + res = JVMTI_ENV_PTR(jvmti)->AddToBootstrapClassLoaderSearch(JVMTI_ENV_ARG(jvmti, segment)); + JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID("VMStart: AddToBootstrapClassLoaderSearch returned error ", + res, JVMTI_ERROR_WRONG_PHASE); +} + +/* + * Check that it is possible to add to the boot class path before VMDeath event return. + */ +void JNICALL +vmDeath(jvmtiEnv *jvmti, JNIEnv* jni) { + jvmtiError res; + + debug_printf("VMDeath event done\n"); + + res = JVMTI_ENV_PTR(jvmti)->AddToBootstrapClassLoaderSearch(JVMTI_ENV_ARG(jvmti, segment)); + /* In the live phase, anything other than an existing JAR file is an invalid path. + So, check that JVMTI_ERROR_ILLEGAL_ARGUMENT error is thrown. + */ + JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID("VMDeath: AddToBootstrapClassLoaderSearch returned error ", + res, JVMTI_ERROR_ILLEGAL_ARGUMENT); +} + +/* + * Check that it is possible to add to the boot class path during the Live phase + */ +void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + jvmtiError res; + + debug_printf("VMInit event done\n"); + + res = JVMTI_ENV_PTR(jvmti)->AddToBootstrapClassLoaderSearch(JVMTI_ENV_ARG(jvmti, segment)); + /* In the live phase, anything other than an existing JAR file is an invalid path. + So, check that JVMTI_ERROR_ILLEGAL_ARGUMENT error is thrown. + */ + JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID("VMInit: AddToBootstrapClassLoaderSearch returned error ", + res, JVMTI_ERROR_ILLEGAL_ARGUMENT); +} + +/* + * Check that it is not possible to add to the boot class path during the Primordial phase + */ +void JNICALL +NativeMethodBind(jvmtiEnv* jvmti, JNIEnv *jni, + jthread thread, jmethodID method, + void* address, void** new_address_ptr) { + jvmtiPhase phase; + jvmtiError res; + + res = JVMTI_ENV_PTR(jvmti)->GetPhase(JVMTI_ENV_ARG(jvmti, &phase)); + JVMTI_ERROR_CHECK_VOID("GetPhase returned error", res); + + if (phase == JVMTI_PHASE_PRIMORDIAL) { + debug_printf("Primordial phase\n"); + + res = JVMTI_ENV_PTR(jvmti)->AddToBootstrapClassLoaderSearch(JVMTI_ENV_ARG(jvmti, segment)); + JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID("Primordial: AddToBootstrapClassLoaderSearch returned error ", + res, JVMTI_ERROR_WRONG_PHASE); + } +} + + +void JNICALL +classFileLoadEvent(jvmtiEnv *jvmti_env, JNIEnv *env, + jclass redefined_class, + jobject loader,const char* name, + jobject protection_domain, + jint class_data_len, + const unsigned char* class_data, + jint* new_class_data_len, + unsigned char** new_class_data) { + + if (name != NULL && (strcmp(name, BOOT_CLASS) == 0)) { + debug_printf("Received class file load hook event for class: \n\t%s\n", + name); + debug_printf("Received class loader: 0x%p \n", loader); + /* Check to make sure Boot class got loaded from bootstrap class path.*/ + + if (loader == NULL) { + boot_class_count++; + } + } +} + + +void init_callbacks() { + memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); + + callbacks.VMInit = vmInit; + callbacks.VMStart = vmStart; + callbacks.VMDeath = vmDeath; + callbacks.NativeMethodBind = NativeMethodBind; + callbacks.ClassFileLoadHook = classFileLoadEvent; +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { + jint res; + char *idx; + + debug_printf("Agent_OnLoad event done\n"); + + if (options && strlen(options) > 0) { + if (strstr(options, "printdump")) { + printdump = 1; + } + + strncpy(segment, options, (size_t) sizeof(segment)/sizeof(char)); + segment[(size_t) sizeof(segment)/sizeof(char) - 1] = 0; + idx = strchr(segment, ','); + if (idx != NULL) *idx = 0; + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res < 0) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + /* Add capabilities */ + res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetAddCapabilities returned error", res); + + + /* Enable events */ + init_callbacks(); + res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); + JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_START,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_START returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_NATIVE_METHOD_BIND,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for NATIVE_METHOD_BIND returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_DEATH returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode CLASS_FILE_LOAD_HOOK returned error", res); + + strcat(segment, "/newclass"); + debug_printf("segment=%s\n", segment); + res = JVMTI_ENV_PTR(jvmti)->AddToBootstrapClassLoaderSearch(JVMTI_ENV_ARG(jvmti, segment)); + JVMTI_ERROR_CHECK("AddToBootStrapClassLoaderSearch returned error", res); + + return JNI_OK; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_functions_AddToBootstrapClassLoaderSearch_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { + + if (boot_class_count != 1) { + printf("Error: no ClassFileLoadHook event for Boot class loaded from bootstrap class path\n"); + iGlobalStatus = 2; + } + return iGlobalStatus; +} + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/libAddToBootstrapClassLoaderSearch.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/libAddToBootstrapClassLoaderSearch.c deleted file mode 100644 index fcef2030c0e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/libAddToBootstrapClassLoaderSearch.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "JvmtiTest.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/libAddToBootstrapClassLoaderSearch.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/libAddToBootstrapClassLoaderSearch.cpp new file mode 100644 index 00000000000..fea00132b93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/AddToBootstrapClassLoaderSearch/JvmtiTest/libAddToBootstrapClassLoaderSearch.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "JvmtiTest.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/JvmtiTest.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/JvmtiTest.c deleted file mode 100644 index d6b72486160..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/JvmtiTest.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_ARG1(x) -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_ARG1(x) x -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define JVMTI_ENV_ARG JNI_ENV_ARG -#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 -#define JVMTI_ENV_PTR JNI_ENV_PTR - -#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf(" %d\n",res); return res;} -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} - -#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf(" %d\n",res); iGlobalStatus = 2; } - -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf(" unexpected error %d\n",res); iGlobalStatus = 2; } - - - -jvmtiEnv *jvmti; -jint iGlobalStatus = 0; -static jvmtiCapabilities jvmti_caps; -static jvmtiEventCallbacks callbacks; - - -int printdump = 0; - - -void debug_printf(char *fmt, ...) { - va_list args; - - va_start(args, fmt); - if (printdump) { - vprintf(fmt, args); - } - va_end(args); -} - - -void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - jvmtiError res; - debug_printf("VMInit event received\n"); - res = JVMTI_ENV_PTR(jvmti_env)->DisposeEnvironment(JVMTI_ENV_ARG1(jvmti_env)); - JVMTI_ERROR_CHECK_VOID("DisposeEnvironment returned error", res); -} - - -void init_callbacks() { - - callbacks.VMInit = vmInit; - -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { - jint res; - jint count; - char **properties; - int i; - - if (options && strlen(options) > 0) { - if (strstr(options, "printdump")) { - printdump = 1; - } - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res < 0) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - /* Enable event call backs. */ - init_callbacks(); - res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); - JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); - - /* Add capabilities */ - res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetAddCapabilities returned error", res); - - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->GetSystemProperties(JVMTI_ENV_ARG(jvmti, &count), &properties); - - JVMTI_ERROR_CHECK("GetSystemProperties returned error", res); - - for (i=0; i< count; i++) { - char *value; - - res = JVMTI_ENV_PTR(jvmti)->GetSystemProperty(JVMTI_ENV_ARG(jvmti, (const char *)properties[i]), &value); - JVMTI_ERROR_CHECK("GetSystemProperty returned error", res); - debug_printf(" %s %s \n", properties[i], value); - - res = JVMTI_ENV_PTR(jvmti)->SetSystemProperty(JVMTI_ENV_ARG(jvmti, (const char *)properties[i]), value); - debug_printf("SetSystemProperty returned error %d\n", res); - - } - - return JNI_OK; -} - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_functions_Dispose_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { - return iGlobalStatus; -} - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/JvmtiTest.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/JvmtiTest.cpp new file mode 100644 index 00000000000..e55de6d7855 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/JvmtiTest.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_ARG1(x) +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_ARG1(x) x +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define JVMTI_ENV_ARG JNI_ENV_ARG +#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 +#define JVMTI_ENV_PTR JNI_ENV_PTR + +#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf(" %d\n",res); return res;} +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} + +#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf(" %d\n",res); iGlobalStatus = 2; } + +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf(" unexpected error %d\n",res); iGlobalStatus = 2; } + + + +jvmtiEnv *jvmti; +jint iGlobalStatus = 0; +static jvmtiCapabilities jvmti_caps; +static jvmtiEventCallbacks callbacks; + + +int printdump = 0; + + +void debug_printf(const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + if (printdump) { + vprintf(fmt, args); + } + va_end(args); +} + + +void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + jvmtiError res; + debug_printf("VMInit event received\n"); + res = JVMTI_ENV_PTR(jvmti_env)->DisposeEnvironment(JVMTI_ENV_ARG1(jvmti_env)); + JVMTI_ERROR_CHECK_VOID("DisposeEnvironment returned error", res); +} + + +void init_callbacks() { + + callbacks.VMInit = vmInit; + +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { + jint res; + jint count; + char **properties; + int i; + + if (options && strlen(options) > 0) { + if (strstr(options, "printdump")) { + printdump = 1; + } + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res < 0) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + /* Enable event call backs. */ + init_callbacks(); + res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); + JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); + + /* Add capabilities */ + res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetAddCapabilities returned error", res); + + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->GetSystemProperties(JVMTI_ENV_ARG(jvmti, &count), &properties); + + JVMTI_ERROR_CHECK("GetSystemProperties returned error", res); + + for (i=0; i< count; i++) { + char *value; + + res = JVMTI_ENV_PTR(jvmti)->GetSystemProperty(JVMTI_ENV_ARG(jvmti, (const char *)properties[i]), &value); + JVMTI_ERROR_CHECK("GetSystemProperty returned error", res); + debug_printf(" %s %s \n", properties[i], value); + + res = JVMTI_ENV_PTR(jvmti)->SetSystemProperty(JVMTI_ENV_ARG(jvmti, (const char *)properties[i]), value); + debug_printf("SetSystemProperty returned error %d\n", res); + + } + + return JNI_OK; +} + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_functions_Dispose_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { + return iGlobalStatus; +} + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/libDispose.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/libDispose.c deleted file mode 100644 index fcef2030c0e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/libDispose.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "JvmtiTest.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/libDispose.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/libDispose.cpp new file mode 100644 index 00000000000..fea00132b93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/Dispose/JvmtiTest/libDispose.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "JvmtiTest.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/gc.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/gc.c deleted file mode 100644 index debfb4638a3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/gc.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_ARG1(x) -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_ARG1(x) x -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define JVMTI_ENV_ARG JNI_ENV_ARG -#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 -#define JVMTI_ENV_PTR JNI_ENV_PTR - -#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} -#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } - -#define THREADS_LIMIT 8 - -jrawMonitorID access_lock; -jvmtiEnv *jvmti; -jint iGlobalStatus = 0; -jthread susp_thrd[THREADS_LIMIT]; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities jvmti_caps; - - -int printdump = 0; -int gc_start_count =0; -int gc_finish_count =0; - - -void debug_printf(char *fmt, ...) { - va_list args; - - va_start(args, fmt); - if (printdump) { - vprintf(fmt, args); - } - va_end(args); -} - - -void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - - debug_printf("VMInit event done\n"); -} - -void JNICALL vmExit(jvmtiEnv *jvmti_env, JNIEnv *env) { - debug_printf("------------ JVMTI_EVENT_VM_DEATH ------------\n"); - debug_printf("JVMTI_EVENT_GARBAGE_COLLECTION_START count: %d\n",gc_start_count); - debug_printf("JVMTI_EVENT_GARBAGE_COLLECTION_FINISH count: %d\n",gc_finish_count); -} - -void JNICALL gc_start(jvmtiEnv *jvmti_env) { - - gc_start_count++; - debug_printf("Event: JVMTI_EVENT_GC_START\n"); -} - -void JNICALL gc_finish(jvmtiEnv *jvmti_env) { - - gc_finish_count++; - debug_printf("Event: JVMTI_EVENT_GC_FINISH\n"); -} - - -void init_callbacks() { - memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); - callbacks.VMInit = vmInit; - callbacks.VMDeath = vmExit; - callbacks.GarbageCollectionStart = gc_start; - callbacks.GarbageCollectionFinish = gc_finish; -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_gc(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_gc(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_gc(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { - jint res; - - if (options && strlen(options) > 0) { - if (strstr(options, "printdump")) { - printdump = 1; - } - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res < 0) { - debug_printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - /* Create data access lock */ - res = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti,"_access_lock"),&access_lock); - JVMTI_ERROR_CHECK("RawMonitorEnter in monitor_contended_entered failed with error code ", res); - - - /* Add capabilities */ - res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); - - /* Enable events */ - init_callbacks(); - res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); - JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_GARBAGE_COLLECTION_START,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for gc start returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_GARBAGE_COLLECTION_FINISH,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for gc finish returned error", res); - - return JNI_OK; -} - - - - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_ForceGarbageCollection_gc_checkGCStart(JNIEnv * env, jclass cls) { - if (gc_start_count == 0) { - printf("Error: JVMTI_EVENT_GARBAGE_COLLECTION_START count = 0\n"); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_ForceGarbageCollection_gc_checkGCFinish(JNIEnv * env, jclass cls) { - if (gc_finish_count == 0) { - printf("Error: JVMTI_EVENT_GARBAGE_COLLECTION_FINISH count = 0\n"); - iGlobalStatus = 2; - } -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_functions_ForceGarbageCollection_gc_GetResult(JNIEnv * env, jclass cls) { - return iGlobalStatus; -} - - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_ForceGarbageCollection_gc_jvmtiForceGC (JNIEnv * env, jclass cls) { - jvmtiError ret; - - debug_printf("jvmti Force gc requested \n"); - ret = JVMTI_ENV_PTR(jvmti)->ForceGarbageCollection(JVMTI_ENV_ARG1(jvmti)); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: ForceGarbageCollection %d \n", ret); - iGlobalStatus = 2; - } -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/gc.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/gc.cpp new file mode 100644 index 00000000000..6b0ffcca4ee --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/gc.cpp @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_ARG1(x) +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_ARG1(x) x +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define JVMTI_ENV_ARG JNI_ENV_ARG +#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 +#define JVMTI_ENV_PTR JNI_ENV_PTR + +#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} +#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } + +#define THREADS_LIMIT 8 + +jrawMonitorID access_lock; +jvmtiEnv *jvmti; +jint iGlobalStatus = 0; +jthread susp_thrd[THREADS_LIMIT]; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities jvmti_caps; + + +int printdump = 0; +int gc_start_count =0; +int gc_finish_count =0; + + +void debug_printf(const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + if (printdump) { + vprintf(fmt, args); + } + va_end(args); +} + + +void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + + debug_printf("VMInit event done\n"); +} + +void JNICALL vmExit(jvmtiEnv *jvmti_env, JNIEnv *env) { + debug_printf("------------ JVMTI_EVENT_VM_DEATH ------------\n"); + debug_printf("JVMTI_EVENT_GARBAGE_COLLECTION_START count: %d\n",gc_start_count); + debug_printf("JVMTI_EVENT_GARBAGE_COLLECTION_FINISH count: %d\n",gc_finish_count); +} + +void JNICALL gc_start(jvmtiEnv *jvmti_env) { + + gc_start_count++; + debug_printf("Event: JVMTI_EVENT_GC_START\n"); +} + +void JNICALL gc_finish(jvmtiEnv *jvmti_env) { + + gc_finish_count++; + debug_printf("Event: JVMTI_EVENT_GC_FINISH\n"); +} + + +void init_callbacks() { + memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); + callbacks.VMInit = vmInit; + callbacks.VMDeath = vmExit; + callbacks.GarbageCollectionStart = gc_start; + callbacks.GarbageCollectionFinish = gc_finish; +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_gc(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_gc(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_gc(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { + jint res; + + if (options && strlen(options) > 0) { + if (strstr(options, "printdump")) { + printdump = 1; + } + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res < 0) { + debug_printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + /* Create data access lock */ + res = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti,"_access_lock"),&access_lock); + JVMTI_ERROR_CHECK("RawMonitorEnter in monitor_contended_entered failed with error code ", res); + + + /* Add capabilities */ + res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); + + /* Enable events */ + init_callbacks(); + res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); + JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_GARBAGE_COLLECTION_START,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for gc start returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_GARBAGE_COLLECTION_FINISH,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for gc finish returned error", res); + + return JNI_OK; +} + + + + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_ForceGarbageCollection_gc_checkGCStart(JNIEnv * env, jclass cls) { + if (gc_start_count == 0) { + printf("Error: JVMTI_EVENT_GARBAGE_COLLECTION_START count = 0\n"); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_ForceGarbageCollection_gc_checkGCFinish(JNIEnv * env, jclass cls) { + if (gc_finish_count == 0) { + printf("Error: JVMTI_EVENT_GARBAGE_COLLECTION_FINISH count = 0\n"); + iGlobalStatus = 2; + } +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_functions_ForceGarbageCollection_gc_GetResult(JNIEnv * env, jclass cls) { + return iGlobalStatus; +} + + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_ForceGarbageCollection_gc_jvmtiForceGC (JNIEnv * env, jclass cls) { + jvmtiError ret; + + debug_printf("jvmti Force gc requested \n"); + ret = JVMTI_ENV_PTR(jvmti)->ForceGarbageCollection(JVMTI_ENV_ARG1(jvmti)); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: ForceGarbageCollection %d \n", ret); + iGlobalStatus = 2; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/libgc.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/libgc.c deleted file mode 100644 index 32626bfaa8b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/libgc.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "gc.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/libgc.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/libgc.cpp new file mode 100644 index 00000000000..d8e1d2a325e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/libgc.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "gc.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/JvmtiTest.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/JvmtiTest.c deleted file mode 100644 index 3b7dc9c4b13..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/JvmtiTest.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_ARG1(x) -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_ARG1(x) x -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define JVMTI_ENV_ARG JNI_ENV_ARG -#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 -#define JVMTI_ENV_PTR JNI_ENV_PTR - -#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} - -#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } - -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } - - - -jvmtiEnv *jvmti; -jint iGlobalStatus = 0; -static jvmtiCapabilities jvmti_caps; - - - -int printdump = 0; - - -void debug_printf(char *fmt, ...) { - va_list args; - - va_start(args, fmt); - if (printdump) { - vprintf(fmt, args); - } - va_end(args); -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { - jint res; - jint count; - char **properties; - int i; - - if (options && strlen(options) > 0) { - if (strstr(options, "printdump")) { - printdump = 1; - } - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res < 0) { - debug_printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - - /* Add capabilities */ - res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetAddCapabilities returned error", res); - - - res = JVMTI_ENV_PTR(jvmti)->GetSystemProperties(JVMTI_ENV_ARG(jvmti, &count), &properties); - - JVMTI_ERROR_CHECK("GetSystemProperties returned error", res); - - for (i=0; i< count; i++) { - char *value; - - res = JVMTI_ENV_PTR(jvmti)->GetSystemProperty(JVMTI_ENV_ARG(jvmti, (const char *)properties[i]), &value); - JVMTI_ERROR_CHECK("GetSystemProperty returned error", res); - debug_printf(" %s %s \n", properties[i], value); - - /* Only writeable properties returns JVMTI_ERROR_NONE. */ - res = JVMTI_ENV_PTR(jvmti)->SetSystemProperty(JVMTI_ENV_ARG(jvmti, (const char *)properties[i]), value); - debug_printf("SetSystemProperty returned error %d\n", res); - - } - - return JNI_OK; -} - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_functions_environment_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { - return iGlobalStatus; -} - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/JvmtiTest.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/JvmtiTest.cpp new file mode 100644 index 00000000000..66e09f74c13 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/JvmtiTest.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_ARG1(x) +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_ARG1(x) x +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define JVMTI_ENV_ARG JNI_ENV_ARG +#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 +#define JVMTI_ENV_PTR JNI_ENV_PTR + +#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} + +#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } + +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } + + + +jvmtiEnv *jvmti; +jint iGlobalStatus = 0; +static jvmtiCapabilities jvmti_caps; + + + +int printdump = 0; + + +void debug_printf(const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + if (printdump) { + vprintf(fmt, args); + } + va_end(args); +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { + jint res; + jint count; + char **properties; + int i; + + if (options && strlen(options) > 0) { + if (strstr(options, "printdump")) { + printdump = 1; + } + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res < 0) { + debug_printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + + /* Add capabilities */ + res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetAddCapabilities returned error", res); + + + res = JVMTI_ENV_PTR(jvmti)->GetSystemProperties(JVMTI_ENV_ARG(jvmti, &count), &properties); + + JVMTI_ERROR_CHECK("GetSystemProperties returned error", res); + + for (i=0; i< count; i++) { + char *value; + + res = JVMTI_ENV_PTR(jvmti)->GetSystemProperty(JVMTI_ENV_ARG(jvmti, (const char *)properties[i]), &value); + JVMTI_ERROR_CHECK("GetSystemProperty returned error", res); + debug_printf(" %s %s \n", properties[i], value); + + /* Only writeable properties returns JVMTI_ERROR_NONE. */ + res = JVMTI_ENV_PTR(jvmti)->SetSystemProperty(JVMTI_ENV_ARG(jvmti, (const char *)properties[i]), value); + debug_printf("SetSystemProperty returned error %d\n", res); + + } + + return JNI_OK; +} + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_functions_environment_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { + return iGlobalStatus; +} + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/libenvironment.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/libenvironment.c deleted file mode 100644 index fcef2030c0e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/libenvironment.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "JvmtiTest.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/libenvironment.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/libenvironment.cpp new file mode 100644 index 00000000000..fea00132b93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/libenvironment.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "JvmtiTest.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/JvmtiTest.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/JvmtiTest.c deleted file mode 100644 index 90b14cd7cb7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/JvmtiTest.c +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_ARG1(x) -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_ARG1(x) x -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define JVMTI_ENV_ARG JNI_ENV_ARG -#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 -#define JVMTI_ENV_PTR JNI_ENV_PTR - -#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} - -#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } - -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } - -#define THREADS_LIMIT 2000 - - -jvmtiEnv *jvmti; -jint iGlobalStatus = 0; -jthread susp_thrd[THREADS_LIMIT]; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities jvmti_caps; -jrawMonitorID jraw_monitor[20]; - -int process_once = 0; - - - -int printdump = 0; - - -void debug_printf(char *fmt, ...) { - va_list args; - - va_start(args, fmt); - if (printdump) { - vprintf(fmt, args); - } - va_end(args); -} - - -void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - - debug_printf("VMInit event done\n"); - -} - -void JNICALL vmExit(jvmtiEnv *jvmti_env, JNIEnv *env) { - debug_printf("------------ JVMTI_EVENT_VM_DEATH ------------\n"); -} - -void JNICALL classFileLoadEvent(jvmtiEnv *jvmti_env, JNIEnv *env, - jclass class_being_redifined, - jobject loader, const char* name, - jobject protection_domain, - jint class_data_len, - const unsigned char* class_data, - jint* new_class_data_len, - unsigned char** new_class_data) { - -} - - - -void init_callbacks() { - memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); - callbacks.VMInit = vmInit; - callbacks.VMDeath = vmExit; - callbacks.ClassFileLoadHook = classFileLoadEvent; -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { - jint res; - - if (options && strlen(options) > 0) { - if (strstr(options, "printdump")) { - printdump = 1; - } - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res < 0) { - debug_printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - - /* Add capabilities */ - res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - /* Enable events */ - init_callbacks(); - res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); - JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res); - - return JNI_OK; -} - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_functions_nosuspendMonitorInfo_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { - return iGlobalStatus; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_nosuspendMonitorInfo_JvmtiTest_CheckMonitorInfo(JNIEnv * env, jclass cls, jthread thr, jobject oobj, jint expected_count) { - - jvmtiError ret; - jint count; - jobject *owned_monitor; - - debug_printf(" jvmti GetMonitorInfo \n"); - - - ret = JVMTI_ENV_PTR(jvmti)->GetOwnedMonitorInfo(JVMTI_ENV_ARG1(jvmti), thr, &count , &owned_monitor); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetMonitorInfo %d \n", ret); - iGlobalStatus = 2; - } - - if (expected_count != 0 && expected_count != count) { - printf("Error: GetMonitorInfo expected count %d but got %d \n", expected_count, count); - iGlobalStatus = 2; - } - - if (expected_count !=0 ) { - - ret = JVMTI_ENV_PTR(jvmti)->GetCurrentContendedMonitor(JVMTI_ENV_ARG1(jvmti), thr, owned_monitor); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetContendedMonitorInfo %d \n", ret); - iGlobalStatus = 2; - } - } - -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/JvmtiTest.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/JvmtiTest.cpp new file mode 100644 index 00000000000..610817de024 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/JvmtiTest.cpp @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_ARG1(x) +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_ARG1(x) x +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define JVMTI_ENV_ARG JNI_ENV_ARG +#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 +#define JVMTI_ENV_PTR JNI_ENV_PTR + +#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} + +#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } + +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } + +#define THREADS_LIMIT 2000 + + +jvmtiEnv *jvmti; +jint iGlobalStatus = 0; +jthread susp_thrd[THREADS_LIMIT]; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities jvmti_caps; +jrawMonitorID jraw_monitor[20]; + +int process_once = 0; + + + +int printdump = 0; + + +void debug_printf(const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + if (printdump) { + vprintf(fmt, args); + } + va_end(args); +} + + +void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + + debug_printf("VMInit event done\n"); + +} + +void JNICALL vmExit(jvmtiEnv *jvmti_env, JNIEnv *env) { + debug_printf("------------ JVMTI_EVENT_VM_DEATH ------------\n"); +} + +void JNICALL classFileLoadEvent(jvmtiEnv *jvmti_env, JNIEnv *env, + jclass class_being_redifined, + jobject loader, const char* name, + jobject protection_domain, + jint class_data_len, + const unsigned char* class_data, + jint* new_class_data_len, + unsigned char** new_class_data) { + +} + + + +void init_callbacks() { + memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); + callbacks.VMInit = vmInit; + callbacks.VMDeath = vmExit; + callbacks.ClassFileLoadHook = classFileLoadEvent; +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { + jint res; + + if (options && strlen(options) > 0) { + if (strstr(options, "printdump")) { + printdump = 1; + } + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res < 0) { + debug_printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + + /* Add capabilities */ + res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + /* Enable events */ + init_callbacks(); + res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); + JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res); + + return JNI_OK; +} + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_functions_nosuspendMonitorInfo_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { + return iGlobalStatus; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_nosuspendMonitorInfo_JvmtiTest_CheckMonitorInfo(JNIEnv * env, jclass cls, jthread thr, jobject oobj, jint expected_count) { + + jvmtiError ret; + jint count; + jobject *owned_monitor; + + debug_printf(" jvmti GetMonitorInfo \n"); + + + ret = JVMTI_ENV_PTR(jvmti)->GetOwnedMonitorInfo(JVMTI_ENV_ARG(jvmti, thr), &count , &owned_monitor); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetMonitorInfo %d \n", ret); + iGlobalStatus = 2; + } + + if (expected_count != 0 && expected_count != count) { + printf("Error: GetMonitorInfo expected count %d but got %d \n", expected_count, count); + iGlobalStatus = 2; + } + + if (expected_count !=0 ) { + + ret = JVMTI_ENV_PTR(jvmti)->GetCurrentContendedMonitor(JVMTI_ENV_ARG(jvmti, thr), owned_monitor); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetContendedMonitorInfo %d \n", ret); + iGlobalStatus = 2; + } + } + +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/libnosuspendMonitorInfo.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/libnosuspendMonitorInfo.c deleted file mode 100644 index fcef2030c0e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/libnosuspendMonitorInfo.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "JvmtiTest.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/libnosuspendMonitorInfo.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/libnosuspendMonitorInfo.cpp new file mode 100644 index 00000000000..fea00132b93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/libnosuspendMonitorInfo.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "JvmtiTest.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/JvmtiTest.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/JvmtiTest.c deleted file mode 100644 index 8dee3c08949..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/JvmtiTest.c +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_ARG1(x) -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_ARG1(x) x -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define JVMTI_ENV_ARG JNI_ENV_ARG -#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 -#define JVMTI_ENV_PTR JNI_ENV_PTR - -#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} - -#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } - -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } - -#define THREADS_LIMIT 2000 - - -jvmtiEnv *jvmti; -jint iGlobalStatus = 0; -jthread susp_thrd[THREADS_LIMIT]; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities jvmti_caps; -jrawMonitorID jraw_monitor[20]; - -int process_once = 0; - - - -int printdump = 0; - - -void debug_printf(char *fmt, ...) { - va_list args; - - va_start(args, fmt); - if (printdump) { - vprintf(fmt, args); - } - va_end(args); -} - - -void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - - debug_printf("VMInit event done\n"); - -} - -void JNICALL vmExit(jvmtiEnv *jvmti_env, JNIEnv *env) { - debug_printf("------------ JVMTI_EVENT_VM_DEATH ------------\n"); -} - -void JNICALL classFileLoadEvent(jvmtiEnv *jvmti_env, JNIEnv *env, - jclass class_being_redifined, - jobject loader, const char* name, - jobject protection_domain, - jint class_data_len, - const unsigned char* class_data, - jint* new_class_data_len, - unsigned char** new_class_data) { - -} - - - -void init_callbacks() { - memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); - callbacks.VMInit = vmInit; - callbacks.VMDeath = vmExit; - callbacks.ClassFileLoadHook = classFileLoadEvent; -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { - jint res; - - if (options && strlen(options) > 0) { - if (strstr(options, "printdump")) { - printdump = 1; - } - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res < 0) { - debug_printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - - /* Add capabilities */ - res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - /* Enable events */ - init_callbacks(); - res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); - JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res); - - return JNI_OK; -} - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { - return iGlobalStatus; -} - - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_CreateRawMonitor(JNIEnv * env, jclass class, jint i) { - jvmtiError ret; - char sz[128]; - - sprintf(sz, "Rawmonitor-%d",i); - debug_printf("jvmti create raw monitor \n"); - ret = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG1(jvmti),sz, &jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: ForceGarbageCollection %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_RawMonitorEnter(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti Raw monitor enter \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Raw monitor enter %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_RawMonitorExit(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti raw monitor exit \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti), jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorExit %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_RawMonitorWait(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti RawMonitorWait \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorWait(JVMTI_ENV_ARG1(jvmti),jraw_monitor[i],-1); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorWait %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_RawMonitorNotify(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti RawMonitorNotify \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorNotifyAll(JVMTI_ENV_ARG1(jvmti),jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorNotify %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT int JNICALL -Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_GetFrameCount(JNIEnv * env, jclass cls, jobject thr) { - jvmtiError ret; - jint count; - - debug_printf("jvmti GetFrameCount \n"); - ret = JVMTI_ENV_PTR(jvmti)->GetFrameCount(JVMTI_ENV_ARG1(jvmti), (jthread)thr, &count); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetFrameCount returned %d \n", ret); - iGlobalStatus = 2; - } - return count; -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_GetStackTrace(JNIEnv * env, jclass cls, jobject thr) { - jvmtiError ret; - jvmtiFrameInfo *stack_buffer = NULL; - jint count = 20; - jclass class; - char *mname; - char *signature; - char *clname; - char *generic; - int i; - - - debug_printf("jvmti GetStackTrace \n"); - - ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG1(jvmti), sizeof(jvmtiFrameInfo) * count, (unsigned char**)&stack_buffer); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Allocate failed with %d \n", ret); - iGlobalStatus = 2; - } - - - ret = JVMTI_ENV_PTR(jvmti)->GetStackTrace(JVMTI_ENV_ARG1(jvmti), - thr, 0, count , stack_buffer, &count); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetStackTrace %d \n", ret); - iGlobalStatus = 2; - } - - debug_printf(" Java Stack trace ---\n"); - - for (i = 0; i < count; i++) { - ret = JVMTI_ENV_PTR(jvmti)->GetMethodDeclaringClass(JVMTI_ENV_ARG1(jvmti), stack_buffer[i].method, &class); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetMethodDeclaringClass %d \n", ret); - iGlobalStatus = 2; - return; - } - - ret = JVMTI_ENV_PTR(jvmti)->GetClassSignature(JVMTI_ENV_ARG1(jvmti), - class, &clname, &generic); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetMethodDeclaringClass %d \n", ret); - iGlobalStatus = 2; - return; - } - - ret = JVMTI_ENV_PTR(jvmti)->GetMethodName(JVMTI_ENV_ARG1(jvmti), - stack_buffer[i].method, &mname, &signature, &generic); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: GetMethodDeclaringClass %d \n", ret); - iGlobalStatus = 2; - return; - } - - debug_printf("[%d] %s::%s(%s) at %lld \n",i,clname, mname, signature, stack_buffer[i].location); - - - } - - - ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG1(jvmti), (unsigned char *)stack_buffer); - if (ret != JVMTI_ERROR_NONE) { - printf("Error: Deallocate failed with %d \n", ret); - iGlobalStatus = 2; - } - - -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_SaveThreadInfo(JNIEnv * env, jclass cls, jobject oobj) { - -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/JvmtiTest.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/JvmtiTest.cpp new file mode 100644 index 00000000000..86643b1fc27 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/JvmtiTest.cpp @@ -0,0 +1,329 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_ARG1(x) +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_ARG1(x) x +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define JVMTI_ENV_ARG JNI_ENV_ARG +#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 +#define JVMTI_ENV_PTR JNI_ENV_PTR + +#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} + +#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } + +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } + +#define THREADS_LIMIT 2000 + + +jvmtiEnv *jvmti; +jint iGlobalStatus = 0; +jthread susp_thrd[THREADS_LIMIT]; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities jvmti_caps; +jrawMonitorID jraw_monitor[20]; + +int process_once = 0; + + + +int printdump = 0; + + +void debug_printf(const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + if (printdump) { + vprintf(fmt, args); + } + va_end(args); +} + + +void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + + debug_printf("VMInit event done\n"); + +} + +void JNICALL vmExit(jvmtiEnv *jvmti_env, JNIEnv *env) { + debug_printf("------------ JVMTI_EVENT_VM_DEATH ------------\n"); +} + +void JNICALL classFileLoadEvent(jvmtiEnv *jvmti_env, JNIEnv *env, + jclass class_being_redifined, + jobject loader, const char* name, + jobject protection_domain, + jint class_data_len, + const unsigned char* class_data, + jint* new_class_data_len, + unsigned char** new_class_data) { + +} + + + +void init_callbacks() { + memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); + callbacks.VMInit = vmInit; + callbacks.VMDeath = vmExit; + callbacks.ClassFileLoadHook = classFileLoadEvent; +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { + jint res; + + if (options && strlen(options) > 0) { + if (strstr(options, "printdump")) { + printdump = 1; + } + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res < 0) { + debug_printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + + /* Add capabilities */ + res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + /* Enable events */ + init_callbacks(); + res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); + JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res); + + return JNI_OK; +} + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { + return iGlobalStatus; +} + + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_CreateRawMonitor(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + char sz[128]; + + sprintf(sz, "Rawmonitor-%d",i); + debug_printf("jvmti create raw monitor \n"); + ret = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti, sz), &jraw_monitor[i]); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: ForceGarbageCollection %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_RawMonitorEnter(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti Raw monitor enter \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, jraw_monitor[i])); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Raw monitor enter %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_RawMonitorExit(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti raw monitor exit \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti, jraw_monitor[i])); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorExit %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_RawMonitorWait(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti RawMonitorWait \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorWait(JVMTI_ENV_ARG(jvmti,jraw_monitor[i]),-1); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorWait %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_RawMonitorNotify(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti RawMonitorNotify \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorNotifyAll(JVMTI_ENV_ARG(jvmti,jraw_monitor[i])); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorNotify %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT int JNICALL +Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_GetFrameCount(JNIEnv * env, jclass cls, jobject thr) { + jvmtiError ret; + jint count; + + debug_printf("jvmti GetFrameCount \n"); + ret = JVMTI_ENV_PTR(jvmti)->GetFrameCount(JVMTI_ENV_ARG(jvmti, (jthread)thr), &count); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetFrameCount returned %d \n", ret); + iGlobalStatus = 2; + } + return count; +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_GetStackTrace(JNIEnv * env, jclass cls, jobject thr) { + jvmtiError ret; + jvmtiFrameInfo *stack_buffer = NULL; + jint count = 20; + jclass klass; + char *mname; + char *signature; + char *clname; + char *generic; + int i; + + + debug_printf("jvmti GetStackTrace \n"); + + ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG(jvmti, sizeof(jvmtiFrameInfo) * count), (unsigned char**)&stack_buffer); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Allocate failed with %d \n", ret); + iGlobalStatus = 2; + } + + + ret = JVMTI_ENV_PTR(jvmti)->GetStackTrace(JVMTI_ENV_ARG(jvmti, thr), 0, count , stack_buffer, &count); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetStackTrace %d \n", ret); + iGlobalStatus = 2; + } + + debug_printf(" Java Stack trace ---\n"); + + for (i = 0; i < count; i++) { + ret = JVMTI_ENV_PTR(jvmti)->GetMethodDeclaringClass(JVMTI_ENV_ARG(jvmti, stack_buffer[i].method), &klass); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetMethodDeclaringClass %d \n", ret); + iGlobalStatus = 2; + return; + } + + ret = JVMTI_ENV_PTR(jvmti)->GetClassSignature(JVMTI_ENV_ARG(jvmti, klass), &clname, &generic); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetMethodDeclaringClass %d \n", ret); + iGlobalStatus = 2; + return; + } + + ret = JVMTI_ENV_PTR(jvmti)->GetMethodName(JVMTI_ENV_ARG(jvmti, stack_buffer[i].method), &mname, &signature, &generic); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: GetMethodDeclaringClass %d \n", ret); + iGlobalStatus = 2; + return; + } + + debug_printf("[%d] %s::%s(%s) at %lld \n",i,clname, mname, signature, stack_buffer[i].location); + + + } + + + ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG(jvmti, (unsigned char *)stack_buffer)); + if (ret != JVMTI_ERROR_NONE) { + printf("Error: Deallocate failed with %d \n", ret); + iGlobalStatus = 2; + } + + +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_nosuspendStackTrace_JvmtiTest_SaveThreadInfo(JNIEnv * env, jclass cls, jobject oobj) { + +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/libnosuspendStackTrace.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/libnosuspendStackTrace.c deleted file mode 100644 index fcef2030c0e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/libnosuspendStackTrace.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "JvmtiTest.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/libnosuspendStackTrace.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/libnosuspendStackTrace.cpp new file mode 100644 index 00000000000..fea00132b93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendStackTrace/JvmtiTest/libnosuspendStackTrace.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "JvmtiTest.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/librawmonitor.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/librawmonitor.c deleted file mode 100644 index e23a0d6cab4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/librawmonitor.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "rawmonitor.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/librawmonitor.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/librawmonitor.cpp new file mode 100644 index 00000000000..3ee43a40f82 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/librawmonitor.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "rawmonitor.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/rawmonitor.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/rawmonitor.c deleted file mode 100644 index 6cc5f9890d7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/rawmonitor.c +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/* - - Unit test to test the following: - - Onload phase: - - 1. CreateRawMonitor - 2. RawMonitorEnter - 3. RawMonitorExit - 4. DestroyRawMonitor - 5. Recursive RawMonitorEnter and DestroyRawMonitor - 6. RawMonitorExit for not owned monitor in onload phase. - 7. RawMonitorExit for not owned monitor in live phase. - - Mixed phase: - - 1. Onload RawMonitorEnter and live phase RawMonitorExit - 2. Onload RawMonitorEnter and start phase RawMonitorExit - 3. Start phase RawMonitorEnter and RawMonitorExit. - 4. Onload RawmonitorEnter and start phase Destroy - - */ - -#include -#include -#include "jvmti.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_ARG1(x) -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_ARG1(x) x -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define JVMTI_ENV_ARG JNI_ENV_ARG -#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 -#define JVMTI_ENV_PTR JNI_ENV_PTR - -#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf(" %d\n",res); return res;} -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf(" unexpected error %d\n",res); return res;} - -#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf(" %d\n",res); iGlobalStatus = 2; } - -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf(" unexpected error %d\n",res); iGlobalStatus = 2; } - -#define THREADS_LIMIT 8 - -jrawMonitorID access_lock; -jrawMonitorID access_lock_not_entered; -jvmtiEnv *jvmti; -jint iGlobalStatus = 0; -jthread main_thread; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities jvmti_caps; -jrawMonitorID jraw_monitor[20]; - -static volatile int process_once = 1; - - - -int printdump = 0; - - -void debug_printf(char *fmt, ...) { - va_list args; - - va_start(args, fmt); - if (printdump) { - vprintf(fmt, args); - } - va_end(args); -} - - -void JNICALL vmStart(jvmtiEnv *jvmti_env, JNIEnv *env) { - jvmtiError res; - res = JVMTI_ENV_PTR(jvmti)->GetCurrentThread(JVMTI_ENV_ARG1(jvmti_env), &main_thread); - JVMTI_ERROR_CHECK_VOID(" JVMTI GetCurrentThread returned error", res); - main_thread = (jthread)JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, main_thread)); -} - -void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - - jvmtiError res; - - debug_printf("VMInit event done\n"); - res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti_env),access_lock); - JVMTI_ERROR_CHECK_VOID(" Raw monitor exit returned error", res); - res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti_env),access_lock); - JVMTI_ERROR_CHECK_VOID(" Raw monitor exit returned error", res); -} - -void JNICALL vmExit(jvmtiEnv *jvmti_env, JNIEnv *env) { - debug_printf("------------ JVMTI_EVENT_VM_DEATH ------------\n"); -} - -void JNICALL classFileLoadHookEvent(jvmtiEnv *jvmti_env, JNIEnv *env, - jclass class_being_redifined, - jobject loader, const char* name, - jobject protection_domain, - jint class_data_len, - const unsigned char* class_data, - jint* new_class_data_len, - unsigned char** new_class_data) { - - jvmtiError res; - jvmtiPhase phase; - jthread thread; - jboolean is_main; - - res = JVMTI_ENV_PTR(jvmti)->GetPhase(JVMTI_ENV_ARG1(jvmti_env), &phase); - JVMTI_ERROR_CHECK_VOID(" JVMTI GetPhase returned error", res); - if (phase != JVMTI_PHASE_START) { - return; /* only the start phase is tested */ - } - res = JVMTI_ENV_PTR(jvmti)->GetCurrentThread(JVMTI_ENV_ARG1(jvmti_env), &thread); - JVMTI_ERROR_CHECK_VOID(" JVMTI GetCurrentThread returned error", res); - is_main = JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, thread), main_thread); - if (is_main == JNI_FALSE) { - return; /* only the main thread is tested */ - } - - debug_printf("------------ classFileLoadHookEvent ------------\n"); - - /* Test raw monitor in start phase */ - - if (process_once) { - - process_once = 0; - - /* test not entered raw monitor */ - res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti_env),access_lock_not_entered); - JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID("Raw monitor exit returned error", res,JVMTI_ERROR_NOT_MONITOR_OWNER); - - /* release lock in start phase */ - res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti_env),access_lock); - JVMTI_ERROR_CHECK_VOID("Raw monitor exit returned error", res); - - /* release lock in start phase */ - res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti_env),access_lock); - JVMTI_ERROR_CHECK_VOID("Raw monitor exit returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),access_lock); - JVMTI_ERROR_CHECK_VOID("Raw monitor enter returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),access_lock); - JVMTI_ERROR_CHECK_VOID("Raw monitor enter returned error", res); - } - -} - - - -void init_callbacks() { - memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); - callbacks.VMStart = vmStart; - callbacks.VMInit = vmInit; - callbacks.VMDeath = vmExit; - callbacks.ClassFileLoadHook = classFileLoadHookEvent; -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_rawmonitor(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_rawmonitor(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_rawmonitor(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { - jint res; - - if (options && strlen(options) > 0) { - if (strstr(options, "printdump")) { - printdump = 1; - } - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res < 0) { - debug_printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - /* Onload phase Create data access lock */ - res = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti,"_access_lock"),&access_lock); - JVMTI_ERROR_CHECK("CreateRawMonitor failed with error code ", res); - res = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti,"_access_lock_not_entered"),&access_lock_not_entered); - JVMTI_ERROR_CHECK("CreateRawMonitor failed with error code ", res); - /* Create this raw monitor in onload and it is used in live phase */ - res = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti,"RawMonitor-0"),&jraw_monitor[0]); - JVMTI_ERROR_CHECK("CreateRawMonitor failed with error code ", res); - - - /* Add capabilities */ - res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); - JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); - - /* Enable events */ - init_callbacks(); - res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); - JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode CLASS_FILE_LOAD_HOOK returned error", res); - - /* acquire lock in onload */ - res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),access_lock); - JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); - - /* release lock in onload */ - res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti),access_lock); - JVMTI_ERROR_CHECK("Raw monitor exit returned error", res); - - /* test not entered raw monitor */ - res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti),access_lock_not_entered); - JVMTI_ERROR_CHECK_EXPECTED_ERROR("Raw monitor exit returned error", res,JVMTI_ERROR_NOT_MONITOR_OWNER); - - /* acquire lock in onload */ - res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),access_lock); - JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),access_lock); - JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),access_lock); - JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); - - /* test Destroy raw monitor in onload phase */ - res = JVMTI_ENV_PTR(jvmti)->DestroyRawMonitor(JVMTI_ENV_ARG1(jvmti),access_lock); - JVMTI_ERROR_CHECK("Destroy Raw monitor returned error", res); - - /* Create data access lock in onload and enter in onload phase */ - res = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti,"_access_lock"),&access_lock); - JVMTI_ERROR_CHECK("CreateRawMonitor failed with error code ", res); - - res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),access_lock); - JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),access_lock); - JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); - - - /* This monitor is entered here and it is released in live phase by a call from java code - */ - res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),jraw_monitor[0]); - JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); - res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),jraw_monitor[0]); - JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); - res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti),jraw_monitor[0]); - JVMTI_ERROR_CHECK("Raw monitor exit returned error", res); - - return JNI_OK; -} - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_functions_rawmonitor_GetResult(JNIEnv * env, jclass cls) { - return iGlobalStatus; -} - - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_rawmonitor_CreateRawMonitor(JNIEnv * env, jclass class, jint i) { - jvmtiError ret; - char sz[128]; - - sprintf(sz, "Rawmonitor-%d",i); - debug_printf("jvmti create raw monitor \n"); - ret = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG1(jvmti),sz, &jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: CreateRawMonitor %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_rawmonitor_RawMonitorEnter(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti Raw monitor enter \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG1(jvmti),jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorEnter %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_rawmonitor_RawMonitorExit(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti raw monitor exit \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG1(jvmti), jraw_monitor[i]); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorExit %d \n", ret); - iGlobalStatus = 2; - } -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_functions_rawmonitor_RawMonitorWait(JNIEnv * env, jclass cls, jint i) { - jvmtiError ret; - - debug_printf("jvmti RawMonitorWait \n"); - ret = JVMTI_ENV_PTR(jvmti)->RawMonitorWait(JVMTI_ENV_ARG1(jvmti),jraw_monitor[i],-1); - - if (ret != JVMTI_ERROR_NONE) { - printf("Error: RawMonitorWait %d \n", ret); - iGlobalStatus = 2; - } -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/rawmonitor.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/rawmonitor.cpp new file mode 100644 index 00000000000..4e7b430f502 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/rawmonitor/rawmonitor.cpp @@ -0,0 +1,367 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* + + Unit test to test the following: + + Onload phase: + + 1. CreateRawMonitor + 2. RawMonitorEnter + 3. RawMonitorExit + 4. DestroyRawMonitor + 5. Recursive RawMonitorEnter and DestroyRawMonitor + 6. RawMonitorExit for not owned monitor in onload phase. + 7. RawMonitorExit for not owned monitor in live phase. + + Mixed phase: + + 1. Onload RawMonitorEnter and live phase RawMonitorExit + 2. Onload RawMonitorEnter and start phase RawMonitorExit + 3. Start phase RawMonitorEnter and RawMonitorExit. + 4. Onload RawmonitorEnter and start phase Destroy + + */ + +#include +#include +#include "jvmti.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_ARG1(x) +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_ARG1(x) x +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define JVMTI_ENV_ARG JNI_ENV_ARG +#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 +#define JVMTI_ENV_PTR JNI_ENV_PTR + +#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf(" %d\n",res); return res;} +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf(" unexpected error %d\n",res); return res;} + +#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf(" %d\n",res); iGlobalStatus = 2; } + +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf(" unexpected error %d\n",res); iGlobalStatus = 2; } + +#define THREADS_LIMIT 8 + +jrawMonitorID access_lock; +jrawMonitorID access_lock_not_entered; +jvmtiEnv *jvmti; +jint iGlobalStatus = 0; +jthread main_thread; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities jvmti_caps; +jrawMonitorID jraw_monitor[20]; + +static volatile int process_once = 1; + + + +int printdump = 0; + + +void debug_printf(const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + if (printdump) { + vprintf(fmt, args); + } + va_end(args); +} + + +void JNICALL vmStart(jvmtiEnv *jvmti_env, JNIEnv *env) { + jvmtiError res; + res = JVMTI_ENV_PTR(jvmti)->GetCurrentThread(JVMTI_ENV_ARG(jvmti_env, &main_thread)); + JVMTI_ERROR_CHECK_VOID(" JVMTI GetCurrentThread returned error", res); + main_thread = (jthread)JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, main_thread)); +} + +void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + + jvmtiError res; + + debug_printf("VMInit event done\n"); + res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti_env, access_lock)); + JVMTI_ERROR_CHECK_VOID(" Raw monitor exit returned error", res); + res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti_env, access_lock)); + JVMTI_ERROR_CHECK_VOID(" Raw monitor exit returned error", res); +} + +void JNICALL vmExit(jvmtiEnv *jvmti_env, JNIEnv *env) { + debug_printf("------------ JVMTI_EVENT_VM_DEATH ------------\n"); +} + +void JNICALL classFileLoadHookEvent(jvmtiEnv *jvmti_env, JNIEnv *env, + jclass class_being_redifined, + jobject loader, const char* name, + jobject protection_domain, + jint class_data_len, + const unsigned char* class_data, + jint* new_class_data_len, + unsigned char** new_class_data) { + + jvmtiError res; + jvmtiPhase phase; + jthread thread; + jboolean is_main; + + res = JVMTI_ENV_PTR(jvmti)->GetPhase(JVMTI_ENV_ARG(jvmti_env, &phase)); + JVMTI_ERROR_CHECK_VOID(" JVMTI GetPhase returned error", res); + if (phase != JVMTI_PHASE_START) { + return; /* only the start phase is tested */ + } + res = JVMTI_ENV_PTR(jvmti)->GetCurrentThread(JVMTI_ENV_ARG(jvmti_env, &thread)); + JVMTI_ERROR_CHECK_VOID(" JVMTI GetCurrentThread returned error", res); + is_main = JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, thread), main_thread); + if (is_main == JNI_FALSE) { + return; /* only the main thread is tested */ + } + + debug_printf("------------ classFileLoadHookEvent ------------\n"); + + /* Test raw monitor in start phase */ + + if (process_once) { + + process_once = 0; + + /* test not entered raw monitor */ + res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti_env, access_lock_not_entered)); + JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID("Raw monitor exit returned error", res,JVMTI_ERROR_NOT_MONITOR_OWNER); + + /* release lock in start phase */ + res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti_env, access_lock)); + JVMTI_ERROR_CHECK_VOID("Raw monitor exit returned error", res); + + /* release lock in start phase */ + res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti_env, access_lock)); + JVMTI_ERROR_CHECK_VOID("Raw monitor exit returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, access_lock)); + JVMTI_ERROR_CHECK_VOID("Raw monitor enter returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, access_lock)); + JVMTI_ERROR_CHECK_VOID("Raw monitor enter returned error", res); + } + +} + + + +void init_callbacks() { + memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); + callbacks.VMStart = vmStart; + callbacks.VMInit = vmInit; + callbacks.VMDeath = vmExit; + callbacks.ClassFileLoadHook = classFileLoadHookEvent; +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_rawmonitor(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_rawmonitor(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_rawmonitor(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { + jint res; + + if (options && strlen(options) > 0) { + if (strstr(options, "printdump")) { + printdump = 1; + } + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res < 0) { + debug_printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + /* Onload phase Create data access lock */ + res = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti,"_access_lock"),&access_lock); + JVMTI_ERROR_CHECK("CreateRawMonitor failed with error code ", res); + res = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti,"_access_lock_not_entered"),&access_lock_not_entered); + JVMTI_ERROR_CHECK("CreateRawMonitor failed with error code ", res); + /* Create this raw monitor in onload and it is used in live phase */ + res = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti,"RawMonitor-0"),&jraw_monitor[0]); + JVMTI_ERROR_CHECK("CreateRawMonitor failed with error code ", res); + + + /* Add capabilities */ + res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); + JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); + + /* Enable events */ + init_callbacks(); + res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); + JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode CLASS_FILE_LOAD_HOOK returned error", res); + + /* acquire lock in onload */ + res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, access_lock)); + JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); + + /* release lock in onload */ + res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti, access_lock)); + JVMTI_ERROR_CHECK("Raw monitor exit returned error", res); + + /* test not entered raw monitor */ + res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti ,access_lock_not_entered)); + JVMTI_ERROR_CHECK_EXPECTED_ERROR("Raw monitor exit returned error", res,JVMTI_ERROR_NOT_MONITOR_OWNER); + + /* acquire lock in onload */ + res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, access_lock)); + JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, access_lock)); + JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, access_lock)); + JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); + + /* test Destroy raw monitor in onload phase */ + res = JVMTI_ENV_PTR(jvmti)->DestroyRawMonitor(JVMTI_ENV_ARG(jvmti, access_lock)); + JVMTI_ERROR_CHECK("Destroy Raw monitor returned error", res); + + /* Create data access lock in onload and enter in onload phase */ + res = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti,"_access_lock"),&access_lock); + JVMTI_ERROR_CHECK("CreateRawMonitor failed with error code ", res); + + res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, access_lock)); + JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, access_lock)); + JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); + + + /* This monitor is entered here and it is released in live phase by a call from java code + */ + res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, jraw_monitor[0])); + JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); + res = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, jraw_monitor[0])); + JVMTI_ERROR_CHECK("Raw monitor enter returned error", res); + res = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti, jraw_monitor[0])); + JVMTI_ERROR_CHECK("Raw monitor exit returned error", res); + + return JNI_OK; +} + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_functions_rawmonitor_GetResult(JNIEnv * env, jclass cls) { + return iGlobalStatus; +} + + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_rawmonitor_CreateRawMonitor(JNIEnv * env, jclass klass, jint i) { + jvmtiError ret; + char sz[128]; + + sprintf(sz, "Rawmonitor-%d",i); + debug_printf("jvmti create raw monitor \n"); + ret = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti, sz), &jraw_monitor[i]); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: CreateRawMonitor %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_rawmonitor_RawMonitorEnter(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti Raw monitor enter \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, jraw_monitor[i])); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorEnter %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_rawmonitor_RawMonitorExit(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti raw monitor exit \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti, jraw_monitor[i])); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorExit %d \n", ret); + iGlobalStatus = 2; + } +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_functions_rawmonitor_RawMonitorWait(JNIEnv * env, jclass cls, jint i) { + jvmtiError ret; + + debug_printf("jvmti RawMonitorWait \n"); + ret = JVMTI_ENV_PTR(jvmti)->RawMonitorWait(JVMTI_ENV_ARG(jvmti, jraw_monitor[i]), -1); + + if (ret != JVMTI_ERROR_NONE) { + printf("Error: RawMonitorWait %d \n", ret); + iGlobalStatus = 2; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/heapref.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/heapref.c deleted file mode 100644 index bdd1f498b2a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/heapref.c +++ /dev/null @@ -1,492 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "jni_tools.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jvmtiCapabilities jvmti_caps; -static jint dummy_user_data = 0; -static jboolean user_data_error_flag = JNI_FALSE; - -#define HEAP_ROOT_REF_KIND_BASE 100 -#define MISSED_REF_KIND_BASE 300 - -typedef enum { - rthread, - rclass, - rother, - rmark -} refKind; - -struct _refLink; - -typedef struct _myTag { - refKind kind; - const struct _myTag* class_tag; - jlong size; - jlong sequence; - jboolean visited; - const char* name; - struct _refLink *ref; -} MyTag; - -typedef struct _refLink { - MyTag* tag; - int reference_kind; - struct _refLink *next; -} refLink; - -static MyTag *fakeRoot = NULL; -static MyTag *missed = NULL; - -static void breakpoint() { - printf("Continuing from BREAKPOINT\n"); -} - -static MyTag *newTag(refKind kind, - const MyTag* class_tag, - jlong size, - const char* name) { - static jlong seq_num = 0; - MyTag* new_tag = NULL; - - new_tag = malloc(sizeof(MyTag)); - if (NULL == new_tag) { - printf("Error (newTag malloc): failed\n"); - result = STATUS_FAILED; - } - new_tag->kind = kind; - new_tag->class_tag = class_tag; - new_tag->size = size; - new_tag->sequence = ++seq_num; - new_tag->visited = JNI_FALSE; - new_tag->name = name; - new_tag->ref = NULL; - return new_tag; -} - -static void setTag(JNIEnv *env, - jobject obj, - refKind kind, - const char* name) { - MyTag *new_tag = NULL; - MyTag *class_tag = NULL; - jvmtiError err; - jlong size = 0; - jclass obj_class = NULL; - jlong haba = 0; - - err = (*jvmti)->GetObjectSize(jvmti, obj, &size); - if (err != JVMTI_ERROR_NONE) { - printf("Error (ObjectSize): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - obj_class = (*env)->GetObjectClass(env, obj); - - err = (*jvmti)->GetTag(jvmti, obj_class, &haba); - class_tag = (MyTag*)(intptr_t)haba; - if (err != JVMTI_ERROR_NONE) { - printf("Error (GetTag): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - if (class_tag != NULL && class_tag->kind != rclass) { - printf("Error class tag which is not a class\n"); - result = STATUS_FAILED; - } - - new_tag = newTag(kind, class_tag, size, name); - - err = (*jvmti)->SetTag(jvmti, obj, (intptr_t)new_tag); - if (err != JVMTI_ERROR_NONE) { - printf("Error (SetTag): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } -} - -static void addRef(MyTag *from, int reference_kind, MyTag *to) { - refLink *new_ref; - - new_ref = malloc(sizeof(refLink)); - if (NULL == new_ref) { - printf("Error (addRef malloc): failed\n"); - result = STATUS_FAILED; - } - new_ref->tag = to; - new_ref->reference_kind = reference_kind; - new_ref->next = from->ref; - from->ref = new_ref; -} - -static const char* reference_label(refLink *link) { - int reference_kind = link->reference_kind; - const char *name = "**unknown**"; - switch (reference_kind) { - case JVMTI_REFERENCE_CLASS: - name = "class"; - break; - case JVMTI_REFERENCE_FIELD: - name = "field"; - break; - case JVMTI_REFERENCE_ARRAY_ELEMENT: - name = "array_element"; - break; - case JVMTI_REFERENCE_CLASS_LOADER: - name = "class_loader"; - break; - case JVMTI_REFERENCE_SIGNERS: - name = "signers"; - break; - case JVMTI_REFERENCE_PROTECTION_DOMAIN: - name = "protection_domain"; - break; - case JVMTI_REFERENCE_INTERFACE: - name = "interface"; - break; - case JVMTI_REFERENCE_STATIC_FIELD: - name = "static_field"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_JNI_GLOBAL: - name = "root::jni_global"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_SYSTEM_CLASS: - name = "root::system_class"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_MONITOR: - name = "root::monitor"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_STACK_LOCAL: - name = "root::local_var"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_JNI_LOCAL: - name = "root::jni_local"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_THREAD: - name = "root::thread"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_OTHER: - name = "root::other"; - break; - default: - printf("Error: Unexpected reference kind %d\n", reference_kind); - result = STATUS_FAILED; - break; - } - return name; -} - -static void walk(MyTag* tag, jint depth, const char* ref_label) { - static const char* const spaces = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "; - static const int len = 86; - const char *indent = spaces + (len - 2 * depth); - - const MyTag* const ctag = tag->class_tag; - const char* const cname = ctag != NULL ? ctag->name : ""; - - printf("%s", indent); - - if (tag->visited) { - printf("", tag->sequence); - } else { - printf("", tag->sequence); - } - if (tag->name) { - printf("%s(%s)", cname, tag->name); - } else { - printf("%s(%"LL"d)", cname, tag->sequence); - } - printf(" -- "); - printf("%s\n", ref_label); - if (!tag->visited) { - refLink *ref; - tag->visited = JNI_TRUE; - for (ref = tag->ref; ref; ref = ref->next) { - walk(ref->tag, depth + 1, reference_label(ref)); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_heapref(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} - -JNIEXPORT jint JNICALL Agent_OnAttach_heapref(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} - -JNIEXPORT jint JNI_OnLoad_heapref(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif - -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - memset((void*)&jvmti_caps, 0, sizeof(jvmtiCapabilities)); - jvmti_caps.can_tag_objects = 1; - err = (*jvmti)->AddCapabilities(jvmti, &jvmti_caps); - if (err != JVMTI_ERROR_NONE) { - printf("Error (AddCapabilities): %s (%d)\n", TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -jvmtiIterationControl JNICALL -heapMarkCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { - const MyTag* const tag = newTag(rmark, (const MyTag*)(intptr_t)class_tag, size, NULL); - *tag_ptr = (intptr_t)tag; - - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - printf("Error (heapMarkCallback): unexpected value of user_data\n"); - result = STATUS_FAILED; - } - return JVMTI_ITERATION_CONTINUE; -} - -jvmtiIterationControl JNICALL -heapRootCallback(jvmtiHeapRootKind root_kind, - jlong class_tag, jlong size, - jlong* tag_ptr, void* user_data) { - refKind kind = rother; - - if (0 == *tag_ptr) { - /* new tag */ - MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL); - addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, tag); - *tag_ptr = (intptr_t)tag; - } else { - /* existing tag */ - addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, (MyTag*)(intptr_t)*tag_ptr); - } - - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - printf("Error (heapRootCallback): unexpected value of user_data\n"); - result = STATUS_FAILED; - } - return JVMTI_ITERATION_CONTINUE; -} - -jvmtiIterationControl JNICALL -stackReferenceCallback(jvmtiHeapRootKind root_kind, - jlong class_tag, jlong size, - jlong* tag_ptr, jlong thread_tag, - jint depth, jmethodID method, - jint slot, void* user_data) { - refKind kind = rother; - - if (0 == *tag_ptr) { - /* new tag */ - MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL); - addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, tag); - *tag_ptr = (intptr_t)tag; - } else { - /* existing tag */ - addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, (MyTag*)(intptr_t)*tag_ptr); - } - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - printf("Error (stackReferenceCallback): unexpected value of user_data\n"); - result = STATUS_FAILED; - } - return JVMTI_ITERATION_CONTINUE; -} - -jvmtiIterationControl JNICALL -objectReferenceCallback(jvmtiObjectReferenceKind reference_kind, - jlong class_tag, jlong size, - jlong* tag_ptr, jlong referrer_tag, - jint referrer_index, void* user_data) { - refKind kind = rother; - MyTag* referrer = NULL; - - if (0 == referrer_tag) { - referrer = missed; - } else { - referrer = (MyTag *)(intptr_t)referrer_tag; - } - - if (0 == *tag_ptr) { - /* new tag */ - MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL); - addRef(referrer, reference_kind, tag); - *tag_ptr = (intptr_t) tag; - } else { - /* existing tag */ - MyTag* tag = (MyTag*)(intptr_t)*tag_ptr; - addRef(referrer, reference_kind, tag); - } - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - printf("Error (objectReferenceCallback): unexpected value of user_data\n"); - result = STATUS_FAILED; - } - return JVMTI_ITERATION_CONTINUE; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_heapref_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jclass *classes; - jint classCount = 0; - jthread *threads; - jint threadCount = 0; - jint i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - fakeRoot = newTag(rother, (const MyTag *)NULL, 0, "FAKE_ROOT"); - missed = newTag(rother, (const MyTag *)NULL, 0, "MISSED"); - - if ((*env)->PushLocalFrame(env, 500) != 0) { - printf("Error (PushLocalFrame): failed\n"); - result = STATUS_FAILED; - } - - err = (*jvmti)->GetLoadedClasses(jvmti, &classCount, &classes); - if (err != JVMTI_ERROR_NONE) { - printf("Error (GetLoadedClasses): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - for (i = 0; i < classCount; ++i) { - char *classSig; - jclass k = classes[i]; - err = (*jvmti)->GetClassSignature(jvmti, k, &classSig, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Error (getClassSignature): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } else { - char* slash = strrchr(classSig, '/'); - const size_t len = strlen(classSig); - if (classSig[len-1] == ';') { - classSig[len-1] = 0; - } - if (*classSig == 'L' && slash != NULL) { - classSig = slash + 1; - } - setTag(env, k, rclass, (const char*)classSig); - } - } - - err = (*jvmti)->GetAllThreads(jvmti, &threadCount, &threads); - if (err != JVMTI_ERROR_NONE) { - printf("Error (GetAllThreads): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - for (i = 0; i < threadCount; ++i) { - jvmtiThreadInfo info; - jthread t = threads[i]; - err = (*jvmti)->GetThreadInfo(jvmti, t, &info); - if (err != JVMTI_ERROR_NONE) { - printf("Error (GetThreadInfo): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } else { - setTag(env, t, rthread, (const char*)info.name); - } - } - - (*env)->PopLocalFrame(env, NULL); - - user_data_error_flag = JNI_FALSE; - err = (*jvmti)->IterateOverHeap(jvmti, - JVMTI_HEAP_OBJECT_UNTAGGED, - heapMarkCallback, - &dummy_user_data); - if (err != JVMTI_ERROR_NONE) { - printf("Error (IterateOverHeap): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - user_data_error_flag = JNI_FALSE; - err = (*jvmti)->IterateOverReachableObjects(jvmti, - heapRootCallback, - stackReferenceCallback, - objectReferenceCallback, - &dummy_user_data); - if (err != JVMTI_ERROR_NONE) { - printf("Error (IterateOverReachableObjects): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf("Heap Dump
\n");
-    walk(fakeRoot, 0, "roots");
-    printf("\n------------------- MISSED ------------------\n\n");
-    walk(missed, 0, "missed");
-    printf("
\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/heapref.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/heapref.cpp new file mode 100644 index 00000000000..8ff4f1c8f5b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/heapref.cpp @@ -0,0 +1,492 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "jni_tools.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jvmtiCapabilities jvmti_caps; +static jint dummy_user_data = 0; +static jboolean user_data_error_flag = JNI_FALSE; + +#define HEAP_ROOT_REF_KIND_BASE 100 +#define MISSED_REF_KIND_BASE 300 + +typedef enum { + rthread, + rclass, + rother, + rmark +} refKind; + +struct _refLink; + +typedef struct _myTag { + refKind kind; + const struct _myTag* class_tag; + jlong size; + jlong sequence; + jboolean visited; + const char* name; + struct _refLink *ref; +} MyTag; + +typedef struct _refLink { + MyTag* tag; + int reference_kind; + struct _refLink *next; +} refLink; + +static MyTag *fakeRoot = NULL; +static MyTag *missed = NULL; + +static void breakpoint() { + printf("Continuing from BREAKPOINT\n"); +} + +static MyTag *newTag(refKind kind, + const MyTag* class_tag, + jlong size, + const char* name) { + static jlong seq_num = 0; + MyTag* new_tag = NULL; + + new_tag = (MyTag*) malloc(sizeof(MyTag)); + if (NULL == new_tag) { + printf("Error (newTag malloc): failed\n"); + result = STATUS_FAILED; + } + new_tag->kind = kind; + new_tag->class_tag = class_tag; + new_tag->size = size; + new_tag->sequence = ++seq_num; + new_tag->visited = JNI_FALSE; + new_tag->name = name; + new_tag->ref = NULL; + return new_tag; +} + +static void setTag(JNIEnv *env, + jobject obj, + refKind kind, + const char* name) { + MyTag *new_tag = NULL; + MyTag *class_tag = NULL; + jvmtiError err; + jlong size = 0; + jclass obj_class = NULL; + jlong haba = 0; + + err = jvmti->GetObjectSize(obj, &size); + if (err != JVMTI_ERROR_NONE) { + printf("Error (ObjectSize): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + obj_class = env->GetObjectClass(obj); + + err = jvmti->GetTag(obj_class, &haba); + class_tag = (MyTag*)(intptr_t)haba; + if (err != JVMTI_ERROR_NONE) { + printf("Error (GetTag): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + if (class_tag != NULL && class_tag->kind != rclass) { + printf("Error class tag which is not a class\n"); + result = STATUS_FAILED; + } + + new_tag = newTag(kind, class_tag, size, name); + + err = jvmti->SetTag(obj, (intptr_t)new_tag); + if (err != JVMTI_ERROR_NONE) { + printf("Error (SetTag): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } +} + +static void addRef(MyTag *from, int reference_kind, MyTag *to) { + refLink *new_ref; + + new_ref = (refLink*) malloc(sizeof(refLink)); + if (NULL == new_ref) { + printf("Error (addRef malloc): failed\n"); + result = STATUS_FAILED; + } + new_ref->tag = to; + new_ref->reference_kind = reference_kind; + new_ref->next = from->ref; + from->ref = new_ref; +} + +static const char* reference_label(refLink *link) { + int reference_kind = link->reference_kind; + const char *name = "**unknown**"; + switch (reference_kind) { + case JVMTI_REFERENCE_CLASS: + name = "class"; + break; + case JVMTI_REFERENCE_FIELD: + name = "field"; + break; + case JVMTI_REFERENCE_ARRAY_ELEMENT: + name = "array_element"; + break; + case JVMTI_REFERENCE_CLASS_LOADER: + name = "class_loader"; + break; + case JVMTI_REFERENCE_SIGNERS: + name = "signers"; + break; + case JVMTI_REFERENCE_PROTECTION_DOMAIN: + name = "protection_domain"; + break; + case JVMTI_REFERENCE_INTERFACE: + name = "interface"; + break; + case JVMTI_REFERENCE_STATIC_FIELD: + name = "static_field"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_JNI_GLOBAL: + name = "root::jni_global"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_SYSTEM_CLASS: + name = "root::system_class"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_MONITOR: + name = "root::monitor"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_STACK_LOCAL: + name = "root::local_var"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_JNI_LOCAL: + name = "root::jni_local"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_THREAD: + name = "root::thread"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_OTHER: + name = "root::other"; + break; + default: + printf("Error: Unexpected reference kind %d\n", reference_kind); + result = STATUS_FAILED; + break; + } + return name; +} + +static void walk(MyTag* tag, jint depth, const char* ref_label) { + static const char* const spaces = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "; + static const int len = 86; + const char *indent = spaces + (len - 2 * depth); + + const MyTag* const ctag = tag->class_tag; + const char* const cname = ctag != NULL ? ctag->name : ""; + + printf("%s", indent); + + if (tag->visited) { + printf("", tag->sequence); + } else { + printf("", tag->sequence); + } + if (tag->name) { + printf("%s(%s)", cname, tag->name); + } else { + printf("%s(%" LL "d)", cname, tag->sequence); + } + printf(" -- "); + printf("%s\n", ref_label); + if (!tag->visited) { + refLink *ref; + tag->visited = JNI_TRUE; + for (ref = tag->ref; ref; ref = ref->next) { + walk(ref->tag, depth + 1, reference_label(ref)); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_heapref(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} + +JNIEXPORT jint JNICALL Agent_OnAttach_heapref(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} + +JNIEXPORT jint JNI_OnLoad_heapref(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif + +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + memset((void*)&jvmti_caps, 0, sizeof(jvmtiCapabilities)); + jvmti_caps.can_tag_objects = 1; + err = jvmti->AddCapabilities(&jvmti_caps); + if (err != JVMTI_ERROR_NONE) { + printf("Error (AddCapabilities): %s (%d)\n", TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +jvmtiIterationControl JNICALL +heapMarkCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { + const MyTag* const tag = newTag(rmark, (const MyTag*)(intptr_t)class_tag, size, NULL); + *tag_ptr = (intptr_t)tag; + + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + printf("Error (heapMarkCallback): unexpected value of user_data\n"); + result = STATUS_FAILED; + } + return JVMTI_ITERATION_CONTINUE; +} + +jvmtiIterationControl JNICALL +heapRootCallback(jvmtiHeapRootKind root_kind, + jlong class_tag, jlong size, + jlong* tag_ptr, void* user_data) { + refKind kind = rother; + + if (0 == *tag_ptr) { + /* new tag */ + MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL); + addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, tag); + *tag_ptr = (intptr_t)tag; + } else { + /* existing tag */ + addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, (MyTag*)(intptr_t)*tag_ptr); + } + + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + printf("Error (heapRootCallback): unexpected value of user_data\n"); + result = STATUS_FAILED; + } + return JVMTI_ITERATION_CONTINUE; +} + +jvmtiIterationControl JNICALL +stackReferenceCallback(jvmtiHeapRootKind root_kind, + jlong class_tag, jlong size, + jlong* tag_ptr, jlong thread_tag, + jint depth, jmethodID method, + jint slot, void* user_data) { + refKind kind = rother; + + if (0 == *tag_ptr) { + /* new tag */ + MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL); + addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, tag); + *tag_ptr = (intptr_t)tag; + } else { + /* existing tag */ + addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, (MyTag*)(intptr_t)*tag_ptr); + } + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + printf("Error (stackReferenceCallback): unexpected value of user_data\n"); + result = STATUS_FAILED; + } + return JVMTI_ITERATION_CONTINUE; +} + +jvmtiIterationControl JNICALL +objectReferenceCallback(jvmtiObjectReferenceKind reference_kind, + jlong class_tag, jlong size, + jlong* tag_ptr, jlong referrer_tag, + jint referrer_index, void* user_data) { + refKind kind = rother; + MyTag* referrer = NULL; + + if (0 == referrer_tag) { + referrer = missed; + } else { + referrer = (MyTag *)(intptr_t)referrer_tag; + } + + if (0 == *tag_ptr) { + /* new tag */ + MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL); + addRef(referrer, reference_kind, tag); + *tag_ptr = (intptr_t) tag; + } else { + /* existing tag */ + MyTag* tag = (MyTag*)(intptr_t)*tag_ptr; + addRef(referrer, reference_kind, tag); + } + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + printf("Error (objectReferenceCallback): unexpected value of user_data\n"); + result = STATUS_FAILED; + } + return JVMTI_ITERATION_CONTINUE; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_heapref_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jclass *classes; + jint classCount = 0; + jthread *threads; + jint threadCount = 0; + jint i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + fakeRoot = newTag(rother, (const MyTag *)NULL, 0, "FAKE_ROOT"); + missed = newTag(rother, (const MyTag *)NULL, 0, "MISSED"); + + if (env->PushLocalFrame(500) != 0) { + printf("Error (PushLocalFrame): failed\n"); + result = STATUS_FAILED; + } + + err = jvmti->GetLoadedClasses(&classCount, &classes); + if (err != JVMTI_ERROR_NONE) { + printf("Error (GetLoadedClasses): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + for (i = 0; i < classCount; ++i) { + char *classSig; + jclass k = classes[i]; + err = jvmti->GetClassSignature(k, &classSig, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Error (getClassSignature): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } else { + char* slash = strrchr(classSig, '/'); + const size_t len = strlen(classSig); + if (classSig[len-1] == ';') { + classSig[len-1] = 0; + } + if (*classSig == 'L' && slash != NULL) { + classSig = slash + 1; + } + setTag(env, k, rclass, (const char*)classSig); + } + } + + err = jvmti->GetAllThreads(&threadCount, &threads); + if (err != JVMTI_ERROR_NONE) { + printf("Error (GetAllThreads): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + for (i = 0; i < threadCount; ++i) { + jvmtiThreadInfo info; + jthread t = threads[i]; + err = jvmti->GetThreadInfo(t, &info); + if (err != JVMTI_ERROR_NONE) { + printf("Error (GetThreadInfo): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } else { + setTag(env, t, rthread, (const char*)info.name); + } + } + + env->PopLocalFrame(NULL); + + user_data_error_flag = JNI_FALSE; + err = jvmti->IterateOverHeap( + JVMTI_HEAP_OBJECT_UNTAGGED, + heapMarkCallback, + &dummy_user_data); + if (err != JVMTI_ERROR_NONE) { + printf("Error (IterateOverHeap): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + user_data_error_flag = JNI_FALSE; + err = jvmti->IterateOverReachableObjects( + heapRootCallback, + stackReferenceCallback, + objectReferenceCallback, + &dummy_user_data); + if (err != JVMTI_ERROR_NONE) { + printf("Error (IterateOverReachableObjects): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf("Heap Dump
\n");
+    walk(fakeRoot, 0, "roots");
+    printf("\n------------------- MISSED ------------------\n\n");
+    walk(missed, 0, "missed");
+    printf("
\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/libheapref.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/libheapref.c deleted file mode 100644 index 03f72184fb9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/libheapref.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "heapref.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/libheapref.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/libheapref.cpp new file mode 100644 index 00000000000..666291f074d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/heapref/libheapref.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "heapref.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/librefignore.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/librefignore.c deleted file mode 100644 index ae529c8f0ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/librefignore.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "refignore.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/librefignore.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/librefignore.cpp new file mode 100644 index 00000000000..546e589bd64 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/librefignore.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "refignore.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/refignore.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/refignore.c deleted file mode 100644 index 2bc5d217a27..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/refignore.c +++ /dev/null @@ -1,490 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "jni_tools.h" -#include "agent_common.h" -#include "JVMTITools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define PASSED 0 -#define STATUS_FAILED 2 - -static jvmtiEnv *jvmti = NULL; -static jint result = PASSED; -static jboolean printdump = JNI_FALSE; -static jvmtiCapabilities jvmti_caps; -static jint dummy_user_data = 0; -static jboolean user_data_error_flag = JNI_FALSE; - -#define HEAP_ROOT_REF_KIND_BASE 100 -#define MISSED_REF_KIND_BASE 300 - -typedef enum { - rthread, - rclass, - rother, - rmark -} refKind; - -struct _refLink; - -typedef struct _myTag { - refKind kind; - const struct _myTag* class_tag; - jlong size; - jlong sequence; - jboolean visited; - const char* name; - struct _refLink *ref; -} MyTag; - -typedef struct _refLink { - MyTag* tag; - int reference_kind; - struct _refLink *next; -} refLink; - -static MyTag *fakeRoot = NULL; -static MyTag *missed = NULL; - -static void breakpoint() { - printf("Continuing from BREAKPOINT\n"); -} - -static MyTag *newTag(refKind kind, - const MyTag* class_tag, - jlong size, - const char* name) { - static jlong seq_num = 0; - MyTag* new_tag = NULL; - - new_tag = malloc(sizeof(MyTag)); - if (NULL == new_tag) { - printf("Error (newTag malloc): failed\n"); - result = STATUS_FAILED; - } - new_tag->kind = kind; - new_tag->class_tag = class_tag; - new_tag->size = size; - new_tag->sequence = ++seq_num; - new_tag->visited = JNI_FALSE; - new_tag->name = name; - new_tag->ref = NULL; - return new_tag; -} - -static void setTag(JNIEnv *env, - jobject obj, - refKind kind, - const char* name) { - MyTag *new_tag = NULL; - MyTag *class_tag = NULL; - jvmtiError err; - jlong size = 0; - jclass obj_class = NULL; - jlong haba = 0; - - err = (*jvmti)->GetObjectSize(jvmti, obj, &size); - if (err != JVMTI_ERROR_NONE) { - printf("Error (ObjectSize): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - obj_class = (*env)->GetObjectClass(env, obj); - - err = (*jvmti)->GetTag(jvmti, obj_class, &haba); - class_tag = (MyTag*)(intptr_t)haba; - if (err != JVMTI_ERROR_NONE) { - printf("Error (GetTag): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - if (class_tag != NULL && class_tag->kind != rclass) { - printf("Error class tag which is not a class\n"); - result = STATUS_FAILED; - } - - new_tag = newTag(kind, class_tag, size, name); - - err = (*jvmti)->SetTag(jvmti, obj, (intptr_t)new_tag); - if (err != JVMTI_ERROR_NONE) { - printf("Error (SetTag): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } -} - -static void addRef(MyTag *from, int reference_kind, MyTag *to) { - refLink *new_ref; - - new_ref = malloc(sizeof(refLink)); - if (NULL == new_ref) { - printf("Error (addRef malloc): failed\n"); - result = STATUS_FAILED; - } - new_ref->tag = to; - new_ref->reference_kind = reference_kind; - new_ref->next = from->ref; - from->ref = new_ref; -} - -static const char* reference_label(refLink *link) { - int reference_kind = link->reference_kind; - const char *name = "**unknown**"; - switch (reference_kind) { - case JVMTI_REFERENCE_CLASS: - name = "class"; - break; - case JVMTI_REFERENCE_FIELD: - name = "field"; - break; - case JVMTI_REFERENCE_ARRAY_ELEMENT: - name = "array_element"; - break; - case JVMTI_REFERENCE_CLASS_LOADER: - name = "class_loader"; - break; - case JVMTI_REFERENCE_SIGNERS: - name = "signers"; - break; - case JVMTI_REFERENCE_PROTECTION_DOMAIN: - name = "protection_domain"; - break; - case JVMTI_REFERENCE_INTERFACE: - name = "interface"; - break; - case JVMTI_REFERENCE_STATIC_FIELD: - name = "static_field"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_JNI_GLOBAL: - name = "root::jni_global"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_SYSTEM_CLASS: - name = "root::system_class"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_MONITOR: - name = "root::monitor"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_STACK_LOCAL: - name = "root::local_var"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_JNI_LOCAL: - name = "root::jni_local"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_THREAD: - name = "root::thread"; - break; - case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_OTHER: - name = "root::other"; - break; - default: - printf("Error: Unexpected reference kind %d\n", reference_kind); - result = STATUS_FAILED; - break; - } - return name; -} - -static void walk(MyTag* tag, jint depth, const char* ref_label) { - static const char* const spaces = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "; - static const int len = 86; - const char *indent = spaces + (len - 2 * depth); - - const MyTag* const ctag = tag->class_tag; - const char* const cname = ctag != NULL ? ctag->name : ""; - - printf("%s", indent); - - if (tag->visited) { - printf("", tag->sequence); - } else { - printf("", tag->sequence); - } - if (tag->name) { - printf("%s(%s)", cname, tag->name); - } else { - printf("%s(%"LL"d)", cname, tag->sequence); - } - printf(" -- "); - printf("%s\n", ref_label); - if (!tag->visited) { - refLink *ref; - tag->visited = JNI_TRUE; - for (ref = tag->ref; ref; ref = ref->next) { - walk(ref->tag, depth + 1, reference_label(ref)); - } - } -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_refignore(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_refignore(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_refignore(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif - -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options != NULL && strcmp(options, "printdump") == 0) { - printdump = JNI_TRUE; - } - - res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), - JVMTI_VERSION_1_1); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - memset((void*)&jvmti_caps, 0, sizeof(jvmtiCapabilities)); - jvmti_caps.can_tag_objects = 1; - err = (*jvmti)->AddCapabilities(jvmti, &jvmti_caps); - if (err != JVMTI_ERROR_NONE) { - printf("Error (AddCapabilities): %s (%d)\n", TranslateError(err), err); - return JNI_ERR; - } - - return JNI_OK; -} - -jvmtiIterationControl JNICALL -heapMarkCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { - const MyTag* const tag = newTag(rmark, (const MyTag*)(intptr_t)class_tag, size, NULL); - *tag_ptr = (intptr_t)tag; - - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - printf("Error (heapMarkCallback): unexpected value of user_data\n"); - result = STATUS_FAILED; - } - return JVMTI_ITERATION_CONTINUE; -} - -jvmtiIterationControl JNICALL -heapRootCallback(jvmtiHeapRootKind root_kind, - jlong class_tag, jlong size, - jlong* tag_ptr, void* user_data) { - refKind kind = rother; - - if (0 == *tag_ptr) { - /* new tag */ - MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL); - addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, tag); - *tag_ptr = (intptr_t)tag; - } else { - /* existing tag */ - addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, (MyTag*)(intptr_t)*tag_ptr); - } - - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - printf("Error (heapRootCallback): unexpected value of user_data\n"); - result = STATUS_FAILED; - } - return JVMTI_ITERATION_CONTINUE; -} - -jvmtiIterationControl JNICALL -stackReferenceCallback(jvmtiHeapRootKind root_kind, - jlong class_tag, jlong size, - jlong* tag_ptr, jlong thread_tag, - jint depth, jmethodID method, - jint slot, void* user_data) { - refKind kind = rother; - - if (0 == *tag_ptr) { - /* new tag */ - MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL); - addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, tag); - *tag_ptr = (intptr_t)tag; - } else { - /* existing tag */ - addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, (MyTag*)(intptr_t)*tag_ptr); - } - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - printf("Error (stackReferenceCallback): unexpected value of user_data\n"); - result = STATUS_FAILED; - } - return JVMTI_ITERATION_CONTINUE; -} - -jvmtiIterationControl JNICALL -objectReferenceCallback(jvmtiObjectReferenceKind reference_kind, - jlong class_tag, jlong size, - jlong* tag_ptr, jlong referrer_tag, - jint referrer_index, void* user_data) { - refKind kind = rother; - MyTag* referrer = NULL; - - if (0 == referrer_tag) { - referrer = missed; - } else { - referrer = (MyTag *)(intptr_t)referrer_tag; - } - - if (0 == *tag_ptr) { - /* new tag */ - MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL); - addRef(referrer, reference_kind, tag); - *tag_ptr = (intptr_t) tag; - } else { - /* existing tag */ - MyTag* tag = (MyTag*)(intptr_t)*tag_ptr; - addRef(referrer, reference_kind, tag); - } - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - printf("Error (objectReferenceCallback): unexpected value of user_data\n"); - result = STATUS_FAILED; - } - return JVMTI_ITERATION_IGNORE; -} - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_refignore_check(JNIEnv *env, jclass cls) { - jvmtiError err; - jclass *classes; - jint classCount = 0; - jthread *threads; - jint threadCount = 0; - jint i; - - if (jvmti == NULL) { - printf("JVMTI client was not properly loaded!\n"); - return STATUS_FAILED; - } - - fakeRoot = newTag(rother, (const MyTag *)NULL, 0, "FAKE_ROOT"); - missed = newTag(rother, (const MyTag *)NULL, 0, "MISSED"); - - if ((*env)->PushLocalFrame(env, 500) != 0) { - printf("Error (PushLocalFrame): failed\n"); - result = STATUS_FAILED; - } - - err = (*jvmti)->GetLoadedClasses(jvmti, &classCount, &classes); - if (err != JVMTI_ERROR_NONE) { - printf("Error (GetLoadedClasses): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - for (i = 0; i < classCount; ++i) { - char *classSig; - jclass k = classes[i]; - err = (*jvmti)->GetClassSignature(jvmti, k, &classSig, NULL); - if (err != JVMTI_ERROR_NONE) { - printf("Error (getClassSignature): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } else { - char* slash = strrchr(classSig, '/'); - const size_t len = strlen(classSig); - if (classSig[len-1] == ';') { - classSig[len-1] = 0; - } - if (*classSig == 'L' && slash != NULL) { - classSig = slash + 1; - } - setTag(env, k, rclass, (const char*)classSig); - } - } - - err = (*jvmti)->GetAllThreads(jvmti, &threadCount, &threads); - if (err != JVMTI_ERROR_NONE) { - printf("Error (GetAllThreads): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - for (i = 0; i < threadCount; ++i) { - jvmtiThreadInfo info; - jthread t = threads[i]; - err = (*jvmti)->GetThreadInfo(jvmti, t, &info); - if (err != JVMTI_ERROR_NONE) { - printf("Error (GetThreadInfo): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } else { - setTag(env, t, rthread, (const char*)info.name); - } - } - - (*env)->PopLocalFrame(env, NULL); - - user_data_error_flag = JNI_FALSE; - err = (*jvmti)->IterateOverHeap(jvmti, - JVMTI_HEAP_OBJECT_UNTAGGED, - heapMarkCallback, - &dummy_user_data); - if (err != JVMTI_ERROR_NONE) { - printf("Error (IterateOverHeap): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - user_data_error_flag = JNI_FALSE; - err = (*jvmti)->IterateOverReachableObjects(jvmti, - heapRootCallback, - stackReferenceCallback, - objectReferenceCallback, - &dummy_user_data); - if (err != JVMTI_ERROR_NONE) { - printf("Error (IterateOverReachableObjects): %s (%d)\n", TranslateError(err), err); - result = STATUS_FAILED; - } - - if (printdump == JNI_TRUE) { - printf("Heap Dump
\n");
-    walk(fakeRoot, 0, "roots");
-    printf("\n------------------- MISSED ------------------\n\n");
-    walk(missed, 0, "missed");
-    printf("
\n"); - } - - return result; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/refignore.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/refignore.cpp new file mode 100644 index 00000000000..03113ccb93e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/refignore.cpp @@ -0,0 +1,490 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "jni_tools.h" +#include "agent_common.h" +#include "JVMTITools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define PASSED 0 +#define STATUS_FAILED 2 + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; +static jboolean printdump = JNI_FALSE; +static jvmtiCapabilities jvmti_caps; +static jint dummy_user_data = 0; +static jboolean user_data_error_flag = JNI_FALSE; + +#define HEAP_ROOT_REF_KIND_BASE 100 +#define MISSED_REF_KIND_BASE 300 + +typedef enum { + rthread, + rclass, + rother, + rmark +} refKind; + +struct _refLink; + +typedef struct _myTag { + refKind kind; + const struct _myTag* class_tag; + jlong size; + jlong sequence; + jboolean visited; + const char* name; + struct _refLink *ref; +} MyTag; + +typedef struct _refLink { + MyTag* tag; + int reference_kind; + struct _refLink *next; +} refLink; + +static MyTag *fakeRoot = NULL; +static MyTag *missed = NULL; + +static void breakpoint() { + printf("Continuing from BREAKPOINT\n"); +} + +static MyTag *newTag(refKind kind, + const MyTag* class_tag, + jlong size, + const char* name) { + static jlong seq_num = 0; + MyTag* new_tag = NULL; + + new_tag = (MyTag*) malloc(sizeof(MyTag)); + if (NULL == new_tag) { + printf("Error (newTag malloc): failed\n"); + result = STATUS_FAILED; + } + new_tag->kind = kind; + new_tag->class_tag = class_tag; + new_tag->size = size; + new_tag->sequence = ++seq_num; + new_tag->visited = JNI_FALSE; + new_tag->name = name; + new_tag->ref = NULL; + return new_tag; +} + +static void setTag(JNIEnv *env, + jobject obj, + refKind kind, + const char* name) { + MyTag *new_tag = NULL; + MyTag *class_tag = NULL; + jvmtiError err; + jlong size = 0; + jclass obj_class = NULL; + jlong haba = 0; + + err = jvmti->GetObjectSize(obj, &size); + if (err != JVMTI_ERROR_NONE) { + printf("Error (ObjectSize): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + obj_class = env->GetObjectClass(obj); + + err = jvmti->GetTag(obj_class, &haba); + class_tag = (MyTag*)(intptr_t)haba; + if (err != JVMTI_ERROR_NONE) { + printf("Error (GetTag): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + if (class_tag != NULL && class_tag->kind != rclass) { + printf("Error class tag which is not a class\n"); + result = STATUS_FAILED; + } + + new_tag = newTag(kind, class_tag, size, name); + + err = jvmti->SetTag(obj, (intptr_t)new_tag); + if (err != JVMTI_ERROR_NONE) { + printf("Error (SetTag): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } +} + +static void addRef(MyTag *from, int reference_kind, MyTag *to) { + refLink *new_ref; + + new_ref = (refLink*) malloc(sizeof(refLink)); + if (NULL == new_ref) { + printf("Error (addRef malloc): failed\n"); + result = STATUS_FAILED; + } + new_ref->tag = to; + new_ref->reference_kind = reference_kind; + new_ref->next = from->ref; + from->ref = new_ref; +} + +static const char* reference_label(refLink *link) { + int reference_kind = link->reference_kind; + const char *name = "**unknown**"; + switch (reference_kind) { + case JVMTI_REFERENCE_CLASS: + name = "class"; + break; + case JVMTI_REFERENCE_FIELD: + name = "field"; + break; + case JVMTI_REFERENCE_ARRAY_ELEMENT: + name = "array_element"; + break; + case JVMTI_REFERENCE_CLASS_LOADER: + name = "class_loader"; + break; + case JVMTI_REFERENCE_SIGNERS: + name = "signers"; + break; + case JVMTI_REFERENCE_PROTECTION_DOMAIN: + name = "protection_domain"; + break; + case JVMTI_REFERENCE_INTERFACE: + name = "interface"; + break; + case JVMTI_REFERENCE_STATIC_FIELD: + name = "static_field"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_JNI_GLOBAL: + name = "root::jni_global"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_SYSTEM_CLASS: + name = "root::system_class"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_MONITOR: + name = "root::monitor"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_STACK_LOCAL: + name = "root::local_var"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_JNI_LOCAL: + name = "root::jni_local"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_THREAD: + name = "root::thread"; + break; + case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_OTHER: + name = "root::other"; + break; + default: + printf("Error: Unexpected reference kind %d\n", reference_kind); + result = STATUS_FAILED; + break; + } + return name; +} + +static void walk(MyTag* tag, jint depth, const char* ref_label) { + static const char* const spaces = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "; + static const int len = 86; + const char *indent = spaces + (len - 2 * depth); + + const MyTag* const ctag = tag->class_tag; + const char* const cname = ctag != NULL ? ctag->name : ""; + + printf("%s", indent); + + if (tag->visited) { + printf("", tag->sequence); + } else { + printf("", tag->sequence); + } + if (tag->name) { + printf("%s(%s)", cname, tag->name); + } else { + printf("%s(%" LL "d)", cname, tag->sequence); + } + printf(" -- "); + printf("%s\n", ref_label); + if (!tag->visited) { + refLink *ref; + tag->visited = JNI_TRUE; + for (ref = tag->ref; ref; ref = ref->next) { + walk(ref->tag, depth + 1, reference_label(ref)); + } + } +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_refignore(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_refignore(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_refignore(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif + +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options != NULL && strcmp(options, "printdump") == 0) { + printdump = JNI_TRUE; + } + + res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_1_1); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + memset((void*)&jvmti_caps, 0, sizeof(jvmtiCapabilities)); + jvmti_caps.can_tag_objects = 1; + err = jvmti->AddCapabilities(&jvmti_caps); + if (err != JVMTI_ERROR_NONE) { + printf("Error (AddCapabilities): %s (%d)\n", TranslateError(err), err); + return JNI_ERR; + } + + return JNI_OK; +} + +jvmtiIterationControl JNICALL +heapMarkCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) { + const MyTag* const tag = newTag(rmark, (const MyTag*)(intptr_t)class_tag, size, NULL); + *tag_ptr = (intptr_t)tag; + + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + printf("Error (heapMarkCallback): unexpected value of user_data\n"); + result = STATUS_FAILED; + } + return JVMTI_ITERATION_CONTINUE; +} + +jvmtiIterationControl JNICALL +heapRootCallback(jvmtiHeapRootKind root_kind, + jlong class_tag, jlong size, + jlong* tag_ptr, void* user_data) { + refKind kind = rother; + + if (0 == *tag_ptr) { + /* new tag */ + MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL); + addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, tag); + *tag_ptr = (intptr_t)tag; + } else { + /* existing tag */ + addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, (MyTag*)(intptr_t)*tag_ptr); + } + + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + printf("Error (heapRootCallback): unexpected value of user_data\n"); + result = STATUS_FAILED; + } + return JVMTI_ITERATION_CONTINUE; +} + +jvmtiIterationControl JNICALL +stackReferenceCallback(jvmtiHeapRootKind root_kind, + jlong class_tag, jlong size, + jlong* tag_ptr, jlong thread_tag, + jint depth, jmethodID method, + jint slot, void* user_data) { + refKind kind = rother; + + if (0 == *tag_ptr) { + /* new tag */ + MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL); + addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, tag); + *tag_ptr = (intptr_t)tag; + } else { + /* existing tag */ + addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, (MyTag*)(intptr_t)*tag_ptr); + } + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + printf("Error (stackReferenceCallback): unexpected value of user_data\n"); + result = STATUS_FAILED; + } + return JVMTI_ITERATION_CONTINUE; +} + +jvmtiIterationControl JNICALL +objectReferenceCallback(jvmtiObjectReferenceKind reference_kind, + jlong class_tag, jlong size, + jlong* tag_ptr, jlong referrer_tag, + jint referrer_index, void* user_data) { + refKind kind = rother; + MyTag* referrer = NULL; + + if (0 == referrer_tag) { + referrer = missed; + } else { + referrer = (MyTag *)(intptr_t)referrer_tag; + } + + if (0 == *tag_ptr) { + /* new tag */ + MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL); + addRef(referrer, reference_kind, tag); + *tag_ptr = (intptr_t) tag; + } else { + /* existing tag */ + MyTag* tag = (MyTag*)(intptr_t)*tag_ptr; + addRef(referrer, reference_kind, tag); + } + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + printf("Error (objectReferenceCallback): unexpected value of user_data\n"); + result = STATUS_FAILED; + } + return JVMTI_ITERATION_IGNORE; +} + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_refignore_check(JNIEnv *env, jclass cls) { + jvmtiError err; + jclass *classes; + jint classCount = 0; + jthread *threads; + jint threadCount = 0; + jint i; + + if (jvmti == NULL) { + printf("JVMTI client was not properly loaded!\n"); + return STATUS_FAILED; + } + + fakeRoot = newTag(rother, (const MyTag *)NULL, 0, "FAKE_ROOT"); + missed = newTag(rother, (const MyTag *)NULL, 0, "MISSED"); + + if (env->PushLocalFrame(500) != 0) { + printf("Error (PushLocalFrame): failed\n"); + result = STATUS_FAILED; + } + + err = jvmti->GetLoadedClasses(&classCount, &classes); + if (err != JVMTI_ERROR_NONE) { + printf("Error (GetLoadedClasses): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + for (i = 0; i < classCount; ++i) { + char *classSig; + jclass k = classes[i]; + err = jvmti->GetClassSignature(k, &classSig, NULL); + if (err != JVMTI_ERROR_NONE) { + printf("Error (getClassSignature): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } else { + char* slash = strrchr(classSig, '/'); + const size_t len = strlen(classSig); + if (classSig[len-1] == ';') { + classSig[len-1] = 0; + } + if (*classSig == 'L' && slash != NULL) { + classSig = slash + 1; + } + setTag(env, k, rclass, (const char*)classSig); + } + } + + err = jvmti->GetAllThreads(&threadCount, &threads); + if (err != JVMTI_ERROR_NONE) { + printf("Error (GetAllThreads): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + for (i = 0; i < threadCount; ++i) { + jvmtiThreadInfo info; + jthread t = threads[i]; + err = jvmti->GetThreadInfo(t, &info); + if (err != JVMTI_ERROR_NONE) { + printf("Error (GetThreadInfo): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } else { + setTag(env, t, rthread, (const char*)info.name); + } + } + + env->PopLocalFrame(NULL); + + user_data_error_flag = JNI_FALSE; + err = jvmti->IterateOverHeap( + JVMTI_HEAP_OBJECT_UNTAGGED, + heapMarkCallback, + &dummy_user_data); + if (err != JVMTI_ERROR_NONE) { + printf("Error (IterateOverHeap): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + user_data_error_flag = JNI_FALSE; + err = jvmti->IterateOverReachableObjects( + heapRootCallback, + stackReferenceCallback, + objectReferenceCallback, + &dummy_user_data); + if (err != JVMTI_ERROR_NONE) { + printf("Error (IterateOverReachableObjects): %s (%d)\n", TranslateError(err), err); + result = STATUS_FAILED; + } + + if (printdump == JNI_TRUE) { + printf("Heap Dump
\n");
+    walk(fakeRoot, 0, "roots");
+    printf("\n------------------- MISSED ------------------\n\n");
+    walk(missed, 0, "missed");
+    printf("
\n"); + } + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/JvmtiTest.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/JvmtiTest.c deleted file mode 100644 index 9fbafc47c13..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/JvmtiTest.c +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - This test case to test the following: - - VMInit initial thread arg. - SetThreadLocalStorage and SetEnvironmentLocalStorage should allow - value to be set to NULL. - */ - -#include -#include -#include -#include "jvmti.h" -#include "jni_tools.h" -#include "agent_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_ARG(x, y) y -#define JNI_ENV_ARG1(x) -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG(x,y) x, y -#define JNI_ENV_ARG1(x) x -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define JVMTI_ENV_ARG JNI_ENV_ARG -#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 -#define JVMTI_ENV_PTR JNI_ENV_PTR - -#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} - -#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } - -#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } - -jvmtiEnv *jvmti; -jint iGlobalStatus = 0; -static jvmtiEventCallbacks callbacks; - -int printdump = 0; - - -void debug_printf(char *fmt, ...) { - va_list args; - - va_start(args, fmt); - if (printdump) { - vprintf(fmt, args); - } - va_end(args); -} - - -intptr_t get_env_local() { - jvmtiError res; - void *val; - res = JVMTI_ENV_PTR(jvmti)->GetEnvironmentLocalStorage(jvmti, &val); - JVMTI_ERROR_CHECK("GetEnvironmentLocalStorage returned error", res); - return (intptr_t)val; -} - -void set_env_local(intptr_t x) { - jvmtiError res; - void *val = (void*)x; - res = JVMTI_ENV_PTR(jvmti)->SetEnvironmentLocalStorage(jvmti, val); - JVMTI_ERROR_CHECK_VOID("SetEnvironmentLocalStorage returned error", res); -} - -intptr_t get_thread_local(jthread thread) { - jvmtiError res; - void *val; - res = JVMTI_ENV_PTR(jvmti)->GetThreadLocalStorage(jvmti, thread, &val); - JVMTI_ERROR_CHECK("GetThreadLocalStorage returned error", res); - return (intptr_t)val; -} - -void set_thread_local(jthread thread, intptr_t x) { - jvmtiError res; - void *val = (void*)x; - res = JVMTI_ENV_PTR(jvmti)->SetThreadLocalStorage(jvmti, thread, val); - JVMTI_ERROR_CHECK_VOID("SetThreadLocalStorage returned error", res); -} - -void check_val(intptr_t x, intptr_t y, char *msg) { - if (x != y) { - printf("Error in %s: expected %" PRIdPTR " to be %" PRIdPTR "\n", msg, x, y); - iGlobalStatus = 2; - } else if (printdump) { - printf("Correct in %s: expected %" PRIdPTR " to be %" PRIdPTR "\n", msg, x, y); - } -} - - -void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread) { - check_val(get_thread_local(thread), 0, "thread initial"); - check_val(get_thread_local(NULL), 0, "thread initial"); - set_thread_local(thread, 35); - check_val(get_thread_local(thread), 35, "thread set non-zero"); - check_val(get_thread_local(NULL), 35, "thread set non-zero"); - set_thread_local(NULL, 0); - check_val(get_thread_local(thread), 0, "thread set zero"); - check_val(get_thread_local(NULL), 0, "thread set zero"); - - check_val(get_env_local(), 14, "env set non-zero"); - set_env_local(77); - check_val(get_env_local(), 77, "env set non-zero"); -} - - -void init_callbacks() { - memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); - callbacks.VMInit = vmInit; -} - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { - jint res; - - if (options && strlen(options) > 0) { - if (strstr(options, "printdump")) { - printdump = 1; - } - } - - res = JNI_ENV_PTR(jvm)-> - GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); - if (res < 0) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - check_val(get_env_local(), 0, "env initial"); - set_env_local(0); - check_val(get_env_local(), 0, "env set zero"); - set_env_local(14); - check_val(get_env_local(), 14, "env set non-zero"); - - /* Enable events */ - init_callbacks(); - res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); - JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL); - JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); - - return JNI_OK; -} - - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_setNullVMInit_JvmtiTest_check(JNIEnv *env, jclass cls) { - check_val(get_env_local(), 77, "env lasts"); - set_env_local(0); - check_val(get_env_local(), 0, "env reset to zero"); - - check_val(get_thread_local(NULL), 0, "thread check"); - - return iGlobalStatus; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/JvmtiTest.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/JvmtiTest.cpp new file mode 100644 index 00000000000..c0b2a931190 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/JvmtiTest.cpp @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + This test case to test the following: + + VMInit initial thread arg. + SetThreadLocalStorage and SetEnvironmentLocalStorage should allow + value to be set to NULL. + */ + +#include +#include +#include +#include "jvmti.h" +#include "jni_tools.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_ARG1(x) +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_ARG1(x) x +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define JVMTI_ENV_ARG JNI_ENV_ARG +#define JVMTI_ENV_ARG1 JNI_ENV_ARG1 +#define JVMTI_ENV_PTR JNI_ENV_PTR + +#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;} +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;} + +#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; } + +#define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; } + +jvmtiEnv *jvmti; +jint iGlobalStatus = 0; +static jvmtiEventCallbacks callbacks; + +int printdump = 0; + + +void debug_printf(char *fmt, ...) { + va_list args; + + va_start(args, fmt); + if (printdump) { + vprintf(fmt, args); + } + va_end(args); +} + + +intptr_t get_env_local() { + jvmtiError res; + void *val; + res = JVMTI_ENV_PTR(jvmti)->GetEnvironmentLocalStorage(JVMTI_ENV_ARG(jvmti, &val)); + JVMTI_ERROR_CHECK("GetEnvironmentLocalStorage returned error", res); + return (intptr_t)val; +} + +void set_env_local(intptr_t x) { + jvmtiError res; + void *val = (void*)x; + res = JVMTI_ENV_PTR(jvmti)->SetEnvironmentLocalStorage(JVMTI_ENV_ARG(jvmti, val)); + JVMTI_ERROR_CHECK_VOID("SetEnvironmentLocalStorage returned error", res); +} + +intptr_t get_thread_local(jthread thread) { + jvmtiError res; + void *val; + res = JVMTI_ENV_PTR(jvmti)->GetThreadLocalStorage(JVMTI_ENV_ARG(jvmti, thread), &val); + JVMTI_ERROR_CHECK("GetThreadLocalStorage returned error", res); + return (intptr_t)val; +} + +void set_thread_local(jthread thread, intptr_t x) { + jvmtiError res; + void *val = (void*)x; + res = JVMTI_ENV_PTR(jvmti)->SetThreadLocalStorage(JVMTI_ENV_ARG(jvmti, thread), val); + JVMTI_ERROR_CHECK_VOID("SetThreadLocalStorage returned error", res); +} + +void check_val(intptr_t x, intptr_t y, const char* msg) { + if (x != y) { + printf("Error in %s: expected %" PRIdPTR " to be %" PRIdPTR "\n", msg, x, y); + iGlobalStatus = 2; + } else if (printdump) { + printf("Correct in %s: expected %" PRIdPTR " to be %" PRIdPTR "\n", msg, x, y); + } +} + + +void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread) { + check_val(get_thread_local(thread), 0, "thread initial"); + check_val(get_thread_local(NULL), 0, "thread initial"); + set_thread_local(thread, 35); + check_val(get_thread_local(thread), 35, "thread set non-zero"); + check_val(get_thread_local(NULL), 35, "thread set non-zero"); + set_thread_local(NULL, 0); + check_val(get_thread_local(thread), 0, "thread set zero"); + check_val(get_thread_local(NULL), 0, "thread set zero"); + + check_val(get_env_local(), 14, "env set non-zero"); + set_env_local(77); + check_val(get_env_local(), 77, "env set non-zero"); +} + + +void init_callbacks() { + memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); + callbacks.VMInit = vmInit; +} + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { + jint res; + + if (options && strlen(options) > 0) { + if (strstr(options, "printdump")) { + printdump = 1; + } + } + + res = JNI_ENV_PTR(jvm)-> + GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); + if (res < 0) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + check_val(get_env_local(), 0, "env initial"); + set_env_local(0); + check_val(get_env_local(), 0, "env set zero"); + set_env_local(14); + check_val(get_env_local(), 14, "env set non-zero"); + + /* Enable events */ + init_callbacks(); + res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks)); + JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti, JVMTI_ENABLE), JVMTI_EVENT_VM_INIT,NULL); + JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res); + + return JNI_OK; +} + + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_setNullVMInit_JvmtiTest_check(JNIEnv *env, jclass cls) { + check_val(get_env_local(), 77, "env lasts"); + set_env_local(0); + check_val(get_env_local(), 0, "env reset to zero"); + + check_val(get_thread_local(NULL), 0, "thread check"); + + return iGlobalStatus; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/libsetNullVMInit.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/libsetNullVMInit.c deleted file mode 100644 index fcef2030c0e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/libsetNullVMInit.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "JvmtiTest.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/libsetNullVMInit.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/libsetNullVMInit.cpp new file mode 100644 index 00000000000..fea00132b93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/setNullVMInit/JvmtiTest/libsetNullVMInit.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "JvmtiTest.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/JvmtiTest.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/JvmtiTest.c deleted file mode 100644 index d7b360d3a66..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/JvmtiTest.c +++ /dev/null @@ -1,382 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - This test case to test the following: - - GetCurrentThreadCpuTime - GetThreadCpuTime - GetTime - */ - -#define VARIANCE (0.10) -#define VARIANCE_PERCENT (VARIANCE * 100.0) - -#include -#include -#include "jvmti.h" -#include "agent_common.h" - -#include "jni_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_ARG - -#ifdef __cplusplus -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -#define JVMTI_ENV_PTR JNI_ENV_PTR - -#define JVMTI_ERROR_CHECK_DURING_ONLOAD(str,res) if ( res != JVMTI_ERROR_NONE) { printf("Fatal error: %s - %d\n", str, res); return JNI_ERR; } - -#define JVMTI_ERROR_CHECK_RETURN(str,res) if ( res != JVMTI_ERROR_NONE) { printf("Error: %s - %d\n", str, res); return; } - -#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf("Error: %s - %d\n", str, res); } - -#define THREADS_LIMIT 200 - - -jvmtiEnv *jvmti; -jint iGlobalStatus = 0; -jthread susp_thrd[THREADS_LIMIT]; -static jvmtiEventCallbacks callbacks; -static jvmtiCapabilities capabilities; -jrawMonitorID jraw_monitor[20]; - jlong initial_time; - - struct ThreadInfo { - jint iterationCount; - jlong currThreadTime; - jlong threadTime; - jweak ref; - } thread_info[THREADS_LIMIT]; - -int printdump = 1; - - -void debug_printf(char *fmt, ...) { - va_list args; - - va_start(args, fmt); - if (printdump) { - vprintf(fmt, args); - } - va_end(args); -} - -void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { - jvmtiError err; - char buffer[32]; - - debug_printf("VMInit event\n"); - - debug_printf("jvmti GetTime \n"); - err = JVMTI_ENV_PTR(jvmti)->GetTime(jvmti_env, &initial_time); - JVMTI_ERROR_CHECK("GetTime", err); - debug_printf(" Initial time: %s ns\n", - jlong_to_string(initial_time, buffer)); -} - -void JNICALL vmExit(jvmtiEnv *jvmti_env, JNIEnv *env) { - debug_printf("VMDeath event\n"); -} - - -void init_callbacks() { - memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); - callbacks.VMInit = vmInit; - callbacks.VMDeath = vmExit; -} - - -#ifdef STATIC_BUILD -JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return Agent_Initialize(jvm, options, reserved); -} -JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { - return JNI_VERSION_1_8; -} -#endif -jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { - jint res; - jvmtiError err; - - if (options && strlen(options) > 0) { - if (strstr(options, "printdump")) { - printdump = 1; - } - } - - res = (*jvm)->GetEnv(jvm, (void **) &jvmti, JVMTI_VERSION_1_1); - if (res < 0) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - - - /* Add capabilities */ - memset(&capabilities, 0, sizeof(jvmtiCapabilities)); - capabilities.can_get_current_thread_cpu_time = 1; - capabilities.can_get_thread_cpu_time = 1; - err = (*jvmti)->AddCapabilities(jvmti, &capabilities); - JVMTI_ERROR_CHECK_DURING_ONLOAD("(AddCapabilities)", err); - - /* Enable events */ - init_callbacks(); - res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - JVMTI_ERROR_CHECK_DURING_ONLOAD("SetEventCallbacks returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,JVMTI_EVENT_VM_INIT,NULL); - JVMTI_ERROR_CHECK_DURING_ONLOAD("SetEventNotificationMode for VM_INIT returned error", res); - - res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,JVMTI_EVENT_VM_DEATH,NULL); - JVMTI_ERROR_CHECK_DURING_ONLOAD("SetEventNotificationMode for vm death event returned error", res); - - return JNI_OK; -} - - -JNIEXPORT jint JNICALL -Java_nsk_jvmti_unit_timers_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { - return iGlobalStatus; -} - -#define milli(x) ((x)/(1000L * 1000L)) - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_timers_JvmtiTest_RegisterCompletedThread(JNIEnv * env, - jclass cls, jthread thread, jint threadNumber, jint iterationCount) { - jvmtiError ret; - jlong curr; - - debug_printf("jvmti GetCurrentThreadCpuTime \n"); - ret = JVMTI_ENV_PTR(jvmti)->GetCurrentThreadCpuTime(jvmti, &curr); - JVMTI_ERROR_CHECK_RETURN("GetCurrentThreadCpuTime", ret); - - thread_info[threadNumber].iterationCount = iterationCount; - thread_info[threadNumber].currThreadTime = curr; - thread_info[threadNumber].ref = JNI_ENV_PTR(env)->NewWeakGlobalRef(env, thread); -} - -static void print_timerinfo(jvmtiTimerInfo* timerInfo) { - char buffer[32]; - char* timerKind; - switch(timerInfo->kind) { - case JVMTI_TIMER_USER_CPU: - timerKind = "JVMTI_TIMER_USER_CPU"; - break; - case JVMTI_TIMER_TOTAL_CPU: - timerKind = "JVMTI_TIMER_TOTAL_CPU"; - break; - case JVMTI_TIMER_ELAPSED: - timerKind = "JVMTI_TIMER_ELAPSED_CPU"; - break; - default: - timerKind = ""; - break; - } - debug_printf(" Max = %s [%s %s] kind = %s\n", - jlong_to_string(timerInfo->max_value, buffer), - timerInfo->may_skip_forward? "skip-forward" : "stable", - timerInfo->may_skip_backward? "skip-backward" : "stable", - timerKind); -} - -JNIEXPORT void JNICALL -Java_nsk_jvmti_unit_timers_JvmtiTest_Analyze(JNIEnv * env, jclass cls) { - jvmtiError ret; - jlong now; - jlong etime; - jint thrCnt; - jvmtiTimerInfo timerInfoCurr; - jvmtiTimerInfo timerInfoOther; - jvmtiTimerInfo timerInfoTime; - jint processor_count; - jint totalIter = 0; - jlong totalTimeCurr = 0; - jlong totalTime = 0; - jlong possibleTime; - double one_iter_cost; - jthread *thrArray; - int k; - int i; - char buffer[32]; - - debug_printf("jvmti GetTime \n"); - ret = JVMTI_ENV_PTR(jvmti)->GetTime(jvmti, &now); - JVMTI_ERROR_CHECK_RETURN("GetTime", ret); - etime = now - initial_time; - debug_printf(" Elapsed time: %s ms\n", - jlong_to_string(milli(etime), buffer)); - - debug_printf("jvmti GetCurrentThreadCpuTimerInfo \n"); - ret = JVMTI_ENV_PTR(jvmti)->GetCurrentThreadCpuTimerInfo(jvmti, &timerInfoCurr); - JVMTI_ERROR_CHECK_RETURN("GetCurrentThreadCpuTimerInfo", ret); - print_timerinfo(&timerInfoCurr); - - debug_printf("jvmti GetThreadCpuTimerInfo \n"); - ret = JVMTI_ENV_PTR(jvmti)->GetThreadCpuTimerInfo(jvmti, &timerInfoOther); - JVMTI_ERROR_CHECK_RETURN("GetThreadCpuTimerInfo", ret); - print_timerinfo(&timerInfoOther); - - debug_printf("jvmti GetTimerInfo \n"); - ret = JVMTI_ENV_PTR(jvmti)->GetTimerInfo(jvmti, &timerInfoTime); - JVMTI_ERROR_CHECK_RETURN("GetTimerInfo", ret); - print_timerinfo(&timerInfoTime); - - debug_printf("jvmti GetAvailableProcessors \n"); - ret = JVMTI_ENV_PTR(jvmti)->GetAvailableProcessors(jvmti, &processor_count); - JVMTI_ERROR_CHECK_RETURN("GetAvailableProcessors", ret); - debug_printf(" processor_count = %d\n", processor_count); - - debug_printf("jvmti GetAllThreads \n"); - ret = JVMTI_ENV_PTR(jvmti)->GetAllThreads(jvmti, &thrCnt, &thrArray); - JVMTI_ERROR_CHECK_RETURN("GetAllThreads", ret); - - for (k = 0; k < thrCnt; ++k) { - jlong oth; - jthread thread; - - thread = thrArray[k]; - ret = JVMTI_ENV_PTR(jvmti)->GetThreadCpuTime(jvmti, thread, &oth); - JVMTI_ERROR_CHECK_RETURN("GetThreadCpuTime", ret); - - for (i = 1; i < THREADS_LIMIT; ++i) { - jweak tref = thread_info[i].ref; - if (tref != 0) { - if (JNI_ENV_PTR(env)->IsSameObject(env, thread, tref)) { - thread_info[i].threadTime = oth; - break; - } - } - } - if (i == THREADS_LIMIT) { - jvmtiThreadInfo info; - info.name = "*retrieval error*"; - ret = JVMTI_ENV_PTR(jvmti)->GetThreadInfo(jvmti, thread, &info); - JVMTI_ERROR_CHECK("GetThreadInfo %d \n", ret); - - debug_printf("non-test thread: %s - %s ms\n", info.name, - jlong_to_string(milli(oth), buffer)); - } - } - for (i = 1; i < THREADS_LIMIT; ++i) { - jweak tref = thread_info[i].ref; - if (tref != 0) { - totalIter += thread_info[i].iterationCount; - totalTimeCurr += thread_info[i].currThreadTime; - totalTime += thread_info[i].threadTime; - } - } - possibleTime = etime * processor_count; - debug_printf("Totals -- \n"); - debug_printf(" Iter = %d\n", totalIter); - debug_printf(" Total GetThreadCpuTime = %s ns", jlong_to_string(totalTime, buffer)); - debug_printf(" %s ms\n", jlong_to_string(milli(totalTime), buffer)); - debug_printf(" Total GetCurrentThreadCpuTimerInfo = %s ns", jlong_to_string(totalTimeCurr, buffer)); - debug_printf(" %s ms\n", jlong_to_string(milli(totalTimeCurr), buffer)); - debug_printf(" GetTime = %s ns", jlong_to_string(etime, buffer)); - debug_printf(" %s ms\n", jlong_to_string(milli(etime), buffer)); - debug_printf(" GetTime * processor_count = %s ns", jlong_to_string(possibleTime, buffer)); - debug_printf(" %s ms\n", jlong_to_string(milli(possibleTime), buffer)); - if (totalTime <= possibleTime) { - debug_printf("Pass: ttime <= possible_time\n"); - } else { - printf("FAIL: ttime > possible_time\n"); - iGlobalStatus = 2; - } - if (totalTimeCurr <= totalTime) { - debug_printf("Pass: ttime_curr <= ttime\n"); - } else { - printf("FAIL: ttime_curr > ttime\n"); - iGlobalStatus = 2; - } - if (totalTimeCurr >= totalTime*(1-VARIANCE)) { - debug_printf("Pass: ttime_curr >= %2.0f%% of ttime\n", 100.0 - VARIANCE_PERCENT); - } else { - printf("FAIL: ttime_curr < %2.0f%% of ttime\n", 100.0 - VARIANCE_PERCENT); - iGlobalStatus = 2; - } - one_iter_cost = (double)totalTime / totalIter; - debug_printf("CURRENT: total time returned by \"GetCurrentThreadCpuTime\".\n"); - debug_printf("OTHER: total time returned by \"GetThreadCpuTime\".\n"); - debug_printf("EXPECT: the expected time if TestThread.run() had a proportional cost across all threads.\n"); - debug_printf("%% DIFF: how much \"Expect\" is off by.\n"); - debug_printf("THREAD ITERATIONS CURRENT OTHER EXPECT % DIFF\n"); - for (i = 1; i < THREADS_LIMIT; ++i) { - jweak tref = thread_info[i].ref; - if (tref != 0) { - jint ic = thread_info[i].iterationCount; - jlong ctt = thread_info[i].currThreadTime; - jlong tt = thread_info[i].threadTime; - double expt = ic * one_iter_cost; - double var = 100.0 * ((double)tt - expt) / expt; - debug_printf("%6d %10d %5s ms", i, ic, - jlong_to_string(milli(ctt), buffer)); - debug_printf(" %5s ms %5.0f ms %7.1f%%\n", - jlong_to_string(milli(tt), buffer), milli(expt), var); - if (ctt <= tt) { - debug_printf("Pass: currThreadTime <= threadTime\n"); - } else { - printf("FAIL: currThreadTime > threadTime\n"); - iGlobalStatus = 2; - } - { - int passed = ctt >= tt*(1-VARIANCE); -#ifdef _WIN32 - // On Windows the timer is only accurate to within 15ms. This sometimes triggers - // failures if the expected max variance is close to or below 15ms. So we don't - // fail in this case. - if (!passed && milli(tt - ctt) <= 15) { - printf("Passing due to special consideration on Windows for 15ms timer accuracy\n"); - passed = 1; - } -#endif - if (passed) { - debug_printf("Pass: currThreadTime(" JLONG_FORMAT ") >= %2.0f%% of threadTime(" JLONG_FORMAT ")\n", - ctt, 100.0 - VARIANCE_PERCENT, tt); - } else { - printf("FAIL: currThreadTime(" JLONG_FORMAT ") < %2.0f%% of threadTime(" JLONG_FORMAT ")\n", - ctt, 100.0 - VARIANCE_PERCENT, tt); - iGlobalStatus = 2; - } - } - } - } -} - - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/JvmtiTest.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/JvmtiTest.cpp new file mode 100644 index 00000000000..9d6edfcf14e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/JvmtiTest.cpp @@ -0,0 +1,385 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + This test case to test the following: + + GetCurrentThreadCpuTime + GetThreadCpuTime + GetTime + */ + +#define VARIANCE (0.10) +#define VARIANCE_PERCENT (VARIANCE * 100.0) + +#include +#include +#include "jvmti.h" +#include "agent_common.h" + +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_PTR(x) x +#define JNI_ENV_ARG(x, y) y +#else +#define JNI_ENV_PTR(x) (*x) +#define JNI_ENV_ARG(x, y) x, y +#endif + +#endif + +#define JVMTI_ENV_PTR JNI_ENV_PTR +#define JVMTI_ENV_ARG JNI_ENV_ARG + +#define JVMTI_ERROR_CHECK_DURING_ONLOAD(str,res) if ( res != JVMTI_ERROR_NONE) { printf("Fatal error: %s - %d\n", str, res); return JNI_ERR; } + +#define JVMTI_ERROR_CHECK_RETURN(str,res) if ( res != JVMTI_ERROR_NONE) { printf("Error: %s - %d\n", str, res); return; } + +#define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf("Error: %s - %d\n", str, res); } + +#define THREADS_LIMIT 200 + + +jvmtiEnv *jvmti; +jint iGlobalStatus = 0; +jthread susp_thrd[THREADS_LIMIT]; +static jvmtiEventCallbacks callbacks; +static jvmtiCapabilities capabilities; +jrawMonitorID jraw_monitor[20]; + jlong initial_time; + + struct ThreadInfo { + jint iterationCount; + jlong currThreadTime; + jlong threadTime; + jweak ref; + } thread_info[THREADS_LIMIT]; + +int printdump = 1; + + +void debug_printf(const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + if (printdump) { + vprintf(fmt, args); + } + va_end(args); +} + +void JNICALL vmInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) { + jvmtiError err; + char buffer[32]; + + debug_printf("VMInit event\n"); + + debug_printf("jvmti GetTime \n"); + err = JVMTI_ENV_PTR(jvmti_env)->GetTime(JVMTI_ENV_ARG(jvmti_env, &initial_time)); + JVMTI_ERROR_CHECK("GetTime", err); + debug_printf(" Initial time: %s ns\n", + jlong_to_string(initial_time, buffer)); +} + +void JNICALL vmExit(jvmtiEnv *jvmti_env, JNIEnv *env) { + debug_printf("VMDeath event\n"); +} + + +void init_callbacks() { + memset((void *)&callbacks, 0, sizeof(jvmtiEventCallbacks)); + callbacks.VMInit = vmInit; + callbacks.VMDeath = vmExit; +} + + +#ifdef STATIC_BUILD +JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} +JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) { + return JNI_VERSION_1_8; +} +#endif +jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { + jint res; + jvmtiError err; + + if (options && strlen(options) > 0) { + if (strstr(options, "printdump")) { + printdump = 1; + } + } + + res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1); + if (res < 0) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + + /* Add capabilities */ + memset(&capabilities, 0, sizeof(jvmtiCapabilities)); + capabilities.can_get_current_thread_cpu_time = 1; + capabilities.can_get_thread_cpu_time = 1; + err = jvmti->AddCapabilities(&capabilities); + JVMTI_ERROR_CHECK_DURING_ONLOAD("(AddCapabilities)", err); + + /* Enable events */ + init_callbacks(); + res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti_env, &callbacks), sizeof(callbacks)); + JVMTI_ERROR_CHECK_DURING_ONLOAD("SetEventCallbacks returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti_env, JVMTI_ENABLE), JVMTI_EVENT_VM_INIT, NULL); + JVMTI_ERROR_CHECK_DURING_ONLOAD("SetEventNotificationMode for VM_INIT returned error", res); + + res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti_env, JVMTI_ENABLE), JVMTI_EVENT_VM_DEATH, NULL); + JVMTI_ERROR_CHECK_DURING_ONLOAD("SetEventNotificationMode for vm death event returned error", res); + + return JNI_OK; +} + + +JNIEXPORT jint JNICALL +Java_nsk_jvmti_unit_timers_JvmtiTest_GetResult(JNIEnv * env, jclass cls) { + return iGlobalStatus; +} + +#define milli(x) ((x)/(1000L * 1000L)) + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_timers_JvmtiTest_RegisterCompletedThread(JNIEnv * env, + jclass cls, jthread thread, jint threadNumber, jint iterationCount) { + jvmtiError ret; + jlong curr; + + debug_printf("jvmti GetCurrentThreadCpuTime \n"); + ret = JVMTI_ENV_PTR(jvmti)->GetCurrentThreadCpuTime(JVMTI_ENV_ARG(jvmti_env, &curr)); + JVMTI_ERROR_CHECK_RETURN("GetCurrentThreadCpuTime", ret); + + thread_info[threadNumber].iterationCount = iterationCount; + thread_info[threadNumber].currThreadTime = curr; + thread_info[threadNumber].ref = JNI_ENV_PTR(env)->NewWeakGlobalRef(JNI_ENV_ARG(env, thread)); +} + +static void print_timerinfo(jvmtiTimerInfo* timerInfo) { + char buffer[32]; + const char* timerKind; + switch(timerInfo->kind) { + case JVMTI_TIMER_USER_CPU: + timerKind = "JVMTI_TIMER_USER_CPU"; + break; + case JVMTI_TIMER_TOTAL_CPU: + timerKind = "JVMTI_TIMER_TOTAL_CPU"; + break; + case JVMTI_TIMER_ELAPSED: + timerKind = "JVMTI_TIMER_ELAPSED_CPU"; + break; + default: + timerKind = ""; + break; + } + debug_printf(" Max = %s [%s %s] kind = %s\n", + jlong_to_string(timerInfo->max_value, buffer), + timerInfo->may_skip_forward? "skip-forward" : "stable", + timerInfo->may_skip_backward? "skip-backward" : "stable", + timerKind); +} + +JNIEXPORT void JNICALL +Java_nsk_jvmti_unit_timers_JvmtiTest_Analyze(JNIEnv * env, jclass cls) { + jvmtiError ret; + jlong now; + jlong etime; + jint thrCnt; + jvmtiTimerInfo timerInfoCurr; + jvmtiTimerInfo timerInfoOther; + jvmtiTimerInfo timerInfoTime; + jint processor_count; + jint totalIter = 0; + jlong totalTimeCurr = 0; + jlong totalTime = 0; + jlong possibleTime; + double one_iter_cost; + jthread *thrArray; + int k; + int i; + char buffer[32]; + + debug_printf("jvmti GetTime \n"); + ret = JVMTI_ENV_PTR(jvmti)->GetTime(JVMTI_ENV_ARG(jvmti_env, &now)); + JVMTI_ERROR_CHECK_RETURN("GetTime", ret); + etime = now - initial_time; + debug_printf(" Elapsed time: %s ms\n", + jlong_to_string(milli(etime), buffer)); + + debug_printf("jvmti GetCurrentThreadCpuTimerInfo \n"); + ret = JVMTI_ENV_PTR(jvmti)->GetCurrentThreadCpuTimerInfo(JVMTI_ENV_ARG(jvmti_env, &timerInfoCurr)); + JVMTI_ERROR_CHECK_RETURN("GetCurrentThreadCpuTimerInfo", ret); + print_timerinfo(&timerInfoCurr); + + debug_printf("jvmti GetThreadCpuTimerInfo \n"); + ret = JVMTI_ENV_PTR(jvmti)->GetThreadCpuTimerInfo(JVMTI_ENV_ARG(jvmti_env, &timerInfoOther)); + JVMTI_ERROR_CHECK_RETURN("GetThreadCpuTimerInfo", ret); + print_timerinfo(&timerInfoOther); + + debug_printf("jvmti GetTimerInfo \n"); + ret = JVMTI_ENV_PTR(jvmti)->GetTimerInfo(JVMTI_ENV_ARG(jvmti_env, &timerInfoTime)); + JVMTI_ERROR_CHECK_RETURN("GetTimerInfo", ret); + print_timerinfo(&timerInfoTime); + + debug_printf("jvmti GetAvailableProcessors \n"); + ret = JVMTI_ENV_PTR(jvmti)->GetAvailableProcessors(JVMTI_ENV_ARG(jvmti_env, &processor_count)); + JVMTI_ERROR_CHECK_RETURN("GetAvailableProcessors", ret); + debug_printf(" processor_count = %d\n", processor_count); + + debug_printf("jvmti GetAllThreads \n"); + ret = JVMTI_ENV_PTR(jvmti)->GetAllThreads(JVMTI_ENV_ARG(jvmti_env, &thrCnt), &thrArray); + JVMTI_ERROR_CHECK_RETURN("GetAllThreads", ret); + + for (k = 0; k < thrCnt; ++k) { + jlong oth; + jthread thread; + + thread = thrArray[k]; + ret = JVMTI_ENV_PTR(jvmti)->GetThreadCpuTime(JVMTI_ENV_ARG(jvmti_env, thread), &oth); + JVMTI_ERROR_CHECK_RETURN("GetThreadCpuTime", ret); + + for (i = 1; i < THREADS_LIMIT; ++i) { + jweak tref = thread_info[i].ref; + if (tref != 0) { + if (JNI_ENV_PTR(env)->IsSameObject(JNI_ENV_ARG(env, thread), tref)) { + thread_info[i].threadTime = oth; + break; + } + } + } + if (i == THREADS_LIMIT) { + jvmtiThreadInfo info; + info.name = (char*) "*retrieval error*"; + ret = JVMTI_ENV_PTR(jvmti)->GetThreadInfo(JVMTI_ENV_ARG(jvmti_env, thread), &info); + JVMTI_ERROR_CHECK("GetThreadInfo %d \n", ret); + + debug_printf("non-test thread: %s - %s ms\n", info.name, + jlong_to_string(milli(oth), buffer)); + } + } + for (i = 1; i < THREADS_LIMIT; ++i) { + jweak tref = thread_info[i].ref; + if (tref != 0) { + totalIter += thread_info[i].iterationCount; + totalTimeCurr += thread_info[i].currThreadTime; + totalTime += thread_info[i].threadTime; + } + } + possibleTime = etime * processor_count; + debug_printf("Totals -- \n"); + debug_printf(" Iter = %d\n", totalIter); + debug_printf(" Total GetThreadCpuTime = %s ns", jlong_to_string(totalTime, buffer)); + debug_printf(" %s ms\n", jlong_to_string(milli(totalTime), buffer)); + debug_printf(" Total GetCurrentThreadCpuTimerInfo = %s ns", jlong_to_string(totalTimeCurr, buffer)); + debug_printf(" %s ms\n", jlong_to_string(milli(totalTimeCurr), buffer)); + debug_printf(" GetTime = %s ns", jlong_to_string(etime, buffer)); + debug_printf(" %s ms\n", jlong_to_string(milli(etime), buffer)); + debug_printf(" GetTime * processor_count = %s ns", jlong_to_string(possibleTime, buffer)); + debug_printf(" %s ms\n", jlong_to_string(milli(possibleTime), buffer)); + if (totalTime <= possibleTime) { + debug_printf("Pass: ttime <= possible_time\n"); + } else { + printf("FAIL: ttime > possible_time\n"); + iGlobalStatus = 2; + } + if (totalTimeCurr <= totalTime) { + debug_printf("Pass: ttime_curr <= ttime\n"); + } else { + printf("FAIL: ttime_curr > ttime\n"); + iGlobalStatus = 2; + } + if (totalTimeCurr >= totalTime*(1-VARIANCE)) { + debug_printf("Pass: ttime_curr >= %2.0f%% of ttime\n", 100.0 - VARIANCE_PERCENT); + } else { + printf("FAIL: ttime_curr < %2.0f%% of ttime\n", 100.0 - VARIANCE_PERCENT); + iGlobalStatus = 2; + } + one_iter_cost = (double)totalTime / totalIter; + debug_printf("CURRENT: total time returned by \"GetCurrentThreadCpuTime\".\n"); + debug_printf("OTHER: total time returned by \"GetThreadCpuTime\".\n"); + debug_printf("EXPECT: the expected time if TestThread.run() had a proportional cost across all threads.\n"); + debug_printf("%% DIFF: how much \"Expect\" is off by.\n"); + debug_printf("THREAD ITERATIONS CURRENT OTHER EXPECT % DIFF\n"); + for (i = 1; i < THREADS_LIMIT; ++i) { + jweak tref = thread_info[i].ref; + if (tref != 0) { + jint ic = thread_info[i].iterationCount; + jlong ctt = thread_info[i].currThreadTime; + jlong tt = thread_info[i].threadTime; + double expt = ic * one_iter_cost; + double var = 100.0 * ((double)tt - expt) / expt; + debug_printf("%6d %10d %5s ms", i, ic, + jlong_to_string(milli(ctt), buffer)); + debug_printf(" %5s ms %5.0f ms %7.1f%%\n", + jlong_to_string(milli(tt), buffer), milli(expt), var); + if (ctt <= tt) { + debug_printf("Pass: currThreadTime <= threadTime\n"); + } else { + printf("FAIL: currThreadTime > threadTime\n"); + iGlobalStatus = 2; + } + { + int passed = ctt >= tt*(1-VARIANCE); +#ifdef _WIN32 + // On Windows the timer is only accurate to within 15ms. This sometimes triggers + // failures if the expected max variance is close to or below 15ms. So we don't + // fail in this case. + if (!passed && milli(tt - ctt) <= 15) { + printf("Passing due to special consideration on Windows for 15ms timer accuracy\n"); + passed = 1; + } +#endif + if (passed) { + debug_printf("Pass: currThreadTime(" JLONG_FORMAT ") >= %2.0f%% of threadTime(" JLONG_FORMAT ")\n", + ctt, 100.0 - VARIANCE_PERCENT, tt); + } else { + printf("FAIL: currThreadTime(" JLONG_FORMAT ") < %2.0f%% of threadTime(" JLONG_FORMAT ")\n", + ctt, 100.0 - VARIANCE_PERCENT, tt); + iGlobalStatus = 2; + } + } + } + } +} + + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/libtimers.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/libtimers.c deleted file mode 100644 index fcef2030c0e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/libtimers.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "JvmtiTest.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/libtimers.cpp b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/libtimers.cpp new file mode 100644 index 00000000000..fea00132b93 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/timers/JvmtiTest/libtimers.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "JvmtiTest.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/StackTraceController.c b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/StackTraceController.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/StackTraceController.c rename to test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/StackTraceController.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/ThreadController.c b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/ThreadController.c deleted file mode 100644 index 592f9223c1b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/ThreadController.c +++ /dev/null @@ -1,531 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include -#include "jni_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FIND_CLASS(_class, _className)\ - if (!NSK_JNI_VERIFY(env, (_class = \ - NSK_CPP_STUB2(FindClass, env, _className)) != NULL))\ - return - -#define GET_OBJECT_CLASS(_class, _obj)\ - if (!NSK_JNI_VERIFY(env, (_class = \ - NSK_CPP_STUB2(GetObjectClass, env, _obj)) != NULL))\ - return - -#define GET_STATIC_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ - if (!NSK_JNI_VERIFY(env, (_fieldID = \ - NSK_CPP_STUB4(GetStaticFieldID, env, _class,\ - _fieldName, _fieldSig)) != NULL))\ - return - -#define GET_STATIC_OBJ_FIELD(_value, _class, _fieldName, _fieldSig)\ - GET_STATIC_FIELD_ID(field, _class, _fieldName, _fieldSig);\ - _value = NSK_CPP_STUB3(GetStaticObjectField, env, _class, \ - field) - -#define GET_STATIC_BOOL_FIELD(_value, _class, _fieldName)\ - GET_STATIC_FIELD_ID(field, _class, _fieldName, "Z");\ - _value = NSK_CPP_STUB3(GetStaticBooleanField, env, _class, field) - -#define GET_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ - if (!NSK_JNI_VERIFY(env, (_fieldID = \ - NSK_CPP_STUB4(GetFieldID, env, _class,\ - _fieldName, _fieldSig)) != NULL))\ - return - -#define GET_INT_FIELD(_value, _obj, _class, _fieldName)\ - GET_FIELD_ID(field, _class, _fieldName, "I");\ - _value = NSK_CPP_STUB3(GetIntField, env, _obj, field) - -#define GET_BOOL_FIELD(_value, _obj, _class, _fieldName)\ - GET_FIELD_ID(field, _class, _fieldName, "Z");\ - _value = NSK_CPP_STUB3(GetBooleanField, env, _obj, field) - -#define GET_LONG_FIELD(_value, _obj, _class, _fieldName)\ - GET_FIELD_ID(field, _class, _fieldName, "J");\ - _value = NSK_CPP_STUB3(GetLongField, env, _obj, field) - -#define GET_STATIC_INT_FIELD(_value, _class, _fieldName)\ - GET_STATIC_FIELD_ID(field, _class, _fieldName, "I");\ - _value = NSK_CPP_STUB3(GetStaticIntField, env, _class, field) - -#define SET_INT_FIELD(_obj, _class, _fieldName, _newValue)\ - GET_FIELD_ID(field, _class, _fieldName, "I");\ - NSK_CPP_STUB4(SetIntField, env, _obj, field, _newValue) - -#define GET_OBJ_FIELD(_value, _obj, _class, _fieldName, _fieldSig)\ - GET_FIELD_ID(field, _class, _fieldName, _fieldSig);\ - _value = NSK_CPP_STUB3(GetObjectField, env, _obj, field) - - -#define GET_ARR_ELEMENT(_arr, _index)\ - NSK_CPP_STUB3(GetObjectArrayElement, env, _arr, _index) - -#define SET_ARR_ELEMENT(_arr, _index, _newValue)\ - NSK_CPP_STUB4(SetObjectArrayElement, env, _arr, _index, _newValue) - -#define GET_STATIC_METHOD_ID(_methodID, _class, _methodName, _sig)\ - if (!NSK_JNI_VERIFY(env, (_methodID = \ - NSK_CPP_STUB4(GetStaticMethodID, env, _class,\ - _methodName, _sig)) != NULL))\ - return - -#define GET_METHOD_ID(_methodID, _class, _methodName, _sig)\ - if (!NSK_JNI_VERIFY(env, (_methodID = \ - NSK_CPP_STUB4(GetMethodID, env, _class,\ - _methodName, _sig)) != NULL))\ - return - -#define CALL_STATIC_VOID_NOPARAM(_class, _methodName)\ - GET_STATIC_METHOD_ID(method, _class, _methodName, "()V");\ - if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallStaticVoidMethod, env,\ - _class, method)))\ - return - -#define CALL_STATIC_VOID(_class, _methodName, _sig, _param)\ - GET_STATIC_METHOD_ID(method, _class, _methodName, _sig);\ - if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB4(CallStaticVoidMethod, env,\ - _class, method, _param)))\ - return - -#define CALL_STATIC_OBJ(_value, _class, _methodName, _sig, _param)\ - GET_STATIC_METHOD_ID(method, _class, _methodName, _sig);\ - _value = NSK_CPP_STUB4(CallStaticObjectMethod, env, _class, method, _param) - -#define CALL_VOID_NOPARAM(_obj, _class, _methodName)\ - GET_METHOD_ID(method, _class, _methodName, "()V");\ - if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallVoidMethod, env, _obj,\ - method)))\ - return - -#define CALL_VOID(_obj, _class, _methodName, _sig, _param)\ - GET_METHOD_ID(method, _class, _methodName, "()V");\ - if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB4(CallVoidMethod, env, _obj,\ - method, _param)))\ - return - -#define CALL_VOID2(_obj, _class, _methodName, _sig, _param1, _param2)\ - GET_METHOD_ID(method, _class, _methodName, _sig);\ - if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB5(CallVoidMethod, env, _obj, \ - method, _param1, _param2)))\ - return - -#define CALL_INT_NOPARAM(_value, _obj, _class, _methodName)\ - GET_METHOD_ID(method, _class, _methodName, "()I");\ - _value = NSK_CPP_STUB3(CallIntMethod, env, _obj, method) - -#define NEW_OBJ(_obj, _class, _constructorName, _sig, _params)\ - GET_METHOD_ID(method, _class, _constructorName, _sig);\ - if (!NSK_JNI_VERIFY(env, (_obj = \ - NSK_CPP_STUB4(NewObject, env, _class, method, _params)) != NULL))\ - return - -#define MONITOR_ENTER(x) \ - NSK_JNI_VERIFY(env, NSK_CPP_STUB2(MonitorEnter, env, x) == 0) - -#define MONITOR_EXIT(x) \ - NSK_JNI_VERIFY(env, NSK_CPP_STUB2(MonitorExit, env, x) == 0) - -#define TRACE(msg)\ - GET_OBJ_FIELD(logger, obj, threadClass, "logger", "Lnsk/share/Log$Logger;");\ - jmsg = NSK_CPP_STUB2(NewStringUTF, env, msg);\ - CALL_VOID2(logger, loggerClass, "trace",\ - "(ILjava/lang/String;)V", 50, jmsg) - - static const char *SctrlClassName="nsk/monitoring/share/ThreadController"; - static const char *SthreadControllerSig - = "Lnsk/monitoring/share/ThreadController;"; - - static const char *SThreadsGroupLocksSig - ="Lnsk/monitoring/share/ThreadsGroupLocks;"; - static const char *SThreadsGroupLocksClassName - ="nsk/monitoring/share/ThreadsGroupLocks"; - - - static const char *SbringState_mn="bringState"; - static const char *SnativeBringState_mn="nativeBringState"; - static const char *SrecursiveMethod_mn="recursiveMethod"; - static const char *SnativeRecursiveMethod_mn="nativeRecursiveMethod"; - static const char *SloggerClassName = "nsk/share/Log$Logger"; - - static const char *Snoparams="()V"; - static const char *Slongparam="(J)V"; - - /* - * Class: nsk_monitoring_share_BaseThread - * Method: nativeRecursiveMethod - * Signature: ()V - */ - JNIEXPORT void JNICALL - Java_nsk_monitoring_share_BaseThread_nativeRecursiveMethod(JNIEnv *env, - jobject obj) { - jint currDepth, maxDepth; - jobject logger; - jstring jmsg; - jfieldID field; - jmethodID method; - - jobject controller; - jclass threadClass, ctrlClass, loggerClass; - - int invocationType; - - GET_OBJECT_CLASS(threadClass, obj); - FIND_CLASS(ctrlClass, SctrlClassName); - FIND_CLASS(loggerClass, SloggerClassName); - - - /* currDepth++ */ - GET_INT_FIELD(currDepth, obj, threadClass, "currentDepth"); - currDepth++; - SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth); - - GET_OBJ_FIELD(controller, obj, threadClass, "controller", - SthreadControllerSig); - GET_INT_FIELD(maxDepth, controller, ctrlClass, "maxDepth"); - - GET_STATIC_INT_FIELD(invocationType, ctrlClass, "invocationType"); - - if (maxDepth - currDepth > 0) - { - CALL_STATIC_VOID_NOPARAM(threadClass, "yield"); - - if (invocationType == 2/*MIXED_TYPE*/) - { - CALL_VOID_NOPARAM(obj, threadClass, SrecursiveMethod_mn); - } - else - { - CALL_VOID_NOPARAM(obj, threadClass, SnativeRecursiveMethod_mn); - } - } - else - { - TRACE("state has been reached"); - if (invocationType == 2/*MIXED_TYPE*/) - { - CALL_VOID_NOPARAM(obj, threadClass, SbringState_mn); - } - else - { - CALL_VOID_NOPARAM(obj, threadClass, SnativeBringState_mn); - } - } - - currDepth--; - GET_OBJECT_CLASS(threadClass, obj); - SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth); - } - - /* - * Class: nsk_monitoring_share_BlockedThread - * Method: nativeBringState - * Signature: ()V - */ - JNIEXPORT void JNICALL - Java_nsk_monitoring_share_BlockedThread_nativeBringState(JNIEnv *env, - jobject obj) { - jobject logger; - jstring jmsg; - jfieldID field; - jmethodID method; - - jclass threadClass, loggerClass; - - jobject STATE; - - //ThreadsGroupLocks: - jclass ThreadsGroupLocks; - jobject threadsGroupLocks; - jmethodID getBarrier; - - - //CountDownLatch - jobject barrier; - jclass CountDownLatch; - - //Blocker - jobject blocker; - jclass Blocker; - - GET_OBJECT_CLASS(threadClass, obj); - - FIND_CLASS(loggerClass, SloggerClassName); - FIND_CLASS(ThreadsGroupLocks, SThreadsGroupLocksClassName); - FIND_CLASS(Blocker, "Lnsk/monitoring/share/ThreadsGroupLocks$Blocker;"); - FIND_CLASS(CountDownLatch, "nsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch"); - - GET_OBJ_FIELD(threadsGroupLocks, obj, threadClass, "threadsGroupLocks", SThreadsGroupLocksSig); - GET_STATIC_OBJ_FIELD(STATE, threadClass, "STATE", "Ljava/lang/Thread$State;"); - GET_OBJ_FIELD(blocker, threadsGroupLocks, ThreadsGroupLocks, "blocker", "Lnsk/monitoring/share/ThreadsGroupLocks$Blocker;"); - - getBarrier = (*env)->GetMethodID(env, ThreadsGroupLocks, "getBarrier", - "(Ljava/lang/Thread$State;)Lnsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch;"); - barrier = (*env)->CallObjectMethod(env, threadsGroupLocks, getBarrier, STATE); - - - TRACE("entering to monitor"); - - CALL_VOID_NOPARAM(barrier, CountDownLatch, "countDown"); - CALL_VOID_NOPARAM(blocker, Blocker, "block"); - TRACE("exiting from monitor"); - - } - - /* - * Class: nsk_monitoring_share_WaitingThread - * Method: nativeBringState - * Signature: ()V - */ - JNIEXPORT void JNICALL - Java_nsk_monitoring_share_WaitingThread_nativeBringState(JNIEnv *env, - jobject obj) { - jobject logger; - jstring jmsg; - jfieldID field; - jmethodID method; - - jclass threadClass, loggerClass; - - //STATE - jobject STATE; - - //ThreadsGroupLocks: - jclass ThreadsGroupLocks; - jobject threadsGroupLocks; - jmethodID getBarrier; - - //CountDownLatch - jobject barrier; - jclass CountDownLatch; - - GET_OBJECT_CLASS(threadClass, obj); - - FIND_CLASS(loggerClass, SloggerClassName); - FIND_CLASS(ThreadsGroupLocks, "nsk/monitoring/share/ThreadsGroupLocks"); - FIND_CLASS(CountDownLatch, "nsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch"); - - GET_STATIC_OBJ_FIELD(STATE, threadClass, "STATE", "Ljava/lang/Thread$State;"); - GET_OBJ_FIELD(threadsGroupLocks, obj, threadClass, "threadsGroupLocks", "Lnsk/monitoring/share/ThreadsGroupLocks;"); - - getBarrier = (*env)->GetMethodID(env, ThreadsGroupLocks, "getBarrier", - "(Ljava/lang/Thread$State;)Lnsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch;"); - barrier = (*env)->CallObjectMethod(env, threadsGroupLocks, getBarrier, STATE); - CALL_VOID_NOPARAM(barrier, CountDownLatch, "countDown"); - - TRACE("waiting on a monitor"); - CALL_VOID_NOPARAM(barrier, CountDownLatch, "await"); - } - - /* - * Class: nsk_monitoring_share_SleepingThread - * Method: nativeBringState - * Signature: ()V - */ - JNIEXPORT void JNICALL - Java_nsk_monitoring_share_SleepingThread_nativeBringState(JNIEnv *env, - jobject obj) { - jfieldID field; - jmethodID method; - - jclass threadClass, loggerClass; - - //STATE - jobject STATE; - - //ThreadsGroupLocks: - jclass ThreadsGroupLocks; - jobject threadsGroupLocks; - jmethodID getBarrier; - - //CountDownLatch - jobject barrier; - jclass CountDownLatch; - - //Thread - jclass Thread; - - jlong sleepTime = 20 * 60 * 1000; - - - GET_OBJECT_CLASS(threadClass, obj); - - FIND_CLASS(loggerClass, SloggerClassName); - FIND_CLASS(ThreadsGroupLocks, "nsk/monitoring/share/ThreadsGroupLocks"); - FIND_CLASS(CountDownLatch, "nsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch"); - - GET_STATIC_OBJ_FIELD(STATE, threadClass, "STATE", "Ljava/lang/Thread$State;"); - GET_OBJ_FIELD(threadsGroupLocks, obj, threadClass, "threadsGroupLocks", "Lnsk/monitoring/share/ThreadsGroupLocks;"); - - // Thread.sleep(3600 * 1000); - FIND_CLASS(Thread, "java/lang/Thread"); - - getBarrier = (*env)->GetMethodID(env, ThreadsGroupLocks, "getBarrier", - "(Ljava/lang/Thread$State;)Lnsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch;"); - barrier = (*env)->CallObjectMethod(env, threadsGroupLocks, getBarrier, STATE); - CALL_VOID_NOPARAM(barrier, CountDownLatch, "countDown"); - - CALL_STATIC_VOID(Thread, "sleep", "(J)V", sleepTime); - } - - /* - * Class: nsk_monitoring_share_RunningThread - * Method: nativeBringState - * Signature: ()V - */ - JNIEXPORT void JNICALL - Java_nsk_monitoring_share_RunningThread_nativeBringState(JNIEnv *env, - jobject obj) { - jobject logger; - jstring jmsg; - jfieldID field; - jmethodID method; - - jclass threadClass, loggerClass; - - //STATE - jobject STATE; - - //ThreadsGroupLocks: - jclass ThreadsGroupLocks; - jobject threadsGroupLocks; - jmethodID getBarrier; - - //CountDownLatch - jobject barrier; - jclass CountDownLatch; - - //Thread - jclass Thread; - - //runnableCanExit - jboolean flag = JNI_FALSE; - - GET_OBJECT_CLASS(threadClass, obj); - - FIND_CLASS(loggerClass, SloggerClassName); - FIND_CLASS(ThreadsGroupLocks, "nsk/monitoring/share/ThreadsGroupLocks"); - FIND_CLASS(CountDownLatch, "nsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch"); - - GET_STATIC_OBJ_FIELD(STATE, threadClass, "STATE", "Ljava/lang/Thread$State;"); - GET_OBJ_FIELD(threadsGroupLocks, obj, threadClass, "threadsGroupLocks", "Lnsk/monitoring/share/ThreadsGroupLocks;"); - - // Thread.sleep(3600 * 1000); - FIND_CLASS(Thread, "java/lang/Thread"); - - getBarrier = (*env)->GetMethodID(env, ThreadsGroupLocks, "getBarrier", - "(Ljava/lang/Thread$State;)Lnsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch;"); - - TRACE("running loop"); - - barrier = (*env)->CallObjectMethod(env, threadsGroupLocks, getBarrier, STATE); - CALL_VOID_NOPARAM(barrier, CountDownLatch, "countDown"); - - // while (!threadsGroupLocks.runnableCanExit.get()) { - // Thread.yield(); - // } - while(flag==JNI_FALSE) - { - GET_BOOL_FIELD(flag, threadsGroupLocks, ThreadsGroupLocks, "runnableCanExit"); - CALL_STATIC_VOID_NOPARAM(Thread, "yield"); - } - - } - - jstring getStateName(JNIEnv *env, jint state) { - switch (state & JVMTI_JAVA_LANG_THREAD_STATE_MASK) { - case JVMTI_JAVA_LANG_THREAD_STATE_NEW: - return (*env)->NewStringUTF(env,"NEW"); - case JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED: - return (*env)->NewStringUTF(env,"TERMINATED"); - case JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE: - return (*env)->NewStringUTF(env,"RUNNABLE"); - case JVMTI_JAVA_LANG_THREAD_STATE_BLOCKED: - return (*env)->NewStringUTF(env,"BLOCKED"); - case JVMTI_JAVA_LANG_THREAD_STATE_WAITING: - return (*env)->NewStringUTF(env, "WAITING"); - case JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITING: - return (*env)->NewStringUTF(env,"TIMED_WAITING"); - } - // should never reach - assert(0); - return 0; - } - - /* - * Class: nsk_monitoring_share_ThreadController - * Method: getThreadState - * Signature: (Ljava/lang/Thread;)Ljava/lang/Thread/State; - */ - JNIEXPORT jobject JNICALL - Java_nsk_monitoring_share_ThreadController_getThreadState(JNIEnv *env, - jobject obj, jobject thread){ - - JavaVM *vm; - jvmtiEnv *jvmti; - jclass ThreadState; - jmethodID method; - jobject threadState; - jstring stateName; - jint state; - - if(!NSK_VERIFY( - NSK_CPP_STUB2(GetJavaVM, env, &vm) == 0)) { - return NULL; - } - - if(!NSK_VERIFY( - NSK_CPP_STUB3(GetEnv, vm, (void **)&jvmti, JVMTI_VERSION_1) - == JNI_OK)) { - return NULL; - } - - if(!NSK_VERIFY( - NSK_CPP_STUB3(GetThreadState, jvmti, (jthread)thread, &state) - == JVMTI_ERROR_NONE)) { - return NULL; - } - - stateName = getStateName(env, state); - if (!NSK_JNI_VERIFY(env, (ThreadState = NSK_CPP_STUB2(FindClass, env, "java/lang/Thread$State")) != NULL)) - return NULL; - - if (!NSK_JNI_VERIFY(env, (method = NSK_CPP_STUB4(GetStaticMethodID, env, ThreadState, "valueOf", "(Ljava/lang/String;)Ljava/lang/Thread$State;")) != NULL)) - return NULL; - threadState = NSK_CPP_STUB4(CallStaticObjectMethod, env, ThreadState, method, stateName); - - return threadState; - } - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/ThreadController.cpp b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/ThreadController.cpp new file mode 100644 index 00000000000..b675d4f2a7f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/ThreadController.cpp @@ -0,0 +1,531 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FIND_CLASS(_class, _className)\ + if (!NSK_JNI_VERIFY(env, (_class = \ + NSK_CPP_STUB2(FindClass, env, _className)) != NULL))\ + return + +#define GET_OBJECT_CLASS(_class, _obj)\ + if (!NSK_JNI_VERIFY(env, (_class = \ + NSK_CPP_STUB2(GetObjectClass, env, _obj)) != NULL))\ + return + +#define GET_STATIC_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ + if (!NSK_JNI_VERIFY(env, (_fieldID = \ + NSK_CPP_STUB4(GetStaticFieldID, env, _class,\ + _fieldName, _fieldSig)) != NULL))\ + return + +#define GET_STATIC_OBJ_FIELD(_value, _class, _fieldName, _fieldSig)\ + GET_STATIC_FIELD_ID(field, _class, _fieldName, _fieldSig);\ + _value = NSK_CPP_STUB3(GetStaticObjectField, env, _class, \ + field) + +#define GET_STATIC_BOOL_FIELD(_value, _class, _fieldName)\ + GET_STATIC_FIELD_ID(field, _class, _fieldName, "Z");\ + _value = NSK_CPP_STUB3(GetStaticBooleanField, env, _class, field) + +#define GET_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ + if (!NSK_JNI_VERIFY(env, (_fieldID = \ + NSK_CPP_STUB4(GetFieldID, env, _class,\ + _fieldName, _fieldSig)) != NULL))\ + return + +#define GET_INT_FIELD(_value, _obj, _class, _fieldName)\ + GET_FIELD_ID(field, _class, _fieldName, "I");\ + _value = NSK_CPP_STUB3(GetIntField, env, _obj, field) + +#define GET_BOOL_FIELD(_value, _obj, _class, _fieldName)\ + GET_FIELD_ID(field, _class, _fieldName, "Z");\ + _value = NSK_CPP_STUB3(GetBooleanField, env, _obj, field) + +#define GET_LONG_FIELD(_value, _obj, _class, _fieldName)\ + GET_FIELD_ID(field, _class, _fieldName, "J");\ + _value = NSK_CPP_STUB3(GetLongField, env, _obj, field) + +#define GET_STATIC_INT_FIELD(_value, _class, _fieldName)\ + GET_STATIC_FIELD_ID(field, _class, _fieldName, "I");\ + _value = NSK_CPP_STUB3(GetStaticIntField, env, _class, field) + +#define SET_INT_FIELD(_obj, _class, _fieldName, _newValue)\ + GET_FIELD_ID(field, _class, _fieldName, "I");\ + NSK_CPP_STUB4(SetIntField, env, _obj, field, _newValue) + +#define GET_OBJ_FIELD(_value, _obj, _class, _fieldName, _fieldSig)\ + GET_FIELD_ID(field, _class, _fieldName, _fieldSig);\ + _value = NSK_CPP_STUB3(GetObjectField, env, _obj, field) + + +#define GET_ARR_ELEMENT(_arr, _index)\ + NSK_CPP_STUB3(GetObjectArrayElement, env, _arr, _index) + +#define SET_ARR_ELEMENT(_arr, _index, _newValue)\ + NSK_CPP_STUB4(SetObjectArrayElement, env, _arr, _index, _newValue) + +#define GET_STATIC_METHOD_ID(_methodID, _class, _methodName, _sig)\ + if (!NSK_JNI_VERIFY(env, (_methodID = \ + NSK_CPP_STUB4(GetStaticMethodID, env, _class,\ + _methodName, _sig)) != NULL))\ + return + +#define GET_METHOD_ID(_methodID, _class, _methodName, _sig)\ + if (!NSK_JNI_VERIFY(env, (_methodID = \ + NSK_CPP_STUB4(GetMethodID, env, _class,\ + _methodName, _sig)) != NULL))\ + return + +#define CALL_STATIC_VOID_NOPARAM(_class, _methodName)\ + GET_STATIC_METHOD_ID(method, _class, _methodName, "()V");\ + if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallStaticVoidMethod, env,\ + _class, method)))\ + return + +#define CALL_STATIC_VOID(_class, _methodName, _sig, _param)\ + GET_STATIC_METHOD_ID(method, _class, _methodName, _sig);\ + if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB4(CallStaticVoidMethod, env,\ + _class, method, _param)))\ + return + +#define CALL_STATIC_OBJ(_value, _class, _methodName, _sig, _param)\ + GET_STATIC_METHOD_ID(method, _class, _methodName, _sig);\ + _value = NSK_CPP_STUB4(CallStaticObjectMethod, env, _class, method, _param) + +#define CALL_VOID_NOPARAM(_obj, _class, _methodName)\ + GET_METHOD_ID(method, _class, _methodName, "()V");\ + if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallVoidMethod, env, _obj,\ + method)))\ + return + +#define CALL_VOID(_obj, _class, _methodName, _sig, _param)\ + GET_METHOD_ID(method, _class, _methodName, "()V");\ + if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB4(CallVoidMethod, env, _obj,\ + method, _param)))\ + return + +#define CALL_VOID2(_obj, _class, _methodName, _sig, _param1, _param2)\ + GET_METHOD_ID(method, _class, _methodName, _sig);\ + if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB5(CallVoidMethod, env, _obj, \ + method, _param1, _param2)))\ + return + +#define CALL_INT_NOPARAM(_value, _obj, _class, _methodName)\ + GET_METHOD_ID(method, _class, _methodName, "()I");\ + _value = NSK_CPP_STUB3(CallIntMethod, env, _obj, method) + +#define NEW_OBJ(_obj, _class, _constructorName, _sig, _params)\ + GET_METHOD_ID(method, _class, _constructorName, _sig);\ + if (!NSK_JNI_VERIFY(env, (_obj = \ + NSK_CPP_STUB4(NewObject, env, _class, method, _params)) != NULL))\ + return + +#define MONITOR_ENTER(x) \ + NSK_JNI_VERIFY(env, NSK_CPP_STUB2(MonitorEnter, env, x) == 0) + +#define MONITOR_EXIT(x) \ + NSK_JNI_VERIFY(env, NSK_CPP_STUB2(MonitorExit, env, x) == 0) + +#define TRACE(msg)\ + GET_OBJ_FIELD(logger, obj, threadClass, "logger", "Lnsk/share/Log$Logger;");\ + jmsg = NSK_CPP_STUB2(NewStringUTF, env, msg);\ + CALL_VOID2(logger, loggerClass, "trace",\ + "(ILjava/lang/String;)V", 50, jmsg) + + static const char *SctrlClassName="nsk/monitoring/share/ThreadController"; + static const char *SthreadControllerSig + = "Lnsk/monitoring/share/ThreadController;"; + + static const char *SThreadsGroupLocksSig + ="Lnsk/monitoring/share/ThreadsGroupLocks;"; + static const char *SThreadsGroupLocksClassName + ="nsk/monitoring/share/ThreadsGroupLocks"; + + + static const char *SbringState_mn="bringState"; + static const char *SnativeBringState_mn="nativeBringState"; + static const char *SrecursiveMethod_mn="recursiveMethod"; + static const char *SnativeRecursiveMethod_mn="nativeRecursiveMethod"; + static const char *SloggerClassName = "nsk/share/Log$Logger"; + + static const char *Snoparams="()V"; + static const char *Slongparam="(J)V"; + + /* + * Class: nsk_monitoring_share_BaseThread + * Method: nativeRecursiveMethod + * Signature: ()V + */ + JNIEXPORT void JNICALL + Java_nsk_monitoring_share_BaseThread_nativeRecursiveMethod(JNIEnv *env, + jobject obj) { + jint currDepth, maxDepth; + jobject logger; + jstring jmsg; + jfieldID field; + jmethodID method; + + jobject controller; + jclass threadClass, ctrlClass, loggerClass; + + int invocationType; + + GET_OBJECT_CLASS(threadClass, obj); + FIND_CLASS(ctrlClass, SctrlClassName); + FIND_CLASS(loggerClass, SloggerClassName); + + + /* currDepth++ */ + GET_INT_FIELD(currDepth, obj, threadClass, "currentDepth"); + currDepth++; + SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth); + + GET_OBJ_FIELD(controller, obj, threadClass, "controller", + SthreadControllerSig); + GET_INT_FIELD(maxDepth, controller, ctrlClass, "maxDepth"); + + GET_STATIC_INT_FIELD(invocationType, ctrlClass, "invocationType"); + + if (maxDepth - currDepth > 0) + { + CALL_STATIC_VOID_NOPARAM(threadClass, "yield"); + + if (invocationType == 2/*MIXED_TYPE*/) + { + CALL_VOID_NOPARAM(obj, threadClass, SrecursiveMethod_mn); + } + else + { + CALL_VOID_NOPARAM(obj, threadClass, SnativeRecursiveMethod_mn); + } + } + else + { + TRACE("state has been reached"); + if (invocationType == 2/*MIXED_TYPE*/) + { + CALL_VOID_NOPARAM(obj, threadClass, SbringState_mn); + } + else + { + CALL_VOID_NOPARAM(obj, threadClass, SnativeBringState_mn); + } + } + + currDepth--; + GET_OBJECT_CLASS(threadClass, obj); + SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth); + } + + /* + * Class: nsk_monitoring_share_BlockedThread + * Method: nativeBringState + * Signature: ()V + */ + JNIEXPORT void JNICALL + Java_nsk_monitoring_share_BlockedThread_nativeBringState(JNIEnv *env, + jobject obj) { + jobject logger; + jstring jmsg; + jfieldID field; + jmethodID method; + + jclass threadClass, loggerClass; + + jobject STATE; + + //ThreadsGroupLocks: + jclass ThreadsGroupLocks; + jobject threadsGroupLocks; + jmethodID getBarrier; + + + //CountDownLatch + jobject barrier; + jclass CountDownLatch; + + //Blocker + jobject blocker; + jclass Blocker; + + GET_OBJECT_CLASS(threadClass, obj); + + FIND_CLASS(loggerClass, SloggerClassName); + FIND_CLASS(ThreadsGroupLocks, SThreadsGroupLocksClassName); + FIND_CLASS(Blocker, "Lnsk/monitoring/share/ThreadsGroupLocks$Blocker;"); + FIND_CLASS(CountDownLatch, "nsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch"); + + GET_OBJ_FIELD(threadsGroupLocks, obj, threadClass, "threadsGroupLocks", SThreadsGroupLocksSig); + GET_STATIC_OBJ_FIELD(STATE, threadClass, "STATE", "Ljava/lang/Thread$State;"); + GET_OBJ_FIELD(blocker, threadsGroupLocks, ThreadsGroupLocks, "blocker", "Lnsk/monitoring/share/ThreadsGroupLocks$Blocker;"); + + getBarrier = env->GetMethodID(ThreadsGroupLocks, "getBarrier", + "(Ljava/lang/Thread$State;)Lnsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch;"); + barrier = env->CallObjectMethod(threadsGroupLocks, getBarrier, STATE); + + + TRACE("entering to monitor"); + + CALL_VOID_NOPARAM(barrier, CountDownLatch, "countDown"); + CALL_VOID_NOPARAM(blocker, Blocker, "block"); + TRACE("exiting from monitor"); + + } + + /* + * Class: nsk_monitoring_share_WaitingThread + * Method: nativeBringState + * Signature: ()V + */ + JNIEXPORT void JNICALL + Java_nsk_monitoring_share_WaitingThread_nativeBringState(JNIEnv *env, + jobject obj) { + jobject logger; + jstring jmsg; + jfieldID field; + jmethodID method; + + jclass threadClass, loggerClass; + + //STATE + jobject STATE; + + //ThreadsGroupLocks: + jclass ThreadsGroupLocks; + jobject threadsGroupLocks; + jmethodID getBarrier; + + //CountDownLatch + jobject barrier; + jclass CountDownLatch; + + GET_OBJECT_CLASS(threadClass, obj); + + FIND_CLASS(loggerClass, SloggerClassName); + FIND_CLASS(ThreadsGroupLocks, "nsk/monitoring/share/ThreadsGroupLocks"); + FIND_CLASS(CountDownLatch, "nsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch"); + + GET_STATIC_OBJ_FIELD(STATE, threadClass, "STATE", "Ljava/lang/Thread$State;"); + GET_OBJ_FIELD(threadsGroupLocks, obj, threadClass, "threadsGroupLocks", "Lnsk/monitoring/share/ThreadsGroupLocks;"); + + getBarrier = env->GetMethodID(ThreadsGroupLocks, "getBarrier", + "(Ljava/lang/Thread$State;)Lnsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch;"); + barrier = env->CallObjectMethod(threadsGroupLocks, getBarrier, STATE); + CALL_VOID_NOPARAM(barrier, CountDownLatch, "countDown"); + + TRACE("waiting on a monitor"); + CALL_VOID_NOPARAM(barrier, CountDownLatch, "await"); + } + + /* + * Class: nsk_monitoring_share_SleepingThread + * Method: nativeBringState + * Signature: ()V + */ + JNIEXPORT void JNICALL + Java_nsk_monitoring_share_SleepingThread_nativeBringState(JNIEnv *env, + jobject obj) { + jfieldID field; + jmethodID method; + + jclass threadClass, loggerClass; + + //STATE + jobject STATE; + + //ThreadsGroupLocks: + jclass ThreadsGroupLocks; + jobject threadsGroupLocks; + jmethodID getBarrier; + + //CountDownLatch + jobject barrier; + jclass CountDownLatch; + + //Thread + jclass Thread; + + jlong sleepTime = 20 * 60 * 1000; + + + GET_OBJECT_CLASS(threadClass, obj); + + FIND_CLASS(loggerClass, SloggerClassName); + FIND_CLASS(ThreadsGroupLocks, "nsk/monitoring/share/ThreadsGroupLocks"); + FIND_CLASS(CountDownLatch, "nsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch"); + + GET_STATIC_OBJ_FIELD(STATE, threadClass, "STATE", "Ljava/lang/Thread$State;"); + GET_OBJ_FIELD(threadsGroupLocks, obj, threadClass, "threadsGroupLocks", "Lnsk/monitoring/share/ThreadsGroupLocks;"); + + // Thread.sleep(3600 * 1000); + FIND_CLASS(Thread, "java/lang/Thread"); + + getBarrier = env->GetMethodID(ThreadsGroupLocks, "getBarrier", + "(Ljava/lang/Thread$State;)Lnsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch;"); + barrier = env->CallObjectMethod(threadsGroupLocks, getBarrier, STATE); + CALL_VOID_NOPARAM(barrier, CountDownLatch, "countDown"); + + CALL_STATIC_VOID(Thread, "sleep", "(J)V", sleepTime); + } + + /* + * Class: nsk_monitoring_share_RunningThread + * Method: nativeBringState + * Signature: ()V + */ + JNIEXPORT void JNICALL + Java_nsk_monitoring_share_RunningThread_nativeBringState(JNIEnv *env, + jobject obj) { + jobject logger; + jstring jmsg; + jfieldID field; + jmethodID method; + + jclass threadClass, loggerClass; + + //STATE + jobject STATE; + + //ThreadsGroupLocks: + jclass ThreadsGroupLocks; + jobject threadsGroupLocks; + jmethodID getBarrier; + + //CountDownLatch + jobject barrier; + jclass CountDownLatch; + + //Thread + jclass Thread; + + //runnableCanExit + jboolean flag = JNI_FALSE; + + GET_OBJECT_CLASS(threadClass, obj); + + FIND_CLASS(loggerClass, SloggerClassName); + FIND_CLASS(ThreadsGroupLocks, "nsk/monitoring/share/ThreadsGroupLocks"); + FIND_CLASS(CountDownLatch, "nsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch"); + + GET_STATIC_OBJ_FIELD(STATE, threadClass, "STATE", "Ljava/lang/Thread$State;"); + GET_OBJ_FIELD(threadsGroupLocks, obj, threadClass, "threadsGroupLocks", "Lnsk/monitoring/share/ThreadsGroupLocks;"); + + // Thread.sleep(3600 * 1000); + FIND_CLASS(Thread, "java/lang/Thread"); + + getBarrier = env->GetMethodID(ThreadsGroupLocks, "getBarrier", + "(Ljava/lang/Thread$State;)Lnsk/monitoring/share/ThreadsGroupLocks$PlainCountDownLatch;"); + + TRACE("running loop"); + + barrier = env->CallObjectMethod(threadsGroupLocks, getBarrier, STATE); + CALL_VOID_NOPARAM(barrier, CountDownLatch, "countDown"); + + // while (!threadsGroupLocks.runnableCanExit.get()) { + // Thread.yield(); + // } + while(flag==JNI_FALSE) + { + GET_BOOL_FIELD(flag, threadsGroupLocks, ThreadsGroupLocks, "runnableCanExit"); + CALL_STATIC_VOID_NOPARAM(Thread, "yield"); + } + + } + + jstring getStateName(JNIEnv *env, jint state) { + switch (state & JVMTI_JAVA_LANG_THREAD_STATE_MASK) { + case JVMTI_JAVA_LANG_THREAD_STATE_NEW: + return env->NewStringUTF("NEW"); + case JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED: + return env->NewStringUTF("TERMINATED"); + case JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE: + return env->NewStringUTF("RUNNABLE"); + case JVMTI_JAVA_LANG_THREAD_STATE_BLOCKED: + return env->NewStringUTF("BLOCKED"); + case JVMTI_JAVA_LANG_THREAD_STATE_WAITING: + return env->NewStringUTF("WAITING"); + case JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITING: + return env->NewStringUTF("TIMED_WAITING"); + } + // should never reach + assert(0); + return 0; + } + + /* + * Class: nsk_monitoring_share_ThreadController + * Method: getThreadState + * Signature: (Ljava/lang/Thread;)Ljava/lang/Thread/State; + */ + JNIEXPORT jobject JNICALL + Java_nsk_monitoring_share_ThreadController_getThreadState(JNIEnv *env, + jobject obj, jobject thread){ + + JavaVM *vm; + jvmtiEnv *jvmti; + jclass ThreadState; + jmethodID method; + jobject threadState; + jstring stateName; + jint state; + + if(!NSK_VERIFY( + NSK_CPP_STUB2(GetJavaVM, env, &vm) == 0)) { + return NULL; + } + + if(!NSK_VERIFY( + NSK_CPP_STUB3(GetEnv, vm, (void **)&jvmti, JVMTI_VERSION_1) + == JNI_OK)) { + return NULL; + } + + if(!NSK_VERIFY( + NSK_CPP_STUB3(GetThreadState, jvmti, (jthread)thread, &state) + == JVMTI_ERROR_NONE)) { + return NULL; + } + + stateName = getStateName(env, state); + if (!NSK_JNI_VERIFY(env, (ThreadState = NSK_CPP_STUB2(FindClass, env, "java/lang/Thread$State")) != NULL)) + return NULL; + + if (!NSK_JNI_VERIFY(env, (method = NSK_CPP_STUB4(GetStaticMethodID, env, ThreadState, "valueOf", "(Ljava/lang/String;)Ljava/lang/Thread$State;")) != NULL)) + return NULL; + threadState = NSK_CPP_STUB4(CallStaticObjectMethod, env, ThreadState, method, stateName); + + return threadState; + } + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libStackTraceController.c b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libStackTraceController.c deleted file mode 100644 index bca604c8842..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libStackTraceController.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "StackTraceController.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libStackTraceController.cpp b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libStackTraceController.cpp new file mode 100644 index 00000000000..1773f31119c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libStackTraceController.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "StackTraceController.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libThreadController.c b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libThreadController.c deleted file mode 100644 index 594ba189f44..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libThreadController.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "ThreadController.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libThreadController.cpp b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libThreadController.cpp new file mode 100644 index 00000000000..4b4071ccdf5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/libThreadController.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "ThreadController.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/Deadlock.c b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/Deadlock.c deleted file mode 100644 index 206fa762371..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/Deadlock.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include "jni_tools.h" - -#define FIND_CLASS(_class, _className)\ - if (!NSK_JNI_VERIFY(env, (_class = \ - NSK_CPP_STUB2(FindClass, env, _className)) != NULL))\ - return - -#define GET_OBJECT_CLASS(_class, _obj)\ - if (!NSK_JNI_VERIFY(env, (_class = \ - NSK_CPP_STUB2(GetObjectClass, env, _obj)) != NULL))\ - return - -#define GET_OBJ_FIELD(_value, _obj, _class, _fieldName, _fieldSig)\ - GET_FIELD_ID(field, _class, _fieldName, _fieldSig);\ - _value = NSK_CPP_STUB3(GetObjectField, env, _obj, field) - -#define GET_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ - if (!NSK_JNI_VERIFY(env, (_fieldID = \ - NSK_CPP_STUB4(GetFieldID, env, _class,\ - _fieldName, _fieldSig)) != NULL))\ - return - -#define GET_METHOD_ID(_methodID, _class, _methodName, _sig)\ - if (!NSK_JNI_VERIFY(env, (_methodID = \ - NSK_CPP_STUB4(GetMethodID, env, _class,\ - _methodName, _sig)) != NULL)) \ - return - -#define CALL_VOID_NOPARAM(_obj, _class, _methodName)\ - GET_METHOD_ID(method, _class, _methodName, "()V");\ - if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallVoidMethod, env, _obj,\ - method))) \ - return - -/* - * Class: nsk_monitoring_share_thread_MonitorDeadlock_DeadlockThread - * Method: nativeLock2 - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_nsk_monitoring_share_thread_Deadlock_00024NativeLocker_lock -(JNIEnv *env, jobject this) { - jclass testBugClass, nativeLockerClass, lockerClass, wicketClass; - jobject lock, inner, step1, step2, step3; - jfieldID field; - jmethodID method; - - GET_OBJECT_CLASS(nativeLockerClass, this); - FIND_CLASS(lockerClass, "nsk/monitoring/share/thread/Deadlock$Locker"); - FIND_CLASS(wicketClass, "nsk/share/Wicket"); - FIND_CLASS(testBugClass, "nsk/share/TestBug"); - GET_OBJ_FIELD(lock, this, nativeLockerClass, "lock", "Ljava/lang/Object;"); - GET_OBJ_FIELD(step1, this, nativeLockerClass, "step1", "Lnsk/share/Wicket;"); - if (step1 == NULL) { - (*env)->ThrowNew(env, testBugClass, "step1 field is null"); - return; - } - GET_OBJ_FIELD(step2, this, nativeLockerClass, "step2", "Lnsk/share/Wicket;"); - if (step2 == NULL) { - (*env)->ThrowNew(env, testBugClass, "step2 field is null"); - return; - } - GET_OBJ_FIELD(step3, this, nativeLockerClass, "step3", "Lnsk/share/Wicket;"); - if (step3 == NULL) { - (*env)->ThrowNew(env, testBugClass, "step3 field is null"); - return; - } - GET_OBJ_FIELD(inner, this, lockerClass, "inner", "Lnsk/monitoring/share/thread/Deadlock$Locker;"); - if ((*env)->MonitorEnter(env, lock) == JNI_OK) { - if (inner == NULL) { - (*env)->ThrowNew(env, testBugClass, "Should not reach here"); - } else { - CALL_VOID_NOPARAM(step1, wicketClass, "unlock"); - CALL_VOID_NOPARAM(step2, wicketClass, "waitFor"); - CALL_VOID_NOPARAM(step3, wicketClass, "unlock"); - CALL_VOID_NOPARAM(inner, lockerClass, "lock"); - } - (*env)->MonitorExit(env, lock); - } else { - (*env)->ThrowNew(env, testBugClass, "MonitorEnter(lock) call failed"); - } -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/Deadlock.cpp b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/Deadlock.cpp new file mode 100644 index 00000000000..78a1c9eaec3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/Deadlock.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FIND_CLASS(_class, _className)\ + if (!NSK_JNI_VERIFY(env, (_class = \ + NSK_CPP_STUB2(FindClass, env, _className)) != NULL))\ + return + +#define GET_OBJECT_CLASS(_class, _obj)\ + if (!NSK_JNI_VERIFY(env, (_class = \ + NSK_CPP_STUB2(GetObjectClass, env, _obj)) != NULL))\ + return + +#define GET_OBJ_FIELD(_value, _obj, _class, _fieldName, _fieldSig)\ + GET_FIELD_ID(field, _class, _fieldName, _fieldSig);\ + _value = NSK_CPP_STUB3(GetObjectField, env, _obj, field) + +#define GET_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ + if (!NSK_JNI_VERIFY(env, (_fieldID = \ + NSK_CPP_STUB4(GetFieldID, env, _class,\ + _fieldName, _fieldSig)) != NULL))\ + return + +#define GET_METHOD_ID(_methodID, _class, _methodName, _sig)\ + if (!NSK_JNI_VERIFY(env, (_methodID = \ + NSK_CPP_STUB4(GetMethodID, env, _class,\ + _methodName, _sig)) != NULL)) \ + return + +#define CALL_VOID_NOPARAM(_obj, _class, _methodName)\ + GET_METHOD_ID(method, _class, _methodName, "()V");\ + if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallVoidMethod, env, _obj,\ + method))) \ + return + +/* + * Class: nsk_monitoring_share_thread_MonitorDeadlock_DeadlockThread + * Method: nativeLock2 + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_nsk_monitoring_share_thread_Deadlock_00024NativeLocker_lock +(JNIEnv *env, jobject o) { + jclass testBugClass, nativeLockerClass, lockerClass, wicketClass; + jobject lock, inner, step1, step2, step3; + jfieldID field; + jmethodID method; + + GET_OBJECT_CLASS(nativeLockerClass, o); + FIND_CLASS(lockerClass, "nsk/monitoring/share/thread/Deadlock$Locker"); + FIND_CLASS(wicketClass, "nsk/share/Wicket"); + FIND_CLASS(testBugClass, "nsk/share/TestBug"); + GET_OBJ_FIELD(lock, o, nativeLockerClass, "lock", "Ljava/lang/Object;"); + GET_OBJ_FIELD(step1, o, nativeLockerClass, "step1", "Lnsk/share/Wicket;"); + if (step1 == NULL) { + env->ThrowNew(testBugClass, "step1 field is null"); + return; + } + GET_OBJ_FIELD(step2, o, nativeLockerClass, "step2", "Lnsk/share/Wicket;"); + if (step2 == NULL) { + env->ThrowNew(testBugClass, "step2 field is null"); + return; + } + GET_OBJ_FIELD(step3, o, nativeLockerClass, "step3", "Lnsk/share/Wicket;"); + if (step3 == NULL) { + env->ThrowNew(testBugClass, "step3 field is null"); + return; + } + GET_OBJ_FIELD(inner, o, lockerClass, "inner", "Lnsk/monitoring/share/thread/Deadlock$Locker;"); + if (env->MonitorEnter(lock) == JNI_OK) { + if (inner == NULL) { + env->ThrowNew(testBugClass, "Should not reach here"); + } else { + CALL_VOID_NOPARAM(step1, wicketClass, "unlock"); + CALL_VOID_NOPARAM(step2, wicketClass, "waitFor"); + CALL_VOID_NOPARAM(step3, wicketClass, "unlock"); + CALL_VOID_NOPARAM(inner, lockerClass, "lock"); + } + env->MonitorExit(lock); + } else { + env->ThrowNew(testBugClass, "MonitorEnter(lock) call failed"); + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/LockingThreads.c b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/LockingThreads.c deleted file mode 100644 index c5370271e0d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/LockingThreads.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include "jni_tools.h" - -#define FIND_CLASS(_class, _className)\ - if (!NSK_JNI_VERIFY(env, (_class = \ - NSK_CPP_STUB2(FindClass, env, _className)) != NULL))\ - return - -#define GET_OBJECT_CLASS(_class, _obj)\ - if (!NSK_JNI_VERIFY(env, (_class = \ - NSK_CPP_STUB2(GetObjectClass, env, _obj)) != NULL))\ - return - -#define GET_OBJ_FIELD(_value, _obj, _class, _fieldName, _fieldSig)\ - GET_FIELD_ID(field, _class, _fieldName, _fieldSig);\ - _value = NSK_CPP_STUB3(GetObjectField, env, _obj, field) - -#define GET_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ - if (!NSK_JNI_VERIFY(env, (_fieldID = \ - NSK_CPP_STUB4(GetFieldID, env, _class,\ - _fieldName, _fieldSig)) != NULL))\ - return - -#define GET_METHOD_ID(_methodID, _class, _methodName, _sig)\ - if (!NSK_JNI_VERIFY(env, (_methodID = \ - NSK_CPP_STUB4(GetMethodID, env, _class,\ - _methodName, _sig)) != NULL))\ - return - -#define CALL_VOID_NOPARAM(_obj, _class, _methodName)\ - GET_METHOD_ID(method, _class, _methodName, "()V");\ - if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallVoidMethod, env, _obj,\ - method)))\ - return -/* - * Class: nsk_monitoring_share_thread_LockingThreads_Thread1 - * Method: B - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_nsk_monitoring_share_thread_LockingThreads_00024Thread1_B - (JNIEnv *env, jobject this) { - jclass testBugClass, threadClass; - jobject lock4, lock5; - jfieldID field; - jmethodID method; - - GET_OBJECT_CLASS(threadClass, this); - FIND_CLASS(testBugClass, "nsk/share/TestBug"); - GET_OBJ_FIELD(lock4, this, threadClass, "lock4", "Lnsk/monitoring/share/thread/LockingThreads$CustomLock;"); - GET_OBJ_FIELD(lock5, this, threadClass, "lock5", "Lnsk/monitoring/share/thread/LockingThreads$CustomLock;"); - if ((*env)->MonitorEnter(env, lock4) == JNI_OK) { - if ((*env)->MonitorEnter(env, lock5) == JNI_OK) { - CALL_VOID_NOPARAM(this, threadClass, "C"); - (*env)->MonitorExit(env, lock5); - } else - (*env)->ThrowNew(env, testBugClass, "MonitorEnter(lock5) call failed"); - (*env)->MonitorExit(env, lock4); - } else - (*env)->ThrowNew(env, testBugClass, "MonitorEnter(lock4) call failed"); -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/LockingThreads.cpp b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/LockingThreads.cpp new file mode 100644 index 00000000000..d02f5e0f9d8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/LockingThreads.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FIND_CLASS(_class, _className)\ + if (!NSK_JNI_VERIFY(env, (_class = \ + NSK_CPP_STUB2(FindClass, env, _className)) != NULL))\ + return + +#define GET_OBJECT_CLASS(_class, _obj)\ + if (!NSK_JNI_VERIFY(env, (_class = \ + NSK_CPP_STUB2(GetObjectClass, env, _obj)) != NULL))\ + return + +#define GET_OBJ_FIELD(_value, _obj, _class, _fieldName, _fieldSig)\ + GET_FIELD_ID(field, _class, _fieldName, _fieldSig);\ + _value = NSK_CPP_STUB3(GetObjectField, env, _obj, field) + +#define GET_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ + if (!NSK_JNI_VERIFY(env, (_fieldID = \ + NSK_CPP_STUB4(GetFieldID, env, _class,\ + _fieldName, _fieldSig)) != NULL))\ + return + +#define GET_METHOD_ID(_methodID, _class, _methodName, _sig)\ + if (!NSK_JNI_VERIFY(env, (_methodID = \ + NSK_CPP_STUB4(GetMethodID, env, _class,\ + _methodName, _sig)) != NULL))\ + return + +#define CALL_VOID_NOPARAM(_obj, _class, _methodName)\ + GET_METHOD_ID(method, _class, _methodName, "()V");\ + if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallVoidMethod, env, _obj,\ + method)))\ + return +/* + * Class: nsk_monitoring_share_thread_LockingThreads_Thread1 + * Method: B + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_nsk_monitoring_share_thread_LockingThreads_00024Thread1_B + (JNIEnv *env, jobject o) { + jclass testBugClass, threadClass; + jobject lock4, lock5; + jfieldID field; + jmethodID method; + + GET_OBJECT_CLASS(threadClass, o); + FIND_CLASS(testBugClass, "nsk/share/TestBug"); + GET_OBJ_FIELD(lock4, o, threadClass, "lock4", "Lnsk/monitoring/share/thread/LockingThreads$CustomLock;"); + GET_OBJ_FIELD(lock5, o, threadClass, "lock5", "Lnsk/monitoring/share/thread/LockingThreads$CustomLock;"); + if (env->MonitorEnter(lock4) == JNI_OK) { + if (env->MonitorEnter(lock5) == JNI_OK) { + CALL_VOID_NOPARAM(o, threadClass, "C"); + env->MonitorExit(lock5); + } else + env->ThrowNew(testBugClass, "MonitorEnter(lock5) call failed"); + env->MonitorExit(lock4); + } else + env->ThrowNew(testBugClass, "MonitorEnter(lock4) call failed"); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/RecursiveMonitoringThread.c b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/RecursiveMonitoringThread.c deleted file mode 100644 index d6de16d39f5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/RecursiveMonitoringThread.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FIND_CLASS(_class, _className)\ - if (!NSK_JNI_VERIFY(env, (_class = \ - NSK_CPP_STUB2(FindClass, env, _className)) != NULL))\ - return - -#define GET_OBJECT_CLASS(_class, _obj)\ - if (!NSK_JNI_VERIFY(env, (_class = \ - NSK_CPP_STUB2(GetObjectClass, env, _obj)) != NULL))\ - return - -#define GET_STATIC_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ - if (!NSK_JNI_VERIFY(env, (_fieldID = \ - NSK_CPP_STUB4(GetStaticFieldID, env, _class,\ - _fieldName, _fieldSig)) != NULL))\ - return - -#define GET_STATIC_OBJ_FIELD(_value, _class, _fieldName, _fieldSig)\ - GET_STATIC_FIELD_ID(field, _class, _fieldName, _fieldSig);\ - _value = NSK_CPP_STUB3(GetStaticObjectField, env, _class, \ - field) - -#define GET_STATIC_BOOL_FIELD(_value, _class, _fieldName)\ - GET_STATIC_FIELD_ID(field, _class, _fieldName, "Z");\ - _value = NSK_CPP_STUB3(GetStaticBooleanField, env, _class, field) - -#define GET_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ - if (!NSK_JNI_VERIFY(env, (_fieldID = \ - NSK_CPP_STUB4(GetFieldID, env, _class,\ - _fieldName, _fieldSig)) != NULL))\ - return - -#define GET_INT_FIELD(_value, _obj, _class, _fieldName)\ - GET_FIELD_ID(field, _class, _fieldName, "I");\ - _value = NSK_CPP_STUB3(GetIntField, env, _obj, field) - -#define GET_LONG_FIELD(_value, _obj, _class, _fieldName)\ - GET_FIELD_ID(field, _class, _fieldName, "J");\ - _value = NSK_CPP_STUB3(GetLongField, env, _obj, field) - -#define GET_STATIC_INT_FIELD(_value, _class, _fieldName)\ - GET_STATIC_FIELD_ID(field, _class, _fieldName, "I");\ - _value = NSK_CPP_STUB3(GetStaticIntField, env, _class, field) - -#define SET_INT_FIELD(_obj, _class, _fieldName, _newValue)\ - GET_FIELD_ID(field, _class, _fieldName, "I");\ - NSK_CPP_STUB4(SetIntField, env, _obj, field, _newValue) - -#define GET_OBJ_FIELD(_value, _obj, _class, _fieldName, _fieldSig)\ - GET_FIELD_ID(field, _class, _fieldName, _fieldSig);\ - _value = NSK_CPP_STUB3(GetObjectField, env, _obj, field) - - -#define GET_ARR_ELEMENT(_arr, _index)\ - NSK_CPP_STUB3(GetObjectArrayElement, env, _arr, _index) - -#define SET_ARR_ELEMENT(_arr, _index, _newValue)\ - NSK_CPP_STUB4(SetObjectArrayElement, env, _arr, _index, _newValue) - -#define GET_STATIC_METHOD_ID(_methodID, _class, _methodName, _sig)\ - if (!NSK_JNI_VERIFY(env, (_methodID = \ - NSK_CPP_STUB4(GetStaticMethodID, env, _class,\ - _methodName, _sig)) != NULL))\ - return - -#define GET_METHOD_ID(_methodID, _class, _methodName, _sig)\ - if (!NSK_JNI_VERIFY(env, (_methodID = \ - NSK_CPP_STUB4(GetMethodID, env, _class,\ - _methodName, _sig)) != NULL))\ - return - -#define CALL_STATIC_VOID_NOPARAM(_class, _methodName)\ - GET_STATIC_METHOD_ID(method, _class, _methodName, "()V");\ - if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallStaticVoidMethod, env,\ - _class, method)))\ - return - -#define CALL_STATIC_VOID(_class, _methodName, _sig, _param)\ - GET_STATIC_METHOD_ID(method, _class, _methodName, _sig);\ - if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB4(CallStaticVoidMethod, env,\ - _class, method, _param)))\ - return - -#define CALL_VOID_NOPARAM(_obj, _class, _methodName)\ - GET_METHOD_ID(method, _class, _methodName, "()V");\ - if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallVoidMethod, env, _obj,\ - method)))\ - return - -#define CALL_VOID(_obj, _class, _methodName, _sig, _param)\ - GET_METHOD_ID(method, _class, _methodName, _sig);\ - if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB4(CallVoidMethod, env, _obj,\ - method, _param)))\ - return - -#define CALL_VOID2(_obj, _class, _methodName, _sig, _param1, _param2)\ - GET_METHOD_ID(method, _class, _methodName, _sig);\ - if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB5(CallVoidMethod, env, _obj, \ - method, _param1, _param2)))\ - return - -#define CALL_INT_NOPARAM(_value, _obj, _class, _methodName)\ - GET_METHOD_ID(method, _class, _methodName, "()I");\ - _value = NSK_CPP_STUB3(CallIntMethod, env, _obj, method) - -#define NEW_OBJ(_obj, _class, _constructorName, _sig, _params)\ - GET_METHOD_ID(method, _class, _constructorName, _sig);\ - if (!NSK_JNI_VERIFY(env, (_obj = \ - NSK_CPP_STUB4(NewObject, env, _class, method, _params)) != NULL))\ - return - -#define MONITOR_ENTER(x) \ - NSK_JNI_VERIFY(env, NSK_CPP_STUB2(MonitorEnter, env, x) == 0) - -#define MONITOR_EXIT(x) \ - NSK_JNI_VERIFY(env, NSK_CPP_STUB2(MonitorExit, env, x) == 0) - -#define TRACE(msg)\ - GET_OBJ_FIELD(logger, obj, threadClass, "logger", "Lnsk/share/Log$Logger;");\ - jmsg = NSK_CPP_STUB2(NewStringUTF, env, msg);\ - CALL_VOID2(logger, loggerClass, "trace",\ - "(ILjava/lang/String;)V", 50, jmsg) - - -/* - * Class: nsk_monitoring_share_thread_RecursiveMonitoringThread - * Method: nativeRecursiveMethod - * Signature: (IZ)V - */ -JNIEXPORT void JNICALL Java_nsk_monitoring_share_thread_RecursiveMonitoringThread_nativeRecursiveMethod -(JNIEnv *env, jobject this, jint currentDepth, jboolean pureNative) { - jclass class; - jmethodID method; - - GET_OBJECT_CLASS(class, this); - if (currentDepth-- > 0) { -/* printf("Current depth: %d\n", currentDepth); */ - CALL_STATIC_VOID_NOPARAM(class, "yield"); - if (pureNative == JNI_TRUE) { - CALL_VOID2(this, class, "nativeRecursiveMethod", "(IZ)V", currentDepth, pureNative); - } else { - CALL_VOID(this, class, "recursiveMethod", "(I)V", currentDepth); - } - } else { - CALL_VOID_NOPARAM(this, class, "runInside"); - } -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/RecursiveMonitoringThread.cpp b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/RecursiveMonitoringThread.cpp new file mode 100644 index 00000000000..9540bf08396 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/RecursiveMonitoringThread.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FIND_CLASS(_class, _className)\ + if (!NSK_JNI_VERIFY(env, (_class = \ + NSK_CPP_STUB2(FindClass, env, _className)) != NULL))\ + return + +#define GET_OBJECT_CLASS(_class, _obj)\ + if (!NSK_JNI_VERIFY(env, (_class = \ + NSK_CPP_STUB2(GetObjectClass, env, _obj)) != NULL))\ + return + +#define GET_STATIC_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ + if (!NSK_JNI_VERIFY(env, (_fieldID = \ + NSK_CPP_STUB4(GetStaticFieldID, env, _class,\ + _fieldName, _fieldSig)) != NULL))\ + return + +#define GET_STATIC_OBJ_FIELD(_value, _class, _fieldName, _fieldSig)\ + GET_STATIC_FIELD_ID(field, _class, _fieldName, _fieldSig);\ + _value = NSK_CPP_STUB3(GetStaticObjectField, env, _class, \ + field) + +#define GET_STATIC_BOOL_FIELD(_value, _class, _fieldName)\ + GET_STATIC_FIELD_ID(field, _class, _fieldName, "Z");\ + _value = NSK_CPP_STUB3(GetStaticBooleanField, env, _class, field) + +#define GET_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ + if (!NSK_JNI_VERIFY(env, (_fieldID = \ + NSK_CPP_STUB4(GetFieldID, env, _class,\ + _fieldName, _fieldSig)) != NULL))\ + return + +#define GET_INT_FIELD(_value, _obj, _class, _fieldName)\ + GET_FIELD_ID(field, _class, _fieldName, "I");\ + _value = NSK_CPP_STUB3(GetIntField, env, _obj, field) + +#define GET_LONG_FIELD(_value, _obj, _class, _fieldName)\ + GET_FIELD_ID(field, _class, _fieldName, "J");\ + _value = NSK_CPP_STUB3(GetLongField, env, _obj, field) + +#define GET_STATIC_INT_FIELD(_value, _class, _fieldName)\ + GET_STATIC_FIELD_ID(field, _class, _fieldName, "I");\ + _value = NSK_CPP_STUB3(GetStaticIntField, env, _class, field) + +#define SET_INT_FIELD(_obj, _class, _fieldName, _newValue)\ + GET_FIELD_ID(field, _class, _fieldName, "I");\ + NSK_CPP_STUB4(SetIntField, env, _obj, field, _newValue) + +#define GET_OBJ_FIELD(_value, _obj, _class, _fieldName, _fieldSig)\ + GET_FIELD_ID(field, _class, _fieldName, _fieldSig);\ + _value = NSK_CPP_STUB3(GetObjectField, env, _obj, field) + + +#define GET_ARR_ELEMENT(_arr, _index)\ + NSK_CPP_STUB3(GetObjectArrayElement, env, _arr, _index) + +#define SET_ARR_ELEMENT(_arr, _index, _newValue)\ + NSK_CPP_STUB4(SetObjectArrayElement, env, _arr, _index, _newValue) + +#define GET_STATIC_METHOD_ID(_methodID, _class, _methodName, _sig)\ + if (!NSK_JNI_VERIFY(env, (_methodID = \ + NSK_CPP_STUB4(GetStaticMethodID, env, _class,\ + _methodName, _sig)) != NULL))\ + return + +#define GET_METHOD_ID(_methodID, _class, _methodName, _sig)\ + if (!NSK_JNI_VERIFY(env, (_methodID = \ + NSK_CPP_STUB4(GetMethodID, env, _class,\ + _methodName, _sig)) != NULL))\ + return + +#define CALL_STATIC_VOID_NOPARAM(_class, _methodName)\ + GET_STATIC_METHOD_ID(method, _class, _methodName, "()V");\ + if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallStaticVoidMethod, env,\ + _class, method)))\ + return + +#define CALL_STATIC_VOID(_class, _methodName, _sig, _param)\ + GET_STATIC_METHOD_ID(method, _class, _methodName, _sig);\ + if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB4(CallStaticVoidMethod, env,\ + _class, method, _param)))\ + return + +#define CALL_VOID_NOPARAM(_obj, _class, _methodName)\ + GET_METHOD_ID(method, _class, _methodName, "()V");\ + if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallVoidMethod, env, _obj,\ + method)))\ + return + +#define CALL_VOID(_obj, _class, _methodName, _sig, _param)\ + GET_METHOD_ID(method, _class, _methodName, _sig);\ + if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB4(CallVoidMethod, env, _obj,\ + method, _param)))\ + return + +#define CALL_VOID2(_obj, _class, _methodName, _sig, _param1, _param2)\ + GET_METHOD_ID(method, _class, _methodName, _sig);\ + if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB5(CallVoidMethod, env, _obj, \ + method, _param1, _param2)))\ + return + +#define CALL_INT_NOPARAM(_value, _obj, _class, _methodName)\ + GET_METHOD_ID(method, _class, _methodName, "()I");\ + _value = NSK_CPP_STUB3(CallIntMethod, env, _obj, method) + +#define NEW_OBJ(_obj, _class, _constructorName, _sig, _params)\ + GET_METHOD_ID(method, _class, _constructorName, _sig);\ + if (!NSK_JNI_VERIFY(env, (_obj = \ + NSK_CPP_STUB4(NewObject, env, _class, method, _params)) != NULL))\ + return + +#define MONITOR_ENTER(x) \ + NSK_JNI_VERIFY(env, NSK_CPP_STUB2(MonitorEnter, env, x) == 0) + +#define MONITOR_EXIT(x) \ + NSK_JNI_VERIFY(env, NSK_CPP_STUB2(MonitorExit, env, x) == 0) + +#define TRACE(msg)\ + GET_OBJ_FIELD(logger, obj, threadClass, "logger", "Lnsk/share/Log$Logger;");\ + jmsg = NSK_CPP_STUB2(NewStringUTF, env, msg);\ + CALL_VOID2(logger, loggerClass, "trace",\ + "(ILjava/lang/String;)V", 50, jmsg) + + +/* + * Class: nsk_monitoring_share_thread_RecursiveMonitoringThread + * Method: nativeRecursiveMethod + * Signature: (IZ)V + */ +JNIEXPORT void JNICALL Java_nsk_monitoring_share_thread_RecursiveMonitoringThread_nativeRecursiveMethod +(JNIEnv *env, jobject o, jint currentDepth, jboolean pureNative) { + jclass klass; + jmethodID method; + + GET_OBJECT_CLASS(klass, o); + if (currentDepth-- > 0) { +/* printf("Current depth: %d\n", currentDepth); */ + CALL_STATIC_VOID_NOPARAM(klass, "yield"); + if (pureNative == JNI_TRUE) { + CALL_VOID2(o, klass, "nativeRecursiveMethod", "(IZ)V", currentDepth, pureNative); + } else { + CALL_VOID(o, klass, "recursiveMethod", "(I)V", currentDepth); + } + } else { + CALL_VOID_NOPARAM(o, klass, "runInside"); + } +} + +#ifdef __cplusplus +} +#endif + diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libDeadlock.c b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libDeadlock.c deleted file mode 100644 index 73e20236b16..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libDeadlock.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "Deadlock.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libDeadlock.cpp b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libDeadlock.cpp new file mode 100644 index 00000000000..f0f062d2462 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libDeadlock.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "Deadlock.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libLockingThreads.c b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libLockingThreads.c deleted file mode 100644 index ed7f3cb9745..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libLockingThreads.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "LockingThreads.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libLockingThreads.cpp b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libLockingThreads.cpp new file mode 100644 index 00000000000..86e4bdf0cd9 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libLockingThreads.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "LockingThreads.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libNativeBlockedThread.c b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libNativeBlockedThread.c deleted file mode 100644 index 837b1eec4c7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libNativeBlockedThread.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include - -/* - * Class: nsk_monitoring_share_thread_NativeBlockedThread - * Method: nativeBlock - * Signature: (Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL Java_nsk_monitoring_share_thread_NativeBlockedThread_nativeBlock -(JNIEnv *env, jobject this, jobject lock) { - if ((*env)->MonitorEnter(env, lock) != JNI_OK) { - (*env)->FatalError(env, "MonitorEnter call failed"); - } - (*env)->MonitorExit(env, lock); -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libNativeBlockedThread.cpp b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libNativeBlockedThread.cpp new file mode 100644 index 00000000000..c4e4e369665 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libNativeBlockedThread.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: nsk_monitoring_share_thread_NativeBlockedThread + * Method: nativeBlock + * Signature: (Ljava/lang/Object;)V + */ +JNIEXPORT void JNICALL Java_nsk_monitoring_share_thread_NativeBlockedThread_nativeBlock +(JNIEnv *env, jobject o, jobject lock) { + if (env->MonitorEnter(lock) != JNI_OK) { + env->FatalError("MonitorEnter call failed"); + } + env->MonitorExit(lock); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libRecursiveMonitoringThread.c b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libRecursiveMonitoringThread.c deleted file mode 100644 index 7240e098796..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libRecursiveMonitoringThread.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "RecursiveMonitoringThread.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libRecursiveMonitoringThread.cpp b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libRecursiveMonitoringThread.cpp new file mode 100644 index 00000000000..8a888c2bbe4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/thread/libRecursiveMonitoringThread.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "RecursiveMonitoringThread.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/JVMDITools.c b/test/hotspot/jtreg/vmTestbase/nsk/share/JVMDITools.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/JVMDITools.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/JVMDITools.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/JVMTIagent.c b/test/hotspot/jtreg/vmTestbase/nsk/share/JVMTIagent.c deleted file mode 100644 index b6afbf8783d..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/JVMTIagent.c +++ /dev/null @@ -1,1276 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * - * JVMTI agent used for run every test from the testbase in a special - * debug mode. This mode is intended to be part of serviceability - * reliability testing. - */ - -#include -#include -#include -#include -#include - -#include "nsk_tools.h" -#include "jni_tools.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -static jvmtiEnv *jvmti = NULL; /* JVMTI env */ -static jvmtiEventCallbacks callbacks; -static jrawMonitorID eventLock; /* raw monitor used for exclusive ownership of HotSwap function */ - -static volatile int debug_mode = 0; /* 0 - verbose mode off; - 1 - verbose mode on; - 2 - verbose mode on including all JVMTI events reporting, - produces a huge number of messages */ - -/* stress level */ -static volatile int stress_lev = 0; /* 0 - default mode: generation of all events except - ExceptionCatch, - MethodEntry/Exit, SingleStep; - 1 - generation of all events except - MethodEntry/Exit, - SingleStep; - 2 - generation of all events except - SingleStep; - 3 - generation of all events, including - ExceptionCatch, - MethodEntry/Exit, - SingleStep - */ - -#define TRUE 1 -#define FALSE 0 - -/**** the following is used for "postVM_DEATH" events watching ****/ -static volatile int vm_death_occured = FALSE; -/************************************************/ - -/**** the following is used for HotSwap mode ****/ - -/* HotSwap modes: - HOTSWAP_OFF - default mode: HotSwap off; - HOTSWAP_EVERY_METHOD_ENTRY - HotSwap tested class in every method entry event - of running test - HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS - HotSwap tested class in every - method entry event of every class - HOTSWAP_EVERY_SINGLE_STEP - HotSwap tested class in every single step event - of running test - HOTSWAP_EVERY_EXCEPTION - HotSwap tested class in every exception event - of running test - HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS - HotSwap tested class in every - exception event of every class - */ - -#define HOTSWAP_OFF 0 -#define HOTSWAP_EVERY_METHOD_ENTRY 2 -#define HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS 20 -#define HOTSWAP_EVERY_SINGLE_STEP 3 -#define HOTSWAP_EVERY_EXCEPTION 4 -#define HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS 40 - -static int hotswap = HOTSWAP_OFF; - -typedef struct { /* test class info */ - char *clazzsig; /* class signature */ - jclass cls; /* a class to be redefined */ - jint bCount; /* number of bytes defining the class */ - jbyte *clsBytes; /* bytes defining the class */ - struct class_info *next; -} class_info; - - -static const char *shortTestName = NULL; /* name of the test without package prefix */ -static jclass rasCls; /* reference to the auxiliary class RASagent used for HotSwap */ -static class_info *clsInfo = NULL, *clsInfoFst = NULL; - -static void lock(JNIEnv*); -static void unlock(JNIEnv*); -static jint allocClsInfo(JNIEnv*, char*, jclass); -static void deallocClsInfo(JNIEnv*); -static int findAndHotSwap(JNIEnv*, jclass); -static int doHotSwap(JNIEnv*, jclass, jint, jbyte*); -static void display(int, const char format[], ...); -static void clearJavaException(JNIEnv*); -static int enableEventsCaps(); -static int addStressEvents(); -static void getVerdict(JNIEnv*, const char *); -/************************************************/ - -/** callback functions **/ -void JNICALL -Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thr, jmethodID method, - jlocation loc) { - - display(1, "#### JVMTIagent: Breakpoint occurred ####\n"); - - getVerdict(jni_env, "Breakpoint"); -} - -void JNICALL -ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jclass class_beeing_redefined, - jobject loader, const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - - display(1, "#### JVMTIagent: ClassFileLoadHook occurred ####\n"); - - getVerdict(jni_env, "ClassFileLoadHook"); -} - -void JNICALL -ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread, jclass klass) { - char *cls_sig; - jint clsByteCount; - - display((hotswap != HOTSWAP_OFF)?0:1, - "#### JVMTIagent: ClassLoad occurred ####\n"); - - getVerdict(jni_env, "ClassLoad"); - - if (hotswap != HOTSWAP_OFF) { - /* enter into a raw monitor for exclusive work with redefined class */ - lock(jni_env); - display(0, "#### JVMTIagent: ClassLoad: >>>>>>>> entered the raw monitor \"eventLock\" ####\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, - jvmti_env, klass, &cls_sig, /*&generic*/NULL))) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to get class signature\n"); - else { - if (shortTestName != NULL) { - if (strstr((const char*) cls_sig, shortTestName) != NULL) { - display(0, "#### JVMTIagent: found test class matched with \"%s\"\n\ -\tsignature=%s\n", - shortTestName, cls_sig); - clsByteCount = allocClsInfo(jni_env, cls_sig, klass); - display(0, "#### JVMTIagent: %d bytes defining the class have been successfully loaded\n", - clsByteCount); - } - } - } - - /* exit from the raw monitor */ - unlock(jni_env); - display(0, "#### JVMTIagent: ClassLoad: <<<<<<<< exited from the raw monitor \"eventLock\" ####\n\n"); - } -} - -void JNICALL -ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jthread thr, jclass cls) { - - display(1, "#### JVMTIagent: ClassPrepare occurred ####\n"); - - getVerdict(jni_env, "ClassPrepare"); -} - -void JNICALL -CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, - const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - - display(1, "#### JVMTIagent: CompiledMethodLoad occurred ####\n"); - - getVerdict(NULL, "CompiledMethodLoad"); -} - -void JNICALL -CompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, - const void* code_addr) { - - display(1, "#### JVMTIagent: CompiledMethodUnload occurred ####\n"); - - getVerdict(NULL, "CompiledMethodUnload"); -} - -void JNICALL -DataDumpRequest(jvmtiEnv *jvmti_env) { - - display(1, "#### JVMTIagent: DataDumpRequest occurred ####\n"); - - getVerdict(NULL, "DataDumpRequest"); -} - -void JNICALL -DynamicCodeGenerated(jvmtiEnv *jvmti_env, - const char* name, - const void* address, - jint length) { - - display(1, "#### JVMTIagent: DynamicCodeGenerated occurred ####\n"); - - getVerdict(NULL, "DynamicCodeGenerated"); -} - -void JNICALL -Exception(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thr, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - jclass decl_clazz; - - display((hotswap == HOTSWAP_EVERY_EXCEPTION || - hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS)?0:1, - "#### JVMTIagent: Exception occurred ####\n"); - - getVerdict(jni_env, "Exception"); - - if (hotswap == HOTSWAP_EVERY_EXCEPTION || - hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, method, &decl_clazz))) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to get method declaring class\n"); - - if (findAndHotSwap(jni_env, decl_clazz) != 0) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to hotswap class\n"); - } -} - -void JNICALL -FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jthread thr, jmethodID method, - jlocation location, jclass field_klass, jobject obj, jfieldID field) { - - display(1, "#### JVMTIagent: FieldAccess occurred ####\n"); - - getVerdict(jni_env, "FieldAccess"); -} - -void JNICALL -FieldModification(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jthread thr, jmethodID method, jlocation location, - jclass field_klass, jobject obj, - jfieldID field, char sig, jvalue new_value) { - - display(1, "#### JVMTIagent: FieldModification occurred ####\n"); - - getVerdict(jni_env, "FieldModification"); -} - -void JNICALL -FramePop(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jthread thr, jmethodID method, jboolean wasPopedByException) { - - display(1, "#### JVMTIagent: FramePop occurred ####\n"); - - getVerdict(jni_env, "FramePop"); -} - -void JNICALL -GarbageCollectionFinish(jvmtiEnv *jvmti_env) { - - display(1, "#### JVMTIagent: GarbageCollectionFinish occurred ####\n"); - - getVerdict(NULL, "GarbageCollectionFinish"); -} - -void JNICALL -GarbageCollectionStart(jvmtiEnv *jvmti_env) { - - display(1, "#### JVMTIagent: GarbageCollectionStart occurred ####\n"); - - getVerdict(NULL, "GarbageCollectionStart"); -} - -void JNICALL -MonitorContendedEnter(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thr, - jobject obj) { - - display(1, "#### JVMTIagent: MonitorContendedEnter occurred ####\n"); - - getVerdict(jni_env, "MonitorContendedEnter"); -} - -void JNICALL -MonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thr, - jobject obj) { - - display(1, "#### JVMTIagent: MonitorContendedEntered occurred ####\n"); - - getVerdict(jni_env, "MonitorContendedEntered"); -} - -void JNICALL -MonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thr, jobject obj, - jlong tout) { - - display(1, "#### JVMTIagent: MonitorWait occurred ####\n"); - - getVerdict(jni_env, "MonitorWait"); -} - -void JNICALL -MonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, - jthread thr, jobject obj, jboolean timed_out) { - - display(1, "#### JVMTIagent: MonitorWaited occurred ####\n"); - - getVerdict(jni_env, "MonitorWaited"); -} - -void JNICALL -NativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, void *addr, void **new_addr) { - - display(1, "#### JVMTIagent: NativeMethodBind occurred ####\n"); - - getVerdict(jni_env, "NativeMethodBind"); -} - -void JNICALL -ObjectFree(jvmtiEnv *jvmti_env, jlong tag) { - - display(1, "#### JVMTIagent: ObjectFree occurred ####\n"); - - getVerdict(NULL, "ObjectFree"); -} - -void JNICALL -ThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread) { - - display(1, "#### JVMTIagent: ThreadEnd occurred ####\n"); - - getVerdict(jni_env, "ThreadEnd"); -} - -void JNICALL -ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread) { - - display(1, "#### JVMTIagent: ThreadStart occurred ####\n"); - - getVerdict(jni_env, "ThreadStart"); -} - -void JNICALL -VMDeath(jvmtiEnv *jvmti_env, JNIEnv *jni_env) { - vm_death_occured = TRUE; - - display(0, "#### JVMTIagent: VMDeath occurred ####\n"); - - if (hotswap != HOTSWAP_OFF) { - deallocClsInfo(jni_env); - display(0, "#### JVMTIagent: allocated memory was successfully freed ####\n"); - } -} - -void JNICALL -VMInit(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thr) { - - display(0, "#### JVMTIagent: VMInit occurred ####\n"); - - getVerdict(jni_env, "VMInit"); -} - -void JNICALL -VMStart(jvmtiEnv *jvmti_env, JNIEnv* jni_env) { - - display(0, "#### JVMTIagent: VMStart occurred ####\n"); - - getVerdict(jni_env, "VMStart"); -} - -JNIEXPORT void JNICALL -VMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jobject object, jclass object_klass, jlong size) { - - display(1, "#### JVMTIagent: VMObjectAlloc occurred ####\n"); - - getVerdict(jni_env, "VMObjectAlloc"); -} - -void JNICALL -SingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - jclass decl_clazz; - - display((hotswap == HOTSWAP_EVERY_SINGLE_STEP)?0:1, - "#### JVMTIagent: SingleStep occurred ####\n"); - - getVerdict(jni_env, "SingleStep"); - - if (hotswap == HOTSWAP_EVERY_SINGLE_STEP) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, method, &decl_clazz))) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to get method declaring class\n"); - - if (findAndHotSwap(jni_env, decl_clazz) != 0) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to hotswap class\n"); - } -} - -void JNICALL -MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jthread thr, jmethodID method) { - jclass decl_clazz; - - display((hotswap == HOTSWAP_EVERY_METHOD_ENTRY || - hotswap == HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS)?0:1, - "#### JVMTIagent: MethodEntry occurred ####\n"); - - getVerdict(jni_env, "MethodEntry"); - - if (hotswap == HOTSWAP_EVERY_METHOD_ENTRY || - hotswap == HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, method, &decl_clazz))) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to get method declaring class\n"); - - if (findAndHotSwap(jni_env, decl_clazz) != 0) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to hotswap class\n"); - } -} - -void JNICALL -MethodExit(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jthread thr, jmethodID method, - jboolean was_poped_by_exc, jvalue return_value) { - - display(1, "#### JVMTIagent: MethodExit occurred ####\n"); - - getVerdict(jni_env, "MethodExit"); -} - -void JNICALL -ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thr, - jmethodID method, jlocation location, jobject exception) { - jclass decl_clazz; - - display((hotswap == HOTSWAP_EVERY_EXCEPTION || - hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS)?0:1, - "#### JVMTIagent: ExceptionCatch occurred ####\n"); - - getVerdict(jni_env, "ExceptionCatch"); - - if (hotswap == HOTSWAP_EVERY_EXCEPTION || - hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, - jvmti_env, method, &decl_clazz))) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to get method declaring class\n"); - - if (findAndHotSwap(jni_env, decl_clazz) != 0) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to hotswap class\n"); - } -} -/************************/ - -static void lock(JNIEnv *jni_env) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, - jvmti, eventLock))) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to enter a raw monitor\n"); -} - -static void unlock(JNIEnv *jni_env) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, - jvmti, eventLock))) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to exit a raw monitor\n"); -} - -JNIEXPORT jint JNICALL -Java_nsk_share_RASagent_setHotSwapMode(JNIEnv *jni_env, jclass cls, - jboolean vrb, jint level, jstring shortName) { - jvmtiCapabilities capabil; - jmethodID mid = NULL; - - if (jvmti == NULL) { - printf("ERROR(%s,%d): JVMTIagent was not properly loaded: JVMTI env = NULL\n", - __FILE__, __LINE__); - return 1; - } - - /* get supported JVMTI capabilities */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, - jvmti, &capabil))) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to get capabilities\n"); - if (capabil.can_redefine_classes != 1) { /* ???????????? */ - printf("ERROR: JVMTIagent: Class File Redefinition (HotSwap) is not implemented in this VM\n"); - return 1; - } - - if (vrb == JNI_TRUE && debug_mode == 0) - debug_mode = 1; - - hotswap = level; - switch (hotswap) { - case HOTSWAP_OFF: - display(0, "#### JVMTIagent: hotswap mode off ####\n"); - return 0; - case HOTSWAP_EVERY_METHOD_ENTRY: - stress_lev = 2; - display(0, "#### JVMTIagent: hotswapping class in every method entry event enabled ####\n\ -\tHotSwap stress level: %d\n", - stress_lev); - break; - case HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS: - stress_lev = 2; - display(0, "#### JVMTIagent: hotswapping class in every method entry event for every class enabled ####\n\ -\tHotSwap stress level: %d\n", - stress_lev); - break; - case HOTSWAP_EVERY_SINGLE_STEP: - stress_lev = 3; - display(0, "#### JVMTIagent: hotswapping class in every single step event enabled ####\n\ -\tHotSwap stress level: %d\n", - stress_lev); - break; - case HOTSWAP_EVERY_EXCEPTION: - stress_lev = 4; - display(0, "#### JVMTIagent: hotswapping class in every exception event enabled ####\n\ -\tHotSwap stress level: %d\n", - stress_lev); - break; - case HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS: - stress_lev = 40; - display(0, "#### JVMTIagent: hotswapping class in every exception event for every class enabled ####\n\ -\tHotSwap stress level: %d\n", - stress_lev); - break; - default: - printf("ERROR(%s,%d): JVMTIagent: unknown value of HotSwap stress level: \"%d\"\n", - __FILE__,__LINE__,hotswap); - return 1; - } - - if (!NSK_JNI_VERIFY(jni_env, (shortTestName = NSK_CPP_STUB3(GetStringUTFChars, - jni_env, shortName, NULL)) != NULL)) { - printf("ERROR: JVMTIagent: unable to get UTF-8 characters of the string\n"); - return 1; - } - display(0, "#### JVMTIagent: short name of current test is \"%s\"\n", - shortTestName); - - if (!NSK_JNI_VERIFY(jni_env, (rasCls = NSK_CPP_STUB2(NewGlobalRef, - jni_env, cls)) != NULL)) { - printf("ERROR JVMTIagent: unable to create a new global reference of the class \"RASagent\"\n"); - return 1; - } - - if (addStressEvents() != 0) { - printf("ERROR(%s,%d): JVMTIagent terminated abnormally! ####\n", - __FILE__,__LINE__); - return 1; - } - - return 0; -} - -static jint allocClsInfo(JNIEnv *jni_env, char *cls_sig, jclass clazz) { - class_info *_clsInfo = NULL; - jmethodID mid = NULL; - jbyteArray classBytes; - jboolean isCopy; - - if ((_clsInfo = (class_info*) - malloc(sizeof(class_info))) == NULL) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: cannot allocate memory for class_info\n"); - - /* fill the structure class_info */ - _clsInfo->clazzsig = cls_sig; - - if (!NSK_JNI_VERIFY(jni_env, ((*_clsInfo).cls = NSK_CPP_STUB2(NewGlobalRef, - jni_env, clazz)) != NULL)) { - printf("ERROR: JVMTIagent: unable to create a new global reference of class \"%s\"\n", - _clsInfo->clazzsig); - free(_clsInfo); - deallocClsInfo(jni_env); - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: unable to create a new global reference of class\n"); - } - - if (!NSK_JNI_VERIFY(jni_env, (mid = - NSK_CPP_STUB4(GetStaticMethodID, jni_env, rasCls, - "loadFromClassFile", "(Ljava/lang/String;)[B")) != NULL)) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: unable to get ID of the method \"loadFromClassFile\"\n"); - - classBytes = (jbyteArray) NSK_CPP_STUB4(CallStaticObjectMethod, - jni_env, rasCls, mid, NSK_CPP_STUB2(NewStringUTF, jni_env, cls_sig)); - - clearJavaException(jni_env); - - (*_clsInfo).bCount = NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes); - - (*_clsInfo).clsBytes = - NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, &isCopy); - - _clsInfo->next = NULL; - - if (clsInfo != NULL) { - clsInfo->next = (struct class_info*) _clsInfo; - } - else { - clsInfoFst = _clsInfo; - } - clsInfo = _clsInfo; - - return (*_clsInfo).bCount; -} - -static void deallocClsInfo(JNIEnv *jni_env) { - class_info *clsInfoCurr = clsInfoFst; - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni_env, rasCls)); - - while(clsInfoCurr != NULL) { - class_info *_clsInfo = clsInfoCurr; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti, (unsigned char*) clsInfoCurr->clazzsig))) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: failed to deallocate memory for clazzsig\n"); - - NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni_env, clsInfoCurr->cls)); - - clsInfoCurr = (class_info*) clsInfoCurr->next; - - free(_clsInfo); - } - /* fix for 4756585: indicate that stucture class_info is empty now */ - clsInfoFst = NULL; -} - -static int findAndHotSwap(JNIEnv *jni_env, jclass clazz) { - int ret_code = 0; - char *clazzsig = NULL; - class_info *clsInfoCurr = clsInfoFst; - - display(1, "\n#### JVMTIagent: findAndHotSwap: obtaining class signature of class to be hotswap ...\n"); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, - jvmti, clazz, &clazzsig, /*&generic*/NULL))) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: findAndHotSwap: failed to get class signature\n"); - else { - display(1, "#### JVMTIagent: findAndHotSwap: ... class signature obtained: \"%s\"\n", - clazzsig); - - /* enter into a raw monitor for exclusive work with redefined class */ - lock(jni_env); - display(0, "#### JVMTIagent: findAndHotSwap: >>>>>>>> entered the raw monitor \"eventLock\" ####\n"); - - while(clsInfoCurr != NULL) { - if (hotswap == HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS || - hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS) { - display(1, "\n#### JVMTIagent: findAndHotSwap: going to hotswap tested class \"%s\" during execution of class \"%s\" ...\n", - clsInfoCurr->clazzsig, clazzsig); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti, (unsigned char*) clazzsig))) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: findAndHotSwap: failed to deallocate memory for clazzsig\n"); - - if (doHotSwap(jni_env, clsInfoCurr->cls, - clsInfoCurr->bCount, clsInfoCurr->clsBytes) != 0) { - ret_code = 1; - break; - } - } - else { - if (strcmp(clazzsig, clsInfoCurr->clazzsig) == 0) { - display(0, "\n#### JVMTIagent: findAndHotSwap: tested class found \"%s\" ...\n", - clazzsig); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, - jvmti, (unsigned char*) clazzsig))) - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: findAndHotSwap: failed to deallocate memory for clazzsig\n"); - - display(0, "\n#### JVMTIagent: findAndHotSwap: going to hotswap tested class \"%s\" ...\n", - clsInfoCurr->clazzsig); - if (doHotSwap(jni_env, clsInfoCurr->cls, - clsInfoCurr->bCount, clsInfoCurr->clsBytes) != 0) { - ret_code = 1; - break; - } - } - } - - clsInfoCurr = (class_info*) clsInfoCurr->next; - } - - /* exit raw monitor */ - unlock(jni_env); - display(0, "#### JVMTIagent: findAndHotSwap: <<<<<<<< exited from the raw monitor \"eventLock\" ####\n\n"); - } - - return ret_code; -} - -static int doHotSwap(JNIEnv *jni_env, jclass redefCls, jint bCount, - jbyte *classBytes) { - jvmtiClassDefinition classDef; - - /* fill the structure jvmtiClassDefinition */ - classDef.klass = redefCls; - classDef.class_byte_count = bCount; - classDef.class_bytes = (unsigned char*) classBytes; - - display(0, "#### JVMTIagent: >>>>>>>> Invoke RedefineClasses():\n\ -\tnew class byte count=%d\n", - classDef.class_byte_count); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, - jvmti, 1, &classDef))) - return 1; - - display(0, "#### JVMTIagent: <<<<<<<< RedefineClasses() is successfully done ####\n"); - - return 0; -} - -static int addStressEvents() { - static int stepEventSet = JNI_FALSE; - static int methodsEventSet = JNI_FALSE; - static int excCatchEventSet = JNI_FALSE; - - if (stress_lev >= 3) { - /* SingleStep events */ - if (stepEventSet == JNI_FALSE) { /* don't set the event twice */ - display(0, "#### JVMTIagent: setting SingleStep events ...\n"); - - callbacks.SingleStep = &SingleStep; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL))) - return JNI_ERR; - - stepEventSet = JNI_TRUE; - - display(0, "#### JVMTIagent: ... setting SingleStep events done\n"); - } - } - - if (stress_lev >= 2) { - /* MethodEntry/Exit events */ - if (methodsEventSet == JNI_FALSE) { /* don't set the event twice */ - display(0, "#### JVMTIagent: setting MethodEntry events ...\n"); - - callbacks.MethodEntry = &MethodEntry; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, NULL))) - return JNI_ERR; - - display(0, "#### JVMTIagent: ... setting MethodEntry events done\n"); - - /* MethodExit events */ - display(0, "#### JVMTIagent: setting MethodExit events ...\n"); - - callbacks.MethodExit = &MethodExit; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_METHOD_EXIT, NULL))) - return JNI_ERR; - - display(0, "#### JVMTIagent: ... setting MethodExit events done\n"); - - methodsEventSet = JNI_TRUE; - } - } - - if (stress_lev >= 1) { - /* ExceptionCatch events */ - if (excCatchEventSet == JNI_FALSE) { /* don't set the event twice */ - display(0, "#### JVMTIagent: setting ExceptionCatch events ...\n"); - - callbacks.ExceptionCatch = &ExceptionCatch; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_EXCEPTION_CATCH, NULL))) - return JNI_ERR; - - excCatchEventSet = JNI_TRUE; - - display(0, "#### JVMTIagent: ... setting ExceptionCatch events done\n"); - } - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &callbacks, sizeof(callbacks)))) - return JNI_ERR; - else - return 0; -} - -static int enableEventsCaps() { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(jvmtiCapabilities)); - - /* add all capabilities */ - caps.can_redefine_classes = 1; - caps.can_generate_breakpoint_events = 1; - caps.can_generate_all_class_hook_events = 1; - caps.can_generate_single_step_events = 1; - caps.can_generate_method_entry_events = 1; - caps.can_generate_method_exit_events = 1; - caps.can_generate_exception_events = 1; - caps.can_generate_compiled_method_load_events = 1; - caps.can_generate_field_access_events = 1; - caps.can_generate_field_modification_events = 1; - caps.can_generate_frame_pop_events = 1; - caps.can_generate_garbage_collection_events = 1; - caps.can_generate_monitor_events = 1; - caps.can_generate_native_method_bind_events = 1; - caps.can_generate_object_free_events = 1; - caps.can_generate_vm_object_alloc_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, - jvmti, &caps))) - return JNI_ERR; - - /* Breakpoint events */ - display(0, "#### JVMTIagent: setting Breakpoint events ...\n"); - - callbacks.Breakpoint = &Breakpoint; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_BREAKPOINT, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting Breakpoint events done\n"); - - /* ClassFileLoadHook events */ - display(0, "#### JVMTIagent: setting ClassFileLoadHook events ...\n"); - - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting ClassFileLoadHook events done\n"); - - /* ClassLoad events */ - display(0, "#### JVMTIagent: setting ClassLoad events ...\n"); - - callbacks.ClassLoad = &ClassLoad; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting ClassLoad events done\n"); - - /* ClassPrepare events */ - display(0, "#### JVMTIagent: setting ClassPrepare events ...\n"); - - callbacks.ClassPrepare = &ClassPrepare; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting ClassPrepare events done\n"); - - /* CompiledMethodLoad events */ - display(0, "#### JVMTIagent: setting CompiledMethodLoad events ...\n"); - - callbacks.CompiledMethodLoad = &CompiledMethodLoad; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting CompiledMethodLoad events done\n"); - - /* CompiledMethodUnload events */ - display(0, "#### JVMTIagent: setting CompiledMethodUnload events ...\n"); - - callbacks.CompiledMethodUnload = &CompiledMethodUnload; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_UNLOAD, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting CompiledMethodUnload events done\n"); - - /* DataDumpRequest events */ - display(0, "#### JVMTIagent: setting DataDumpRequest events ...\n"); - - callbacks.DataDumpRequest = &DataDumpRequest; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_DATA_DUMP_REQUEST, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting DataDumpRequest events done\n"); - - /* DynamicCodeGenerated events */ - display(0, "#### JVMTIagent: setting DynamicCodeGenerated events ...\n"); - - callbacks.DynamicCodeGenerated = &DynamicCodeGenerated; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_DYNAMIC_CODE_GENERATED, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting DynamicCodeGenerated events done\n"); - - /* Exception events */ - display(0, "#### JVMTIagent: setting Exception events ...\n"); - - callbacks.Exception = &Exception; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_EXCEPTION, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting Exception events done\n"); - - /* FieldAccess events */ - display(0, "#### JVMTIagent: setting FieldAccess events ...\n"); - - callbacks.FieldAccess = &FieldAccess; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_FIELD_ACCESS, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting FieldAccess events done\n"); - - /* FieldModification events */ - display(0, "#### JVMTIagent: setting FieldModification events ...\n"); - - callbacks.FieldModification = &FieldModification; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_FIELD_MODIFICATION, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting FieldModification events done\n"); - - /* FramePop events */ - display(0, "#### JVMTIagent: setting FramePop events ...\n"); - - callbacks.FramePop = &FramePop; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_FRAME_POP, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting FramePop events done\n"); - - /* GarbageCollectionFinish events */ - display(0, "#### JVMTIagent: setting GarbageCollectionFinish events ...\n"); - - callbacks.GarbageCollectionFinish = &GarbageCollectionFinish; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting GarbageCollectionFinish events done\n"); - - /* GarbageCollectionStart events */ - display(0, "#### JVMTIagent: setting GarbageCollectionStart events ...\n"); - - callbacks.GarbageCollectionStart = &GarbageCollectionStart; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_START, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting GarbageCollectionStart events done\n"); - - /* MonitorContendedEnter events */ - display(0, "#### JVMTIagent: setting MonitorContendedEnter events ...\n"); - - callbacks.MonitorContendedEnter = &MonitorContendedEnter; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTER, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting MonitorContendedEnter events done\n"); - - /* MonitorContendedEntered events */ - display(0, "#### JVMTIagent: setting MonitorContendedEntered events ...\n"); - - callbacks.MonitorContendedEntered = &MonitorContendedEntered; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting MonitorContendedEntered events done\n"); - - /* MonitorWait events */ - display(0, "#### JVMTIagent: setting MonitorWait events ...\n"); - - callbacks.MonitorWait = &MonitorWait; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_WAIT, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting MonitorWait events done\n"); - - /* MonitorWaited events */ - display(0, "#### JVMTIagent: setting MonitorWaited events ...\n"); - - callbacks.MonitorWaited = &MonitorWaited; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_WAITED, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting MonitorWaited events done\n"); - - /* NativeMethodBind events */ - display(0, "#### JVMTIagent: setting NativeMethodBind events ...\n"); - - callbacks.NativeMethodBind = &NativeMethodBind; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_NATIVE_METHOD_BIND, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting NativeMethodBind events done\n"); - - /* ObjectFree events */ - display(0, "#### JVMTIagent: setting ObjectFree events ...\n"); - - callbacks.ObjectFree = &ObjectFree; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting ObjectFree events done\n"); - - /* ThreadEnd events */ - display(0, "#### JVMTIagent: setting ThreadEnd events ...\n"); - - callbacks.ThreadEnd = &ThreadEnd; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_THREAD_END, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting ThreadEnd events done\n"); - - /* ThreadStart events */ - display(0, "#### JVMTIagent: setting ThreadStart events ...\n"); - - callbacks.ThreadStart = &ThreadStart; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting ThreadStart events done\n"); - - /* VMDeath events */ - display(0, "#### JVMTIagent: setting VMDeath events ...\n"); - - callbacks.VMDeath = &VMDeath; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting VMDeath events done\n"); - - /* VMInit events */ - display(0, "#### JVMTIagent: setting VMInit events ...\n"); - - callbacks.VMInit = &VMInit; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting VMInit events done\n"); - - /* VMStart events */ - display(0, "#### JVMTIagent: setting VMStart events ...\n"); - - callbacks.VMStart = &VMStart; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_START, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting VMStart events done\n"); - - /* VMObjectAlloc events */ - display(0, "#### JVMTIagent: setting VMObjectAlloc events ...\n"); - - callbacks.VMObjectAlloc = &VMObjectAlloc; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_OBJECT_ALLOC, NULL))) - return JNI_ERR; - display(0, "#### JVMTIagent: ... setting VMObjectAlloc events done\n"); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - return 0; -} - -static void clearJavaException(JNIEnv* jni_env) { - if (NSK_CPP_STUB1(ExceptionOccurred, jni_env)) { - - NSK_CPP_STUB1(ExceptionDescribe, jni_env); - NSK_CPP_STUB1(ExceptionClear, jni_env); - - NSK_CPP_STUB2(FatalError, jni_env, - "JVMTIagent: exception occurred in java code, aborting\n"); - } -} - -static int get_tok(char **src, char *buf, int buflen, char sep) { - int i; - char *p = *src; - for (i = 0; i < buflen; i++) { - if (p[i] == 0 || p[i] == sep) { - buf[i] = 0; - if (p[i] == sep) { - i++; - } - *src += i; - return i; - } - buf[i] = p[i]; - } - /* overflow */ - return 0; -} - -static void doSetup(char *str) { - if (str == 0) - str = ""; - - if ((strcmp(str, "help")) == 0) { - printf("#### JVMTIagent usage: -agentlib:JVMTIagent[=[help]|[=[verbose]|[verbose2],[stress0|stress1|stress2|stress3]]]\n"); - printf("#### where: help\tprint this message\n"); - printf("#### verbose\tturn verbose mode on\n"); - printf("#### verbose2\tturn extended verbose mode on (including reporting JVMTI events)\n"); - printf("#### stress0, or empty value\tturn stress level 0 on (default mode):\n"); - printf("#### enable event generation except ExceptionCatch, MethodEntry/Exit, SingleStep\n"); - printf("#### stress1\tturn stress level 1 on:\n"); - printf("#### enable generation of ExceptionCatch events\n"); - printf("#### stress2\tturn stress level 2 on:\n"); - printf("#### enable generation of ExceptionCatch,\n"); - printf("#### MethodEntry/Exit events\n"); - printf("#### stress3\tturn stress level 3 on:\n"); - printf("#### enable generation of ExceptionCatch,\n"); - printf("#### MethodEntry/Exit,\n"); - printf("#### SingleStep events\n"); - exit(1); - } - - while (*str) { - char buf[1000]; - - if (!get_tok(&str, buf, sizeof(buf), ',')) { - printf("ERROR: JVMTIagent: bad option: \"%s\"!\n", str); - exit(1); - } - if ((strcmp(buf, "verbose")) == 0) { - printf("#### JVMTIagent: turned verbose mode on ####\n"); - debug_mode = 1; - } - if ((strcmp(buf, "verbose2")) == 0) { - printf("#### JVMTIagent: turned extended verbose mode on ####\n"); - debug_mode = 2; - } - if ((strcmp(buf, "stress0")) == 0) { - if (debug_mode > 0) - printf("#### JVMTIagent: turned stress level 0 on ####\n"); - stress_lev = 0; - } - if ((strcmp(buf, "stress1")) == 0) { - if (debug_mode > 0) - printf("#### JVMTIagent: turned stress level 1 on ####\n"); - stress_lev = 1; - } - if ((strcmp(buf, "stress2")) == 0) { - if (debug_mode > 0) - printf("#### JVMTIagent: turned stress level 2 on ####\n"); - stress_lev = 2; - } - if ((strcmp(buf, "stress3")) == 0) { - if (debug_mode > 0) - printf("#### JVMTIagent: turned stress level 3 on ####\n"); - stress_lev = 3; - } - } -} - -static void getVerdict(JNIEnv *jni_env, const char *evnt) { - char error_msg[80]; - - if (vm_death_occured == TRUE) { - sprintf(error_msg, "JVMTIagent: getVerdict: %s event occured after VMDeath", - evnt); - - if (jni_env==NULL) { /* some event callbacks have no pointer to jni */ - printf("ERROR: %s\n", error_msg); - exit(97); - } - else - NSK_CPP_STUB2(FatalError, jni_env, error_msg); - } -} - -static void display(int level, const char format[], ...) { - va_list ar; - - if (debug_mode > level) { - va_start(ar, format); - vprintf(format, ar); - va_end(ar); - } -} - -/* agent procedure */ -static void JNICALL -agentProc(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg) { -} - -JNIEXPORT jint JNICALL -Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) { - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - doSetup(options); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, - jvmti, "_event_lock", &eventLock))) - return JNI_ERR; - - if (enableEventsCaps() == 0 && addStressEvents() == 0) { - display(0, "#### JVMTIagent: all events were successfully enabled and capabilities/events callbacks set ####\n\n"); - } else { - printf("ERROR(%s,%d): JVMTIagent terminated abnormally! ####\n", - __FILE__,__LINE__); - return JNI_ERR; - } - - /* register agent proc and arg */ - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/JVMTIagent.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/JVMTIagent.cpp new file mode 100644 index 00000000000..7469606e872 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/JVMTIagent.cpp @@ -0,0 +1,1276 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * + * JVMTI agent used for run every test from the testbase in a special + * debug mode. This mode is intended to be part of serviceability + * reliability testing. + */ + +#include +#include +#include +#include +#include + +#include "nsk_tools.h" +#include "jni_tools.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jvmtiEnv *jvmti = NULL; /* JVMTI env */ +static jvmtiEventCallbacks callbacks; +static jrawMonitorID eventLock; /* raw monitor used for exclusive ownership of HotSwap function */ + +static volatile int debug_mode = 0; /* 0 - verbose mode off; + 1 - verbose mode on; + 2 - verbose mode on including all JVMTI events reporting, + produces a huge number of messages */ + +/* stress level */ +static volatile int stress_lev = 0; /* 0 - default mode: generation of all events except + ExceptionCatch, + MethodEntry/Exit, SingleStep; + 1 - generation of all events except + MethodEntry/Exit, + SingleStep; + 2 - generation of all events except + SingleStep; + 3 - generation of all events, including + ExceptionCatch, + MethodEntry/Exit, + SingleStep + */ + +#define TRUE 1 +#define FALSE 0 + +/**** the following is used for "postVM_DEATH" events watching ****/ +static volatile int vm_death_occured = FALSE; +/************************************************/ + +/**** the following is used for HotSwap mode ****/ + +/* HotSwap modes: + HOTSWAP_OFF - default mode: HotSwap off; + HOTSWAP_EVERY_METHOD_ENTRY - HotSwap tested class in every method entry event + of running test + HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS - HotSwap tested class in every + method entry event of every class + HOTSWAP_EVERY_SINGLE_STEP - HotSwap tested class in every single step event + of running test + HOTSWAP_EVERY_EXCEPTION - HotSwap tested class in every exception event + of running test + HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS - HotSwap tested class in every + exception event of every class + */ + +#define HOTSWAP_OFF 0 +#define HOTSWAP_EVERY_METHOD_ENTRY 2 +#define HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS 20 +#define HOTSWAP_EVERY_SINGLE_STEP 3 +#define HOTSWAP_EVERY_EXCEPTION 4 +#define HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS 40 + +static int hotswap = HOTSWAP_OFF; + +typedef struct { /* test class info */ + char *clazzsig; /* class signature */ + jclass cls; /* a class to be redefined */ + jint bCount; /* number of bytes defining the class */ + jbyte *clsBytes; /* bytes defining the class */ + struct class_info *next; +} class_info; + + +static const char *shortTestName = NULL; /* name of the test without package prefix */ +static jclass rasCls; /* reference to the auxiliary class RASagent used for HotSwap */ +static class_info *clsInfo = NULL, *clsInfoFst = NULL; + +static void lock(JNIEnv*); +static void unlock(JNIEnv*); +static jint allocClsInfo(JNIEnv*, char*, jclass); +static void deallocClsInfo(JNIEnv*); +static int findAndHotSwap(JNIEnv*, jclass); +static int doHotSwap(JNIEnv*, jclass, jint, jbyte*); +static void display(int, const char format[], ...); +static void clearJavaException(JNIEnv*); +static int enableEventsCaps(); +static int addStressEvents(); +static void getVerdict(JNIEnv*, const char *); +/************************************************/ + +/** callback functions **/ +void JNICALL +Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thr, jmethodID method, + jlocation loc) { + + display(1, "#### JVMTIagent: Breakpoint occurred ####\n"); + + getVerdict(jni_env, "Breakpoint"); +} + +void JNICALL +ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jclass class_beeing_redefined, + jobject loader, const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + + display(1, "#### JVMTIagent: ClassFileLoadHook occurred ####\n"); + + getVerdict(jni_env, "ClassFileLoadHook"); +} + +void JNICALL +ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread, jclass klass) { + char *cls_sig; + jint clsByteCount; + + display((hotswap != HOTSWAP_OFF)?0:1, + "#### JVMTIagent: ClassLoad occurred ####\n"); + + getVerdict(jni_env, "ClassLoad"); + + if (hotswap != HOTSWAP_OFF) { + /* enter into a raw monitor for exclusive work with redefined class */ + lock(jni_env); + display(0, "#### JVMTIagent: ClassLoad: >>>>>>>> entered the raw monitor \"eventLock\" ####\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, + jvmti_env, klass, &cls_sig, /*&generic*/NULL))) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to get class signature\n"); + else { + if (shortTestName != NULL) { + if (strstr((const char*) cls_sig, shortTestName) != NULL) { + display(0, "#### JVMTIagent: found test class matched with \"%s\"\n\ +\tsignature=%s\n", + shortTestName, cls_sig); + clsByteCount = allocClsInfo(jni_env, cls_sig, klass); + display(0, "#### JVMTIagent: %d bytes defining the class have been successfully loaded\n", + clsByteCount); + } + } + } + + /* exit from the raw monitor */ + unlock(jni_env); + display(0, "#### JVMTIagent: ClassLoad: <<<<<<<< exited from the raw monitor \"eventLock\" ####\n\n"); + } +} + +void JNICALL +ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jthread thr, jclass cls) { + + display(1, "#### JVMTIagent: ClassPrepare occurred ####\n"); + + getVerdict(jni_env, "ClassPrepare"); +} + +void JNICALL +CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, + const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + + display(1, "#### JVMTIagent: CompiledMethodLoad occurred ####\n"); + + getVerdict(NULL, "CompiledMethodLoad"); +} + +void JNICALL +CompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, + const void* code_addr) { + + display(1, "#### JVMTIagent: CompiledMethodUnload occurred ####\n"); + + getVerdict(NULL, "CompiledMethodUnload"); +} + +void JNICALL +DataDumpRequest(jvmtiEnv *jvmti_env) { + + display(1, "#### JVMTIagent: DataDumpRequest occurred ####\n"); + + getVerdict(NULL, "DataDumpRequest"); +} + +void JNICALL +DynamicCodeGenerated(jvmtiEnv *jvmti_env, + const char* name, + const void* address, + jint length) { + + display(1, "#### JVMTIagent: DynamicCodeGenerated occurred ####\n"); + + getVerdict(NULL, "DynamicCodeGenerated"); +} + +void JNICALL +Exception(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thr, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + jclass decl_clazz; + + display((hotswap == HOTSWAP_EVERY_EXCEPTION || + hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS)?0:1, + "#### JVMTIagent: Exception occurred ####\n"); + + getVerdict(jni_env, "Exception"); + + if (hotswap == HOTSWAP_EVERY_EXCEPTION || + hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, method, &decl_clazz))) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to get method declaring class\n"); + + if (findAndHotSwap(jni_env, decl_clazz) != 0) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to hotswap class\n"); + } +} + +void JNICALL +FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jthread thr, jmethodID method, + jlocation location, jclass field_klass, jobject obj, jfieldID field) { + + display(1, "#### JVMTIagent: FieldAccess occurred ####\n"); + + getVerdict(jni_env, "FieldAccess"); +} + +void JNICALL +FieldModification(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jthread thr, jmethodID method, jlocation location, + jclass field_klass, jobject obj, + jfieldID field, char sig, jvalue new_value) { + + display(1, "#### JVMTIagent: FieldModification occurred ####\n"); + + getVerdict(jni_env, "FieldModification"); +} + +void JNICALL +FramePop(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jthread thr, jmethodID method, jboolean wasPopedByException) { + + display(1, "#### JVMTIagent: FramePop occurred ####\n"); + + getVerdict(jni_env, "FramePop"); +} + +void JNICALL +GarbageCollectionFinish(jvmtiEnv *jvmti_env) { + + display(1, "#### JVMTIagent: GarbageCollectionFinish occurred ####\n"); + + getVerdict(NULL, "GarbageCollectionFinish"); +} + +void JNICALL +GarbageCollectionStart(jvmtiEnv *jvmti_env) { + + display(1, "#### JVMTIagent: GarbageCollectionStart occurred ####\n"); + + getVerdict(NULL, "GarbageCollectionStart"); +} + +void JNICALL +MonitorContendedEnter(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thr, + jobject obj) { + + display(1, "#### JVMTIagent: MonitorContendedEnter occurred ####\n"); + + getVerdict(jni_env, "MonitorContendedEnter"); +} + +void JNICALL +MonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thr, + jobject obj) { + + display(1, "#### JVMTIagent: MonitorContendedEntered occurred ####\n"); + + getVerdict(jni_env, "MonitorContendedEntered"); +} + +void JNICALL +MonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thr, jobject obj, + jlong tout) { + + display(1, "#### JVMTIagent: MonitorWait occurred ####\n"); + + getVerdict(jni_env, "MonitorWait"); +} + +void JNICALL +MonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, + jthread thr, jobject obj, jboolean timed_out) { + + display(1, "#### JVMTIagent: MonitorWaited occurred ####\n"); + + getVerdict(jni_env, "MonitorWaited"); +} + +void JNICALL +NativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, void *addr, void **new_addr) { + + display(1, "#### JVMTIagent: NativeMethodBind occurred ####\n"); + + getVerdict(jni_env, "NativeMethodBind"); +} + +void JNICALL +ObjectFree(jvmtiEnv *jvmti_env, jlong tag) { + + display(1, "#### JVMTIagent: ObjectFree occurred ####\n"); + + getVerdict(NULL, "ObjectFree"); +} + +void JNICALL +ThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread) { + + display(1, "#### JVMTIagent: ThreadEnd occurred ####\n"); + + getVerdict(jni_env, "ThreadEnd"); +} + +void JNICALL +ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread) { + + display(1, "#### JVMTIagent: ThreadStart occurred ####\n"); + + getVerdict(jni_env, "ThreadStart"); +} + +void JNICALL +VMDeath(jvmtiEnv *jvmti_env, JNIEnv *jni_env) { + vm_death_occured = TRUE; + + display(0, "#### JVMTIagent: VMDeath occurred ####\n"); + + if (hotswap != HOTSWAP_OFF) { + deallocClsInfo(jni_env); + display(0, "#### JVMTIagent: allocated memory was successfully freed ####\n"); + } +} + +void JNICALL +VMInit(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thr) { + + display(0, "#### JVMTIagent: VMInit occurred ####\n"); + + getVerdict(jni_env, "VMInit"); +} + +void JNICALL +VMStart(jvmtiEnv *jvmti_env, JNIEnv* jni_env) { + + display(0, "#### JVMTIagent: VMStart occurred ####\n"); + + getVerdict(jni_env, "VMStart"); +} + +JNIEXPORT void JNICALL +VMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jobject object, jclass object_klass, jlong size) { + + display(1, "#### JVMTIagent: VMObjectAlloc occurred ####\n"); + + getVerdict(jni_env, "VMObjectAlloc"); +} + +void JNICALL +SingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + jclass decl_clazz; + + display((hotswap == HOTSWAP_EVERY_SINGLE_STEP)?0:1, + "#### JVMTIagent: SingleStep occurred ####\n"); + + getVerdict(jni_env, "SingleStep"); + + if (hotswap == HOTSWAP_EVERY_SINGLE_STEP) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, method, &decl_clazz))) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to get method declaring class\n"); + + if (findAndHotSwap(jni_env, decl_clazz) != 0) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to hotswap class\n"); + } +} + +void JNICALL +MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jthread thr, jmethodID method) { + jclass decl_clazz; + + display((hotswap == HOTSWAP_EVERY_METHOD_ENTRY || + hotswap == HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS)?0:1, + "#### JVMTIagent: MethodEntry occurred ####\n"); + + getVerdict(jni_env, "MethodEntry"); + + if (hotswap == HOTSWAP_EVERY_METHOD_ENTRY || + hotswap == HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, method, &decl_clazz))) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to get method declaring class\n"); + + if (findAndHotSwap(jni_env, decl_clazz) != 0) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to hotswap class\n"); + } +} + +void JNICALL +MethodExit(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jthread thr, jmethodID method, + jboolean was_poped_by_exc, jvalue return_value) { + + display(1, "#### JVMTIagent: MethodExit occurred ####\n"); + + getVerdict(jni_env, "MethodExit"); +} + +void JNICALL +ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thr, + jmethodID method, jlocation location, jobject exception) { + jclass decl_clazz; + + display((hotswap == HOTSWAP_EVERY_EXCEPTION || + hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS)?0:1, + "#### JVMTIagent: ExceptionCatch occurred ####\n"); + + getVerdict(jni_env, "ExceptionCatch"); + + if (hotswap == HOTSWAP_EVERY_EXCEPTION || + hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, + jvmti_env, method, &decl_clazz))) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to get method declaring class\n"); + + if (findAndHotSwap(jni_env, decl_clazz) != 0) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to hotswap class\n"); + } +} +/************************/ + +static void lock(JNIEnv *jni_env) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, + jvmti, eventLock))) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to enter a raw monitor\n"); +} + +static void unlock(JNIEnv *jni_env) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, + jvmti, eventLock))) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to exit a raw monitor\n"); +} + +JNIEXPORT jint JNICALL +Java_nsk_share_RASagent_setHotSwapMode(JNIEnv *jni_env, jclass cls, + jboolean vrb, jint level, jstring shortName) { + jvmtiCapabilities capabil; + jmethodID mid = NULL; + + if (jvmti == NULL) { + printf("ERROR(%s,%d): JVMTIagent was not properly loaded: JVMTI env = NULL\n", + __FILE__, __LINE__); + return 1; + } + + /* get supported JVMTI capabilities */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, + jvmti, &capabil))) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to get capabilities\n"); + if (capabil.can_redefine_classes != 1) { /* ???????????? */ + printf("ERROR: JVMTIagent: Class File Redefinition (HotSwap) is not implemented in this VM\n"); + return 1; + } + + if (vrb == JNI_TRUE && debug_mode == 0) + debug_mode = 1; + + hotswap = level; + switch (hotswap) { + case HOTSWAP_OFF: + display(0, "#### JVMTIagent: hotswap mode off ####\n"); + return 0; + case HOTSWAP_EVERY_METHOD_ENTRY: + stress_lev = 2; + display(0, "#### JVMTIagent: hotswapping class in every method entry event enabled ####\n\ +\tHotSwap stress level: %d\n", + stress_lev); + break; + case HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS: + stress_lev = 2; + display(0, "#### JVMTIagent: hotswapping class in every method entry event for every class enabled ####\n\ +\tHotSwap stress level: %d\n", + stress_lev); + break; + case HOTSWAP_EVERY_SINGLE_STEP: + stress_lev = 3; + display(0, "#### JVMTIagent: hotswapping class in every single step event enabled ####\n\ +\tHotSwap stress level: %d\n", + stress_lev); + break; + case HOTSWAP_EVERY_EXCEPTION: + stress_lev = 4; + display(0, "#### JVMTIagent: hotswapping class in every exception event enabled ####\n\ +\tHotSwap stress level: %d\n", + stress_lev); + break; + case HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS: + stress_lev = 40; + display(0, "#### JVMTIagent: hotswapping class in every exception event for every class enabled ####\n\ +\tHotSwap stress level: %d\n", + stress_lev); + break; + default: + printf("ERROR(%s,%d): JVMTIagent: unknown value of HotSwap stress level: \"%d\"\n", + __FILE__,__LINE__,hotswap); + return 1; + } + + if (!NSK_JNI_VERIFY(jni_env, (shortTestName = NSK_CPP_STUB3(GetStringUTFChars, + jni_env, shortName, NULL)) != NULL)) { + printf("ERROR: JVMTIagent: unable to get UTF-8 characters of the string\n"); + return 1; + } + display(0, "#### JVMTIagent: short name of current test is \"%s\"\n", + shortTestName); + + if (!NSK_JNI_VERIFY(jni_env, (rasCls = NSK_CPP_STUB2(NewGlobalRef, + jni_env, cls)) != NULL)) { + printf("ERROR JVMTIagent: unable to create a new global reference of the class \"RASagent\"\n"); + return 1; + } + + if (addStressEvents() != 0) { + printf("ERROR(%s,%d): JVMTIagent terminated abnormally! ####\n", + __FILE__,__LINE__); + return 1; + } + + return 0; +} + +static jint allocClsInfo(JNIEnv *jni_env, char *cls_sig, jclass clazz) { + class_info *_clsInfo = NULL; + jmethodID mid = NULL; + jbyteArray classBytes; + jboolean isCopy; + + if ((_clsInfo = (class_info*) + malloc(sizeof(class_info))) == NULL) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: cannot allocate memory for class_info\n"); + + /* fill the structure class_info */ + _clsInfo->clazzsig = cls_sig; + + if (!NSK_JNI_VERIFY(jni_env, ((*_clsInfo).cls = NSK_CPP_STUB2(NewGlobalRef, + jni_env, clazz)) != NULL)) { + printf("ERROR: JVMTIagent: unable to create a new global reference of class \"%s\"\n", + _clsInfo->clazzsig); + free(_clsInfo); + deallocClsInfo(jni_env); + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: unable to create a new global reference of class\n"); + } + + if (!NSK_JNI_VERIFY(jni_env, (mid = + NSK_CPP_STUB4(GetStaticMethodID, jni_env, rasCls, + "loadFromClassFile", "(Ljava/lang/String;)[B")) != NULL)) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: unable to get ID of the method \"loadFromClassFile\"\n"); + + classBytes = (jbyteArray) NSK_CPP_STUB4(CallStaticObjectMethod, + jni_env, rasCls, mid, NSK_CPP_STUB2(NewStringUTF, jni_env, cls_sig)); + + clearJavaException(jni_env); + + (*_clsInfo).bCount = NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes); + + (*_clsInfo).clsBytes = + NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, &isCopy); + + _clsInfo->next = NULL; + + if (clsInfo != NULL) { + clsInfo->next = (struct class_info*) _clsInfo; + } + else { + clsInfoFst = _clsInfo; + } + clsInfo = _clsInfo; + + return (*_clsInfo).bCount; +} + +static void deallocClsInfo(JNIEnv *jni_env) { + class_info *clsInfoCurr = clsInfoFst; + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni_env, rasCls)); + + while(clsInfoCurr != NULL) { + class_info *_clsInfo = clsInfoCurr; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti, (unsigned char*) clsInfoCurr->clazzsig))) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: failed to deallocate memory for clazzsig\n"); + + NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni_env, clsInfoCurr->cls)); + + clsInfoCurr = (class_info*) clsInfoCurr->next; + + free(_clsInfo); + } + /* fix for 4756585: indicate that stucture class_info is empty now */ + clsInfoFst = NULL; +} + +static int findAndHotSwap(JNIEnv *jni_env, jclass clazz) { + int ret_code = 0; + char *clazzsig = NULL; + class_info *clsInfoCurr = clsInfoFst; + + display(1, "\n#### JVMTIagent: findAndHotSwap: obtaining class signature of class to be hotswap ...\n"); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, + jvmti, clazz, &clazzsig, /*&generic*/NULL))) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: findAndHotSwap: failed to get class signature\n"); + else { + display(1, "#### JVMTIagent: findAndHotSwap: ... class signature obtained: \"%s\"\n", + clazzsig); + + /* enter into a raw monitor for exclusive work with redefined class */ + lock(jni_env); + display(0, "#### JVMTIagent: findAndHotSwap: >>>>>>>> entered the raw monitor \"eventLock\" ####\n"); + + while(clsInfoCurr != NULL) { + if (hotswap == HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS || + hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS) { + display(1, "\n#### JVMTIagent: findAndHotSwap: going to hotswap tested class \"%s\" during execution of class \"%s\" ...\n", + clsInfoCurr->clazzsig, clazzsig); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti, (unsigned char*) clazzsig))) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: findAndHotSwap: failed to deallocate memory for clazzsig\n"); + + if (doHotSwap(jni_env, clsInfoCurr->cls, + clsInfoCurr->bCount, clsInfoCurr->clsBytes) != 0) { + ret_code = 1; + break; + } + } + else { + if (strcmp(clazzsig, clsInfoCurr->clazzsig) == 0) { + display(0, "\n#### JVMTIagent: findAndHotSwap: tested class found \"%s\" ...\n", + clazzsig); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, + jvmti, (unsigned char*) clazzsig))) + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: findAndHotSwap: failed to deallocate memory for clazzsig\n"); + + display(0, "\n#### JVMTIagent: findAndHotSwap: going to hotswap tested class \"%s\" ...\n", + clsInfoCurr->clazzsig); + if (doHotSwap(jni_env, clsInfoCurr->cls, + clsInfoCurr->bCount, clsInfoCurr->clsBytes) != 0) { + ret_code = 1; + break; + } + } + } + + clsInfoCurr = (class_info*) clsInfoCurr->next; + } + + /* exit raw monitor */ + unlock(jni_env); + display(0, "#### JVMTIagent: findAndHotSwap: <<<<<<<< exited from the raw monitor \"eventLock\" ####\n\n"); + } + + return ret_code; +} + +static int doHotSwap(JNIEnv *jni_env, jclass redefCls, jint bCount, + jbyte *classBytes) { + jvmtiClassDefinition classDef; + + /* fill the structure jvmtiClassDefinition */ + classDef.klass = redefCls; + classDef.class_byte_count = bCount; + classDef.class_bytes = (unsigned char*) classBytes; + + display(0, "#### JVMTIagent: >>>>>>>> Invoke RedefineClasses():\n\ +\tnew class byte count=%d\n", + classDef.class_byte_count); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, + jvmti, 1, &classDef))) + return 1; + + display(0, "#### JVMTIagent: <<<<<<<< RedefineClasses() is successfully done ####\n"); + + return 0; +} + +static int addStressEvents() { + static int stepEventSet = JNI_FALSE; + static int methodsEventSet = JNI_FALSE; + static int excCatchEventSet = JNI_FALSE; + + if (stress_lev >= 3) { + /* SingleStep events */ + if (stepEventSet == JNI_FALSE) { /* don't set the event twice */ + display(0, "#### JVMTIagent: setting SingleStep events ...\n"); + + callbacks.SingleStep = &SingleStep; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL))) + return JNI_ERR; + + stepEventSet = JNI_TRUE; + + display(0, "#### JVMTIagent: ... setting SingleStep events done\n"); + } + } + + if (stress_lev >= 2) { + /* MethodEntry/Exit events */ + if (methodsEventSet == JNI_FALSE) { /* don't set the event twice */ + display(0, "#### JVMTIagent: setting MethodEntry events ...\n"); + + callbacks.MethodEntry = &MethodEntry; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, NULL))) + return JNI_ERR; + + display(0, "#### JVMTIagent: ... setting MethodEntry events done\n"); + + /* MethodExit events */ + display(0, "#### JVMTIagent: setting MethodExit events ...\n"); + + callbacks.MethodExit = &MethodExit; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_METHOD_EXIT, NULL))) + return JNI_ERR; + + display(0, "#### JVMTIagent: ... setting MethodExit events done\n"); + + methodsEventSet = JNI_TRUE; + } + } + + if (stress_lev >= 1) { + /* ExceptionCatch events */ + if (excCatchEventSet == JNI_FALSE) { /* don't set the event twice */ + display(0, "#### JVMTIagent: setting ExceptionCatch events ...\n"); + + callbacks.ExceptionCatch = &ExceptionCatch; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_EXCEPTION_CATCH, NULL))) + return JNI_ERR; + + excCatchEventSet = JNI_TRUE; + + display(0, "#### JVMTIagent: ... setting ExceptionCatch events done\n"); + } + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &callbacks, sizeof(callbacks)))) + return JNI_ERR; + else + return 0; +} + +static int enableEventsCaps() { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(jvmtiCapabilities)); + + /* add all capabilities */ + caps.can_redefine_classes = 1; + caps.can_generate_breakpoint_events = 1; + caps.can_generate_all_class_hook_events = 1; + caps.can_generate_single_step_events = 1; + caps.can_generate_method_entry_events = 1; + caps.can_generate_method_exit_events = 1; + caps.can_generate_exception_events = 1; + caps.can_generate_compiled_method_load_events = 1; + caps.can_generate_field_access_events = 1; + caps.can_generate_field_modification_events = 1; + caps.can_generate_frame_pop_events = 1; + caps.can_generate_garbage_collection_events = 1; + caps.can_generate_monitor_events = 1; + caps.can_generate_native_method_bind_events = 1; + caps.can_generate_object_free_events = 1; + caps.can_generate_vm_object_alloc_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, + jvmti, &caps))) + return JNI_ERR; + + /* Breakpoint events */ + display(0, "#### JVMTIagent: setting Breakpoint events ...\n"); + + callbacks.Breakpoint = &Breakpoint; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_BREAKPOINT, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting Breakpoint events done\n"); + + /* ClassFileLoadHook events */ + display(0, "#### JVMTIagent: setting ClassFileLoadHook events ...\n"); + + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting ClassFileLoadHook events done\n"); + + /* ClassLoad events */ + display(0, "#### JVMTIagent: setting ClassLoad events ...\n"); + + callbacks.ClassLoad = &ClassLoad; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting ClassLoad events done\n"); + + /* ClassPrepare events */ + display(0, "#### JVMTIagent: setting ClassPrepare events ...\n"); + + callbacks.ClassPrepare = &ClassPrepare; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting ClassPrepare events done\n"); + + /* CompiledMethodLoad events */ + display(0, "#### JVMTIagent: setting CompiledMethodLoad events ...\n"); + + callbacks.CompiledMethodLoad = &CompiledMethodLoad; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting CompiledMethodLoad events done\n"); + + /* CompiledMethodUnload events */ + display(0, "#### JVMTIagent: setting CompiledMethodUnload events ...\n"); + + callbacks.CompiledMethodUnload = &CompiledMethodUnload; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_UNLOAD, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting CompiledMethodUnload events done\n"); + + /* DataDumpRequest events */ + display(0, "#### JVMTIagent: setting DataDumpRequest events ...\n"); + + callbacks.DataDumpRequest = &DataDumpRequest; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_DATA_DUMP_REQUEST, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting DataDumpRequest events done\n"); + + /* DynamicCodeGenerated events */ + display(0, "#### JVMTIagent: setting DynamicCodeGenerated events ...\n"); + + callbacks.DynamicCodeGenerated = &DynamicCodeGenerated; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_DYNAMIC_CODE_GENERATED, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting DynamicCodeGenerated events done\n"); + + /* Exception events */ + display(0, "#### JVMTIagent: setting Exception events ...\n"); + + callbacks.Exception = &Exception; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_EXCEPTION, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting Exception events done\n"); + + /* FieldAccess events */ + display(0, "#### JVMTIagent: setting FieldAccess events ...\n"); + + callbacks.FieldAccess = &FieldAccess; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_FIELD_ACCESS, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting FieldAccess events done\n"); + + /* FieldModification events */ + display(0, "#### JVMTIagent: setting FieldModification events ...\n"); + + callbacks.FieldModification = &FieldModification; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_FIELD_MODIFICATION, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting FieldModification events done\n"); + + /* FramePop events */ + display(0, "#### JVMTIagent: setting FramePop events ...\n"); + + callbacks.FramePop = &FramePop; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_FRAME_POP, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting FramePop events done\n"); + + /* GarbageCollectionFinish events */ + display(0, "#### JVMTIagent: setting GarbageCollectionFinish events ...\n"); + + callbacks.GarbageCollectionFinish = &GarbageCollectionFinish; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting GarbageCollectionFinish events done\n"); + + /* GarbageCollectionStart events */ + display(0, "#### JVMTIagent: setting GarbageCollectionStart events ...\n"); + + callbacks.GarbageCollectionStart = &GarbageCollectionStart; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_START, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting GarbageCollectionStart events done\n"); + + /* MonitorContendedEnter events */ + display(0, "#### JVMTIagent: setting MonitorContendedEnter events ...\n"); + + callbacks.MonitorContendedEnter = &MonitorContendedEnter; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTER, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting MonitorContendedEnter events done\n"); + + /* MonitorContendedEntered events */ + display(0, "#### JVMTIagent: setting MonitorContendedEntered events ...\n"); + + callbacks.MonitorContendedEntered = &MonitorContendedEntered; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting MonitorContendedEntered events done\n"); + + /* MonitorWait events */ + display(0, "#### JVMTIagent: setting MonitorWait events ...\n"); + + callbacks.MonitorWait = &MonitorWait; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_WAIT, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting MonitorWait events done\n"); + + /* MonitorWaited events */ + display(0, "#### JVMTIagent: setting MonitorWaited events ...\n"); + + callbacks.MonitorWaited = &MonitorWaited; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_WAITED, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting MonitorWaited events done\n"); + + /* NativeMethodBind events */ + display(0, "#### JVMTIagent: setting NativeMethodBind events ...\n"); + + callbacks.NativeMethodBind = &NativeMethodBind; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_NATIVE_METHOD_BIND, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting NativeMethodBind events done\n"); + + /* ObjectFree events */ + display(0, "#### JVMTIagent: setting ObjectFree events ...\n"); + + callbacks.ObjectFree = &ObjectFree; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting ObjectFree events done\n"); + + /* ThreadEnd events */ + display(0, "#### JVMTIagent: setting ThreadEnd events ...\n"); + + callbacks.ThreadEnd = &ThreadEnd; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_THREAD_END, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting ThreadEnd events done\n"); + + /* ThreadStart events */ + display(0, "#### JVMTIagent: setting ThreadStart events ...\n"); + + callbacks.ThreadStart = &ThreadStart; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting ThreadStart events done\n"); + + /* VMDeath events */ + display(0, "#### JVMTIagent: setting VMDeath events ...\n"); + + callbacks.VMDeath = &VMDeath; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting VMDeath events done\n"); + + /* VMInit events */ + display(0, "#### JVMTIagent: setting VMInit events ...\n"); + + callbacks.VMInit = &VMInit; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting VMInit events done\n"); + + /* VMStart events */ + display(0, "#### JVMTIagent: setting VMStart events ...\n"); + + callbacks.VMStart = &VMStart; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_START, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting VMStart events done\n"); + + /* VMObjectAlloc events */ + display(0, "#### JVMTIagent: setting VMObjectAlloc events ...\n"); + + callbacks.VMObjectAlloc = &VMObjectAlloc; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_OBJECT_ALLOC, NULL))) + return JNI_ERR; + display(0, "#### JVMTIagent: ... setting VMObjectAlloc events done\n"); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + return 0; +} + +static void clearJavaException(JNIEnv* jni_env) { + if (NSK_CPP_STUB1(ExceptionOccurred, jni_env)) { + + NSK_CPP_STUB1(ExceptionDescribe, jni_env); + NSK_CPP_STUB1(ExceptionClear, jni_env); + + NSK_CPP_STUB2(FatalError, jni_env, + "JVMTIagent: exception occurred in java code, aborting\n"); + } +} + +static int get_tok(char **src, char *buf, int buflen, char sep) { + int i; + char *p = *src; + for (i = 0; i < buflen; i++) { + if (p[i] == 0 || p[i] == sep) { + buf[i] = 0; + if (p[i] == sep) { + i++; + } + *src += i; + return i; + } + buf[i] = p[i]; + } + /* overflow */ + return 0; +} + +static void doSetup(char *str) { + if (str == 0) + str = (char*) ""; + + if ((strcmp(str, "help")) == 0) { + printf("#### JVMTIagent usage: -agentlib:JVMTIagent[=[help]|[=[verbose]|[verbose2],[stress0|stress1|stress2|stress3]]]\n"); + printf("#### where: help\tprint this message\n"); + printf("#### verbose\tturn verbose mode on\n"); + printf("#### verbose2\tturn extended verbose mode on (including reporting JVMTI events)\n"); + printf("#### stress0, or empty value\tturn stress level 0 on (default mode):\n"); + printf("#### enable event generation except ExceptionCatch, MethodEntry/Exit, SingleStep\n"); + printf("#### stress1\tturn stress level 1 on:\n"); + printf("#### enable generation of ExceptionCatch events\n"); + printf("#### stress2\tturn stress level 2 on:\n"); + printf("#### enable generation of ExceptionCatch,\n"); + printf("#### MethodEntry/Exit events\n"); + printf("#### stress3\tturn stress level 3 on:\n"); + printf("#### enable generation of ExceptionCatch,\n"); + printf("#### MethodEntry/Exit,\n"); + printf("#### SingleStep events\n"); + exit(1); + } + + while (*str) { + char buf[1000]; + + if (!get_tok(&str, buf, sizeof(buf), ',')) { + printf("ERROR: JVMTIagent: bad option: \"%s\"!\n", str); + exit(1); + } + if ((strcmp(buf, "verbose")) == 0) { + printf("#### JVMTIagent: turned verbose mode on ####\n"); + debug_mode = 1; + } + if ((strcmp(buf, "verbose2")) == 0) { + printf("#### JVMTIagent: turned extended verbose mode on ####\n"); + debug_mode = 2; + } + if ((strcmp(buf, "stress0")) == 0) { + if (debug_mode > 0) + printf("#### JVMTIagent: turned stress level 0 on ####\n"); + stress_lev = 0; + } + if ((strcmp(buf, "stress1")) == 0) { + if (debug_mode > 0) + printf("#### JVMTIagent: turned stress level 1 on ####\n"); + stress_lev = 1; + } + if ((strcmp(buf, "stress2")) == 0) { + if (debug_mode > 0) + printf("#### JVMTIagent: turned stress level 2 on ####\n"); + stress_lev = 2; + } + if ((strcmp(buf, "stress3")) == 0) { + if (debug_mode > 0) + printf("#### JVMTIagent: turned stress level 3 on ####\n"); + stress_lev = 3; + } + } +} + +static void getVerdict(JNIEnv *jni_env, const char *evnt) { + char error_msg[80]; + + if (vm_death_occured == TRUE) { + sprintf(error_msg, "JVMTIagent: getVerdict: %s event occured after VMDeath", + evnt); + + if (jni_env==NULL) { /* some event callbacks have no pointer to jni */ + printf("ERROR: %s\n", error_msg); + exit(97); + } + else + NSK_CPP_STUB2(FatalError, jni_env, error_msg); + } +} + +static void display(int level, const char format[], ...) { + va_list ar; + + if (debug_mode > level) { + va_start(ar, format); + vprintf(format, ar); + va_end(ar); + } +} + +/* agent procedure */ +static void JNICALL +agentProc(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg) { +} + +JNIEXPORT jint JNICALL +Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) { + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + doSetup(options); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, + jvmti, "_event_lock", &eventLock))) + return JNI_ERR; + + if (enableEventsCaps() == 0 && addStressEvents() == 0) { + display(0, "#### JVMTIagent: all events were successfully enabled and capabilities/events callbacks set ####\n\n"); + } else { + printf("ERROR(%s,%d): JVMTIagent terminated abnormally! ####\n", + __FILE__,__LINE__); + return JNI_ERR; + } + + /* register agent proc and arg */ + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/aod.c b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/aod.c deleted file mode 100644 index 6956ce55516..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/aod.c +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -static volatile int internalError = 0; - -/* - * This function can be used to inform AOD framework that some non critical for test logic - * error happened inside shared function (e.g. JVMTI Deallocate failed). - * - * If this function was called status of all finishing AOD agents is changed to failed. - */ - -void nsk_aod_internal_error() { - NSK_COMPLAIN0("WARNING: some error happened inside common function, see log for details\n"); - internalError = 1; -} - -void nsk_free_options(Options* options) { - if (options != NULL) { - int i; - for (i = 0; i < NSK_AOD_MAX_OPTIONS; i++) { - if (options->names[i] != NULL) { - free(options->names[i]); - } - if (options->values[i] != NULL) { - free(options->values[i]); - } - } - free(options); - } -} -/* - * Work with agent options - */ - -/* - * Parse options and create structure Options - */ -static Options* nsk_aod_createOptionsObject(char* optionsString) { - int i = 0; - Options* options; - char* name; - char* value; - char* sep; - - if (optionsString == NULL) { - NSK_COMPLAIN0("options were not passed to the native agent\n"); - return NULL; - } - options = (Options*) malloc(sizeof(Options)); - memset(options, 0, sizeof(Options)); - options->size = 0; - name = optionsString; - while (name != NULL && i < NSK_AOD_MAX_OPTIONS) { - sep = strchr(name, '='); - if (sep == NULL) { // name not found - NSK_COMPLAIN1("Invalid options format: '%s'\n", optionsString); - nsk_free_options(options); - return NULL; - } - *sep = '\0'; - options->names[i] = strdup(name); - value = sep + 1; - if (*value == '\0') { // value not found - NSK_COMPLAIN1("Option '%s' is empty\n", options->names[i]); - nsk_free_options(options); - return NULL; - } - sep = strchr(value, ' '); - if (sep != NULL) { - *sep = '\0'; - name = sep + 1; - } else { - name = strchr(value, '\0'); - } - options->values[i] = strdup(value); - i++; - - if (*name == '\0') { - name = NULL; - } - } - if (name != NULL) { - NSK_COMPLAIN1("WARNING: not all options were parsed, only %d options can be specified\n", - NSK_AOD_MAX_OPTIONS); - } - options->size = i; - return options; -} - -Options* nsk_aod_createOptions(char* optionsString) { - Options* options; - - if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptionsObject(optionsString)) != NULL)) - return NULL; - - if (!NSK_VERIFY(nsk_aod_optionSpecified(options, NSK_AOD_AGENT_NAME_OPTION))) { - NSK_COMPLAIN0("Agent name wasn't specified\n"); - return NULL; - } - - /* - * verbose mode is true by default - */ - nsk_setVerboseMode(NSK_TRUE); - - if (nsk_aod_optionSpecified(options, NSK_AOD_VERBOSE_OPTION)) { - if (strcmp(nsk_aod_getOptionValue(options, NSK_AOD_VERBOSE_OPTION), "false") == 0) - nsk_setVerboseMode(NSK_FALSE); - } - - return options; -} - -const char* nsk_aod_getOptionValue(Options* options, const char* option) { - int i; - - if (!NSK_VERIFY(options != NULL)) { - NSK_COMPLAIN0("Options NULL\n"); - return NULL; - } - - for(i = 0; i < options->size; i++) { - if (strcmp(option, options->names[i]) == 0) { - return options->values[i]; - } - } - - NSK_COMPLAIN1("Option '%s' isn't defined\n", option); - - return NULL; -} - -int nsk_aod_optionSpecified(Options* options, const char* option) { - int i; - - if (!NSK_VERIFY(options != NULL)) { - NSK_COMPLAIN0("Options NULL\n"); - return NSK_FALSE; - } - - for(i = 0; i < options->size; i++) { - if (strcmp(option, options->names[i]) == 0) { - return NSK_TRUE; - } - } - - return NSK_FALSE; -} - -/* - * Agent synchronization with target application - */ - -static const char* TARGET_APP_CLASS_NAME = "nsk/share/aod/TargetApplicationWaitingAgents"; - -static const char* AGENT_LOADED_METHOD_NAME = "agentLoaded"; -static const char* AGENT_LOADED_METHOD_SIGNATURE = "(Ljava/lang/String;)V"; - -static const char* AGENT_FINISHED_METHOD_NAME = "agentFinished"; -static const char* AGENT_FINISHED_METHOD_SIGNATURE = "(Ljava/lang/String;Z)V"; - -static jclass targetAppClass = NULL; -static jmethodID agentLoadedMethod = NULL; -static jmethodID agentFinishedMethod = NULL; - -// this function is used to notify target application that native agent has been loaded -int nsk_aod_agentLoaded(JNIEnv* jni, const char* agentName) { - jstring agentNameString; - - NSK_DISPLAY1("Agent %s is loaded\n", agentName); - - if (targetAppClass == NULL) { - /* - * FindClass returns local reference, to cache reference to target application class - * global reference should be created - */ - jclass localTargetAppClass; - if (!NSK_JNI_VERIFY(jni, (localTargetAppClass = - NSK_CPP_STUB2(FindClass, jni, TARGET_APP_CLASS_NAME)) != NULL)) { - return NSK_FALSE; - } - - if (!NSK_JNI_VERIFY(jni, (targetAppClass = - NSK_CPP_STUB2(NewGlobalRef, jni, localTargetAppClass)) != NULL)) { - return NSK_FALSE; - } - } - - if (agentLoadedMethod == NULL) { - if (!NSK_JNI_VERIFY(jni, (agentLoadedMethod = - NSK_CPP_STUB4(GetStaticMethodID, jni, targetAppClass, - AGENT_LOADED_METHOD_NAME, AGENT_LOADED_METHOD_SIGNATURE)) != NULL)) - return NSK_FALSE; - } - - if (!NSK_JNI_VERIFY(jni, (agentNameString = - NSK_CPP_STUB2(NewStringUTF, jni, agentName)) != NULL)) - return NSK_FALSE; - - NSK_CPP_STUB4(CallStaticVoidMethod, jni, targetAppClass, agentLoadedMethod, agentNameString); - - return NSK_TRUE; -} - -// this function is used to notify target application that native agent has been finished execution -int nsk_aod_agentFinished(JNIEnv* jni, const char* agentName, int success) { - jstring agentNameString; - - if (!targetAppClass) { - NSK_COMPLAIN1("%s: TEST LOGIC ERROR: method 'agentFinished' was called before "\ - "targetAppClass was initialized\n", agentName); - return NSK_FALSE; - } - - if (internalError && success) { - success = 0; - NSK_COMPLAIN1("Status of agent '%s' is 'passed', but some error happened during test execution "\ - "(see log for details), change agent status to 'failed'\n", - agentName); - } - - NSK_DISPLAY2("Agent %s finished (success: %d)\n", agentName, success); - - if (agentFinishedMethod == NULL) { - if (!NSK_JNI_VERIFY(jni, (agentFinishedMethod = - NSK_CPP_STUB4(GetStaticMethodID, jni, targetAppClass, - AGENT_FINISHED_METHOD_NAME, AGENT_FINISHED_METHOD_SIGNATURE)) != NULL)) - return NSK_FALSE; - } - - if (!NSK_JNI_VERIFY(jni, (agentNameString = NSK_CPP_STUB2(NewStringUTF, jni, agentName)) != NULL)) - return NSK_FALSE; - - NSK_CPP_STUB5(CallStaticVoidMethod, jni, targetAppClass, - agentFinishedMethod, agentNameString, success ? JNI_TRUE : JNI_FALSE); - - return NSK_TRUE; -} - -/* - * Auxiliary functions - */ - -// JNI env creation - -JNIEnv* nsk_aod_createJNIEnv(JavaVM* vm) { - JNIEnv* jni; - NSK_CPP_STUB3(GetEnv, vm, (void**)&jni, JNI_VERSION_1_2); - - NSK_VERIFY(jni != NULL); - - return jni; -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/aod.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/aod.cpp new file mode 100644 index 00000000000..71eb1159630 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/aod.cpp @@ -0,0 +1,288 @@ +/* + * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +static volatile int internalError = 0; + +/* + * This function can be used to inform AOD framework that some non critical for test logic + * error happened inside shared function (e.g. JVMTI Deallocate failed). + * + * If this function was called status of all finishing AOD agents is changed to failed. + */ + +void nsk_aod_internal_error() { + NSK_COMPLAIN0("WARNING: some error happened inside common function, see log for details\n"); + internalError = 1; +} + +void nsk_free_options(Options* options) { + if (options != NULL) { + int i; + for (i = 0; i < NSK_AOD_MAX_OPTIONS; i++) { + if (options->names[i] != NULL) { + free(options->names[i]); + } + if (options->values[i] != NULL) { + free(options->values[i]); + } + } + free(options); + } +} +/* + * Work with agent options + */ + +/* + * Parse options and create structure Options + */ +static Options* nsk_aod_createOptionsObject(char* optionsString) { + int i = 0; + Options* options; + char* name; + char* value; + char* sep; + + if (optionsString == NULL) { + NSK_COMPLAIN0("options were not passed to the native agent\n"); + return NULL; + } + options = (Options*) malloc(sizeof(Options)); + memset(options, 0, sizeof(Options)); + options->size = 0; + name = optionsString; + while (name != NULL && i < NSK_AOD_MAX_OPTIONS) { + sep = strchr(name, '='); + if (sep == NULL) { // name not found + NSK_COMPLAIN1("Invalid options format: '%s'\n", optionsString); + nsk_free_options(options); + return NULL; + } + *sep = '\0'; + options->names[i] = strdup(name); + value = sep + 1; + if (*value == '\0') { // value not found + NSK_COMPLAIN1("Option '%s' is empty\n", options->names[i]); + nsk_free_options(options); + return NULL; + } + sep = strchr(value, ' '); + if (sep != NULL) { + *sep = '\0'; + name = sep + 1; + } else { + name = strchr(value, '\0'); + } + options->values[i] = strdup(value); + i++; + + if (*name == '\0') { + name = NULL; + } + } + if (name != NULL) { + NSK_COMPLAIN1("WARNING: not all options were parsed, only %d options can be specified\n", + NSK_AOD_MAX_OPTIONS); + } + options->size = i; + return options; +} + +Options* nsk_aod_createOptions(char* optionsString) { + Options* options; + + if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptionsObject(optionsString)) != NULL)) + return NULL; + + if (!NSK_VERIFY(nsk_aod_optionSpecified(options, NSK_AOD_AGENT_NAME_OPTION))) { + NSK_COMPLAIN0("Agent name wasn't specified\n"); + return NULL; + } + + /* + * verbose mode is true by default + */ + nsk_setVerboseMode(NSK_TRUE); + + if (nsk_aod_optionSpecified(options, NSK_AOD_VERBOSE_OPTION)) { + if (strcmp(nsk_aod_getOptionValue(options, NSK_AOD_VERBOSE_OPTION), "false") == 0) + nsk_setVerboseMode(NSK_FALSE); + } + + return options; +} + +const char* nsk_aod_getOptionValue(Options* options, const char* option) { + int i; + + if (!NSK_VERIFY(options != NULL)) { + NSK_COMPLAIN0("Options NULL\n"); + return NULL; + } + + for(i = 0; i < options->size; i++) { + if (strcmp(option, options->names[i]) == 0) { + return options->values[i]; + } + } + + NSK_COMPLAIN1("Option '%s' isn't defined\n", option); + + return NULL; +} + +int nsk_aod_optionSpecified(Options* options, const char* option) { + int i; + + if (!NSK_VERIFY(options != NULL)) { + NSK_COMPLAIN0("Options NULL\n"); + return NSK_FALSE; + } + + for(i = 0; i < options->size; i++) { + if (strcmp(option, options->names[i]) == 0) { + return NSK_TRUE; + } + } + + return NSK_FALSE; +} + +/* + * Agent synchronization with target application + */ + +static const char* TARGET_APP_CLASS_NAME = "nsk/share/aod/TargetApplicationWaitingAgents"; + +static const char* AGENT_LOADED_METHOD_NAME = "agentLoaded"; +static const char* AGENT_LOADED_METHOD_SIGNATURE = "(Ljava/lang/String;)V"; + +static const char* AGENT_FINISHED_METHOD_NAME = "agentFinished"; +static const char* AGENT_FINISHED_METHOD_SIGNATURE = "(Ljava/lang/String;Z)V"; + +static jclass targetAppClass = NULL; +static jmethodID agentLoadedMethod = NULL; +static jmethodID agentFinishedMethod = NULL; + +// this function is used to notify target application that native agent has been loaded +int nsk_aod_agentLoaded(JNIEnv* jni, const char* agentName) { + jstring agentNameString; + + NSK_DISPLAY1("Agent %s is loaded\n", agentName); + + if (targetAppClass == NULL) { + /* + * FindClass returns local reference, to cache reference to target application class + * global reference should be created + */ + jclass localTargetAppClass; + if (!NSK_JNI_VERIFY(jni, (localTargetAppClass = + NSK_CPP_STUB2(FindClass, jni, TARGET_APP_CLASS_NAME)) != NULL)) { + return NSK_FALSE; + } + + if (!NSK_JNI_VERIFY(jni, (targetAppClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, localTargetAppClass)) != NULL)) { + return NSK_FALSE; + } + } + + if (agentLoadedMethod == NULL) { + if (!NSK_JNI_VERIFY(jni, (agentLoadedMethod = + NSK_CPP_STUB4(GetStaticMethodID, jni, targetAppClass, + AGENT_LOADED_METHOD_NAME, AGENT_LOADED_METHOD_SIGNATURE)) != NULL)) + return NSK_FALSE; + } + + if (!NSK_JNI_VERIFY(jni, (agentNameString = + NSK_CPP_STUB2(NewStringUTF, jni, agentName)) != NULL)) + return NSK_FALSE; + + NSK_CPP_STUB4(CallStaticVoidMethod, jni, targetAppClass, agentLoadedMethod, agentNameString); + + return NSK_TRUE; +} + +// this function is used to notify target application that native agent has been finished execution +int nsk_aod_agentFinished(JNIEnv* jni, const char* agentName, int success) { + jstring agentNameString; + + if (!targetAppClass) { + NSK_COMPLAIN1("%s: TEST LOGIC ERROR: method 'agentFinished' was called before "\ + "targetAppClass was initialized\n", agentName); + return NSK_FALSE; + } + + if (internalError && success) { + success = 0; + NSK_COMPLAIN1("Status of agent '%s' is 'passed', but some error happened during test execution "\ + "(see log for details), change agent status to 'failed'\n", + agentName); + } + + NSK_DISPLAY2("Agent %s finished (success: %d)\n", agentName, success); + + if (agentFinishedMethod == NULL) { + if (!NSK_JNI_VERIFY(jni, (agentFinishedMethod = + NSK_CPP_STUB4(GetStaticMethodID, jni, targetAppClass, + AGENT_FINISHED_METHOD_NAME, AGENT_FINISHED_METHOD_SIGNATURE)) != NULL)) + return NSK_FALSE; + } + + if (!NSK_JNI_VERIFY(jni, (agentNameString = NSK_CPP_STUB2(NewStringUTF, jni, agentName)) != NULL)) + return NSK_FALSE; + + NSK_CPP_STUB5(CallStaticVoidMethod, jni, targetAppClass, + agentFinishedMethod, agentNameString, success ? JNI_TRUE : JNI_FALSE); + + return NSK_TRUE; +} + +/* + * Auxiliary functions + */ + +// JNI env creation + +JNIEnv* nsk_aod_createJNIEnv(JavaVM* vm) { + JNIEnv* jni; + NSK_CPP_STUB3(GetEnv, vm, (void**)&jni, JNI_VERSION_1_2); + + NSK_VERIFY(jni != NULL); + + return jni; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.c deleted file mode 100644 index 244bc2e3b32..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jni_BooleanArrayCriticalLocker - * Method: criticalNative - * Signature: ([Z)Z - */ -JNIEXPORT jboolean JNICALL Java_nsk_share_gc_lock_jni_BooleanArrayCriticalLocker_criticalNative -(JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jsize size, i; - jbooleanArray arr; - jboolean *pa; - jboolean hash = JNI_TRUE; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return JNI_FALSE; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return JNI_FALSE; - } - } - arr = (*env)->GetObjectField(env, this, objFieldId); - if (arr == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return JNI_FALSE; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - size = (*env)->GetArrayLength(env, arr); - start_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - start_time < enterTime) { - pa = (*env)->GetPrimitiveArrayCritical(env, arr, NULL); - if (pa != NULL) { - for (i = 0; i < size; ++i) - hash ^= pa[i]; - } else { - hash = JNI_FALSE; - } - mssleep((long) sleepTime); - (*env)->ReleasePrimitiveArrayCritical(env, arr, pa, 0); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, arr); - return hash; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.cpp new file mode 100644 index 00000000000..bc003d7c432 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jni_BooleanArrayCriticalLocker + * Method: criticalNative + * Signature: ([Z)Z + */ +JNIEXPORT jboolean JNICALL Java_nsk_share_gc_lock_jni_BooleanArrayCriticalLocker_criticalNative +(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jsize size, i; + jbooleanArray arr; + jboolean *pa; + jboolean hash = JNI_TRUE; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return JNI_FALSE; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return JNI_FALSE; + } + } + arr = (jbooleanArray) env->GetObjectField(o, objFieldId); + if (arr == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return JNI_FALSE; + } + env->SetObjectField(o, objFieldId, NULL); + size = env->GetArrayLength(arr); + start_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - start_time < enterTime) { + pa = (jboolean*) env->GetPrimitiveArrayCritical(arr, NULL); + if (pa != NULL) { + for (i = 0; i < size; ++i) + hash ^= pa[i]; + } else { + hash = JNI_FALSE; + } + mssleep((long) sleepTime); + env->ReleasePrimitiveArrayCritical(arr, pa, 0); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, arr); + return hash; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.c deleted file mode 100644 index 5347f7e8c19..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jni_ByteArrayCriticalLocker - * Method: criticalNative - */ -JNIEXPORT jbyte JNICALL Java_nsk_share_gc_lock_jni_ByteArrayCriticalLocker_criticalNative -(JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jsize size, i; - jbyteArray arr; - jbyte *pa; - jbyte hash = 0; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return 0; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return 0; - } - } - arr = (*env)->GetObjectField(env, this, objFieldId); - if (arr == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return 0; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - size = (*env)->GetArrayLength(env, arr); - start_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - start_time < enterTime) { - pa = (*env)->GetPrimitiveArrayCritical(env, arr, NULL); - if (pa != NULL) { - for (i = 0; i < size; ++i) - hash ^= pa[i]; - } else { - hash = 0; - } - mssleep((long) sleepTime); - (*env)->ReleasePrimitiveArrayCritical(env, arr, pa, 0); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, arr); - return hash; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.cpp new file mode 100644 index 00000000000..8b0a9ba87fd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jni_ByteArrayCriticalLocker + * Method: criticalNative + */ +JNIEXPORT jbyte JNICALL Java_nsk_share_gc_lock_jni_ByteArrayCriticalLocker_criticalNative +(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jsize size, i; + jbyteArray arr; + jbyte *pa; + jbyte hash = 0; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return 0; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return 0; + } + } + arr = (jbyteArray) env->GetObjectField(o, objFieldId); + if (arr == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return 0; + } + env->SetObjectField(o, objFieldId, NULL); + size = env->GetArrayLength(arr); + start_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - start_time < enterTime) { + pa = (jbyte*) env->GetPrimitiveArrayCritical(arr, NULL); + if (pa != NULL) { + for (i = 0; i < size; ++i) + hash ^= pa[i]; + } else { + hash = 0; + } + mssleep((long) sleepTime); + env->ReleasePrimitiveArrayCritical(arr, pa, 0); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, arr); + return hash; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.c deleted file mode 100644 index 91ad693e6ee..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jni_CharArrayCriticalLocker - * Method: criticalNative - * Signature: ([Z)Z - */ -JNIEXPORT jchar JNICALL Java_nsk_share_gc_lock_jni_CharArrayCriticalLocker_criticalNative -(JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jsize size, i; - jcharArray arr; - jchar *pa; - jchar hash = 0; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return 0; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return 0; - } - } - arr = (*env)->GetObjectField(env, this, objFieldId); - if (arr == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return JNI_FALSE; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - size = (*env)->GetArrayLength(env, arr); - start_time = time(NULL); - current_time = 0; - enterTime /= 1000; - while (current_time - start_time < enterTime) { - pa = (*env)->GetPrimitiveArrayCritical(env, arr, NULL); - if (pa != NULL) { - for (i = 0; i < size; ++i) - hash ^= pa[i]; - } else { - hash = 0; - } - mssleep((long) sleepTime); - (*env)->ReleasePrimitiveArrayCritical(env, arr, pa, 0); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, arr); - return hash; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.cpp new file mode 100644 index 00000000000..62d4ca39872 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jni_CharArrayCriticalLocker + * Method: criticalNative + * Signature: ([Z)Z + */ +JNIEXPORT jchar JNICALL Java_nsk_share_gc_lock_jni_CharArrayCriticalLocker_criticalNative +(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jsize size, i; + jcharArray arr; + jchar *pa; + jchar hash = 0; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return 0; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return 0; + } + } + arr = (jcharArray) env->GetObjectField(o, objFieldId); + if (arr == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return JNI_FALSE; + } + env->SetObjectField(o, objFieldId, NULL); + size = env->GetArrayLength(arr); + start_time = time(NULL); + current_time = 0; + enterTime /= 1000; + while (current_time - start_time < enterTime) { + pa = (jchar*) env->GetPrimitiveArrayCritical(arr, NULL); + if (pa != NULL) { + for (i = 0; i < size; ++i) + hash ^= pa[i]; + } else { + hash = 0; + } + mssleep((long) sleepTime); + env->ReleasePrimitiveArrayCritical(arr, pa, 0); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, arr); + return hash; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.c deleted file mode 100644 index 2e70012f2b2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jni_DoubleArrayCriticalLocker - * Method: criticalNative - * Signature: ([Z)Z - */ -JNIEXPORT jdouble JNICALL Java_nsk_share_gc_lock_jni_DoubleArrayCriticalLocker_criticalNative -(JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jsize size, i; - jdoubleArray arr; - jdouble *pa; - jdouble hash = 0; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return 0; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return 0; - } - } - arr = (*env)->GetObjectField(env, this, objFieldId); - if (arr == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return JNI_FALSE; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - size = (*env)->GetArrayLength(env, arr); - start_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - start_time < enterTime) { - pa = (*env)->GetPrimitiveArrayCritical(env, arr, NULL); - if (pa != NULL) { - for (i = 0; i < size; ++i) - hash += pa[i]; - } else { - hash = 0; - } - mssleep((long) sleepTime); - (*env)->ReleasePrimitiveArrayCritical(env, arr, pa, 0); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, arr); - return hash; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.cpp new file mode 100644 index 00000000000..7dd09f40821 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jni_DoubleArrayCriticalLocker + * Method: criticalNative + * Signature: ([Z)Z + */ +JNIEXPORT jdouble JNICALL Java_nsk_share_gc_lock_jni_DoubleArrayCriticalLocker_criticalNative +(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jsize size, i; + jdoubleArray arr; + jdouble *pa; + jdouble hash = 0; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return 0; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return 0; + } + } + arr = (jdoubleArray) env->GetObjectField(o, objFieldId); + if (arr == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return JNI_FALSE; + } + env->SetObjectField(o, objFieldId, NULL); + size = env->GetArrayLength(arr); + start_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - start_time < enterTime) { + pa = (jdouble*) env->GetPrimitiveArrayCritical(arr, NULL); + if (pa != NULL) { + for (i = 0; i < size; ++i) + hash += pa[i]; + } else { + hash = 0; + } + mssleep((long) sleepTime); + env->ReleasePrimitiveArrayCritical(arr, pa, 0); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, arr); + return hash; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.c deleted file mode 100644 index c5720c46381..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jni_FloatArrayCriticalLocker - * Method: criticalNative - * Signature: ([Z)Z - */ -JNIEXPORT jfloat JNICALL Java_nsk_share_gc_lock_jni_FloatArrayCriticalLocker_criticalNative -(JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jsize size, i; - jfloatArray arr; - jfloat *pa; - jfloat hash = 0; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return 0; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return 0; - } - } - arr = (*env)->GetObjectField(env, this, objFieldId); - if (arr == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return JNI_FALSE; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - size = (*env)->GetArrayLength(env, arr); - start_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - start_time < enterTime) { - pa = (*env)->GetPrimitiveArrayCritical(env, arr, NULL); - if (pa != NULL) { - for (i = 0; i < size; ++i) - hash += pa[i]; - } else { - hash = 0; - } - mssleep((long) sleepTime); - (*env)->ReleasePrimitiveArrayCritical(env, arr, pa, 0); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, arr); - return hash; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.cpp new file mode 100644 index 00000000000..49c29376272 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jni_FloatArrayCriticalLocker + * Method: criticalNative + * Signature: ([Z)Z + */ +JNIEXPORT jfloat JNICALL Java_nsk_share_gc_lock_jni_FloatArrayCriticalLocker_criticalNative +(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jsize size, i; + jfloatArray arr; + jfloat *pa; + jfloat hash = 0; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return 0; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return 0; + } + } + arr = (jfloatArray) env->GetObjectField(o, objFieldId); + if (arr == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return JNI_FALSE; + } + env->SetObjectField(o, objFieldId, NULL); + size = env->GetArrayLength(arr); + start_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - start_time < enterTime) { + pa = (jfloat*) env->GetPrimitiveArrayCritical(arr, NULL); + if (pa != NULL) { + for (i = 0; i < size; ++i) + hash += pa[i]; + } else { + hash = 0; + } + mssleep((long) sleepTime); + env->ReleasePrimitiveArrayCritical(arr, pa, 0); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, arr); + return hash; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.c deleted file mode 100644 index cd0074f14a3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jni_IntArrayCriticalLocker - * Method: criticalNative - * Signature: ([Z)Z - */ -JNIEXPORT jint JNICALL Java_nsk_share_gc_lock_jni_IntArrayCriticalLocker_criticalNative -(JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jsize size, i; - jintArray arr; - jint *pa; - jint hash = 0; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return 0; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return 0; - } - } - arr = (*env)->GetObjectField(env, this, objFieldId); - if (arr == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return JNI_FALSE; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - size = (*env)->GetArrayLength(env, arr); - start_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - start_time < enterTime) { - pa = (*env)->GetPrimitiveArrayCritical(env, arr, NULL); - if (pa != NULL) { - for (i = 0; i < size; ++i) - hash ^= pa[i]; - } else { - hash = 0; - } - mssleep((long) sleepTime); - (*env)->ReleasePrimitiveArrayCritical(env, arr, pa, 0); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, arr); - return hash; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.cpp new file mode 100644 index 00000000000..413be6efb54 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jni_IntArrayCriticalLocker + * Method: criticalNative + * Signature: ([Z)Z + */ +JNIEXPORT jint JNICALL Java_nsk_share_gc_lock_jni_IntArrayCriticalLocker_criticalNative +(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jsize size, i; + jintArray arr; + jint *pa; + jint hash = 0; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return 0; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return 0; + } + } + arr = (jintArray) env->GetObjectField(o, objFieldId); + if (arr == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return JNI_FALSE; + } + env->SetObjectField(o, objFieldId, NULL); + size = env->GetArrayLength(arr); + start_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - start_time < enterTime) { + pa = (jint*) env->GetPrimitiveArrayCritical(arr, NULL); + if (pa != NULL) { + for (i = 0; i < size; ++i) + hash ^= pa[i]; + } else { + hash = 0; + } + mssleep((long) sleepTime); + env->ReleasePrimitiveArrayCritical(arr, pa, 0); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, arr); + return hash; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.c deleted file mode 100644 index 6a58cd47ee6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jni_LongArrayCriticalLocker - * Method: criticalNative - * Signature: ([Z)Z - */ -JNIEXPORT jlong JNICALL Java_nsk_share_gc_lock_jni_LongArrayCriticalLocker_criticalNative -(JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jsize size, i; - jlongArray arr; - jlong *pa; - jlong hash = 0; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return 0; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return 0; - } - } - arr = (*env)->GetObjectField(env, this, objFieldId); - if (arr == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return JNI_FALSE; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - size = (*env)->GetArrayLength(env, arr); - start_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - start_time < enterTime) { - pa = (*env)->GetPrimitiveArrayCritical(env, arr, NULL); - if (pa != NULL) { - for (i = 0; i < size; ++i) - hash ^= pa[i]; - } else { - hash = 0; - } - mssleep((long) sleepTime); - (*env)->ReleasePrimitiveArrayCritical(env, arr, pa, 0); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, arr); - return hash; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.cpp new file mode 100644 index 00000000000..254fe347bf3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jni_LongArrayCriticalLocker + * Method: criticalNative + * Signature: ([Z)Z + */ +JNIEXPORT jlong JNICALL Java_nsk_share_gc_lock_jni_LongArrayCriticalLocker_criticalNative +(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jsize size, i; + jlongArray arr; + jlong *pa; + jlong hash = 0; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return 0; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return 0; + } + } + arr = (jlongArray) env->GetObjectField(o, objFieldId); + if (arr == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return JNI_FALSE; + } + env->SetObjectField(o, objFieldId, NULL); + size = env->GetArrayLength(arr); + start_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - start_time < enterTime) { + pa = (jlong*) env->GetPrimitiveArrayCritical(arr, NULL); + if (pa != NULL) { + for (i = 0; i < size; ++i) + hash ^= pa[i]; + } else { + hash = 0; + } + mssleep((long) sleepTime); + env->ReleasePrimitiveArrayCritical(arr, pa, 0); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, arr); + return hash; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.c deleted file mode 100644 index e69173323bb..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jni_ShortArrayCriticalLocker - * Method: criticalNative - * Signature: ([Z)Z - */ -JNIEXPORT jshort JNICALL Java_nsk_share_gc_lock_jni_ShortArrayCriticalLocker_criticalNative -(JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jsize size, i; - jshortArray arr; - jshort *pa; - jshort hash = 0; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return 0; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return 0; - } - } - arr = (*env)->GetObjectField(env, this, objFieldId); - if (arr == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return JNI_FALSE; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - size = (*env)->GetArrayLength(env, arr); - start_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - start_time < enterTime) { - pa = (*env)->GetPrimitiveArrayCritical(env, arr, NULL); - if (pa != NULL) { - for (i = 0; i < size; ++i) - hash ^= pa[i]; - } else { - hash = 0; - } - mssleep((long) sleepTime); - (*env)->ReleasePrimitiveArrayCritical(env, arr, pa, 0); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, arr); - return hash; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.cpp new file mode 100644 index 00000000000..d2d32db8863 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jni_ShortArrayCriticalLocker + * Method: criticalNative + * Signature: ([Z)Z + */ +JNIEXPORT jshort JNICALL Java_nsk_share_gc_lock_jni_ShortArrayCriticalLocker_criticalNative +(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jsize size, i; + jshortArray arr; + jshort *pa; + jshort hash = 0; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return 0; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return 0; + } + } + arr = (jshortArray) env->GetObjectField(o, objFieldId); + if (arr == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return JNI_FALSE; + } + env->SetObjectField(o, objFieldId, NULL); + size = env->GetArrayLength(arr); + start_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - start_time < enterTime) { + pa = (jshort*) env->GetPrimitiveArrayCritical(arr, NULL); + if (pa != NULL) { + for (i = 0; i < size; ++i) + hash ^= pa[i]; + } else { + hash = 0; + } + mssleep((long) sleepTime); + env->ReleasePrimitiveArrayCritical(arr, pa, 0); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, arr); + return hash; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.c deleted file mode 100644 index 4eb6b8bbd3e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jni_StringCriticalLocker - * Method: criticalNative - * Signature: ([Z)Z - */ -JNIEXPORT jchar JNICALL Java_nsk_share_gc_lock_jni_StringCriticalLocker_criticalNative -(JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jsize size, i; - jstring str; - const jchar *pa; - jchar hash = 0; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return JNI_FALSE; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return JNI_FALSE; - } - } - str = (*env)->GetObjectField(env, this, objFieldId); - if (str == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return JNI_FALSE; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - size = (*env)->GetStringLength(env, str); - start_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - start_time < enterTime) { - pa = (*env)->GetStringCritical(env, str, NULL); - if (pa != NULL) { - for (i = 0; i < size; ++i) - hash ^= pa[i]; - } else { - hash = JNI_FALSE; - } - mssleep((long) sleepTime); - (*env)->ReleaseStringCritical(env, str, pa); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, str); - return hash; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.cpp new file mode 100644 index 00000000000..dea2909cb46 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jni_StringCriticalLocker + * Method: criticalNative + * Signature: ([Z)Z + */ +JNIEXPORT jchar JNICALL Java_nsk_share_gc_lock_jni_StringCriticalLocker_criticalNative +(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jsize size, i; + jstring str; + const jchar *pa; + jchar hash = 0; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return JNI_FALSE; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return JNI_FALSE; + } + } + str = (jstring) env->GetObjectField(o, objFieldId); + if (str == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return JNI_FALSE; + } + env->SetObjectField(o, objFieldId, NULL); + size = env->GetStringLength(str); + start_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - start_time < enterTime) { + pa = env->GetStringCritical(str, NULL); + if (pa != NULL) { + for (i = 0; i < size; ++i) + hash ^= pa[i]; + } else { + hash = JNI_FALSE; + } + mssleep((long) sleepTime); + env->ReleaseStringCritical(str, pa); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, str); + return hash; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libBooleanArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libBooleanArrayCriticalLocker.c deleted file mode 100644 index a5683339d30..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libBooleanArrayCriticalLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "BooleanArrayCriticalLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libBooleanArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libBooleanArrayCriticalLocker.cpp new file mode 100644 index 00000000000..76d22beac45 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libBooleanArrayCriticalLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "BooleanArrayCriticalLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libByteArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libByteArrayCriticalLocker.c deleted file mode 100644 index 03158c2b48f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libByteArrayCriticalLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "ByteArrayCriticalLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libByteArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libByteArrayCriticalLocker.cpp new file mode 100644 index 00000000000..8af310a3e90 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libByteArrayCriticalLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "ByteArrayCriticalLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libCharArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libCharArrayCriticalLocker.c deleted file mode 100644 index 987ba46761e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libCharArrayCriticalLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "CharArrayCriticalLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libCharArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libCharArrayCriticalLocker.cpp new file mode 100644 index 00000000000..9f38546e957 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libCharArrayCriticalLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "CharArrayCriticalLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libDoubleArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libDoubleArrayCriticalLocker.c deleted file mode 100644 index e932d69637c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libDoubleArrayCriticalLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "DoubleArrayCriticalLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libDoubleArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libDoubleArrayCriticalLocker.cpp new file mode 100644 index 00000000000..9377164bccc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libDoubleArrayCriticalLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "DoubleArrayCriticalLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libFloatArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libFloatArrayCriticalLocker.c deleted file mode 100644 index fff61ffb92f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libFloatArrayCriticalLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "FloatArrayCriticalLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libFloatArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libFloatArrayCriticalLocker.cpp new file mode 100644 index 00000000000..0db5d1eeccd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libFloatArrayCriticalLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "FloatArrayCriticalLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libIntArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libIntArrayCriticalLocker.c deleted file mode 100644 index 4765d038d93..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libIntArrayCriticalLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "IntArrayCriticalLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libIntArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libIntArrayCriticalLocker.cpp new file mode 100644 index 00000000000..ac8f5049e67 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libIntArrayCriticalLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "IntArrayCriticalLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libLongArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libLongArrayCriticalLocker.c deleted file mode 100644 index 87788815e65..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libLongArrayCriticalLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "LongArrayCriticalLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libLongArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libLongArrayCriticalLocker.cpp new file mode 100644 index 00000000000..e790517159d --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libLongArrayCriticalLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "LongArrayCriticalLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libShortArrayCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libShortArrayCriticalLocker.c deleted file mode 100644 index 4de61dd2186..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libShortArrayCriticalLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "ShortArrayCriticalLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libShortArrayCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libShortArrayCriticalLocker.cpp new file mode 100644 index 00000000000..b17f0d1f6d1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libShortArrayCriticalLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "ShortArrayCriticalLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libStringCriticalLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libStringCriticalLocker.c deleted file mode 100644 index a3d2807f7de..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libStringCriticalLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "StringCriticalLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libStringCriticalLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libStringCriticalLocker.cpp new file mode 100644 index 00000000000..80d120648b1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/libStringCriticalLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "StringCriticalLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.c deleted file mode 100644 index deebad377f1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jniref_JNIGlobalRefLocker - * Method: criticalNative - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jniref_JNIGlobalRefLocker_criticalNative - (JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jobject obj; - jobject gref; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return; - } - } - obj = (*env)->GetObjectField(env, this, objFieldId); - if (obj == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - start_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - start_time < enterTime) { - gref = (*env)->NewGlobalRef(env, obj); - mssleep((long) sleepTime); - (*env)->DeleteGlobalRef(env, gref); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, obj); -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.cpp new file mode 100644 index 00000000000..5e9317f39a7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jniref_JNIGlobalRefLocker + * Method: criticalNative + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jniref_JNIGlobalRefLocker_criticalNative + (JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jobject obj; + jobject gref; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return; + } + } + obj = env->GetObjectField(o, objFieldId); + if (obj == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return; + } + env->SetObjectField(o, objFieldId, NULL); + start_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - start_time < enterTime) { + gref = env->NewGlobalRef(obj); + mssleep((long) sleepTime); + env->DeleteGlobalRef(gref); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, obj); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.c deleted file mode 100644 index bb8a478b76e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jniref_JNILocalRefLocker - * Method: criticalNative - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jniref_JNILocalRefLocker_criticalNative - (JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jobject obj; - jobject gref; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return; - } - } - obj = (*env)->GetObjectField(env, this, objFieldId); - if (obj == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - start_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - start_time < enterTime) { - gref = (*env)->NewLocalRef(env, obj); - mssleep((long) sleepTime); - (*env)->DeleteLocalRef(env, gref); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, obj); -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.cpp new file mode 100644 index 00000000000..cdd61e83535 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jniref_JNILocalRefLocker + * Method: criticalNative + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jniref_JNILocalRefLocker_criticalNative + (JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jobject obj; + jobject gref; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return; + } + } + obj = env->GetObjectField(o, objFieldId); + if (obj == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return; + } + env->SetObjectField(o, objFieldId, NULL); + start_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - start_time < enterTime) { + gref = env->NewLocalRef(obj); + mssleep((long) sleepTime); + env->DeleteLocalRef(gref); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, obj); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.c deleted file mode 100644 index 55e6eddfb47..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jniref_JNIRefLocker - * Method: criticalNative - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jniref_JNIRefLocker_criticalNative - (JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jobject obj; - jobject gref, lref, gwref; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return; - } - } - obj = (*env)->GetObjectField(env, this, objFieldId); - if (obj == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - start_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - start_time < enterTime) { - gref = (*env)->NewGlobalRef(env, obj); - lref = (*env)->NewLocalRef(env, obj); - gwref = (*env)->NewWeakGlobalRef(env, obj); - mssleep((long) sleepTime); - (*env)->DeleteGlobalRef(env, gref); - (*env)->DeleteLocalRef(env, lref); - (*env)->DeleteWeakGlobalRef(env, gwref); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, obj); -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.cpp new file mode 100644 index 00000000000..c16eba1ed10 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jniref_JNIRefLocker + * Method: criticalNative + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jniref_JNIRefLocker_criticalNative + (JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jobject obj; + jobject gref, lref, gwref; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return; + } + } + obj = env->GetObjectField(o, objFieldId); + if (obj == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return; + } + env->SetObjectField(o, objFieldId, NULL); + start_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - start_time < enterTime) { + gref = env->NewGlobalRef(obj); + lref = env->NewLocalRef(obj); + gwref = env->NewWeakGlobalRef(obj); + mssleep((long) sleepTime); + env->DeleteGlobalRef(gref); + env->DeleteLocalRef(lref); + env->DeleteWeakGlobalRef(gwref); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, obj); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.c deleted file mode 100644 index 9670aa4e3e2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -static jfieldID objFieldId = NULL; - -/* - * Class: nsk_share_gc_lock_jniref_JNIWeakGlobalRefLocker - * Method: criticalNative - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jniref_JNIWeakGlobalRefLocker_criticalNative - (JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - jobject obj; - jobject gref; - time_t start_time, current_time; - - if (objFieldId == NULL) { - jclass class = (*env)->GetObjectClass(env, this); - if (class == NULL) { - printf("Error: GetObjectClass returned NULL\n"); - return; - } - objFieldId = (*env)->GetFieldID(env, class, "obj", "Ljava/lang/Object;"); - if (objFieldId == NULL) { - printf("Error: GetFieldID returned NULL\n"); - return; - } - } - obj = (*env)->GetObjectField(env, this, objFieldId); - if (obj == NULL) { - printf("Error: GetObjectField returned NULL\n"); - return; - } - (*env)->SetObjectField(env, this, objFieldId, NULL); - start_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - start_time < enterTime) { - gref = (*env)->NewWeakGlobalRef(env, obj); - mssleep((long) sleepTime); - (*env)->DeleteWeakGlobalRef(env, gref); - mssleep((long) sleepTime); - current_time = time(NULL); - } - (*env)->SetObjectField(env, this, objFieldId, obj); -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.cpp new file mode 100644 index 00000000000..73898c5eeba --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jfieldID objFieldId = NULL; + +/* + * Class: nsk_share_gc_lock_jniref_JNIWeakGlobalRefLocker + * Method: criticalNative + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jniref_JNIWeakGlobalRefLocker_criticalNative + (JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + jobject obj; + jobject gref; + time_t start_time, current_time; + + if (objFieldId == NULL) { + jclass klass = env->GetObjectClass(o); + if (klass == NULL) { + printf("Error: GetObjectClass returned NULL\n"); + return; + } + objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;"); + if (objFieldId == NULL) { + printf("Error: GetFieldID returned NULL\n"); + return; + } + } + obj = env->GetObjectField(o, objFieldId); + if (obj == NULL) { + printf("Error: GetObjectField returned NULL\n"); + return; + } + env->SetObjectField(o, objFieldId, NULL); + start_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - start_time < enterTime) { + gref = env->NewWeakGlobalRef(obj); + mssleep((long) sleepTime); + env->DeleteWeakGlobalRef(gref); + mssleep((long) sleepTime); + current_time = time(NULL); + } + env->SetObjectField(o, objFieldId, obj); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIGlobalRefLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIGlobalRefLocker.c deleted file mode 100644 index a4ad4143ba5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIGlobalRefLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "JNIGlobalRefLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIGlobalRefLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIGlobalRefLocker.cpp new file mode 100644 index 00000000000..d523fba861a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIGlobalRefLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "JNIGlobalRefLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNILocalRefLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNILocalRefLocker.c deleted file mode 100644 index 30ac62059f9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNILocalRefLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "JNILocalRefLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNILocalRefLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNILocalRefLocker.cpp new file mode 100644 index 00000000000..615e25924d4 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNILocalRefLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "JNILocalRefLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIRefLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIRefLocker.c deleted file mode 100644 index 01283c5d38a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIRefLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "JNIRefLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIRefLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIRefLocker.cpp new file mode 100644 index 00000000000..9856147ca28 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIRefLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "JNIRefLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIWeakGlobalRefLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIWeakGlobalRefLocker.c deleted file mode 100644 index acc5ed0a301..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIWeakGlobalRefLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "JNIWeakGlobalRefLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIWeakGlobalRefLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIWeakGlobalRefLocker.cpp new file mode 100644 index 00000000000..7cc53e8b2ec --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/libJNIWeakGlobalRefLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "JNIWeakGlobalRefLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/JVMTIAllocLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/JVMTIAllocLocker.c deleted file mode 100644 index 5cd139f1e88..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/JVMTIAllocLocker.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include -#include "jni_tools.h" - -static jvmtiEnv *jvmti = NULL; -static jvmtiCapabilities caps; - -JNIEXPORT jint JNICALL -Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) { - jint res; - - res = (*jvm)->GetEnv(jvm, (void **) &jvmti, JVMTI_VERSION_1_0); - if (res != JNI_OK || jvmti == NULL) { - printf("Wrong result of a valid call to GetEnv!\n"); - return JNI_ERR; - } - return JNI_OK; -} - -/* - * Class: nsk_share_gc_lock_jvmti_JVMTIAllocLocker - * Method: jVMTIAllocSection - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jvmti_JVMTIAllocLocker_jVMTIAllocSection -(JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - unsigned char *ptr; - time_t current_time, old_time; - jvmtiError err; - old_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - old_time < enterTime) { - err = (*jvmti)->Allocate(jvmti, 1, &ptr); - mssleep((long) sleepTime); - err = (*jvmti)->Deallocate(jvmti, ptr); - mssleep((long) sleepTime); - current_time = time(NULL); - } -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/JVMTIAllocLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/JVMTIAllocLocker.cpp new file mode 100644 index 00000000000..5b29dc6f679 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/JVMTIAllocLocker.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jvmtiEnv *jvmti = NULL; +static jvmtiCapabilities caps; + +JNIEXPORT jint JNICALL +Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) { + jint res; + + res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_0); + if (res != JNI_OK || jvmti == NULL) { + printf("Wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + return JNI_OK; +} + +/* + * Class: nsk_share_gc_lock_jvmti_JVMTIAllocLocker + * Method: jVMTIAllocSection + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jvmti_JVMTIAllocLocker_jVMTIAllocSection +(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + unsigned char *ptr; + time_t current_time, old_time; + jvmtiError err; + old_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - old_time < enterTime) { + err = jvmti->Allocate(1, &ptr); + mssleep((long) sleepTime); + err = jvmti->Deallocate(ptr); + mssleep((long) sleepTime); + current_time = time(NULL); + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/libJVMTIAllocLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/libJVMTIAllocLocker.c deleted file mode 100644 index 24be085d2a6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/libJVMTIAllocLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "JVMTIAllocLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/libJVMTIAllocLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/libJVMTIAllocLocker.cpp new file mode 100644 index 00000000000..7ca5b368919 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/libJVMTIAllocLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "JVMTIAllocLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/MallocLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/MallocLocker.c deleted file mode 100644 index 9afe41af645..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/MallocLocker.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include "jni_tools.h" - -/* - * Class: nsk_share_gc_lock_malloc_MallocLocker - * Method: mallocSection - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_nsk_share_gc_lock_malloc_MallocLocker_mallocSection -(JNIEnv *env, jobject this, jlong enterTime, jlong sleepTime) { - char *ptr; - time_t current_time, old_time; - old_time = time(NULL); - enterTime /= 1000; - current_time = 0; - while (current_time - old_time < enterTime) { - ptr = malloc(1); - mssleep((long) sleepTime); - free(ptr); - mssleep((long) sleepTime); - current_time = time(NULL); - } -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/MallocLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/MallocLocker.cpp new file mode 100644 index 00000000000..13ccd3e2e8b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/MallocLocker.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: nsk_share_gc_lock_malloc_MallocLocker + * Method: mallocSection + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_nsk_share_gc_lock_malloc_MallocLocker_mallocSection +(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) { + void *ptr; + time_t current_time, old_time; + old_time = time(NULL); + enterTime /= 1000; + current_time = 0; + while (current_time - old_time < enterTime) { + ptr = malloc(1); + mssleep((long) sleepTime); + free(ptr); + mssleep((long) sleepTime); + current_time = time(NULL); + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/libMallocLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/libMallocLocker.c deleted file mode 100644 index e99e8b042c0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/libMallocLocker.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "MallocLocker.c" -#include "jni_tools.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/libMallocLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/libMallocLocker.cpp new file mode 100644 index 00000000000..f6df5bc238c --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/libMallocLocker.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "MallocLocker.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/MonitorEnterExecutor.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/MonitorEnterExecutor.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/jdi/MonitorEnterExecutor.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/jdi/MonitorEnterExecutor.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/libMonitorEnterExecutor.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/libMonitorEnterExecutor.c deleted file mode 100644 index db9236055d0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/libMonitorEnterExecutor.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "nsk_tools.c" -#include "MonitorEnterExecutor.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/libMonitorEnterExecutor.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/libMonitorEnterExecutor.cpp new file mode 100644 index 00000000000..74c5455fbbb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/libMonitorEnterExecutor.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "nsk_tools.cpp" +#include "MonitorEnterExecutor.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jni/JNIreferences.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jni/JNIreferences.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/jni/JNIreferences.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/jni/JNIreferences.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jni/jni_tools.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jni/jni_tools.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/jni/jni_tools.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/jni/jni_tools.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jni/libJNIreferences.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jni/libJNIreferences.c deleted file mode 100644 index d5bcd73b9c8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jni/libJNIreferences.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "JNIreferences.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jni/libJNIreferences.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jni/libJNIreferences.cpp new file mode 100644 index 00000000000..2f7210a99dc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jni/libJNIreferences.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "JNIreferences.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/libNativeMethodsTestThread.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/libNativeMethodsTestThread.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/jpda/libNativeMethodsTestThread.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/jpda/libNativeMethodsTestThread.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/bootclssearch_agent.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/bootclssearch_agent.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/bootclssearch_agent.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/bootclssearch_agent.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/libbootclssearch_agent.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/libbootclssearch_agent.c deleted file mode 100644 index bcc5f7e0510..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/libbootclssearch_agent.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "bootclssearch_agent.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/libbootclssearch_agent.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/libbootclssearch_agent.cpp new file mode 100644 index 00000000000..9e2a76b549a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToBootstrapClassLoaderSearch/libbootclssearch_agent.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "bootclssearch_agent.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/libsystemclssearch_agent.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/libsystemclssearch_agent.c deleted file mode 100644 index 297b9d4586c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/libsystemclssearch_agent.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "systemclssearch_agent.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/libsystemclssearch_agent.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/libsystemclssearch_agent.cpp new file mode 100644 index 00000000000..1b28d8b12ff --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/libsystemclssearch_agent.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "systemclssearch_agent.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/systemclssearch_agent.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/systemclssearch_agent.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/systemclssearch_agent.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/AddToSystemClassLoaderSearch/systemclssearch_agent.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/Injector.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/Injector.c deleted file mode 100644 index fcf0be365f2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/Injector.c +++ /dev/null @@ -1,1207 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "Injector.h" - -/* ========================================================================== */ - -/* Opcode Lengths */ -static const u1 opcLengths[] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 3, /* 0- 19 */ - 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20- 39 */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, /* 40- 59 */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60- 79 */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80- 99 */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 100-119 */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, /* 120-139 */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, /* 140-159 */ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 1, 1, 1, 1, 1, 1, 3, 3, /* 160-179 */ - 3, 3, 3, 3, 3, 5, 5, 3, 2, 3, 1, 1, 3, 3, 1, 1, 0, 4, 3, 3, /* 180-199 */ - 5, 5, 1 /* 200- */ -}; - -static const int GROWTH_FACTOR = 2; -static const char* codeAttributeName = "Code"; -static const char* lineNumberAttributeName = "LineNumberTable"; -static const char* localVarAttributeName = "LocalVariableTable"; -static const char* localVarTypeAttributeName = "LocalVariableTypeTable"; -static const char* stackMapAttributeName= "StackMapTable"; - -static u2 codeAttributeIndex; -static u2 lineNumberAttributeIndex; -static u2 localVarAttributeIndex; -static u2 localVarTypeAttributeIndex; -static u2 stackMapAttributeIndex; - -static const u1 SAME_BEGIN = 0; -static const u1 SAME_END = 63; - -static const u1 SAME_LOCALS_1_STACK_ITEM_BEGIN = 64; -static const u1 SAME_LOCALS_1_STACK_ITEM_END = 127; - -//Tags in the range [128-246] are reserved for future use. - -static const u1 SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247; - -static const u1 CHOP_BEGIN = 248; -static const u1 CHOP_END = 250; - -static const u1 SAME_FRAME_EXTENDED = 251; - -static const u1 APPEND_BEGIN = 252; -static const u1 APPEND_END = 254; - -static const u1 FULL_FRAME = 255; - -static const u1 ITEM_Object = 7; -static const u1 ITEM_Uninitialized = 8; - -static u2 stackFrameOffset = 0; - -static int mode; -static const u1* orig; -static u1* gen; - -static u1* inputPos; -static const u1* endPos; -static u1* genPos; -static u1* markPos; - -static char** constantPool; -static u2 constantPoolSize; -static u2 constantPoolCount; - -static u1 callBytes[] = { opc_invokestatic, 0, 0 }; -static u1 allocBytes[] = { opc_invokestatic, 0, 0 }; -static u1 zeroBytes[] = { 0, 0, 0 }; - -static u4 codeLength; -static u4* map; -static jbyte* widening; - -/* ========================================================================== */ - -#ifdef __cplusplus -extern "C" { -#endif - - static u1 get_u1() { - return *inputPos++; - } - - static u2 get_u2() { - u1* p = inputPos; - inputPos += 2; - return (u2)p[1] | ((u2)p[0]<<8); - } - - static u4 get_u4() { - u1* p = inputPos; - inputPos += 4; - return (u4)p[3] | ((u4)p[2]<<8) | ((u4)p[1]<<16) | ((u4)p[0]<<24); - } - - static void put_u1(u1 v) { - *genPos++ = v; - } - - static void put_u2(u2 v) { - *genPos++ = (u1)(v>>8); - *genPos++ = (u1)(v & 0xFF); - } - - static void put_u4(u4 v) { - *genPos++ = (u1)(v>>24); - *genPos++ = (u1)(v>>16); - *genPos++ = (u1)(v>>8); - *genPos++ = (u1)(v & 0xFF); - } - - static void set_u4(u1* pos, u4 v) { - *pos++ = (u1)(v>>24); - *pos++ = (u1)(v>>16); - *pos++ = (u1)(v>>8); - *pos++ = (u1)(v & 0xFF); - } - - static u1 copy_u1() { - u1 v = get_u1(); - put_u1(v); - return v; - } - - static u2 copy_u2() { - u2 v = get_u2(); - put_u2(v); - return v; - } - - static u4 copy_u4() { - u4 v = get_u4(); - put_u4(v); - return v; - } - - static void copy(int count) { - memcpy(genPos, inputPos, count); - inputPos += count; - genPos += count; - } - - static void skip(int count) { - inputPos += count; - } - - static void get(u1* bytes, int count) { - memcpy(bytes, inputPos, count); - inputPos += count; - } - - static void put(u1* bytes, int count) { - memcpy(genPos, bytes, count); - genPos += count; - } - - static void markLocalPositionStart() { - markPos = inputPos; - } - - static u4 localPosition() { - return (u4) (inputPos - markPos); - } - - void recallPosition() { - inputPos = markPos; - } - - static u4 generatedPosition() { - return (u4) (genPos - gen); - } - - static void randomAccessWriteU2(int pos, u2 v) { - gen[pos] = (u1)(v>>8); - gen[pos+1] = (u1)(v & 0xFF); - } - - static void randomAccessWriteU4(int pos, u4 v) { - gen[pos] = (u1)(v>>24); - gen[pos+1] = (u1)(v>>16); - gen[pos+2] = (u1)(v>>8); - gen[pos+3] = (u1)(v & 0xFF); - } - - static int copyConstantPool(u2 constantPoolCount) { - u2 i; - u2 len; - char* utf8; - - constantPoolSize = constantPoolCount; - - NSK_DISPLAY1("copying ConstantPool: %d\n", constantPoolSize); - constantPool = (char**) malloc(constantPoolSize * sizeof(char*)); - if (!NSK_VERIFY(constantPool != NULL)) { - NSK_COMPLAIN0("out of memory\n"); - return NSK_FALSE; - } - - memset(constantPool, 0, constantPoolSize * sizeof(char*)); - - codeAttributeIndex = 0; - lineNumberAttributeIndex = 0; - localVarAttributeIndex = 0; - localVarTypeAttributeIndex = 0; - stackMapAttributeIndex = 0; - - for (i = 1; i < constantPoolSize; i++) { - u1 tag = copy_u1(); - switch (tag) { - case CONSTANT_Class: - case CONSTANT_String: - case CONSTANT_MethodType: - copy(2); - break; - case CONSTANT_MethodHandle: - copy(3); - break; - case CONSTANT_Fieldref: - case CONSTANT_Methodref: - case CONSTANT_InterfaceMethodref: - case CONSTANT_Integer: - case CONSTANT_Float: - case CONSTANT_NameAndType: - case CONSTANT_InvokeDynamic: - copy(4); - break; - case CONSTANT_Long: - case CONSTANT_Double: - copy(8); - i++; /* takes two CP entries */ - break; - case CONSTANT_Utf8: - len = copy_u2(); - utf8 = (char*) malloc(len + 1); - if (!NSK_VERIFY(utf8 != NULL)) { - NSK_COMPLAIN0("out of memory\n"); - return NSK_FALSE; - } - get((u1*) utf8, len); - utf8[len] = 0; - constantPool[i] = utf8; - if (strcmp(utf8, codeAttributeName) == 0) { - codeAttributeIndex = i; - } else if (strcmp(utf8, lineNumberAttributeName) == 0) { - lineNumberAttributeIndex = i; - } else if (strcmp(utf8, localVarAttributeName) == 0) { - localVarAttributeIndex = i; - } else if (strcmp(utf8, localVarTypeAttributeName) == 0) { - localVarTypeAttributeIndex = i; - } else if (strcmp(utf8, stackMapAttributeName) == 0) { - stackMapAttributeIndex = i; - } - put((u1*) utf8, len); - break; - default: - NSK_COMPLAIN2("%d unexpected constant pool tag: %d\n", i, tag); - return NSK_FALSE; - } - } - - return NSK_TRUE; - } - - static void freeConstantPool() { - u2 i; - - for (i = 1; i < constantPoolSize; i++) { - if (constantPool[i] != NULL) { - free(constantPool[i]); - } - } - - free(constantPool); - } - - /* ========================================================================== */ - - /* Copy the exception table for this method code */ - static void copyExceptionTable() { - u2 tableLength; - u2 i; - - tableLength = copy_u2(); - NSK_DISPLAY1("ExceptionTable length: %d\n", tableLength); - for (i = tableLength; i > 0; i--) { - put_u2((u2) map[get_u2()]); /* start_pc */ - put_u2((u2) map[get_u2()]); /* end_pc */ - put_u2((u2) map[get_u2()]); /* handler_pc */ - copy(2); /* catch_type */ - } - } - - /* Copy the line number table for this method code */ - static void copyLineNumberAttr() { - u2 tableLength; - u2 i; - - copy(4); /* attr len */ - - tableLength = copy_u2(); - - NSK_DISPLAY1("LineNumberTable length: %d\n", tableLength); - for (i = tableLength; i > 0; i--) { - put_u2((u2) map[get_u2()]); /* start_pc */ - copy(2); /* line_number */ - } - } - - /* Copy the local variable table for this method code */ - static void copyLocalVarAttr() { - u2 tableLength; - u2 startPC; - u2 i; - - copy(4); /* attr len */ - - tableLength = copy_u2(); - - NSK_DISPLAY1("LocalVariableTable length: %d\n", tableLength); - for (i = tableLength; i > 0; i--) { - startPC = get_u2(); - put_u2((u2) map[startPC]); /* start_pc */ - put_u2((u2) (map[startPC + get_u2()] - map[startPC])); /* length */ - copy(6); /* name_index, descriptor_index, index */ - } - } - - /* Copy the local variable type table for this method code */ - static void copyLocalVarTypeAttr() { - u2 tableLength; - u2 startPC; - u2 i; - - copy(4); /* attr len */ - - tableLength = copy_u2(); - - NSK_DISPLAY1("LocalVariableTypeTable length: %d\n", tableLength); - for (i = tableLength; i > 0; i--) { - startPC = get_u2(); - put_u2((u2) map[startPC]); /* start_pc */ - put_u2((u2) (map[startPC + get_u2()] - map[startPC])); /* length */ - copy(6); /* name_index, signature_index, index */ - } - } - - static u2 calculateOffsetDelta(u2 frameNumber, u2 frameOffsetDelta) { - u2 oldOffset; - u2 newOffset; - if(frameNumber == 0) { - stackFrameOffset = frameOffsetDelta; - return (u2) map[stackFrameOffset]; - } else { - oldOffset = (u2) map[stackFrameOffset]; - stackFrameOffset = stackFrameOffset + frameOffsetDelta + 1; - newOffset = (u2) map[stackFrameOffset - 1]; - return newOffset - oldOffset; - } - } - - static void copyVerificationTypeInfo(u2 count) { - u2 i; - u2 offset; - u1 tag; - for(i=0; i= SAME_BEGIN) && (frame_type <= SAME_END)) { - // same_frame { - // u1 frame_type = SAME; /* 0-63 */ - // } - - put_u1(SAME_FRAME_EXTENDED); - put_u2(calculateOffsetDelta(i, (u2) frame_type)); - - } else if((frame_type >= SAME_LOCALS_1_STACK_ITEM_BEGIN) && (frame_type<=SAME_LOCALS_1_STACK_ITEM_END)) { - // same_locals_1_stack_item_frame { - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM;/* 64-127 */ - // verification_type_info stack[1]; - // } - - put_u1(SAME_LOCALS_1_STACK_ITEM_EXTENDED); - put_u2(calculateOffsetDelta(i, (u2) (frame_type-64))); - copyVerificationTypeInfo(1); - - // Tags in the range [128-246] are reserved for future use. - } else if(frame_type == SAME_LOCALS_1_STACK_ITEM_EXTENDED) { - // same_locals_1_stack_item_frame_extended { - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */ - // u2 offset_delta; - // verification_type_info stack[1]; - // } - - put_u1(SAME_LOCALS_1_STACK_ITEM_EXTENDED); - frameOffsetDelta = get_u2(); - put_u2(calculateOffsetDelta(i, frameOffsetDelta)); - copyVerificationTypeInfo(1); - - } else if((frame_type >= CHOP_BEGIN) && (frame_type <= CHOP_END)) { - // chop_frame { - // u1 frame_type = CHOP; /* 248-250 */ - // u2 offset_delta; - // } - put_u1((u1)frame_type); - frameOffsetDelta = get_u2(); - put_u2(calculateOffsetDelta(i, frameOffsetDelta)); - - } else if(frame_type == SAME_FRAME_EXTENDED) { - // same_frame_extended { - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251 */ - // u2 offset_delta; - // } - - put_u1(SAME_FRAME_EXTENDED); - frameOffsetDelta = get_u2(); - put_u2(calculateOffsetDelta(i, frameOffsetDelta)); - - } else if((frame_type >= APPEND_BEGIN) && (frame_type <= APPEND_END)) { - // append_frame { - // u1 frame_type = APPEND; /* 252-254 */ - // u2 offset_delta; - // verification_type_info locals[frame_type - 251]; - // } - - put_u1((u1)frame_type); - frameOffsetDelta = get_u2(); - put_u2(calculateOffsetDelta(i, frameOffsetDelta)); - copyVerificationTypeInfo((u1)(frame_type - 251)); - - } else if(frame_type == FULL_FRAME) { - // sfull_frame { - // u1 frame_type = FULL_FRAME; /* 255 */ - // u2 offset_delta; - // u2 number_of_locals; - // verification_type_info locals[number_of_locals]; - // u2 number_of_stack_items; - // verification_type_info stack[number_of_stack_items]; - //} - - put_u1(FULL_FRAME); - frameOffsetDelta = get_u2(); - put_u2(calculateOffsetDelta(i, frameOffsetDelta)); - number_of_locals = copy_u2(); - copyVerificationTypeInfo(number_of_locals); - number_of_stack_items = copy_u2(); - copyVerificationTypeInfo(number_of_stack_items); - - } - - } - set_u4(lenPtr,(u4)((genPos-lenPtr) - 4)); - - } - - /* ========================================================================== */ - - static void injectBytes(u4 at, u4 len) { - u4 i; - - NSK_DISPLAY2("Injecting %d bytes at %d\n", len, at); - for (i = at; i <= codeLength; i++) { - map[i] += len; - } - } - - static void widen(u4 at, jbyte len) { - u4 i; - jbyte delta = len - widening[at]; - - NSK_DISPLAY2("Widening to %d bytes at %d\n", len, at); - /* mark at beginning of instruction */ - widening[at] = len; - /* inject at end of instruction */ - for (i = localPosition(); i <= codeLength; i++) { - map[i] += delta; - } - } - - /* ========================================================================== */ - - /** - * Walk one instruction writing the transformed instruction. - */ - static void writeInstruction() { - u4 pos = localPosition(); - u4 newPos = map[pos]; - u1 opcode = get_u1(); - - switch (opcode) { - - case opc_wide: - put_u1(opcode); - copy(copy_u1() == opc_iinc ? 4 : 2); - break; - - case opc_new: - case opc_newarray: - case opc_anewarray: - case opc_multianewarray: - put_u1(opcode); - copy(opcLengths[opcode] - 1); - if (mode == BCI_MODE_ALLOC) { - put(allocBytes, 3); - } - break; - - case opc_jsr_w: - case opc_goto_w: - put_u1(opcode); - put_u4(map[pos + get_u4()] - newPos); - break; - - case opc_jsr: - case opc_goto: - case opc_ifeq: - case opc_ifge: - case opc_ifgt: - case opc_ifle: - case opc_iflt: - case opc_ifne: - case opc_if_icmpeq: - case opc_if_icmpne: - case opc_if_icmpge: - case opc_if_icmpgt: - case opc_if_icmple: - case opc_if_icmplt: - case opc_if_acmpeq: - case opc_if_acmpne: - case opc_ifnull: - case opc_ifnonnull: { - u1 newOpcode = opcode; - jbyte widened = widening[pos]; - if (widened == 0) { /* not widened */ - put_u1(opcode); - put_u2((u2) (map[pos + (jshort) get_u2()] - newPos)); - } else if (widened == 2) { /* wide form */ - if (opcode == opc_jsr) { - newOpcode = opc_jsr_w; - } else if (opcode == opc_jsr) { - newOpcode = opc_goto_w; - } else { - NSK_COMPLAIN1("unexpected opcode: %d\n", opcode); - } - put_u1(newOpcode); - put_u4(map[pos + (jshort) get_u2()] - newPos); - } else if (widened == 5) { /* insert goto_w */ - switch (opcode) { - case opc_ifeq: - newOpcode = opc_ifne; - break; - case opc_ifge: - newOpcode = opc_iflt; - break; - case opc_ifgt: - newOpcode = opc_ifle; - break; - case opc_ifle: - newOpcode = opc_ifgt; - break; - case opc_iflt: - newOpcode = opc_ifge; - break; - case opc_ifne: - newOpcode = opc_ifeq; - break; - case opc_if_icmpeq: - newOpcode = opc_if_icmpne; - break; - case opc_if_icmpne: - newOpcode = opc_if_icmpeq; - break; - case opc_if_icmpge: - newOpcode = opc_if_icmplt; - break; - case opc_if_icmpgt: - newOpcode = opc_if_icmple; - break; - case opc_if_icmple: - newOpcode = opc_if_icmpgt; - break; - case opc_if_icmplt: - newOpcode = opc_if_icmpge; - break; - case opc_if_acmpeq: - newOpcode = opc_if_acmpne; - break; - case opc_if_acmpne: - newOpcode = opc_if_acmpeq; - break; - case opc_ifnull: - newOpcode = opc_ifnonnull; - break; - case opc_ifnonnull: - newOpcode = opc_ifnull; - break; - default: - NSK_COMPLAIN1("unexpected opcode: %d\n", opcode); - break; - } - put_u1(newOpcode); /* write inverse branch */ - put_u1(3 + 5); /* beyond if and goto_w */ - put_u1(opc_goto_w); /* add a goto_w */ - put_u4(map[pos + (jshort) get_u2()] - newPos); - } else { - NSK_COMPLAIN2("unexpected widening: %d, pos=0x%x\n", - widened, pos); - } - break; - } - - case opc_tableswitch: { - u4 i, low, high; - - put_u1(opcode); - - /* skip old padding */ - skip(((pos+4) & (~3)) - (pos+1)); - - /* write new padding */ - put(zeroBytes, ((newPos+4) & (~3)) - (newPos+1)); - put_u4(map[pos + get_u4()] - newPos); - - low = copy_u4(); - high = copy_u4(); - for (i = low; i <= high; i++) { - put_u4(map[pos + get_u4()] - newPos); - } - - break; - } - - case opc_lookupswitch: { - u4 i, npairs; - - put_u1(opcode); - - /* skip old padding */ - skip(((pos+4) & (~3)) - (pos+1)); - - /* write new padding */ - put(zeroBytes, ((newPos+4) & (~3)) - (newPos+1)); - put_u4(map[pos + get_u4()] - newPos); - - npairs = copy_u4(); - for (i = npairs; i > 0; i--) { - copy_u4(); - put_u4(map[pos + get_u4()] - newPos); - } - - break; - } - - default: - put_u1(opcode); - copy(opcLengths[opcode] - 1); - break; - } - - } - - /* ========================================================================== */ - - /** - * Walk one instruction adjusting for insertions - */ - static int adjustInstruction() { - u4 pos = localPosition(); - u4 newPos = map[pos]; - u1 opcode = get_u1(); - - switch (opcode) { - - case opc_wide: - skip(get_u1() == opc_iinc ? 4 : 2); - break; - - case opc_jsr: - case opc_goto: - case opc_ifeq: - case opc_ifge: - case opc_ifgt: - case opc_ifle: - case opc_iflt: - case opc_ifne: - case opc_if_icmpeq: - case opc_if_icmpne: - case opc_if_icmpge: - case opc_if_icmpgt: - case opc_if_icmple: - case opc_if_icmplt: - case opc_if_acmpeq: - case opc_if_acmpne: - case opc_ifnull: - case opc_ifnonnull: { - jbyte widened = widening[pos]; - if (widened == 0) { /* not yet widened */ - jint delta = (jshort) get_u2(); - u4 target = pos + delta; - u4 newTarget = map[target]; - jint newDelta = newTarget - newPos; - if ((newDelta < -32768) || (newDelta > 32767)) { - if ((opcode == opc_jsr) || (opcode == opc_goto)) { - widen(pos, 2); /* will convert to wide */ - } else { - widen(pos, 5); /* will inject goto_w */ - } - return NSK_FALSE; /* cause restart */ - } - } - break; - } - - case opc_tableswitch: { - jbyte widened = widening[pos]; - u4 low; - jbyte deltaPadding; - - /* skip old padding and default */ - skip(((pos+4) & (~3)) - (pos+1) + 4); - low = get_u4(); - skip((get_u4() - low + 1) * 4); - - deltaPadding = ((newPos+4) & (~3)) - newPos - ((pos+4) & (~3)) + pos; - if (widened != deltaPadding) { - widen(pos, deltaPadding); - return NSK_FALSE; /* cause restart */ - } - break; - } - - case opc_lookupswitch: { - jbyte widened = widening[pos]; - jbyte deltaPadding; - - /* skip old padding and default */ - skip(((pos+4) & (~3)) - (pos+1) + 4); - skip(get_u4() * 8); - - deltaPadding = ((newPos+4) & (~3)) - newPos - ((pos+4) & (~3)) + pos; - if (widened != deltaPadding) { - widen(pos, deltaPadding); - return NSK_FALSE; /* cause restart */ - } - break; - } - - default: - skip(opcLengths[opcode] - 1); - break; - } - - return NSK_TRUE; - } - - /* ========================================================================== */ - - /** - * Walk one instruction inserting instrumentation at specified instructions - */ - static void insertAtInstruction() { - u4 pos = localPosition(); - u1 opcode = get_u1(); - - switch (opcode) { - - case opc_wide: - /* no support for instrumenting wide instructions */ - skip(get_u1() == opc_iinc ? 4 : 2); - break; - - case opc_new: - case opc_newarray: - case opc_anewarray: - case opc_multianewarray: - skip(opcLengths[opcode] - 1); - injectBytes(localPosition(), 3); - break; - - case opc_tableswitch: - /* skip 4-byte boundry padding and default */ - skip(((pos+4) & (~3)) - (pos+1) + 4); - { - u4 low = get_u4(); - skip((get_u4() - low + 1) * 4); - } - break; - - case opc_lookupswitch: - /* skip 4-byte boundry padding and default */ - skip(((pos+4) & (~3)) - (pos+1) + 4); - skip(get_u4() * 8); - break; - - default: - skip(opcLengths[opcode] - 1); - break; - - } - } - - static void adjustOffsets() { - recallPosition(); - - if (mode == BCI_MODE_CALL) { - /* instrument calls - method entry */ - injectBytes(0, 3); - } - - if (mode == BCI_MODE_ALLOC) { - /* instrument allocations */ - while (localPosition() < codeLength) { - insertAtInstruction(); - } - recallPosition(); - } - - NSK_DISPLAY0("Searching for adjustments...\n"); - while (localPosition() < codeLength) { - if (!adjustInstruction()) { - recallPosition(); - NSK_DISPLAY0("Restarting adjustments after change...\n"); - } - } - - NSK_DISPLAY0("Writing new code...\n"); - recallPosition(); - - if (mode == BCI_MODE_CALL) { - put(callBytes, 3); - } - - while (localPosition() < codeLength) { - writeInstruction(); - } - } - - /* ========================================================================== */ - - static void copyAttr() { - u4 len; - - copy(2); - len = copy_u4(); - NSK_DISPLAY1("attr len: %d\n", len); - copy(len); - } - - static void copyAttrs(u2 attrCount) { - u2 i; - - for (i = attrCount; i > 0; i--) { - copyAttr(); - } - } - - static void copyFields() { - u2 count; - u2 attrCount; - u2 i; - - count = copy_u2(); - NSK_DISPLAY1("fields count: %d\n", count); - for (i = count; i > 0; i--) { - /* access, name, descriptor */ - copy(2 + 2 + 2); - attrCount = copy_u2(); - NSK_DISPLAY1("field attrCount: %d\n", attrCount); - copyAttrs(attrCount); - } - } - - static void copyAttrForCode() { - u2 nameIndex = copy_u2(); - - /* check for Code attr */ - if (nameIndex == lineNumberAttributeIndex) { - copyLineNumberAttr(); - } else if (nameIndex == localVarAttributeIndex) { - copyLocalVarAttr(); - } else if (nameIndex == localVarTypeAttributeIndex) { - copyLocalVarTypeAttr(); - } else if (nameIndex == stackMapAttributeIndex) { - copyStackMapAttr(); - } else { - u4 len = copy_u4(); - NSK_DISPLAY1("code attr len: %d\n", len); - copy(len); - } - } - - static void copyCodeAttr(char* name) { - u4 attrLengthPos; - u4 attrLength; - u4 newAttrLength; - u4 codeLengthPos; - u4 newCodeLength; - u2 attrCount; - u4 i; - - attrLengthPos = generatedPosition(); - attrLength = copy_u4(); - - NSK_DISPLAY2("Code attr found: %s, pos=0x%x\n", name, - inputPos - orig - 6); - - /* max_stack, max_locals */ - copy(2 + 2); - - codeLengthPos = generatedPosition(); - codeLength = copy_u4(); - - if (codeLength == 0) { - NSK_COMPLAIN0("code_length must be greater than zero\n"); - return; - } - - if (mode == BCI_MODE_EMCP) { - /* copy remainder minus already copied */ - copy(attrLength - 8); - return; - } - - markLocalPositionStart(); - - map = (u4*) malloc((codeLength + 1) * sizeof(u4)); - for (i = 0; i <= codeLength; i++) { - map[i] = i; - } - - widening = (jbyte*) malloc(codeLength + 1); - memset(widening, 0, codeLength + 1); - - adjustOffsets(); - - /* fix up code length */ - newCodeLength = generatedPosition() - (codeLengthPos + 4); - randomAccessWriteU4(codeLengthPos, newCodeLength); - NSK_DISPLAY2("code length old: %d, new: %d\n", - codeLength, newCodeLength); - - copyExceptionTable(); - - attrCount = copy_u2(); - for (i = attrCount; i > 0; i--) { - copyAttrForCode(); - } - - free(map); - free(widening); - - /* fix up attr length */ - newAttrLength = generatedPosition() - (attrLengthPos + 4); - randomAccessWriteU4(attrLengthPos, newAttrLength); - NSK_DISPLAY2("attr length old: %d, new: %d\n", - attrLength, newAttrLength); - } - - static void copyAttrForMethod(char* name) { - u2 nameIndex; - - nameIndex = copy_u2(); - if (nameIndex == codeAttributeIndex) { - copyCodeAttr(name); - } else { - u4 len = copy_u4(); - - NSK_DISPLAY1("method attr len: %d\n", len); - copy(len); - } - } - - static void copyMethod() { - u2 accessFlags; - u2 methodNameIdx; - char* name; - u2 attrCount; - u2 i; - - accessFlags = copy_u2(); - methodNameIdx = copy_u2(); - name = constantPool[methodNameIdx]; - - /* descriptor */ - copy(2); - - attrCount = copy_u2(); - NSK_DISPLAY1("method attrCount: %d\n", attrCount); - for (i = attrCount; i > 0; i--) { - copyAttrForMethod(name); - } - } - - static void copyMethods() { - u2 count; - u2 i; - - count = copy_u2(); - NSK_DISPLAY1("methods count: %d\n", count); - for (i = count; i > 0; i--) { - copyMethod(); - } - } - - static u2 writeCPEntryUtf8(char* str) { - u2 i; - u2 len = (u2) strlen(str); - put_u1(CONSTANT_Utf8); - put_u2(len); - for (i = 0; i < len; i++) { - put_u1(str[i]); - } - return constantPoolCount++; - } - - static u2 writeCPEntryClass(u2 classNameIndex) { - put_u1(CONSTANT_Class); - put_u2(classNameIndex); - return constantPoolCount++; - } - - static u2 writeCPEntryNameAndType(u2 nameIndex, u2 descrIndex) { - put_u1(CONSTANT_NameAndType); - put_u2(nameIndex); - put_u2(descrIndex); - return constantPoolCount++; - } - - static u2 writeCPEntryMethodRef(u2 classIndex, u2 nameAndTypeIndex) { - put_u1(CONSTANT_Methodref); - put_u2(classIndex); - put_u2(nameAndTypeIndex); - return constantPoolCount++; - } - - static u2 writeCPEntryFieldRef(u2 classIndex, u2 nameAndTypeIndex) { - put_u1(CONSTANT_Fieldref); - put_u2(classIndex); - put_u2(nameAndTypeIndex); - return constantPoolCount++; - } - - static u2 addFieldToConstantPool(u2 classIndex, char* fieldName, char* descr) { - u2 fieldNameIndex = writeCPEntryUtf8(fieldName); - u2 descrIndex = writeCPEntryUtf8(descr); - u2 nameAndTypeIndex = writeCPEntryNameAndType(fieldNameIndex, descrIndex); - u2 fieldIndex = writeCPEntryFieldRef(classIndex, nameAndTypeIndex); - return fieldIndex; - } - - static u2 addMethodToConstantPool(u2 classIndex, char* methodName, char* descr) { - u2 methodNameIndex = writeCPEntryUtf8(methodName); - u2 descrIndex = writeCPEntryUtf8(descr); - u2 nameAndTypeIndex = writeCPEntryNameAndType(methodNameIndex, descrIndex); - u2 methodIndex = writeCPEntryMethodRef(classIndex, nameAndTypeIndex); - return methodIndex; - } - - static u2 addClassToConstantPool(char* className) { - u2 classNameIndex = writeCPEntryUtf8(className); - u2 classIndex = writeCPEntryClass(classNameIndex); - return classIndex; - } - - /* ========================================================================== */ - - int Inject(const u1* old_bytes, const jint old_length, - u1** new_bytes, jint* new_length, int bci_mode) { - u4 constantPoolCountPos; - u2 profiler; - u2 interfaceCount; - u2 attrCount; - - //printf("inject\n"); - NSK_DISPLAY3("Injecting bytecodes: mode=%d, bytes=0x%p, len=%d\n", - bci_mode, old_bytes, old_length); - - mode = bci_mode; - orig = old_bytes; - inputPos = (u1*) orig; - endPos = orig + old_length; - gen = (u1*) malloc(old_length * GROWTH_FACTOR); - if (!NSK_VERIFY(gen != NULL)) { - NSK_COMPLAIN0("out of memory\n"); - return NSK_FALSE; - } - - genPos = gen; - - /* magic + minor/major version */ - copy(4 + 2 + 2); - - constantPoolCountPos = generatedPosition(); - constantPoolCount = copy_u2(); - - /* copy old constant pool */ - if (!copyConstantPool(constantPoolCount)) { - return NSK_FALSE; - } - NSK_DISPLAY1("ConstantPool expanded from: %d\n", constantPoolCount); - - profiler = addClassToConstantPool("nsk/share/jvmti/ProfileCollector"); - - if (mode == BCI_MODE_ALLOC) { - u2 allocTracker = - addMethodToConstantPool(profiler, "allocTracker", "()V"); - allocBytes[1] = (u1) (allocTracker >> 8); - allocBytes[2] = (u1) (allocTracker & 0xFF); - } - - if (mode == BCI_MODE_CALL) { - u2 callTracker = - addMethodToConstantPool(profiler, "callTracker", "()V"); - callBytes[1] = (u1) (callTracker >> 8); - callBytes[2] = (u1) (callTracker & 0xFF); - } - - /* access, this, super */ - copy(2 + 2 + 2); - - interfaceCount = copy_u2(); - NSK_DISPLAY1("interfaceCount: %d\n", interfaceCount); - copy(interfaceCount * 2); - - copyFields(); - copyMethods(); - - attrCount = copy_u2(); - NSK_DISPLAY1("class attrCount: %d\n", attrCount); - copyAttrs(attrCount); - - randomAccessWriteU2(constantPoolCountPos, constantPoolCount); - NSK_DISPLAY1("New constant pool size: %d\n", constantPoolCount); - - *new_length = (jint) (genPos - gen); - *new_bytes = realloc(gen, *new_length); - - freeConstantPool(); - - return NSK_TRUE; - } - - /* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/Injector.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/Injector.cpp new file mode 100644 index 00000000000..00bd8fcdd9f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/Injector.cpp @@ -0,0 +1,1207 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "Injector.h" + +/* ========================================================================== */ + +/* Opcode Lengths */ +static const u1 opcLengths[] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 3, /* 0- 19 */ + 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20- 39 */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, /* 40- 59 */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60- 79 */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80- 99 */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 100-119 */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, /* 120-139 */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, /* 140-159 */ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 1, 1, 1, 1, 1, 1, 3, 3, /* 160-179 */ + 3, 3, 3, 3, 3, 5, 5, 3, 2, 3, 1, 1, 3, 3, 1, 1, 0, 4, 3, 3, /* 180-199 */ + 5, 5, 1 /* 200- */ +}; + +static const int GROWTH_FACTOR = 2; +static const char* codeAttributeName = "Code"; +static const char* lineNumberAttributeName = "LineNumberTable"; +static const char* localVarAttributeName = "LocalVariableTable"; +static const char* localVarTypeAttributeName = "LocalVariableTypeTable"; +static const char* stackMapAttributeName= "StackMapTable"; + +static u2 codeAttributeIndex; +static u2 lineNumberAttributeIndex; +static u2 localVarAttributeIndex; +static u2 localVarTypeAttributeIndex; +static u2 stackMapAttributeIndex; + +static const u1 SAME_BEGIN = 0; +static const u1 SAME_END = 63; + +static const u1 SAME_LOCALS_1_STACK_ITEM_BEGIN = 64; +static const u1 SAME_LOCALS_1_STACK_ITEM_END = 127; + +//Tags in the range [128-246] are reserved for future use. + +static const u1 SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247; + +static const u1 CHOP_BEGIN = 248; +static const u1 CHOP_END = 250; + +static const u1 SAME_FRAME_EXTENDED = 251; + +static const u1 APPEND_BEGIN = 252; +static const u1 APPEND_END = 254; + +static const u1 FULL_FRAME = 255; + +static const u1 ITEM_Object = 7; +static const u1 ITEM_Uninitialized = 8; + +static u2 stackFrameOffset = 0; + +static int mode; +static const u1* orig; +static u1* gen; + +static u1* inputPos; +static const u1* endPos; +static u1* genPos; +static u1* markPos; + +static char** constantPool; +static u2 constantPoolSize; +static u2 constantPoolCount; + +static u1 callBytes[] = { opc_invokestatic, 0, 0 }; +static u1 allocBytes[] = { opc_invokestatic, 0, 0 }; +static u1 zeroBytes[] = { 0, 0, 0 }; + +static u4 codeLength; +static u4* map; +static jbyte* widening; + +/* ========================================================================== */ + +#ifdef __cplusplus +extern "C" { +#endif + + static u1 get_u1() { + return *inputPos++; + } + + static u2 get_u2() { + u1* p = inputPos; + inputPos += 2; + return (u2)p[1] | ((u2)p[0]<<8); + } + + static u4 get_u4() { + u1* p = inputPos; + inputPos += 4; + return (u4)p[3] | ((u4)p[2]<<8) | ((u4)p[1]<<16) | ((u4)p[0]<<24); + } + + static void put_u1(u1 v) { + *genPos++ = v; + } + + static void put_u2(u2 v) { + *genPos++ = (u1)(v>>8); + *genPos++ = (u1)(v & 0xFF); + } + + static void put_u4(u4 v) { + *genPos++ = (u1)(v>>24); + *genPos++ = (u1)(v>>16); + *genPos++ = (u1)(v>>8); + *genPos++ = (u1)(v & 0xFF); + } + + static void set_u4(u1* pos, u4 v) { + *pos++ = (u1)(v>>24); + *pos++ = (u1)(v>>16); + *pos++ = (u1)(v>>8); + *pos++ = (u1)(v & 0xFF); + } + + static u1 copy_u1() { + u1 v = get_u1(); + put_u1(v); + return v; + } + + static u2 copy_u2() { + u2 v = get_u2(); + put_u2(v); + return v; + } + + static u4 copy_u4() { + u4 v = get_u4(); + put_u4(v); + return v; + } + + static void copy(int count) { + memcpy(genPos, inputPos, count); + inputPos += count; + genPos += count; + } + + static void skip(int count) { + inputPos += count; + } + + static void get(u1* bytes, int count) { + memcpy(bytes, inputPos, count); + inputPos += count; + } + + static void put(u1* bytes, int count) { + memcpy(genPos, bytes, count); + genPos += count; + } + + static void markLocalPositionStart() { + markPos = inputPos; + } + + static u4 localPosition() { + return (u4) (inputPos - markPos); + } + + void recallPosition() { + inputPos = markPos; + } + + static u4 generatedPosition() { + return (u4) (genPos - gen); + } + + static void randomAccessWriteU2(int pos, u2 v) { + gen[pos] = (u1)(v>>8); + gen[pos+1] = (u1)(v & 0xFF); + } + + static void randomAccessWriteU4(int pos, u4 v) { + gen[pos] = (u1)(v>>24); + gen[pos+1] = (u1)(v>>16); + gen[pos+2] = (u1)(v>>8); + gen[pos+3] = (u1)(v & 0xFF); + } + + static int copyConstantPool(u2 constantPoolCount) { + u2 i; + u2 len; + char* utf8; + + constantPoolSize = constantPoolCount; + + NSK_DISPLAY1("copying ConstantPool: %d\n", constantPoolSize); + constantPool = (char**) malloc(constantPoolSize * sizeof(char*)); + if (!NSK_VERIFY(constantPool != NULL)) { + NSK_COMPLAIN0("out of memory\n"); + return NSK_FALSE; + } + + memset(constantPool, 0, constantPoolSize * sizeof(char*)); + + codeAttributeIndex = 0; + lineNumberAttributeIndex = 0; + localVarAttributeIndex = 0; + localVarTypeAttributeIndex = 0; + stackMapAttributeIndex = 0; + + for (i = 1; i < constantPoolSize; i++) { + u1 tag = copy_u1(); + switch (tag) { + case CONSTANT_Class: + case CONSTANT_String: + case CONSTANT_MethodType: + copy(2); + break; + case CONSTANT_MethodHandle: + copy(3); + break; + case CONSTANT_Fieldref: + case CONSTANT_Methodref: + case CONSTANT_InterfaceMethodref: + case CONSTANT_Integer: + case CONSTANT_Float: + case CONSTANT_NameAndType: + case CONSTANT_InvokeDynamic: + copy(4); + break; + case CONSTANT_Long: + case CONSTANT_Double: + copy(8); + i++; /* takes two CP entries */ + break; + case CONSTANT_Utf8: + len = copy_u2(); + utf8 = (char*) malloc(len + 1); + if (!NSK_VERIFY(utf8 != NULL)) { + NSK_COMPLAIN0("out of memory\n"); + return NSK_FALSE; + } + get((u1*) utf8, len); + utf8[len] = 0; + constantPool[i] = utf8; + if (strcmp(utf8, codeAttributeName) == 0) { + codeAttributeIndex = i; + } else if (strcmp(utf8, lineNumberAttributeName) == 0) { + lineNumberAttributeIndex = i; + } else if (strcmp(utf8, localVarAttributeName) == 0) { + localVarAttributeIndex = i; + } else if (strcmp(utf8, localVarTypeAttributeName) == 0) { + localVarTypeAttributeIndex = i; + } else if (strcmp(utf8, stackMapAttributeName) == 0) { + stackMapAttributeIndex = i; + } + put((u1*) utf8, len); + break; + default: + NSK_COMPLAIN2("%d unexpected constant pool tag: %d\n", i, tag); + return NSK_FALSE; + } + } + + return NSK_TRUE; + } + + static void freeConstantPool() { + u2 i; + + for (i = 1; i < constantPoolSize; i++) { + if (constantPool[i] != NULL) { + free(constantPool[i]); + } + } + + free(constantPool); + } + + /* ========================================================================== */ + + /* Copy the exception table for this method code */ + static void copyExceptionTable() { + u2 tableLength; + u2 i; + + tableLength = copy_u2(); + NSK_DISPLAY1("ExceptionTable length: %d\n", tableLength); + for (i = tableLength; i > 0; i--) { + put_u2((u2) map[get_u2()]); /* start_pc */ + put_u2((u2) map[get_u2()]); /* end_pc */ + put_u2((u2) map[get_u2()]); /* handler_pc */ + copy(2); /* catch_type */ + } + } + + /* Copy the line number table for this method code */ + static void copyLineNumberAttr() { + u2 tableLength; + u2 i; + + copy(4); /* attr len */ + + tableLength = copy_u2(); + + NSK_DISPLAY1("LineNumberTable length: %d\n", tableLength); + for (i = tableLength; i > 0; i--) { + put_u2((u2) map[get_u2()]); /* start_pc */ + copy(2); /* line_number */ + } + } + + /* Copy the local variable table for this method code */ + static void copyLocalVarAttr() { + u2 tableLength; + u2 startPC; + u2 i; + + copy(4); /* attr len */ + + tableLength = copy_u2(); + + NSK_DISPLAY1("LocalVariableTable length: %d\n", tableLength); + for (i = tableLength; i > 0; i--) { + startPC = get_u2(); + put_u2((u2) map[startPC]); /* start_pc */ + put_u2((u2) (map[startPC + get_u2()] - map[startPC])); /* length */ + copy(6); /* name_index, descriptor_index, index */ + } + } + + /* Copy the local variable type table for this method code */ + static void copyLocalVarTypeAttr() { + u2 tableLength; + u2 startPC; + u2 i; + + copy(4); /* attr len */ + + tableLength = copy_u2(); + + NSK_DISPLAY1("LocalVariableTypeTable length: %d\n", tableLength); + for (i = tableLength; i > 0; i--) { + startPC = get_u2(); + put_u2((u2) map[startPC]); /* start_pc */ + put_u2((u2) (map[startPC + get_u2()] - map[startPC])); /* length */ + copy(6); /* name_index, signature_index, index */ + } + } + + static u2 calculateOffsetDelta(u2 frameNumber, u2 frameOffsetDelta) { + u2 oldOffset; + u2 newOffset; + if(frameNumber == 0) { + stackFrameOffset = frameOffsetDelta; + return (u2) map[stackFrameOffset]; + } else { + oldOffset = (u2) map[stackFrameOffset]; + stackFrameOffset = stackFrameOffset + frameOffsetDelta + 1; + newOffset = (u2) map[stackFrameOffset - 1]; + return newOffset - oldOffset; + } + } + + static void copyVerificationTypeInfo(u2 count) { + u2 i; + u2 offset; + u1 tag; + for(i=0; i= SAME_LOCALS_1_STACK_ITEM_BEGIN) && (frame_type<=SAME_LOCALS_1_STACK_ITEM_END)) { + // same_locals_1_stack_item_frame { + // u1 frame_type = SAME_LOCALS_1_STACK_ITEM;/* 64-127 */ + // verification_type_info stack[1]; + // } + + put_u1(SAME_LOCALS_1_STACK_ITEM_EXTENDED); + put_u2(calculateOffsetDelta(i, (u2) (frame_type-64))); + copyVerificationTypeInfo(1); + + // Tags in the range [128-246] are reserved for future use. + } else if(frame_type == SAME_LOCALS_1_STACK_ITEM_EXTENDED) { + // same_locals_1_stack_item_frame_extended { + // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */ + // u2 offset_delta; + // verification_type_info stack[1]; + // } + + put_u1(SAME_LOCALS_1_STACK_ITEM_EXTENDED); + frameOffsetDelta = get_u2(); + put_u2(calculateOffsetDelta(i, frameOffsetDelta)); + copyVerificationTypeInfo(1); + + } else if((frame_type >= CHOP_BEGIN) && (frame_type <= CHOP_END)) { + // chop_frame { + // u1 frame_type = CHOP; /* 248-250 */ + // u2 offset_delta; + // } + put_u1((u1)frame_type); + frameOffsetDelta = get_u2(); + put_u2(calculateOffsetDelta(i, frameOffsetDelta)); + + } else if(frame_type == SAME_FRAME_EXTENDED) { + // same_frame_extended { + // u1 frame_type = SAME_FRAME_EXTENDED; /* 251 */ + // u2 offset_delta; + // } + + put_u1(SAME_FRAME_EXTENDED); + frameOffsetDelta = get_u2(); + put_u2(calculateOffsetDelta(i, frameOffsetDelta)); + + } else if((frame_type >= APPEND_BEGIN) && (frame_type <= APPEND_END)) { + // append_frame { + // u1 frame_type = APPEND; /* 252-254 */ + // u2 offset_delta; + // verification_type_info locals[frame_type - 251]; + // } + + put_u1((u1)frame_type); + frameOffsetDelta = get_u2(); + put_u2(calculateOffsetDelta(i, frameOffsetDelta)); + copyVerificationTypeInfo((u1)(frame_type - 251)); + + } else if(frame_type == FULL_FRAME) { + // sfull_frame { + // u1 frame_type = FULL_FRAME; /* 255 */ + // u2 offset_delta; + // u2 number_of_locals; + // verification_type_info locals[number_of_locals]; + // u2 number_of_stack_items; + // verification_type_info stack[number_of_stack_items]; + //} + + put_u1(FULL_FRAME); + frameOffsetDelta = get_u2(); + put_u2(calculateOffsetDelta(i, frameOffsetDelta)); + number_of_locals = copy_u2(); + copyVerificationTypeInfo(number_of_locals); + number_of_stack_items = copy_u2(); + copyVerificationTypeInfo(number_of_stack_items); + + } + + } + set_u4(lenPtr,(u4)((genPos-lenPtr) - 4)); + + } + + /* ========================================================================== */ + + static void injectBytes(u4 at, u4 len) { + u4 i; + + NSK_DISPLAY2("Injecting %d bytes at %d\n", len, at); + for (i = at; i <= codeLength; i++) { + map[i] += len; + } + } + + static void widen(u4 at, jbyte len) { + u4 i; + jbyte delta = len - widening[at]; + + NSK_DISPLAY2("Widening to %d bytes at %d\n", len, at); + /* mark at beginning of instruction */ + widening[at] = len; + /* inject at end of instruction */ + for (i = localPosition(); i <= codeLength; i++) { + map[i] += delta; + } + } + + /* ========================================================================== */ + + /** + * Walk one instruction writing the transformed instruction. + */ + static void writeInstruction() { + u4 pos = localPosition(); + u4 newPos = map[pos]; + u1 opcode = get_u1(); + + switch (opcode) { + + case opc_wide: + put_u1(opcode); + copy(copy_u1() == opc_iinc ? 4 : 2); + break; + + case opc_new: + case opc_newarray: + case opc_anewarray: + case opc_multianewarray: + put_u1(opcode); + copy(opcLengths[opcode] - 1); + if (mode == BCI_MODE_ALLOC) { + put(allocBytes, 3); + } + break; + + case opc_jsr_w: + case opc_goto_w: + put_u1(opcode); + put_u4(map[pos + get_u4()] - newPos); + break; + + case opc_jsr: + case opc_goto: + case opc_ifeq: + case opc_ifge: + case opc_ifgt: + case opc_ifle: + case opc_iflt: + case opc_ifne: + case opc_if_icmpeq: + case opc_if_icmpne: + case opc_if_icmpge: + case opc_if_icmpgt: + case opc_if_icmple: + case opc_if_icmplt: + case opc_if_acmpeq: + case opc_if_acmpne: + case opc_ifnull: + case opc_ifnonnull: { + u1 newOpcode = opcode; + jbyte widened = widening[pos]; + if (widened == 0) { /* not widened */ + put_u1(opcode); + put_u2((u2) (map[pos + (jshort) get_u2()] - newPos)); + } else if (widened == 2) { /* wide form */ + if (opcode == opc_jsr) { + newOpcode = opc_jsr_w; + } else if (opcode == opc_jsr) { + newOpcode = opc_goto_w; + } else { + NSK_COMPLAIN1("unexpected opcode: %d\n", opcode); + } + put_u1(newOpcode); + put_u4(map[pos + (jshort) get_u2()] - newPos); + } else if (widened == 5) { /* insert goto_w */ + switch (opcode) { + case opc_ifeq: + newOpcode = opc_ifne; + break; + case opc_ifge: + newOpcode = opc_iflt; + break; + case opc_ifgt: + newOpcode = opc_ifle; + break; + case opc_ifle: + newOpcode = opc_ifgt; + break; + case opc_iflt: + newOpcode = opc_ifge; + break; + case opc_ifne: + newOpcode = opc_ifeq; + break; + case opc_if_icmpeq: + newOpcode = opc_if_icmpne; + break; + case opc_if_icmpne: + newOpcode = opc_if_icmpeq; + break; + case opc_if_icmpge: + newOpcode = opc_if_icmplt; + break; + case opc_if_icmpgt: + newOpcode = opc_if_icmple; + break; + case opc_if_icmple: + newOpcode = opc_if_icmpgt; + break; + case opc_if_icmplt: + newOpcode = opc_if_icmpge; + break; + case opc_if_acmpeq: + newOpcode = opc_if_acmpne; + break; + case opc_if_acmpne: + newOpcode = opc_if_acmpeq; + break; + case opc_ifnull: + newOpcode = opc_ifnonnull; + break; + case opc_ifnonnull: + newOpcode = opc_ifnull; + break; + default: + NSK_COMPLAIN1("unexpected opcode: %d\n", opcode); + break; + } + put_u1(newOpcode); /* write inverse branch */ + put_u1(3 + 5); /* beyond if and goto_w */ + put_u1(opc_goto_w); /* add a goto_w */ + put_u4(map[pos + (jshort) get_u2()] - newPos); + } else { + NSK_COMPLAIN2("unexpected widening: %d, pos=0x%x\n", + widened, pos); + } + break; + } + + case opc_tableswitch: { + u4 i, low, high; + + put_u1(opcode); + + /* skip old padding */ + skip(((pos+4) & (~3)) - (pos+1)); + + /* write new padding */ + put(zeroBytes, ((newPos+4) & (~3)) - (newPos+1)); + put_u4(map[pos + get_u4()] - newPos); + + low = copy_u4(); + high = copy_u4(); + for (i = low; i <= high; i++) { + put_u4(map[pos + get_u4()] - newPos); + } + + break; + } + + case opc_lookupswitch: { + u4 i, npairs; + + put_u1(opcode); + + /* skip old padding */ + skip(((pos+4) & (~3)) - (pos+1)); + + /* write new padding */ + put(zeroBytes, ((newPos+4) & (~3)) - (newPos+1)); + put_u4(map[pos + get_u4()] - newPos); + + npairs = copy_u4(); + for (i = npairs; i > 0; i--) { + copy_u4(); + put_u4(map[pos + get_u4()] - newPos); + } + + break; + } + + default: + put_u1(opcode); + copy(opcLengths[opcode] - 1); + break; + } + + } + + /* ========================================================================== */ + + /** + * Walk one instruction adjusting for insertions + */ + static int adjustInstruction() { + u4 pos = localPosition(); + u4 newPos = map[pos]; + u1 opcode = get_u1(); + + switch (opcode) { + + case opc_wide: + skip(get_u1() == opc_iinc ? 4 : 2); + break; + + case opc_jsr: + case opc_goto: + case opc_ifeq: + case opc_ifge: + case opc_ifgt: + case opc_ifle: + case opc_iflt: + case opc_ifne: + case opc_if_icmpeq: + case opc_if_icmpne: + case opc_if_icmpge: + case opc_if_icmpgt: + case opc_if_icmple: + case opc_if_icmplt: + case opc_if_acmpeq: + case opc_if_acmpne: + case opc_ifnull: + case opc_ifnonnull: { + jbyte widened = widening[pos]; + if (widened == 0) { /* not yet widened */ + jint delta = (jshort) get_u2(); + u4 target = pos + delta; + u4 newTarget = map[target]; + jint newDelta = newTarget - newPos; + if ((newDelta < -32768) || (newDelta > 32767)) { + if ((opcode == opc_jsr) || (opcode == opc_goto)) { + widen(pos, 2); /* will convert to wide */ + } else { + widen(pos, 5); /* will inject goto_w */ + } + return NSK_FALSE; /* cause restart */ + } + } + break; + } + + case opc_tableswitch: { + jbyte widened = widening[pos]; + u4 low; + jbyte deltaPadding; + + /* skip old padding and default */ + skip(((pos+4) & (~3)) - (pos+1) + 4); + low = get_u4(); + skip((get_u4() - low + 1) * 4); + + deltaPadding = ((newPos+4) & (~3)) - newPos - ((pos+4) & (~3)) + pos; + if (widened != deltaPadding) { + widen(pos, deltaPadding); + return NSK_FALSE; /* cause restart */ + } + break; + } + + case opc_lookupswitch: { + jbyte widened = widening[pos]; + jbyte deltaPadding; + + /* skip old padding and default */ + skip(((pos+4) & (~3)) - (pos+1) + 4); + skip(get_u4() * 8); + + deltaPadding = ((newPos+4) & (~3)) - newPos - ((pos+4) & (~3)) + pos; + if (widened != deltaPadding) { + widen(pos, deltaPadding); + return NSK_FALSE; /* cause restart */ + } + break; + } + + default: + skip(opcLengths[opcode] - 1); + break; + } + + return NSK_TRUE; + } + + /* ========================================================================== */ + + /** + * Walk one instruction inserting instrumentation at specified instructions + */ + static void insertAtInstruction() { + u4 pos = localPosition(); + u1 opcode = get_u1(); + + switch (opcode) { + + case opc_wide: + /* no support for instrumenting wide instructions */ + skip(get_u1() == opc_iinc ? 4 : 2); + break; + + case opc_new: + case opc_newarray: + case opc_anewarray: + case opc_multianewarray: + skip(opcLengths[opcode] - 1); + injectBytes(localPosition(), 3); + break; + + case opc_tableswitch: + /* skip 4-byte boundry padding and default */ + skip(((pos+4) & (~3)) - (pos+1) + 4); + { + u4 low = get_u4(); + skip((get_u4() - low + 1) * 4); + } + break; + + case opc_lookupswitch: + /* skip 4-byte boundry padding and default */ + skip(((pos+4) & (~3)) - (pos+1) + 4); + skip(get_u4() * 8); + break; + + default: + skip(opcLengths[opcode] - 1); + break; + + } + } + + static void adjustOffsets() { + recallPosition(); + + if (mode == BCI_MODE_CALL) { + /* instrument calls - method entry */ + injectBytes(0, 3); + } + + if (mode == BCI_MODE_ALLOC) { + /* instrument allocations */ + while (localPosition() < codeLength) { + insertAtInstruction(); + } + recallPosition(); + } + + NSK_DISPLAY0("Searching for adjustments...\n"); + while (localPosition() < codeLength) { + if (!adjustInstruction()) { + recallPosition(); + NSK_DISPLAY0("Restarting adjustments after change...\n"); + } + } + + NSK_DISPLAY0("Writing new code...\n"); + recallPosition(); + + if (mode == BCI_MODE_CALL) { + put(callBytes, 3); + } + + while (localPosition() < codeLength) { + writeInstruction(); + } + } + + /* ========================================================================== */ + + static void copyAttr() { + u4 len; + + copy(2); + len = copy_u4(); + NSK_DISPLAY1("attr len: %d\n", len); + copy(len); + } + + static void copyAttrs(u2 attrCount) { + u2 i; + + for (i = attrCount; i > 0; i--) { + copyAttr(); + } + } + + static void copyFields() { + u2 count; + u2 attrCount; + u2 i; + + count = copy_u2(); + NSK_DISPLAY1("fields count: %d\n", count); + for (i = count; i > 0; i--) { + /* access, name, descriptor */ + copy(2 + 2 + 2); + attrCount = copy_u2(); + NSK_DISPLAY1("field attrCount: %d\n", attrCount); + copyAttrs(attrCount); + } + } + + static void copyAttrForCode() { + u2 nameIndex = copy_u2(); + + /* check for Code attr */ + if (nameIndex == lineNumberAttributeIndex) { + copyLineNumberAttr(); + } else if (nameIndex == localVarAttributeIndex) { + copyLocalVarAttr(); + } else if (nameIndex == localVarTypeAttributeIndex) { + copyLocalVarTypeAttr(); + } else if (nameIndex == stackMapAttributeIndex) { + copyStackMapAttr(); + } else { + u4 len = copy_u4(); + NSK_DISPLAY1("code attr len: %d\n", len); + copy(len); + } + } + + static void copyCodeAttr(char* name) { + u4 attrLengthPos; + u4 attrLength; + u4 newAttrLength; + u4 codeLengthPos; + u4 newCodeLength; + u2 attrCount; + u4 i; + + attrLengthPos = generatedPosition(); + attrLength = copy_u4(); + + NSK_DISPLAY2("Code attr found: %s, pos=0x%x\n", name, + inputPos - orig - 6); + + /* max_stack, max_locals */ + copy(2 + 2); + + codeLengthPos = generatedPosition(); + codeLength = copy_u4(); + + if (codeLength == 0) { + NSK_COMPLAIN0("code_length must be greater than zero\n"); + return; + } + + if (mode == BCI_MODE_EMCP) { + /* copy remainder minus already copied */ + copy(attrLength - 8); + return; + } + + markLocalPositionStart(); + + map = (u4*) malloc((codeLength + 1) * sizeof(u4)); + for (i = 0; i <= codeLength; i++) { + map[i] = i; + } + + widening = (jbyte*) malloc(codeLength + 1); + memset(widening, 0, codeLength + 1); + + adjustOffsets(); + + /* fix up code length */ + newCodeLength = generatedPosition() - (codeLengthPos + 4); + randomAccessWriteU4(codeLengthPos, newCodeLength); + NSK_DISPLAY2("code length old: %d, new: %d\n", + codeLength, newCodeLength); + + copyExceptionTable(); + + attrCount = copy_u2(); + for (i = attrCount; i > 0; i--) { + copyAttrForCode(); + } + + free(map); + free(widening); + + /* fix up attr length */ + newAttrLength = generatedPosition() - (attrLengthPos + 4); + randomAccessWriteU4(attrLengthPos, newAttrLength); + NSK_DISPLAY2("attr length old: %d, new: %d\n", + attrLength, newAttrLength); + } + + static void copyAttrForMethod(char* name) { + u2 nameIndex; + + nameIndex = copy_u2(); + if (nameIndex == codeAttributeIndex) { + copyCodeAttr(name); + } else { + u4 len = copy_u4(); + + NSK_DISPLAY1("method attr len: %d\n", len); + copy(len); + } + } + + static void copyMethod() { + u2 accessFlags; + u2 methodNameIdx; + char* name; + u2 attrCount; + u2 i; + + accessFlags = copy_u2(); + methodNameIdx = copy_u2(); + name = constantPool[methodNameIdx]; + + /* descriptor */ + copy(2); + + attrCount = copy_u2(); + NSK_DISPLAY1("method attrCount: %d\n", attrCount); + for (i = attrCount; i > 0; i--) { + copyAttrForMethod(name); + } + } + + static void copyMethods() { + u2 count; + u2 i; + + count = copy_u2(); + NSK_DISPLAY1("methods count: %d\n", count); + for (i = count; i > 0; i--) { + copyMethod(); + } + } + + static u2 writeCPEntryUtf8(const char* str) { + u2 i; + u2 len = (u2) strlen(str); + put_u1(CONSTANT_Utf8); + put_u2(len); + for (i = 0; i < len; i++) { + put_u1(str[i]); + } + return constantPoolCount++; + } + + static u2 writeCPEntryClass(u2 classNameIndex) { + put_u1(CONSTANT_Class); + put_u2(classNameIndex); + return constantPoolCount++; + } + + static u2 writeCPEntryNameAndType(u2 nameIndex, u2 descrIndex) { + put_u1(CONSTANT_NameAndType); + put_u2(nameIndex); + put_u2(descrIndex); + return constantPoolCount++; + } + + static u2 writeCPEntryMethodRef(u2 classIndex, u2 nameAndTypeIndex) { + put_u1(CONSTANT_Methodref); + put_u2(classIndex); + put_u2(nameAndTypeIndex); + return constantPoolCount++; + } + + static u2 writeCPEntryFieldRef(u2 classIndex, u2 nameAndTypeIndex) { + put_u1(CONSTANT_Fieldref); + put_u2(classIndex); + put_u2(nameAndTypeIndex); + return constantPoolCount++; + } + + static u2 addFieldToConstantPool(u2 classIndex, char* fieldName, char* descr) { + u2 fieldNameIndex = writeCPEntryUtf8(fieldName); + u2 descrIndex = writeCPEntryUtf8(descr); + u2 nameAndTypeIndex = writeCPEntryNameAndType(fieldNameIndex, descrIndex); + u2 fieldIndex = writeCPEntryFieldRef(classIndex, nameAndTypeIndex); + return fieldIndex; + } + + static u2 addMethodToConstantPool(u2 classIndex, const char* methodName, const char* descr) { + u2 methodNameIndex = writeCPEntryUtf8(methodName); + u2 descrIndex = writeCPEntryUtf8(descr); + u2 nameAndTypeIndex = writeCPEntryNameAndType(methodNameIndex, descrIndex); + u2 methodIndex = writeCPEntryMethodRef(classIndex, nameAndTypeIndex); + return methodIndex; + } + + static u2 addClassToConstantPool(const char* className) { + u2 classNameIndex = writeCPEntryUtf8(className); + u2 classIndex = writeCPEntryClass(classNameIndex); + return classIndex; + } + + /* ========================================================================== */ + + int Inject(const u1* old_bytes, const jint old_length, + u1** new_bytes, jint* new_length, int bci_mode) { + u4 constantPoolCountPos; + u2 profiler; + u2 interfaceCount; + u2 attrCount; + + //printf("inject\n"); + NSK_DISPLAY3("Injecting bytecodes: mode=%d, bytes=0x%p, len=%d\n", + bci_mode, old_bytes, old_length); + + mode = bci_mode; + orig = old_bytes; + inputPos = (u1*) orig; + endPos = orig + old_length; + gen = (u1*) malloc(old_length * GROWTH_FACTOR); + if (!NSK_VERIFY(gen != NULL)) { + NSK_COMPLAIN0("out of memory\n"); + return NSK_FALSE; + } + + genPos = gen; + + /* magic + minor/major version */ + copy(4 + 2 + 2); + + constantPoolCountPos = generatedPosition(); + constantPoolCount = copy_u2(); + + /* copy old constant pool */ + if (!copyConstantPool(constantPoolCount)) { + return NSK_FALSE; + } + NSK_DISPLAY1("ConstantPool expanded from: %d\n", constantPoolCount); + + profiler = addClassToConstantPool("nsk/share/jvmti/ProfileCollector"); + + if (mode == BCI_MODE_ALLOC) { + u2 allocTracker = + addMethodToConstantPool(profiler, "allocTracker", "()V"); + allocBytes[1] = (u1) (allocTracker >> 8); + allocBytes[2] = (u1) (allocTracker & 0xFF); + } + + if (mode == BCI_MODE_CALL) { + u2 callTracker = + addMethodToConstantPool(profiler, "callTracker", "()V"); + callBytes[1] = (u1) (callTracker >> 8); + callBytes[2] = (u1) (callTracker & 0xFF); + } + + /* access, this, super */ + copy(2 + 2 + 2); + + interfaceCount = copy_u2(); + NSK_DISPLAY1("interfaceCount: %d\n", interfaceCount); + copy(interfaceCount * 2); + + copyFields(); + copyMethods(); + + attrCount = copy_u2(); + NSK_DISPLAY1("class attrCount: %d\n", attrCount); + copyAttrs(attrCount); + + randomAccessWriteU2(constantPoolCountPos, constantPoolCount); + NSK_DISPLAY1("New constant pool size: %d\n", constantPoolCount); + + *new_length = (jint) (genPos - gen); + *new_bytes = (u1*) realloc(gen, *new_length); + + freeConstantPool(); + + return NSK_TRUE; + } + + /* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/JVMTITools.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/JVMTITools.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/JVMTITools.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/JVMTITools.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_common/agent_common.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_common/agent_common.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_common/agent_common.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_common/agent_common.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_tools.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_tools.c deleted file mode 100644 index b61d254f41b..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_tools.c +++ /dev/null @@ -1,815 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include - -#include "native_thread.h" -#include "jni_tools.h" -#include "jvmti_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -/* Be careful: do not build shared library which will be linked with different - * agent libs while global variables are used - * Now the same source is used to build different agent libs, so these - * variables are not shared between agents */ - -static jthread agentThread = NULL; -static jvmtiStartFunction agentThreadProc = NULL; -static void* agentThreadArg = NULL; - - -typedef enum {NEW, RUNNABLE, WAITING, SUSPENDED, TERMINATED} thread_state_t; - -typedef struct agent_data_t { - volatile thread_state_t thread_state; - int last_debuggee_status; - jrawMonitorID monitor; -} agent_data_t; - -static agent_data_t agent_data; - -static jvmtiEnv* jvmti_env = NULL; -static JavaVM* jvm = NULL; -static JNIEnv* jni_env = NULL; - -static volatile int currentAgentStatus = NSK_STATUS_PASSED; - -/* ============================================================================= */ - -void nsk_jvmti_setFailStatus() { - currentAgentStatus = NSK_STATUS_FAILED; -} - -int nsk_jvmti_isFailStatus() { - return (nsk_jvmti_getStatus() != NSK_STATUS_PASSED); -} - -jint nsk_jvmti_getStatus() { - return currentAgentStatus; -} - -/* ============================================================================= */ -static jvmtiError init_agent_data(jvmtiEnv *jvmti_env, agent_data_t *data) { - data->thread_state = NEW; - data->last_debuggee_status = NSK_STATUS_PASSED; - - return NSK_CPP_STUB3(CreateRawMonitor, jvmti_env, "agent_data_monitor", &data->monitor); -} - -/** Reset agent data to prepare for another run. */ -void nsk_jvmti_resetAgentData() { - rawMonitorEnter(jvmti_env, agent_data.monitor); - /* wait for agentThreadWrapper() to finish */ - while (agent_data.thread_state != TERMINATED) { - rawMonitorWait(jvmti_env, agent_data.monitor, 10); - } - agent_data.thread_state = NEW; - agent_data.last_debuggee_status = NSK_STATUS_PASSED; - rawMonitorExit(jvmti_env, agent_data.monitor); -} - -static jvmtiError free_agent_data(jvmtiEnv *jvmti_env, agent_data_t *data) { - return NSK_CPP_STUB2(DestroyRawMonitor, jvmti_env, data->monitor); -} - -/** Create JVMTI environment. */ -jvmtiEnv* nsk_jvmti_createJVMTIEnv(JavaVM* javaVM, void* reserved) { - jvm = javaVM; - if (!NSK_VERIFY( - NSK_CPP_STUB3(GetEnv, javaVM, (void **)&jvmti_env, JVMTI_VERSION_1_1) == JNI_OK)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - if (!NSK_JVMTI_VERIFY(init_agent_data(jvmti_env, &agent_data))) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - return jvmti_env; -} - -/** Dispose JVMTI environment */ -static int nsk_jvmti_disposeJVMTIEnv(jvmtiEnv* jvmti_env) { - if (jvmti_env != NULL) { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB1(DisposeEnvironment, jvmti_env))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - if (!NSK_JVMTI_VERIFY(free_agent_data(jvmti_env, &agent_data))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - return NSK_TRUE; -} - -/** Get JNI environment for agent thread. */ -JNIEnv* nsk_jvmti_getAgentJNIEnv() { - return jni_env; -} - -/** Get JVMTI environment for agent */ -jvmtiEnv* nsk_jvmti_getAgentJVMTIEnv() { - return jvmti_env; -} - -/* ============================================================================= */ -static void set_agent_thread_state(thread_state_t value) { - rawMonitorEnter(jvmti_env, agent_data.monitor); - agent_data.thread_state = value; - rawMonitorNotify(jvmti_env, agent_data.monitor); - rawMonitorExit(jvmti_env, agent_data.monitor); -} - -/** Wrapper for user agent thread. */ -static void JNICALL -agentThreadWrapper(jvmtiEnv* jvmti_env, JNIEnv* agentJNI, void* arg) { - jni_env = agentJNI; - - /* run user agent proc */ - { - set_agent_thread_state(RUNNABLE); - - NSK_TRACE((*agentThreadProc)(jvmti_env, agentJNI, agentThreadArg)); - - set_agent_thread_state(TERMINATED); - } - - /* finalize agent thread */ - { - /* gelete global ref for agent thread */ - NSK_CPP_STUB2(DeleteGlobalRef, agentJNI, agentThread); - agentThread = NULL; - } -} - -/** Start wrapper for user agent thread. */ -static jthread startAgentThreadWrapper(JNIEnv *jni_env, jvmtiEnv* jvmti_env) { - const jint THREAD_PRIORITY = JVMTI_THREAD_MAX_PRIORITY; - const char* THREAD_NAME = "JVMTI agent thread"; - const char* THREAD_CLASS_NAME = "java/lang/Thread"; - const char* THREAD_CTOR_NAME = ""; - const char* THREAD_CTOR_SIGNATURE = "(Ljava/lang/String;)V"; - - jobject threadName = NULL; - jclass threadClass = NULL; - jmethodID threadCtor = NULL; - jobject threadObject = NULL; - jobject threadGlobalRef = NULL; - - if (!NSK_JNI_VERIFY(jni_env, (threadClass = - NSK_CPP_STUB2(FindClass, jni_env, THREAD_CLASS_NAME)) != NULL)) { - return NULL; - } - - if (!NSK_JNI_VERIFY(jni_env, (threadCtor = - NSK_CPP_STUB4(GetMethodID, jni_env, threadClass, THREAD_CTOR_NAME, THREAD_CTOR_SIGNATURE)) != NULL)) - return NULL; - - if (!NSK_JNI_VERIFY(jni_env, (threadName = - NSK_CPP_STUB2(NewStringUTF, jni_env, THREAD_NAME)) != NULL)) - return NULL; - - if (!NSK_JNI_VERIFY(jni_env, (threadObject = - NSK_CPP_STUB4(NewObject, jni_env, threadClass, threadCtor, threadName)) != NULL)) - return NULL; - - if (!NSK_JNI_VERIFY(jni_env, (threadGlobalRef = - NSK_CPP_STUB2(NewGlobalRef, jni_env, threadObject)) != NULL)) { - NSK_CPP_STUB2(DeleteLocalRef, jni_env, threadObject); - return NULL; - } - agentThread = (jthread)threadGlobalRef; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(RunAgentThread, jvmti_env, agentThread, - &agentThreadWrapper, agentThreadArg, THREAD_PRIORITY))) { - NSK_CPP_STUB2(DeleteGlobalRef, jni_env, threadGlobalRef); - NSK_CPP_STUB2(DeleteLocalRef, jni_env, threadObject); - return NULL; - } - return agentThread; -} - -/** Register user agent thread with arg. */ -int nsk_jvmti_setAgentProc(jvmtiStartFunction proc, void* arg) { - agentThreadProc = proc; - agentThreadArg = arg; - return NSK_TRUE; -} - -/** Get agent thread ref. */ -jthread nsk_jvmti_getAgentThread() { - return agentThread; -} - -/** Run registered user agent thread via wrapper. */ -static jthread nsk_jvmti_runAgentThread(JNIEnv *jni_env, jvmtiEnv* jvmti_env) { - /* start agent thread wrapper */ - jthread thread = startAgentThreadWrapper(jni_env, jvmti_env); - if (thread == NULL) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - return thread; -} - -/* ============================================================================= */ - -/** Sleep current thread. */ -void nsk_jvmti_sleep(jlong timeout) { - int seconds = (int)((timeout + 999) / 1000); - THREAD_sleep(seconds); -} - -/** Sync point called from Java code. */ -static jint syncDebuggeeStatus(JNIEnv* jni_env, jvmtiEnv* jvmti_env, jint debuggeeStatus) { - jint result = NSK_STATUS_FAILED; - - rawMonitorEnter(jvmti_env, agent_data.monitor); - - /* save last debugee status */ - agent_data.last_debuggee_status = debuggeeStatus; - - /* we don't enter if-stmt in second call */ - if (agent_data.thread_state == NEW) { - if (nsk_jvmti_runAgentThread(jni_env, jvmti_env) == NULL) - goto monitor_exit_and_return; - - /* SP2.2-w - wait for agent thread */ - while (agent_data.thread_state == NEW) { - rawMonitorWait(jvmti_env, agent_data.monitor, 0); - } - } - - /* wait for sync permit */ - /* we don't enter loop in first call */ - while (agent_data.thread_state != WAITING && agent_data.thread_state != TERMINATED) { - /* SP4.2-w - second wait for agent thread */ - rawMonitorWait(jvmti_env, agent_data.monitor, 0); - } - - if (agent_data.thread_state != TERMINATED) { - agent_data.thread_state = SUSPENDED; - /* SP3.2-n - notify to start test */ - /* SP6.2-n - notify to end test */ - rawMonitorNotify(jvmti_env, agent_data.monitor); - } - else { - NSK_COMPLAIN0("Debuggee status sync aborted because agent thread has finished\n"); - goto monitor_exit_and_return; - } - - /* update status from debuggee */ - if (debuggeeStatus != NSK_STATUS_PASSED) { - nsk_jvmti_setFailStatus(); - } - - while (agent_data.thread_state == SUSPENDED) { - /* SP5.2-w - wait while testing */ - /* SP7.2 - wait for agent end */ - rawMonitorWait(jvmti_env, agent_data.monitor, 0); - } - - agent_data.last_debuggee_status = nsk_jvmti_getStatus(); - result = agent_data.last_debuggee_status; - -monitor_exit_and_return: - rawMonitorExit(jvmti_env, agent_data.monitor); - return result; -} - -/** Wait for sync point with Java code. */ -int nsk_jvmti_waitForSync(jlong timeout) { - static const int inc_timeout = 1000; - - jlong t = 0; - int result = NSK_TRUE; - - rawMonitorEnter(jvmti_env, agent_data.monitor); - - agent_data.thread_state = WAITING; - - /* SP2.2-n - notify agent is waiting and wait */ - /* SP4.1-n - notify agent is waiting and wait */ - rawMonitorNotify(jvmti_env, agent_data.monitor); - - while (agent_data.thread_state == WAITING) { - /* SP3.2-w - wait to start test */ - /* SP6.2-w - wait to end test */ - rawMonitorWait(jvmti_env, agent_data.monitor, inc_timeout); - - if (timeout == 0) continue; - - t += inc_timeout; - - if (t >= timeout) break; - } - - if (agent_data.thread_state == WAITING) { - NSK_COMPLAIN1("No status sync occured for timeout: %"LL"d ms\n", timeout); - nsk_jvmti_setFailStatus(); - result = NSK_FALSE; - } - - rawMonitorExit(jvmti_env, agent_data.monitor); - - return result; -} - -/** Resume java code suspended on sync point. */ -int nsk_jvmti_resumeSync() { - int result; - rawMonitorEnter(jvmti_env, agent_data.monitor); - - if (agent_data.thread_state == SUSPENDED) { - result = NSK_TRUE; - agent_data.thread_state = RUNNABLE; - /* SP5.2-n - notify suspend done */ - /* SP7.2-n - notify agent end */ - rawMonitorNotify(jvmti_env, agent_data.monitor); - } - else { - NSK_COMPLAIN0("Debuggee was not suspended on status sync\n"); - nsk_jvmti_setFailStatus(); - result = NSK_FALSE; - } - - rawMonitorExit(jvmti_env, agent_data.monitor); - return NSK_TRUE; -} - -/** Native function for Java code to provide sync point. */ -JNIEXPORT jint JNICALL -Java_nsk_share_jvmti_DebugeeClass_checkStatus(JNIEnv* jni_env, jclass cls, jint debuggeeStatus) { - jint status; - NSK_TRACE(status = syncDebuggeeStatus(jni_env, jvmti_env, debuggeeStatus)); - return status; -} - -/** Native function for Java code to reset agent data. */ -JNIEXPORT void JNICALL -Java_nsk_share_jvmti_DebugeeClass_resetAgentData(JNIEnv* jni_env, jclass cls) { - NSK_TRACE(nsk_jvmti_resetAgentData()); -} - -/* ============================================================================= */ - -/** Find loaded class by signature. */ -jclass nsk_jvmti_classBySignature(const char signature[]) { - jclass* classes = NULL; - jint count = 0; - jclass foundClass = NULL; - int i; - - if (!NSK_VERIFY(signature != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetLoadedClasses, jvmti_env, &count, &classes))) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - for (i = 0; i < count; i++) { - char* sig = NULL; - char* generic = NULL; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, classes[i], &sig, &generic))) { - nsk_jvmti_setFailStatus(); - break; - } - - if (sig != NULL && strcmp(signature, sig) == 0) { - foundClass = classes[i]; - } - - if (!(NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig)) - && NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)generic)))) { - nsk_jvmti_setFailStatus(); - break; - } - - if (foundClass != NULL) - break; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)classes))) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - if (!NSK_JNI_VERIFY(jni_env, (foundClass = (jclass) - NSK_CPP_STUB2(NewGlobalRef, jni_env, foundClass)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - return foundClass; -} - -/** Find alive thread by name. */ -jthread nsk_jvmti_threadByName(const char name[]) { - jthread* threads = NULL; - jint count = 0; - jthread foundThread = NULL; - int i; - - if (!NSK_VERIFY(name != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetAllThreads, jvmti_env, &count, &threads))) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - for (i = 0; i < count; i++) { - jvmtiThreadInfo info; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetThreadInfo, jvmti_env, threads[i], &info))) { - nsk_jvmti_setFailStatus(); - break; - } - - if (info.name != NULL && strcmp(name, info.name) == 0) { - foundThread = threads[i]; - break; - } - } - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)threads))) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - if (!NSK_JNI_VERIFY(jni_env, (foundThread = (jthread) - NSK_CPP_STUB2(NewGlobalRef, jni_env, foundThread)) != NULL)) { - nsk_jvmti_setFailStatus(); - return NULL; - } - - return foundThread; -} - - -/* ============================================================================= */ - -/** Add all capabilities for finding line locations. */ -int nsk_jvmti_addLocationCapabilities() { - jvmtiCapabilities caps; - - memset(&caps, 0, sizeof(caps)); - caps.can_get_line_numbers = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti_env, &caps))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/** Add all capabilities for using breakpoints. */ -int nsk_jvmti_addBreakpointCapabilities() { - jvmtiCapabilities caps; - - if (!nsk_jvmti_addLocationCapabilities()) - return NSK_FALSE; - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_breakpoint_events = 1; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB2(AddCapabilities, jvmti_env, &caps))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/** Find line location. */ -jlocation nsk_jvmti_getLineLocation(jclass cls, jmethodID method, int line) { - jint count = 0; - jvmtiLineNumberEntry* table = NULL; - jlocation location = NSK_JVMTI_INVALID_JLOCATION; - int i; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetLineNumberTable, jvmti_env, method, &count, &table))) - return NSK_JVMTI_INVALID_JLOCATION; - - for (i = 0; i < count; i++) { - if (table[i].line_number == line) { - location = table[i].start_location; - break; - } - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)table))) - return NSK_JVMTI_INVALID_JLOCATION; - - return location; -} - -/** Set breakpoint to a line. */ -jlocation nsk_jvmti_setLineBreakpoint(jclass cls, jmethodID method, int line) { - jlocation location = NSK_JVMTI_INVALID_JLOCATION; - - if (!NSK_VERIFY((location = - nsk_jvmti_getLineLocation(cls, method, line)) != NSK_JVMTI_INVALID_JLOCATION)) - return NSK_JVMTI_INVALID_JLOCATION; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetBreakpoint, jvmti_env, method, location))) - return NSK_JVMTI_INVALID_JLOCATION; - - return location; -} - -/** Remove breakpoint from a line. */ -jlocation nsk_jvmti_clearLineBreakpoint(jclass cls, jmethodID method, int line) { - jlocation location = NSK_JVMTI_INVALID_JLOCATION; - - if (!NSK_VERIFY((location = - nsk_jvmti_getLineLocation(cls, method, line)) != NSK_JVMTI_INVALID_JLOCATION)) - return NSK_JVMTI_INVALID_JLOCATION; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(ClearBreakpoint, jvmti_env, method, location))) - return NSK_JVMTI_INVALID_JLOCATION; - - return location; -} - -/* ============================================================================= */ - -/** Enable or disable given events. */ -int nsk_jvmti_enableEvents(jvmtiEventMode enable, int size, jvmtiEvent list[], jthread thread) { - int i; - - for (i = 0; i < size; i++) { - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, enable, - list[i], thread))) { - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - } - return NSK_TRUE; -} - -/* ============================================================================= */ - -typedef jint (JNICALL *checkStatus_type)(JNIEnv* jni_env, jclass cls, jint debuggeeStatus); - -static checkStatus_type checkStatus_func = NULL; - -/** - * Proxy function to gain sequential access to checkStatus of each agent - */ -JNIEXPORT jint JNICALL -MA_checkStatus(JNIEnv* jni_env, jclass cls, jint debuggeeStatus) { - jint status; - - NSK_TRACE(status = syncDebuggeeStatus(jni_env, jvmti_env, debuggeeStatus)); - return (*checkStatus_func)(jni_env, cls, status); -} - -/** - * nativeMethodBind callback: - * if needed, redirects checkStatus native method call - */ -static void JNICALL nativeMethodBind(jvmtiEnv* jvmti_env, JNIEnv *jni_env, - jthread thread, jmethodID mid, - void* address, void** new_address_ptr) { - const char* BIND_CLASS_NAME = "Lnsk/share/jvmti/DebugeeClass;"; - const char* BIND_METHOD_NAME = "checkStatus"; - const char* BIND_METHOD_SIGNATURE = "(I)I"; - - jvmtiPhase phase; - jclass cls; - char *class_sig = NULL; - char *name = NULL; - char *sig = NULL; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { - nsk_jvmti_setFailStatus(); - return; - } - - if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE) - return; - - if (NSK_JVMTI_VERIFY( - NSK_CPP_STUB5(GetMethodName, jvmti_env, mid, &name, &sig, NULL))) { - if (strcmp(name, BIND_METHOD_NAME) == 0 && - strcmp(sig, BIND_METHOD_SIGNATURE) == 0) { - - if (NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(GetMethodDeclaringClass, jvmti_env, mid, &cls)) - && NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(GetClassSignature, jvmti_env, cls, &class_sig, NULL)) - && strcmp(class_sig, BIND_CLASS_NAME) == 0 - && address != (void*)Java_nsk_share_jvmti_DebugeeClass_checkStatus) { - checkStatus_func = (checkStatus_type)address; - NSK_TRACE(*new_address_ptr = (void*)MA_checkStatus); - } - } - } - - if (name != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - - if (sig != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); - - if (class_sig != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)class_sig); -} - -/** - * Initialize multiple agent: - * establish processing of nativeMethodBind events - */ -int nsk_jvmti_init_MA(jvmtiEventCallbacks* callbacks) { - - if (callbacks == NULL) { - NSK_COMPLAIN0("callbacks should not be NULL\n"); - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - if (callbacks->NativeMethodBind != NULL) { - NSK_COMPLAIN0("callbacks.NativeMethodBind should be NULL\n"); - nsk_jvmti_setFailStatus(); - return NSK_FALSE; - } - - { - jvmtiCapabilities caps; - memset(&caps, 0, sizeof(caps)); - caps.can_generate_native_method_bind_events = 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti_env, &caps))) - return NSK_FALSE; - } - - callbacks->NativeMethodBind = nativeMethodBind; - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(SetEventCallbacks, jvmti_env, callbacks, - sizeof(jvmtiEventCallbacks)))) - return NSK_FALSE; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_ENABLE, - JVMTI_EVENT_NATIVE_METHOD_BIND, NULL))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -int nsk_jvmti_isOptionalEvent(jvmtiEvent event) { - - return (event == JVMTI_EVENT_EXCEPTION) - || (event == JVMTI_EVENT_EXCEPTION_CATCH) - || (event == JVMTI_EVENT_SINGLE_STEP) - || (event == JVMTI_EVENT_FRAME_POP) - || (event == JVMTI_EVENT_BREAKPOINT) - || (event == JVMTI_EVENT_FIELD_ACCESS) - || (event == JVMTI_EVENT_FIELD_MODIFICATION) - || (event == JVMTI_EVENT_METHOD_ENTRY) - || (event == JVMTI_EVENT_METHOD_EXIT) - || (event == JVMTI_EVENT_NATIVE_METHOD_BIND) - || (event == JVMTI_EVENT_COMPILED_METHOD_LOAD) - || (event == JVMTI_EVENT_COMPILED_METHOD_UNLOAD) - || (event == JVMTI_EVENT_MONITOR_WAIT) - || (event == JVMTI_EVENT_MONITOR_WAITED) - || (event == JVMTI_EVENT_MONITOR_CONTENDED_ENTER) - || (event == JVMTI_EVENT_MONITOR_CONTENDED_ENTERED) - || (event == JVMTI_EVENT_GARBAGE_COLLECTION_START) - || (event == JVMTI_EVENT_GARBAGE_COLLECTION_FINISH) - || (event == JVMTI_EVENT_OBJECT_FREE) - || (event == JVMTI_EVENT_VM_OBJECT_ALLOC); -} - -/* ============================================================================= */ - -void nsk_jvmti_showPossessedCapabilities(jvmtiEnv *jvmti_env) { - - jvmtiCapabilities caps; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, jvmti_env, &caps))) { - return; - } - - NSK_DISPLAY0("\n"); - NSK_DISPLAY0("Possessed capabilities:\n"); - NSK_DISPLAY0("-----------------------\n"); - if (caps.can_tag_objects) - NSK_DISPLAY0("\tcan_tag_objects\n"); - if (caps.can_generate_field_modification_events) - NSK_DISPLAY0("\tcan_generate_field_modification_events\n"); - if (caps.can_generate_field_access_events) - NSK_DISPLAY0("\tcan_generate_field_access_events\n"); - if (caps.can_get_bytecodes) - NSK_DISPLAY0("\tcan_get_bytecodes\n"); - if (caps.can_get_synthetic_attribute) - NSK_DISPLAY0("\tcan_get_synthetic_attribute\n"); - if (caps.can_get_owned_monitor_info) - NSK_DISPLAY0("\tcan_get_owned_monitor_info\n"); - if (caps.can_get_current_contended_monitor) - NSK_DISPLAY0("\tcan_get_current_contended_monitor\n"); - if (caps.can_get_monitor_info) - NSK_DISPLAY0("\tcan_get_monitor_info\n"); - if (caps.can_pop_frame) - NSK_DISPLAY0("\tcan_pop_frame\n"); - if (caps.can_redefine_classes) - NSK_DISPLAY0("\tcan_redefine_classes\n"); - if (caps.can_signal_thread) - NSK_DISPLAY0("\tcan_signal_thread\n"); - if (caps.can_get_source_file_name) - NSK_DISPLAY0("\tcan_get_source_file_name\n"); - if (caps.can_get_line_numbers) - NSK_DISPLAY0("\tcan_get_line_numbers\n"); - if (caps.can_get_source_debug_extension) - NSK_DISPLAY0("\tcan_get_source_debug_extension\n"); - if (caps.can_access_local_variables) - NSK_DISPLAY0("\tcan_access_local_variables\n"); - if (caps.can_maintain_original_method_order) - NSK_DISPLAY0("\tcan_maintain_original_method_order\n"); - if (caps.can_generate_single_step_events) - NSK_DISPLAY0("\tcan_generate_single_step_events\n"); - if (caps.can_generate_exception_events) - NSK_DISPLAY0("\tcan_generate_exception_events\n"); - if (caps.can_generate_frame_pop_events) - NSK_DISPLAY0("\tcan_generate_frame_pop_events\n"); - if (caps.can_generate_breakpoint_events) - NSK_DISPLAY0("\tcan_generate_breakpoint_events\n"); - if (caps.can_suspend) - NSK_DISPLAY0("\tcan_suspend\n"); - if (caps.can_get_current_thread_cpu_time) - NSK_DISPLAY0("\tcan_get_current_thread_cpu_time\n"); - if (caps.can_get_thread_cpu_time) - NSK_DISPLAY0("\tcan_get_thread_cpu_time\n"); - if (caps.can_generate_method_entry_events) - NSK_DISPLAY0("\tcan_generate_method_entry_events\n"); - if (caps.can_generate_method_exit_events) - NSK_DISPLAY0("\tcan_generate_method_exit_events\n"); - if (caps.can_generate_all_class_hook_events) - NSK_DISPLAY0("\tcan_generate_all_class_hook_events\n"); - if (caps.can_generate_compiled_method_load_events) - NSK_DISPLAY0("\tcan_generate_compiled_method_load_events\n"); - if (caps.can_generate_monitor_events) - NSK_DISPLAY0("\tcan_generate_monitor_events\n"); - if (caps.can_generate_vm_object_alloc_events) - NSK_DISPLAY0("\tcan_generate_vm_object_alloc_events\n"); - if (caps.can_generate_native_method_bind_events) - NSK_DISPLAY0("\tcan_generate_native_method_bind_events\n"); - if (caps.can_generate_garbage_collection_events) - NSK_DISPLAY0("\tcan_generate_garbage_collection_events\n"); - if (caps.can_generate_object_free_events) - NSK_DISPLAY0("\tcan_generate_object_free_events\n"); - - NSK_DISPLAY0("\n"); -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_tools.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_tools.cpp new file mode 100644 index 00000000000..09e08ac2245 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_tools.cpp @@ -0,0 +1,815 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include + +#include "native_thread.h" +#include "jni_tools.h" +#include "jvmti_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +/* Be careful: do not build shared library which will be linked with different + * agent libs while global variables are used + * Now the same source is used to build different agent libs, so these + * variables are not shared between agents */ + +static jthread agentThread = NULL; +static jvmtiStartFunction agentThreadProc = NULL; +static void* agentThreadArg = NULL; + + +typedef enum {NEW, RUNNABLE, WAITING, SUSPENDED, TERMINATED} thread_state_t; + +typedef struct agent_data_t { + volatile thread_state_t thread_state; + int last_debuggee_status; + jrawMonitorID monitor; +} agent_data_t; + +static agent_data_t agent_data; + +static jvmtiEnv* jvmti_env = NULL; +static JavaVM* jvm = NULL; +static JNIEnv* jni_env = NULL; + +static volatile int currentAgentStatus = NSK_STATUS_PASSED; + +/* ============================================================================= */ + +void nsk_jvmti_setFailStatus() { + currentAgentStatus = NSK_STATUS_FAILED; +} + +int nsk_jvmti_isFailStatus() { + return (nsk_jvmti_getStatus() != NSK_STATUS_PASSED); +} + +jint nsk_jvmti_getStatus() { + return currentAgentStatus; +} + +/* ============================================================================= */ +static jvmtiError init_agent_data(jvmtiEnv *jvmti_env, agent_data_t *data) { + data->thread_state = NEW; + data->last_debuggee_status = NSK_STATUS_PASSED; + + return NSK_CPP_STUB3(CreateRawMonitor, jvmti_env, "agent_data_monitor", &data->monitor); +} + +/** Reset agent data to prepare for another run. */ +void nsk_jvmti_resetAgentData() { + rawMonitorEnter(jvmti_env, agent_data.monitor); + /* wait for agentThreadWrapper() to finish */ + while (agent_data.thread_state != TERMINATED) { + rawMonitorWait(jvmti_env, agent_data.monitor, 10); + } + agent_data.thread_state = NEW; + agent_data.last_debuggee_status = NSK_STATUS_PASSED; + rawMonitorExit(jvmti_env, agent_data.monitor); +} + +static jvmtiError free_agent_data(jvmtiEnv *jvmti_env, agent_data_t *data) { + return NSK_CPP_STUB2(DestroyRawMonitor, jvmti_env, data->monitor); +} + +/** Create JVMTI environment. */ +jvmtiEnv* nsk_jvmti_createJVMTIEnv(JavaVM* javaVM, void* reserved) { + jvm = javaVM; + if (!NSK_VERIFY( + NSK_CPP_STUB3(GetEnv, javaVM, (void **)&jvmti_env, JVMTI_VERSION_1_1) == JNI_OK)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + if (!NSK_JVMTI_VERIFY(init_agent_data(jvmti_env, &agent_data))) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + return jvmti_env; +} + +/** Dispose JVMTI environment */ +static int nsk_jvmti_disposeJVMTIEnv(jvmtiEnv* jvmti_env) { + if (jvmti_env != NULL) { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB1(DisposeEnvironment, jvmti_env))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + if (!NSK_JVMTI_VERIFY(free_agent_data(jvmti_env, &agent_data))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + return NSK_TRUE; +} + +/** Get JNI environment for agent thread. */ +JNIEnv* nsk_jvmti_getAgentJNIEnv() { + return jni_env; +} + +/** Get JVMTI environment for agent */ +jvmtiEnv* nsk_jvmti_getAgentJVMTIEnv() { + return jvmti_env; +} + +/* ============================================================================= */ +static void set_agent_thread_state(thread_state_t value) { + rawMonitorEnter(jvmti_env, agent_data.monitor); + agent_data.thread_state = value; + rawMonitorNotify(jvmti_env, agent_data.monitor); + rawMonitorExit(jvmti_env, agent_data.monitor); +} + +/** Wrapper for user agent thread. */ +static void JNICALL +agentThreadWrapper(jvmtiEnv* jvmti_env, JNIEnv* agentJNI, void* arg) { + jni_env = agentJNI; + + /* run user agent proc */ + { + set_agent_thread_state(RUNNABLE); + + NSK_TRACE((*agentThreadProc)(jvmti_env, agentJNI, agentThreadArg)); + + set_agent_thread_state(TERMINATED); + } + + /* finalize agent thread */ + { + /* gelete global ref for agent thread */ + NSK_CPP_STUB2(DeleteGlobalRef, agentJNI, agentThread); + agentThread = NULL; + } +} + +/** Start wrapper for user agent thread. */ +static jthread startAgentThreadWrapper(JNIEnv *jni_env, jvmtiEnv* jvmti_env) { + const jint THREAD_PRIORITY = JVMTI_THREAD_MAX_PRIORITY; + const char* THREAD_NAME = "JVMTI agent thread"; + const char* THREAD_CLASS_NAME = "java/lang/Thread"; + const char* THREAD_CTOR_NAME = ""; + const char* THREAD_CTOR_SIGNATURE = "(Ljava/lang/String;)V"; + + jobject threadName = NULL; + jclass threadClass = NULL; + jmethodID threadCtor = NULL; + jobject threadObject = NULL; + jobject threadGlobalRef = NULL; + + if (!NSK_JNI_VERIFY(jni_env, (threadClass = + NSK_CPP_STUB2(FindClass, jni_env, THREAD_CLASS_NAME)) != NULL)) { + return NULL; + } + + if (!NSK_JNI_VERIFY(jni_env, (threadCtor = + NSK_CPP_STUB4(GetMethodID, jni_env, threadClass, THREAD_CTOR_NAME, THREAD_CTOR_SIGNATURE)) != NULL)) + return NULL; + + if (!NSK_JNI_VERIFY(jni_env, (threadName = + NSK_CPP_STUB2(NewStringUTF, jni_env, THREAD_NAME)) != NULL)) + return NULL; + + if (!NSK_JNI_VERIFY(jni_env, (threadObject = + NSK_CPP_STUB4(NewObject, jni_env, threadClass, threadCtor, threadName)) != NULL)) + return NULL; + + if (!NSK_JNI_VERIFY(jni_env, (threadGlobalRef = + NSK_CPP_STUB2(NewGlobalRef, jni_env, threadObject)) != NULL)) { + NSK_CPP_STUB2(DeleteLocalRef, jni_env, threadObject); + return NULL; + } + agentThread = (jthread)threadGlobalRef; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(RunAgentThread, jvmti_env, agentThread, + &agentThreadWrapper, agentThreadArg, THREAD_PRIORITY))) { + NSK_CPP_STUB2(DeleteGlobalRef, jni_env, threadGlobalRef); + NSK_CPP_STUB2(DeleteLocalRef, jni_env, threadObject); + return NULL; + } + return agentThread; +} + +/** Register user agent thread with arg. */ +int nsk_jvmti_setAgentProc(jvmtiStartFunction proc, void* arg) { + agentThreadProc = proc; + agentThreadArg = arg; + return NSK_TRUE; +} + +/** Get agent thread ref. */ +jthread nsk_jvmti_getAgentThread() { + return agentThread; +} + +/** Run registered user agent thread via wrapper. */ +static jthread nsk_jvmti_runAgentThread(JNIEnv *jni_env, jvmtiEnv* jvmti_env) { + /* start agent thread wrapper */ + jthread thread = startAgentThreadWrapper(jni_env, jvmti_env); + if (thread == NULL) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + return thread; +} + +/* ============================================================================= */ + +/** Sleep current thread. */ +void nsk_jvmti_sleep(jlong timeout) { + int seconds = (int)((timeout + 999) / 1000); + THREAD_sleep(seconds); +} + +/** Sync point called from Java code. */ +static jint syncDebuggeeStatus(JNIEnv* jni_env, jvmtiEnv* jvmti_env, jint debuggeeStatus) { + jint result = NSK_STATUS_FAILED; + + rawMonitorEnter(jvmti_env, agent_data.monitor); + + /* save last debugee status */ + agent_data.last_debuggee_status = debuggeeStatus; + + /* we don't enter if-stmt in second call */ + if (agent_data.thread_state == NEW) { + if (nsk_jvmti_runAgentThread(jni_env, jvmti_env) == NULL) + goto monitor_exit_and_return; + + /* SP2.2-w - wait for agent thread */ + while (agent_data.thread_state == NEW) { + rawMonitorWait(jvmti_env, agent_data.monitor, 0); + } + } + + /* wait for sync permit */ + /* we don't enter loop in first call */ + while (agent_data.thread_state != WAITING && agent_data.thread_state != TERMINATED) { + /* SP4.2-w - second wait for agent thread */ + rawMonitorWait(jvmti_env, agent_data.monitor, 0); + } + + if (agent_data.thread_state != TERMINATED) { + agent_data.thread_state = SUSPENDED; + /* SP3.2-n - notify to start test */ + /* SP6.2-n - notify to end test */ + rawMonitorNotify(jvmti_env, agent_data.monitor); + } + else { + NSK_COMPLAIN0("Debuggee status sync aborted because agent thread has finished\n"); + goto monitor_exit_and_return; + } + + /* update status from debuggee */ + if (debuggeeStatus != NSK_STATUS_PASSED) { + nsk_jvmti_setFailStatus(); + } + + while (agent_data.thread_state == SUSPENDED) { + /* SP5.2-w - wait while testing */ + /* SP7.2 - wait for agent end */ + rawMonitorWait(jvmti_env, agent_data.monitor, 0); + } + + agent_data.last_debuggee_status = nsk_jvmti_getStatus(); + result = agent_data.last_debuggee_status; + +monitor_exit_and_return: + rawMonitorExit(jvmti_env, agent_data.monitor); + return result; +} + +/** Wait for sync point with Java code. */ +int nsk_jvmti_waitForSync(jlong timeout) { + static const int inc_timeout = 1000; + + jlong t = 0; + int result = NSK_TRUE; + + rawMonitorEnter(jvmti_env, agent_data.monitor); + + agent_data.thread_state = WAITING; + + /* SP2.2-n - notify agent is waiting and wait */ + /* SP4.1-n - notify agent is waiting and wait */ + rawMonitorNotify(jvmti_env, agent_data.monitor); + + while (agent_data.thread_state == WAITING) { + /* SP3.2-w - wait to start test */ + /* SP6.2-w - wait to end test */ + rawMonitorWait(jvmti_env, agent_data.monitor, inc_timeout); + + if (timeout == 0) continue; + + t += inc_timeout; + + if (t >= timeout) break; + } + + if (agent_data.thread_state == WAITING) { + NSK_COMPLAIN1("No status sync occured for timeout: %" LL "d ms\n", timeout); + nsk_jvmti_setFailStatus(); + result = NSK_FALSE; + } + + rawMonitorExit(jvmti_env, agent_data.monitor); + + return result; +} + +/** Resume java code suspended on sync point. */ +int nsk_jvmti_resumeSync() { + int result; + rawMonitorEnter(jvmti_env, agent_data.monitor); + + if (agent_data.thread_state == SUSPENDED) { + result = NSK_TRUE; + agent_data.thread_state = RUNNABLE; + /* SP5.2-n - notify suspend done */ + /* SP7.2-n - notify agent end */ + rawMonitorNotify(jvmti_env, agent_data.monitor); + } + else { + NSK_COMPLAIN0("Debuggee was not suspended on status sync\n"); + nsk_jvmti_setFailStatus(); + result = NSK_FALSE; + } + + rawMonitorExit(jvmti_env, agent_data.monitor); + return NSK_TRUE; +} + +/** Native function for Java code to provide sync point. */ +JNIEXPORT jint JNICALL +Java_nsk_share_jvmti_DebugeeClass_checkStatus(JNIEnv* jni_env, jclass cls, jint debuggeeStatus) { + jint status; + NSK_TRACE(status = syncDebuggeeStatus(jni_env, jvmti_env, debuggeeStatus)); + return status; +} + +/** Native function for Java code to reset agent data. */ +JNIEXPORT void JNICALL +Java_nsk_share_jvmti_DebugeeClass_resetAgentData(JNIEnv* jni_env, jclass cls) { + NSK_TRACE(nsk_jvmti_resetAgentData()); +} + +/* ============================================================================= */ + +/** Find loaded class by signature. */ +jclass nsk_jvmti_classBySignature(const char signature[]) { + jclass* classes = NULL; + jint count = 0; + jclass foundClass = NULL; + int i; + + if (!NSK_VERIFY(signature != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetLoadedClasses, jvmti_env, &count, &classes))) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + for (i = 0; i < count; i++) { + char* sig = NULL; + char* generic = NULL; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, classes[i], &sig, &generic))) { + nsk_jvmti_setFailStatus(); + break; + } + + if (sig != NULL && strcmp(signature, sig) == 0) { + foundClass = classes[i]; + } + + if (!(NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig)) + && NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)generic)))) { + nsk_jvmti_setFailStatus(); + break; + } + + if (foundClass != NULL) + break; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)classes))) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + if (!NSK_JNI_VERIFY(jni_env, (foundClass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni_env, foundClass)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + return foundClass; +} + +/** Find alive thread by name. */ +jthread nsk_jvmti_threadByName(const char name[]) { + jthread* threads = NULL; + jint count = 0; + jthread foundThread = NULL; + int i; + + if (!NSK_VERIFY(name != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetAllThreads, jvmti_env, &count, &threads))) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + for (i = 0; i < count; i++) { + jvmtiThreadInfo info; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetThreadInfo, jvmti_env, threads[i], &info))) { + nsk_jvmti_setFailStatus(); + break; + } + + if (info.name != NULL && strcmp(name, info.name) == 0) { + foundThread = threads[i]; + break; + } + } + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)threads))) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + if (!NSK_JNI_VERIFY(jni_env, (foundThread = (jthread) + NSK_CPP_STUB2(NewGlobalRef, jni_env, foundThread)) != NULL)) { + nsk_jvmti_setFailStatus(); + return NULL; + } + + return foundThread; +} + + +/* ============================================================================= */ + +/** Add all capabilities for finding line locations. */ +int nsk_jvmti_addLocationCapabilities() { + jvmtiCapabilities caps; + + memset(&caps, 0, sizeof(caps)); + caps.can_get_line_numbers = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti_env, &caps))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/** Add all capabilities for using breakpoints. */ +int nsk_jvmti_addBreakpointCapabilities() { + jvmtiCapabilities caps; + + if (!nsk_jvmti_addLocationCapabilities()) + return NSK_FALSE; + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_breakpoint_events = 1; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB2(AddCapabilities, jvmti_env, &caps))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/** Find line location. */ +jlocation nsk_jvmti_getLineLocation(jclass cls, jmethodID method, int line) { + jint count = 0; + jvmtiLineNumberEntry* table = NULL; + jlocation location = NSK_JVMTI_INVALID_JLOCATION; + int i; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetLineNumberTable, jvmti_env, method, &count, &table))) + return NSK_JVMTI_INVALID_JLOCATION; + + for (i = 0; i < count; i++) { + if (table[i].line_number == line) { + location = table[i].start_location; + break; + } + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)table))) + return NSK_JVMTI_INVALID_JLOCATION; + + return location; +} + +/** Set breakpoint to a line. */ +jlocation nsk_jvmti_setLineBreakpoint(jclass cls, jmethodID method, int line) { + jlocation location = NSK_JVMTI_INVALID_JLOCATION; + + if (!NSK_VERIFY((location = + nsk_jvmti_getLineLocation(cls, method, line)) != NSK_JVMTI_INVALID_JLOCATION)) + return NSK_JVMTI_INVALID_JLOCATION; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetBreakpoint, jvmti_env, method, location))) + return NSK_JVMTI_INVALID_JLOCATION; + + return location; +} + +/** Remove breakpoint from a line. */ +jlocation nsk_jvmti_clearLineBreakpoint(jclass cls, jmethodID method, int line) { + jlocation location = NSK_JVMTI_INVALID_JLOCATION; + + if (!NSK_VERIFY((location = + nsk_jvmti_getLineLocation(cls, method, line)) != NSK_JVMTI_INVALID_JLOCATION)) + return NSK_JVMTI_INVALID_JLOCATION; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(ClearBreakpoint, jvmti_env, method, location))) + return NSK_JVMTI_INVALID_JLOCATION; + + return location; +} + +/* ============================================================================= */ + +/** Enable or disable given events. */ +int nsk_jvmti_enableEvents(jvmtiEventMode enable, int size, jvmtiEvent list[], jthread thread) { + int i; + + for (i = 0; i < size; i++) { + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, enable, + list[i], thread))) { + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + } + return NSK_TRUE; +} + +/* ============================================================================= */ + +typedef jint (JNICALL *checkStatus_type)(JNIEnv* jni_env, jclass cls, jint debuggeeStatus); + +static checkStatus_type checkStatus_func = NULL; + +/** + * Proxy function to gain sequential access to checkStatus of each agent + */ +JNIEXPORT jint JNICALL +MA_checkStatus(JNIEnv* jni_env, jclass cls, jint debuggeeStatus) { + jint status; + + NSK_TRACE(status = syncDebuggeeStatus(jni_env, jvmti_env, debuggeeStatus)); + return (*checkStatus_func)(jni_env, cls, status); +} + +/** + * nativeMethodBind callback: + * if needed, redirects checkStatus native method call + */ +static void JNICALL nativeMethodBind(jvmtiEnv* jvmti_env, JNIEnv *jni_env, + jthread thread, jmethodID mid, + void* address, void** new_address_ptr) { + const char* BIND_CLASS_NAME = "Lnsk/share/jvmti/DebugeeClass;"; + const char* BIND_METHOD_NAME = "checkStatus"; + const char* BIND_METHOD_SIGNATURE = "(I)I"; + + jvmtiPhase phase; + jclass cls; + char *class_sig = NULL; + char *name = NULL; + char *sig = NULL; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) { + nsk_jvmti_setFailStatus(); + return; + } + + if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE) + return; + + if (NSK_JVMTI_VERIFY( + NSK_CPP_STUB5(GetMethodName, jvmti_env, mid, &name, &sig, NULL))) { + if (strcmp(name, BIND_METHOD_NAME) == 0 && + strcmp(sig, BIND_METHOD_SIGNATURE) == 0) { + + if (NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(GetMethodDeclaringClass, jvmti_env, mid, &cls)) + && NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(GetClassSignature, jvmti_env, cls, &class_sig, NULL)) + && strcmp(class_sig, BIND_CLASS_NAME) == 0 + && address != (void*)Java_nsk_share_jvmti_DebugeeClass_checkStatus) { + checkStatus_func = (checkStatus_type)address; + NSK_TRACE(*new_address_ptr = (void*)MA_checkStatus); + } + } + } + + if (name != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + + if (sig != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig); + + if (class_sig != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)class_sig); +} + +/** + * Initialize multiple agent: + * establish processing of nativeMethodBind events + */ +int nsk_jvmti_init_MA(jvmtiEventCallbacks* callbacks) { + + if (callbacks == NULL) { + NSK_COMPLAIN0("callbacks should not be NULL\n"); + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + if (callbacks->NativeMethodBind != NULL) { + NSK_COMPLAIN0("callbacks.NativeMethodBind should be NULL\n"); + nsk_jvmti_setFailStatus(); + return NSK_FALSE; + } + + { + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(caps)); + caps.can_generate_native_method_bind_events = 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti_env, &caps))) + return NSK_FALSE; + } + + callbacks->NativeMethodBind = nativeMethodBind; + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(SetEventCallbacks, jvmti_env, callbacks, + sizeof(jvmtiEventCallbacks)))) + return NSK_FALSE; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_ENABLE, + JVMTI_EVENT_NATIVE_METHOD_BIND, NULL))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +int nsk_jvmti_isOptionalEvent(jvmtiEvent event) { + + return (event == JVMTI_EVENT_EXCEPTION) + || (event == JVMTI_EVENT_EXCEPTION_CATCH) + || (event == JVMTI_EVENT_SINGLE_STEP) + || (event == JVMTI_EVENT_FRAME_POP) + || (event == JVMTI_EVENT_BREAKPOINT) + || (event == JVMTI_EVENT_FIELD_ACCESS) + || (event == JVMTI_EVENT_FIELD_MODIFICATION) + || (event == JVMTI_EVENT_METHOD_ENTRY) + || (event == JVMTI_EVENT_METHOD_EXIT) + || (event == JVMTI_EVENT_NATIVE_METHOD_BIND) + || (event == JVMTI_EVENT_COMPILED_METHOD_LOAD) + || (event == JVMTI_EVENT_COMPILED_METHOD_UNLOAD) + || (event == JVMTI_EVENT_MONITOR_WAIT) + || (event == JVMTI_EVENT_MONITOR_WAITED) + || (event == JVMTI_EVENT_MONITOR_CONTENDED_ENTER) + || (event == JVMTI_EVENT_MONITOR_CONTENDED_ENTERED) + || (event == JVMTI_EVENT_GARBAGE_COLLECTION_START) + || (event == JVMTI_EVENT_GARBAGE_COLLECTION_FINISH) + || (event == JVMTI_EVENT_OBJECT_FREE) + || (event == JVMTI_EVENT_VM_OBJECT_ALLOC); +} + +/* ============================================================================= */ + +void nsk_jvmti_showPossessedCapabilities(jvmtiEnv *jvmti_env) { + + jvmtiCapabilities caps; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, jvmti_env, &caps))) { + return; + } + + NSK_DISPLAY0("\n"); + NSK_DISPLAY0("Possessed capabilities:\n"); + NSK_DISPLAY0("-----------------------\n"); + if (caps.can_tag_objects) + NSK_DISPLAY0("\tcan_tag_objects\n"); + if (caps.can_generate_field_modification_events) + NSK_DISPLAY0("\tcan_generate_field_modification_events\n"); + if (caps.can_generate_field_access_events) + NSK_DISPLAY0("\tcan_generate_field_access_events\n"); + if (caps.can_get_bytecodes) + NSK_DISPLAY0("\tcan_get_bytecodes\n"); + if (caps.can_get_synthetic_attribute) + NSK_DISPLAY0("\tcan_get_synthetic_attribute\n"); + if (caps.can_get_owned_monitor_info) + NSK_DISPLAY0("\tcan_get_owned_monitor_info\n"); + if (caps.can_get_current_contended_monitor) + NSK_DISPLAY0("\tcan_get_current_contended_monitor\n"); + if (caps.can_get_monitor_info) + NSK_DISPLAY0("\tcan_get_monitor_info\n"); + if (caps.can_pop_frame) + NSK_DISPLAY0("\tcan_pop_frame\n"); + if (caps.can_redefine_classes) + NSK_DISPLAY0("\tcan_redefine_classes\n"); + if (caps.can_signal_thread) + NSK_DISPLAY0("\tcan_signal_thread\n"); + if (caps.can_get_source_file_name) + NSK_DISPLAY0("\tcan_get_source_file_name\n"); + if (caps.can_get_line_numbers) + NSK_DISPLAY0("\tcan_get_line_numbers\n"); + if (caps.can_get_source_debug_extension) + NSK_DISPLAY0("\tcan_get_source_debug_extension\n"); + if (caps.can_access_local_variables) + NSK_DISPLAY0("\tcan_access_local_variables\n"); + if (caps.can_maintain_original_method_order) + NSK_DISPLAY0("\tcan_maintain_original_method_order\n"); + if (caps.can_generate_single_step_events) + NSK_DISPLAY0("\tcan_generate_single_step_events\n"); + if (caps.can_generate_exception_events) + NSK_DISPLAY0("\tcan_generate_exception_events\n"); + if (caps.can_generate_frame_pop_events) + NSK_DISPLAY0("\tcan_generate_frame_pop_events\n"); + if (caps.can_generate_breakpoint_events) + NSK_DISPLAY0("\tcan_generate_breakpoint_events\n"); + if (caps.can_suspend) + NSK_DISPLAY0("\tcan_suspend\n"); + if (caps.can_get_current_thread_cpu_time) + NSK_DISPLAY0("\tcan_get_current_thread_cpu_time\n"); + if (caps.can_get_thread_cpu_time) + NSK_DISPLAY0("\tcan_get_thread_cpu_time\n"); + if (caps.can_generate_method_entry_events) + NSK_DISPLAY0("\tcan_generate_method_entry_events\n"); + if (caps.can_generate_method_exit_events) + NSK_DISPLAY0("\tcan_generate_method_exit_events\n"); + if (caps.can_generate_all_class_hook_events) + NSK_DISPLAY0("\tcan_generate_all_class_hook_events\n"); + if (caps.can_generate_compiled_method_load_events) + NSK_DISPLAY0("\tcan_generate_compiled_method_load_events\n"); + if (caps.can_generate_monitor_events) + NSK_DISPLAY0("\tcan_generate_monitor_events\n"); + if (caps.can_generate_vm_object_alloc_events) + NSK_DISPLAY0("\tcan_generate_vm_object_alloc_events\n"); + if (caps.can_generate_native_method_bind_events) + NSK_DISPLAY0("\tcan_generate_native_method_bind_events\n"); + if (caps.can_generate_garbage_collection_events) + NSK_DISPLAY0("\tcan_generate_garbage_collection_events\n"); + if (caps.can_generate_object_free_events) + NSK_DISPLAY0("\tcan_generate_object_free_events\n"); + + NSK_DISPLAY0("\n"); +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/aod/jvmti_aod.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/aod/jvmti_aod.c deleted file mode 100644 index e73deda6efa..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/aod/jvmti_aod.c +++ /dev/null @@ -1,352 +0,0 @@ -/* - * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void nsk_jvmti_aod_disableEventAndFinish(const char* agentName, jvmtiEvent event, int success, jvmtiEnv *jvmti, JNIEnv* jni) { - if (!nsk_jvmti_aod_disableEvent(jvmti, event)) - success = 0; - - nsk_aod_agentFinished(jni, agentName, success); -} - -void nsk_jvmti_aod_disableEventsAndFinish(const char* agentName, jvmtiEvent events[], int eventsNumber, int success, jvmtiEnv *jvmti, JNIEnv* jni) { - if (!nsk_jvmti_aod_disableEvents(jvmti, events, eventsNumber)) - success = 0; - - nsk_aod_agentFinished(jni, agentName, success); -} - -/* - * Work with agent options - */ - -struct { - jvmtiEnv *jvmti; - Options *options; -} multiagentsOptions[MAX_MULTIPLE_AGENTS]; - -static volatile int multiagentsCount = 0; - -int nsk_jvmti_aod_addMultiagentsOptions(jvmtiEnv *jvmti, Options *options) { - if (multiagentsCount >= MAX_MULTIPLE_AGENTS) { - NSK_COMPLAIN1("To many agents, max agents count is %d\n", MAX_MULTIPLE_AGENTS); - return NSK_FALSE; - } - - multiagentsOptions[multiagentsCount].jvmti = jvmti; - multiagentsOptions[multiagentsCount].options = options; - multiagentsCount++; - - NSK_DISPLAY3("Options for agent %s were added (jvmtiEnv: %p, agentsCount: %d)\n", - nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION), - jvmti, - multiagentsCount); - - return NSK_TRUE; -} - -Options* nsk_jvmti_aod_getMultiagentsOptions(jvmtiEnv *jvmti) { - int i; - for (i = 0; i < multiagentsCount; i++) { - if (multiagentsOptions[i].jvmti == jvmti) { - return multiagentsOptions[i].options; - } - } - - NSK_COMPLAIN1("Options for jvmtiEnv %p weren't found\n", jvmti); - - return NULL; -} - -/* - * Auxiliary functions - */ - -void nsk_jvmti_aod_deallocate(jvmtiEnv *jvmti, unsigned char* mem) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti, mem))) { - NSK_COMPLAIN0("Deallocate failed\n"); - - /* - * if deallocate fails it isn't critical and test execution can continue without problems, - * just call nsk_aod_internal_error to inform framework about this error - */ - nsk_aod_internal_error(); - } -} - -int nsk_jvmti_aod_getClassName(jvmtiEnv *jvmti, jclass klass, char classNameBuffer[]) { - char* className; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti, klass, &className, NULL))) { - NSK_COMPLAIN0("Failed to get class name\n"); - classNameBuffer[0] = '\0'; - return NSK_FALSE; - } else { - strcpy(classNameBuffer, className); - - nsk_jvmti_aod_deallocate(jvmti, (unsigned char*)className); - - return NSK_TRUE; - } -} - -int nsk_jvmti_aod_getThreadName(jvmtiEnv * jvmti, jthread thread, char threadNameBuffer[]) { - jvmtiThreadInfo info; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti, thread, &info))){ - NSK_COMPLAIN0("Failed to get thread info\n"); - threadNameBuffer[0] = '\0'; - return NSK_FALSE; - } else { - strcpy(threadNameBuffer, info.name); - - nsk_jvmti_aod_deallocate(jvmti, (unsigned char*)info.name); - - return NSK_TRUE; - } -} - -// events enabling/disabling - -int nsk_jvmti_aod_disableEvents(jvmtiEnv* jvmti, jvmtiEvent events[], int eventsNumber) { - int i; - int status = NSK_TRUE; - - for (i = 0; i < eventsNumber; i++) { - if (!nsk_jvmti_aod_disableEvent(jvmti, events[i])) { - status = NSK_FALSE; - } - } - - return status; -} - -int nsk_jvmti_aod_enableEvents(jvmtiEnv* jvmti, jvmtiEvent events[], int eventsNumber) { - int i; - for (i = 0; i < eventsNumber; i++) { - if (!nsk_jvmti_aod_enableEvent(jvmti, events[i])) - return NSK_FALSE; - } - - return NSK_TRUE; -} - -// java threads creation - -jthread nsk_jvmti_aod_createThread(JNIEnv *jni) { - jclass klass ; - jmethodID threadConstructor; - jthread thread; - - if (!NSK_JNI_VERIFY(jni, - (klass = NSK_CPP_STUB2(FindClass, jni, "java/lang/Thread")) != NULL )) { - NSK_COMPLAIN0("Failed to get the java.lang.Thread class\n"); - return NULL; - } - if (!NSK_JNI_VERIFY(jni, - (threadConstructor = NSK_CPP_STUB4(GetMethodID, jni, klass, "", "()V") ) != NULL )) { - NSK_COMPLAIN0("Failed to get java.lang.Thread constructor\n"); - return NULL; - } - - if (!NSK_JNI_VERIFY (jni, - (thread = NSK_CPP_STUB4(NewObject, jni, klass, threadConstructor, NULL)) != NULL ) ) { - NSK_COMPLAIN0("Failed to create Thread object\n"); - return NULL; - } - - if (!NSK_JNI_VERIFY(jni, (thread = - NSK_CPP_STUB2(NewGlobalRef, jni, thread)) != NULL)) { - NSK_COMPLAIN0("Failed to create global reference\n"); - return NULL; - } - - return thread; -} - -jthread nsk_jvmti_aod_createThreadWithName(JNIEnv *jni, char* threadName) { - jclass klass ; - jmethodID threadConstructor; - jthread thread; - jstring threadNameString; - - if (!NSK_JNI_VERIFY(jni, (threadNameString = - NSK_CPP_STUB2(NewStringUTF, jni, threadName)) != NULL)) - return NULL; - - if (!NSK_JNI_VERIFY(jni, - (klass = NSK_CPP_STUB2(FindClass, jni, "java/lang/Thread")) != NULL )) { - NSK_COMPLAIN0("Failed to get the java.lang.Thread class\n"); - return NULL; - } - if (!NSK_JNI_VERIFY(jni, - (threadConstructor = NSK_CPP_STUB4(GetMethodID, jni, klass, "", "(Ljava/lang/String;)V") ) != NULL )) { - NSK_COMPLAIN0("Failed to get java.lang.Thread constructor\n"); - return NULL; - } - - if (!NSK_JNI_VERIFY(jni, - (thread = NSK_CPP_STUB4(NewObject, jni, klass, threadConstructor, threadNameString)) != NULL ) ) { - NSK_COMPLAIN0("Failed to create Thread object\n"); - return NULL; - } - - if (!NSK_JNI_VERIFY(jni, (thread = - NSK_CPP_STUB2(NewGlobalRef, jni, thread)) != NULL)) { - NSK_COMPLAIN0("Failed to create global reference\n"); - return NULL; - } - - return thread; -} - -// class redefinition - -int nsk_jvmti_aod_redefineClass( - Options * options, - jvmtiEnv * jvmti, - jclass classToRedefine, - const char * fileName) { - - if (!nsk_aod_optionSpecified(options, PATH_TO_NEW_BYTE_CODE_OPTION)) { - NSK_COMPLAIN1("Option '%s' isn't specified\n", PATH_TO_NEW_BYTE_CODE_OPTION); - return NSK_FALSE; - } - if (fileName == NULL) { - NSK_COMPLAIN0("File name is NULL\n"); - return NSK_FALSE; - } - { - char file [1024]; - - sprintf(file,"%s/%s.class", - nsk_aod_getOptionValue(options, PATH_TO_NEW_BYTE_CODE_OPTION), - fileName); - NSK_DISPLAY1("File with new bytecode: '%s'\n", file); - - { - FILE *bytecode; - unsigned char * classBytes; - jvmtiError error; - jint size; - - bytecode = fopen(file, "rb"); - error= JVMTI_ERROR_NONE; - if ( bytecode == NULL ) { - NSK_COMPLAIN1("Error opening file '%s'\n", file); - return NSK_FALSE; - } - - NSK_DISPLAY1("Opening file '%s' \n", file); - fseek(bytecode, 0, SEEK_END); - size = ftell(bytecode); - NSK_DISPLAY1("File size= %ld\n", ftell(bytecode)); - rewind(bytecode); - error = (*jvmti)->Allocate(jvmti, size, &classBytes); - if ( error != JVMTI_ERROR_NONE) { - NSK_DISPLAY1("Failed to create memory %s\n", TranslateError(error)); - return NSK_FALSE; - } - - if ( ((jint) fread( classBytes, 1, size, bytecode )) != size ) { - NSK_COMPLAIN0("Failed to read all the bytes, could be less or more\n"); - fclose(bytecode); - return NSK_FALSE; - } else { - NSK_DISPLAY0("File read completely \n"); - } - fclose(bytecode); - { - jvmtiClassDefinition classDef; - classDef.klass = classToRedefine; - classDef.class_byte_count= size; - classDef.class_bytes = classBytes; - NSK_DISPLAY0("Redefining\n"); - error = (*jvmti)->RedefineClasses(jvmti, 1, &classDef); - if ( error != JVMTI_ERROR_NONE ) { - NSK_DISPLAY1("# error occured while redefining %s ", - TranslateError(error) ); - return NSK_FALSE; - } - } - } - } - return NSK_TRUE; -} - -// capabilities - -void printCapabilities(jvmtiCapabilities caps) { - #define printCap(name) NSK_DISPLAY1(#name ": %d\n", caps.name) - - printCap(can_tag_objects); - printCap(can_generate_field_modification_events); - printCap(can_generate_field_access_events); - printCap(can_get_bytecodes); - printCap(can_get_synthetic_attribute); - printCap(can_get_owned_monitor_info); - printCap(can_get_current_contended_monitor); - printCap(can_get_monitor_info); - printCap(can_pop_frame); - printCap(can_redefine_classes); - printCap(can_signal_thread); - printCap(can_get_source_file_name); - printCap(can_get_line_numbers); - printCap(can_get_source_debug_extension); - printCap(can_access_local_variables); - printCap(can_maintain_original_method_order); - printCap(can_generate_single_step_events); - printCap(can_generate_exception_events); - printCap(can_generate_frame_pop_events); - printCap(can_generate_breakpoint_events); - printCap(can_suspend); - printCap(can_redefine_any_class); - printCap(can_get_current_thread_cpu_time); - printCap(can_get_thread_cpu_time); - printCap(can_generate_method_entry_events); - printCap(can_generate_method_exit_events); - printCap(can_generate_all_class_hook_events); - printCap(can_generate_compiled_method_load_events); - printCap(can_generate_monitor_events); - printCap(can_generate_vm_object_alloc_events); - printCap(can_generate_native_method_bind_events); - printCap(can_generate_garbage_collection_events); - printCap(can_generate_object_free_events); - printCap(can_force_early_return); - printCap(can_get_owned_monitor_stack_depth_info); - printCap(can_get_constant_pool); - printCap(can_set_native_method_prefix); - printCap(can_retransform_classes); - printCap(can_retransform_any_class); - - #undef printCap -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/aod/jvmti_aod.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/aod/jvmti_aod.cpp new file mode 100644 index 00000000000..7e78c193120 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/aod/jvmti_aod.cpp @@ -0,0 +1,352 @@ +/* + * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void nsk_jvmti_aod_disableEventAndFinish(const char* agentName, jvmtiEvent event, int success, jvmtiEnv *jvmti, JNIEnv* jni) { + if (!nsk_jvmti_aod_disableEvent(jvmti, event)) + success = 0; + + nsk_aod_agentFinished(jni, agentName, success); +} + +void nsk_jvmti_aod_disableEventsAndFinish(const char* agentName, jvmtiEvent events[], int eventsNumber, int success, jvmtiEnv *jvmti, JNIEnv* jni) { + if (!nsk_jvmti_aod_disableEvents(jvmti, events, eventsNumber)) + success = 0; + + nsk_aod_agentFinished(jni, agentName, success); +} + +/* + * Work with agent options + */ + +struct { + jvmtiEnv *jvmti; + Options *options; +} multiagentsOptions[MAX_MULTIPLE_AGENTS]; + +static volatile int multiagentsCount = 0; + +int nsk_jvmti_aod_addMultiagentsOptions(jvmtiEnv *jvmti, Options *options) { + if (multiagentsCount >= MAX_MULTIPLE_AGENTS) { + NSK_COMPLAIN1("To many agents, max agents count is %d\n", MAX_MULTIPLE_AGENTS); + return NSK_FALSE; + } + + multiagentsOptions[multiagentsCount].jvmti = jvmti; + multiagentsOptions[multiagentsCount].options = options; + multiagentsCount++; + + NSK_DISPLAY3("Options for agent %s were added (jvmtiEnv: %p, agentsCount: %d)\n", + nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION), + jvmti, + multiagentsCount); + + return NSK_TRUE; +} + +Options* nsk_jvmti_aod_getMultiagentsOptions(jvmtiEnv *jvmti) { + int i; + for (i = 0; i < multiagentsCount; i++) { + if (multiagentsOptions[i].jvmti == jvmti) { + return multiagentsOptions[i].options; + } + } + + NSK_COMPLAIN1("Options for jvmtiEnv %p weren't found\n", jvmti); + + return NULL; +} + +/* + * Auxiliary functions + */ + +void nsk_jvmti_aod_deallocate(jvmtiEnv *jvmti, unsigned char* mem) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti, mem))) { + NSK_COMPLAIN0("Deallocate failed\n"); + + /* + * if deallocate fails it isn't critical and test execution can continue without problems, + * just call nsk_aod_internal_error to inform framework about this error + */ + nsk_aod_internal_error(); + } +} + +int nsk_jvmti_aod_getClassName(jvmtiEnv *jvmti, jclass klass, char classNameBuffer[]) { + char* className; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti, klass, &className, NULL))) { + NSK_COMPLAIN0("Failed to get class name\n"); + classNameBuffer[0] = '\0'; + return NSK_FALSE; + } else { + strcpy(classNameBuffer, className); + + nsk_jvmti_aod_deallocate(jvmti, (unsigned char*)className); + + return NSK_TRUE; + } +} + +int nsk_jvmti_aod_getThreadName(jvmtiEnv * jvmti, jthread thread, char threadNameBuffer[]) { + jvmtiThreadInfo info; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti, thread, &info))){ + NSK_COMPLAIN0("Failed to get thread info\n"); + threadNameBuffer[0] = '\0'; + return NSK_FALSE; + } else { + strcpy(threadNameBuffer, info.name); + + nsk_jvmti_aod_deallocate(jvmti, (unsigned char*)info.name); + + return NSK_TRUE; + } +} + +// events enabling/disabling + +int nsk_jvmti_aod_disableEvents(jvmtiEnv* jvmti, jvmtiEvent events[], int eventsNumber) { + int i; + int status = NSK_TRUE; + + for (i = 0; i < eventsNumber; i++) { + if (!nsk_jvmti_aod_disableEvent(jvmti, events[i])) { + status = NSK_FALSE; + } + } + + return status; +} + +int nsk_jvmti_aod_enableEvents(jvmtiEnv* jvmti, jvmtiEvent events[], int eventsNumber) { + int i; + for (i = 0; i < eventsNumber; i++) { + if (!nsk_jvmti_aod_enableEvent(jvmti, events[i])) + return NSK_FALSE; + } + + return NSK_TRUE; +} + +// java threads creation + +jthread nsk_jvmti_aod_createThread(JNIEnv *jni) { + jclass klass ; + jmethodID threadConstructor; + jthread thread; + + if (!NSK_JNI_VERIFY(jni, + (klass = NSK_CPP_STUB2(FindClass, jni, "java/lang/Thread")) != NULL )) { + NSK_COMPLAIN0("Failed to get the java.lang.Thread class\n"); + return NULL; + } + if (!NSK_JNI_VERIFY(jni, + (threadConstructor = NSK_CPP_STUB4(GetMethodID, jni, klass, "", "()V") ) != NULL )) { + NSK_COMPLAIN0("Failed to get java.lang.Thread constructor\n"); + return NULL; + } + + if (!NSK_JNI_VERIFY (jni, + (thread = NSK_CPP_STUB4(NewObject, jni, klass, threadConstructor, NULL)) != NULL ) ) { + NSK_COMPLAIN0("Failed to create Thread object\n"); + return NULL; + } + + if (!NSK_JNI_VERIFY(jni, (thread = + NSK_CPP_STUB2(NewGlobalRef, jni, thread)) != NULL)) { + NSK_COMPLAIN0("Failed to create global reference\n"); + return NULL; + } + + return thread; +} + +jthread nsk_jvmti_aod_createThreadWithName(JNIEnv *jni, const char* threadName) { + jclass klass ; + jmethodID threadConstructor; + jthread thread; + jstring threadNameString; + + if (!NSK_JNI_VERIFY(jni, (threadNameString = + NSK_CPP_STUB2(NewStringUTF, jni, threadName)) != NULL)) + return NULL; + + if (!NSK_JNI_VERIFY(jni, + (klass = NSK_CPP_STUB2(FindClass, jni, "java/lang/Thread")) != NULL )) { + NSK_COMPLAIN0("Failed to get the java.lang.Thread class\n"); + return NULL; + } + if (!NSK_JNI_VERIFY(jni, + (threadConstructor = NSK_CPP_STUB4(GetMethodID, jni, klass, "", "(Ljava/lang/String;)V") ) != NULL )) { + NSK_COMPLAIN0("Failed to get java.lang.Thread constructor\n"); + return NULL; + } + + if (!NSK_JNI_VERIFY(jni, + (thread = NSK_CPP_STUB4(NewObject, jni, klass, threadConstructor, threadNameString)) != NULL ) ) { + NSK_COMPLAIN0("Failed to create Thread object\n"); + return NULL; + } + + if (!NSK_JNI_VERIFY(jni, (thread = + NSK_CPP_STUB2(NewGlobalRef, jni, thread)) != NULL)) { + NSK_COMPLAIN0("Failed to create global reference\n"); + return NULL; + } + + return thread; +} + +// class redefinition + +int nsk_jvmti_aod_redefineClass( + Options * options, + jvmtiEnv * jvmti, + jclass classToRedefine, + const char * fileName) { + + if (!nsk_aod_optionSpecified(options, PATH_TO_NEW_BYTE_CODE_OPTION)) { + NSK_COMPLAIN1("Option '%s' isn't specified\n", PATH_TO_NEW_BYTE_CODE_OPTION); + return NSK_FALSE; + } + if (fileName == NULL) { + NSK_COMPLAIN0("File name is NULL\n"); + return NSK_FALSE; + } + { + char file [1024]; + + sprintf(file,"%s/%s.class", + nsk_aod_getOptionValue(options, PATH_TO_NEW_BYTE_CODE_OPTION), + fileName); + NSK_DISPLAY1("File with new bytecode: '%s'\n", file); + + { + FILE *bytecode; + unsigned char * classBytes; + jvmtiError error; + jint size; + + bytecode = fopen(file, "rb"); + error= JVMTI_ERROR_NONE; + if ( bytecode == NULL ) { + NSK_COMPLAIN1("Error opening file '%s'\n", file); + return NSK_FALSE; + } + + NSK_DISPLAY1("Opening file '%s' \n", file); + fseek(bytecode, 0, SEEK_END); + size = ftell(bytecode); + NSK_DISPLAY1("File size= %ld\n", ftell(bytecode)); + rewind(bytecode); + error = jvmti->Allocate(size, &classBytes); + if ( error != JVMTI_ERROR_NONE) { + NSK_DISPLAY1("Failed to create memory %s\n", TranslateError(error)); + return NSK_FALSE; + } + + if ( ((jint) fread( classBytes, 1, size, bytecode )) != size ) { + NSK_COMPLAIN0("Failed to read all the bytes, could be less or more\n"); + fclose(bytecode); + return NSK_FALSE; + } else { + NSK_DISPLAY0("File read completely \n"); + } + fclose(bytecode); + { + jvmtiClassDefinition classDef; + classDef.klass = classToRedefine; + classDef.class_byte_count= size; + classDef.class_bytes = classBytes; + NSK_DISPLAY0("Redefining\n"); + error = jvmti->RedefineClasses(1, &classDef); + if ( error != JVMTI_ERROR_NONE ) { + NSK_DISPLAY1("# error occured while redefining %s ", + TranslateError(error) ); + return NSK_FALSE; + } + } + } + } + return NSK_TRUE; +} + +// capabilities + +void printCapabilities(jvmtiCapabilities caps) { + #define printCap(name) NSK_DISPLAY1(#name ": %d\n", caps.name) + + printCap(can_tag_objects); + printCap(can_generate_field_modification_events); + printCap(can_generate_field_access_events); + printCap(can_get_bytecodes); + printCap(can_get_synthetic_attribute); + printCap(can_get_owned_monitor_info); + printCap(can_get_current_contended_monitor); + printCap(can_get_monitor_info); + printCap(can_pop_frame); + printCap(can_redefine_classes); + printCap(can_signal_thread); + printCap(can_get_source_file_name); + printCap(can_get_line_numbers); + printCap(can_get_source_debug_extension); + printCap(can_access_local_variables); + printCap(can_maintain_original_method_order); + printCap(can_generate_single_step_events); + printCap(can_generate_exception_events); + printCap(can_generate_frame_pop_events); + printCap(can_generate_breakpoint_events); + printCap(can_suspend); + printCap(can_redefine_any_class); + printCap(can_get_current_thread_cpu_time); + printCap(can_get_thread_cpu_time); + printCap(can_generate_method_entry_events); + printCap(can_generate_method_exit_events); + printCap(can_generate_all_class_hook_events); + printCap(can_generate_compiled_method_load_events); + printCap(can_generate_monitor_events); + printCap(can_generate_vm_object_alloc_events); + printCap(can_generate_native_method_bind_events); + printCap(can_generate_garbage_collection_events); + printCap(can_generate_object_free_events); + printCap(can_force_early_return); + printCap(can_get_owned_monitor_stack_depth_info); + printCap(can_get_constant_pool); + printCap(can_set_native_method_prefix); + printCap(can_retransform_classes); + printCap(can_retransform_any_class); + + #undef printCap +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/aod/jvmti_aod.h b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/aod/jvmti_aod.h index 965f6eb0c49..18e2c5e7dcf 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/aod/jvmti_aod.h +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/aod/jvmti_aod.h @@ -80,7 +80,7 @@ int nsk_jvmti_aod_disableEvents(jvmtiEnv* jvmti, jvmtiEvent events[], int events jthread nsk_jvmti_aod_createThread(JNIEnv *jni); -jthread nsk_jvmti_aod_createThreadWithName(JNIEnv *jni, char* threadName); +jthread nsk_jvmti_aod_createThreadWithName(JNIEnv *jni, const char* threadName); // class redefinition diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/HotSwap.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/HotSwap.c deleted file mode 100644 index 0d7d0c46344..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/HotSwap.c +++ /dev/null @@ -1,505 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "Injector.h" -#include "agent_common.h" - -#define PASSED 0 - -#ifdef __cplusplus -extern "C" { -#endif - -/* ========================================================================== */ - -#define DEFAULT_MAX_NUMBER_OF_CLASSES 100 -#define DEFAULT_NUMBER_OF_SAMPLES 10 -#define DEFAULT_SAMPLING_INTERVAL 100 -#define DEFAULT_PACKAGE_NAME "nsk/jvmti/scenarios/hotswap" -#define PROFILE_CLASS_NAME "nsk/share/jvmti/ProfileCollector" - -enum { - VM_MODE_COMPILED = 0, - VM_MODE_INTERPRETED = 1, - VM_MODE_MIXED = 2 -}; - -/* scaffold objects */ -static jlong timeout = 0; - -/* test options */ -static int number_of_samples; -static jlong sampling_interval; -static const char* package_name; -static size_t package_name_length; -static int vm_mode = VM_MODE_COMPILED; -static int bci_mode = BCI_MODE_EMCP; -static int sync_freq = 0; - -static jclass profile_klass = NULL; -static jfieldID count_field = NULL; - -/* test objects */ -static int max_classes; -static char** names = NULL; -static jvmtiClassDefinition* old_class_def = NULL; -static jvmtiClassDefinition* new_class_def = NULL; -static int classCount = 0; -static int newFlag = NSK_FALSE; - -/* ========================================================================== */ - -static int redefine(jvmtiEnv* jvmti, jvmtiClassDefinition* class_def) { - - if (!NSK_VERIFY(classCount != 0)) - return NSK_FALSE; - - NSK_DISPLAY1("Redefining %d classes...\n", classCount); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, - jvmti, classCount, class_def))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/** callback functions **/ - -static void JNICALL -ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, - jclass class_being_redefined, jobject loader, - const char* name, jobject protection_domain, - jint class_data_len, const unsigned char* class_data, - jint *new_class_data_len, unsigned char** new_class_data) { - jint name_len; - - if (name != NULL && classCount < max_classes && - class_being_redefined == NULL && - (strcmp(name, PROFILE_CLASS_NAME) != 0) && - (strncmp(name, package_name, package_name_length) == 0)) { - NSK_DISPLAY1("ClassFileLoadHook: %s\n", name); - name_len = (jint) strlen(name) + 1; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti_env, - name_len, (unsigned char**) &names[classCount]))) { - nsk_jvmti_setFailStatus(); - return; - } - memcpy(names[classCount], name, name_len); - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, - jvmti_env, class_data_len, (unsigned char**) - &old_class_def[classCount].class_bytes))) { - nsk_jvmti_setFailStatus(); - return; - } - memcpy((unsigned char*) old_class_def[classCount].class_bytes, - class_data, class_data_len); - old_class_def[classCount].class_byte_count = class_data_len; - classCount++; - } -} - -static int CompiledMethodLoadEventsCount = 0; - -static void JNICALL -CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, - jint code_size, const void* code_addr, jint map_length, - const jvmtiAddrLocationMap* map, const void* compile_info) { - char *name = NULL; - char *signature = NULL; - - CompiledMethodLoadEventsCount++; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, - jvmti_env, method, &name, &signature, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY3("CompiledMethodLoad event: %s%s (0x%p)\n", - name, signature, code_addr); - if (name != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); - if (signature != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); -} - -static int SingleStepEventsCount = 0; - -static void JNICALL -SingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, - jmethodID method, jlocation location) { - - SingleStepEventsCount++; -} - -static int ExceptionEventsCount = 0; - -static void JNICALL -Exception(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread, - jmethodID method, jlocation location, jobject exception, - jmethodID catch_method, jlocation catch_location) { - - if (sync_freq && ((ExceptionEventsCount % sync_freq) == 0)) { - - if (nsk_getVerboseMode()) { - jclass klass = NULL; - char *signature = NULL; - - if (!NSK_JNI_VERIFY(jni_env, (klass = - NSK_CPP_STUB2(GetObjectClass, jni_env, exception)) != NULL)) { - nsk_jvmti_setFailStatus(); - return; - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti_env, - klass, &signature, NULL))) { - nsk_jvmti_setFailStatus(); - return; - } - NSK_DISPLAY2("Exception event %d: %s\n", - ExceptionEventsCount, signature); - if (signature != NULL) - NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); - } - - if (!redefine(jvmti_env, (bci_mode != BCI_MODE_EMCP && newFlag) ? - new_class_def : old_class_def)) - nsk_jvmti_setFailStatus(); - - NSK_DISPLAY1("SingleStepEventsCount: %d\n", SingleStepEventsCount); - if (vm_mode == VM_MODE_MIXED) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti_env, ((newFlag) ? JVMTI_DISABLE : JVMTI_ENABLE), - JVMTI_EVENT_SINGLE_STEP, NULL))) - nsk_jvmti_setFailStatus(); - } - - if (nsk_getVerboseMode() && bci_mode != BCI_MODE_EMCP) { - jint profileCount = NSK_CPP_STUB3(GetStaticIntField, jni_env, - profile_klass, count_field); - NSK_DISPLAY1("profileCount: %d\n", profileCount); - } - - newFlag = (newFlag) ? NSK_FALSE : NSK_TRUE; - } - - ExceptionEventsCount++; -} - -/* ========================================================================== */ - -static jrawMonitorID waitLock = NULL; - -static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { - int i; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) - return NSK_FALSE; - - if (vm_mode != VM_MODE_COMPILED) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL))) - return NSK_FALSE; - } - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, - jvmti, "waitLock", &waitLock))) - return NSK_FALSE; - - for (i = 0; i < classCount; i++) { - NSK_DISPLAY1("Find class: %s\n", names[i]); - if (!NSK_JNI_VERIFY(jni, (old_class_def[i].klass = - NSK_CPP_STUB2(FindClass, jni, names[i])) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (old_class_def[i].klass = - NSK_CPP_STUB2(NewGlobalRef, jni, - old_class_def[i].klass)) != NULL)) - return NSK_FALSE; - } - - if (bci_mode != BCI_MODE_EMCP) { - NSK_DISPLAY1("Find class: %s\n", PROFILE_CLASS_NAME); - if (!NSK_JNI_VERIFY(jni, (profile_klass = - NSK_CPP_STUB2(FindClass, jni, PROFILE_CLASS_NAME)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (profile_klass = - NSK_CPP_STUB2(NewGlobalRef, jni, profile_klass)) != NULL)) - return NSK_FALSE; - - if (!NSK_JNI_VERIFY(jni, (count_field = - NSK_CPP_STUB4(GetStaticFieldID, jni, profile_klass, - (bci_mode == BCI_MODE_CALL) ? "callCount" : "allocCount", - "I")) != NULL)) - return NSK_FALSE; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, - classCount * sizeof(jvmtiClassDefinition), - (unsigned char**) &new_class_def))) - return NSK_FALSE; - - for (i = 0; i < classCount; i++) { - new_class_def[i].klass = old_class_def[i].klass; - if (!Inject(old_class_def[i].class_bytes, - old_class_def[i].class_byte_count, - (unsigned char**) &new_class_def[i].class_bytes, - &new_class_def[i].class_byte_count, bci_mode)) - return NSK_FALSE; - } - } - - if (sync_freq) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_EXCEPTION, NULL))) - return NSK_FALSE; - } - - return NSK_TRUE; -} - -/* ========================================================================== */ - -static int wait_for(jvmtiEnv* jvmti, jlong millis) { - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, waitLock))) - return NSK_FALSE; - - if (!NSK_JVMTI_VERIFY( - NSK_CPP_STUB3(RawMonitorWait, jvmti, waitLock, millis))) - nsk_jvmti_setFailStatus(); - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, waitLock))) - return NSK_FALSE; - - return NSK_TRUE; -} - -/* ========================================================================== */ - -/** Agent algorithm. */ -static void JNICALL -agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { - int i; - - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (!prepare(jvmti, jni)) { - nsk_jvmti_setFailStatus(); - return; - } - - /* resume debugee and wait for sync */ - if (!nsk_jvmti_resumeSync()) - return; - if (!nsk_jvmti_waitForSync(timeout)) - return; - - if (sync_freq) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_DISABLE, JVMTI_EVENT_EXCEPTION, NULL))) - nsk_jvmti_setFailStatus(); - } else { - - for (i = 0; i < number_of_samples && !nsk_jvmti_isFailStatus(); i++) { - wait_for(jvmti, sampling_interval); - - if (!redefine(jvmti, (bci_mode != BCI_MODE_EMCP && newFlag) ? - new_class_def : old_class_def)) - nsk_jvmti_setFailStatus(); - - NSK_DISPLAY1("SingleStepEventsCount: %d\n", SingleStepEventsCount); - if (vm_mode == VM_MODE_MIXED) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, (((i % 2)==0) ? JVMTI_DISABLE : JVMTI_ENABLE), - JVMTI_EVENT_SINGLE_STEP, NULL))) - nsk_jvmti_setFailStatus(); - } - - if (nsk_getVerboseMode() && bci_mode != BCI_MODE_EMCP) { - jint profileCount = NSK_CPP_STUB3(GetStaticIntField, jni, - profile_klass, count_field); - NSK_DISPLAY1("profileCount: %d\n", profileCount); - } - - newFlag = (newFlag) ? NSK_FALSE : NSK_TRUE; - } - - } - - if (vm_mode != VM_MODE_COMPILED) { - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, NULL))) - nsk_jvmti_setFailStatus(); - } - - if (!nsk_jvmti_resumeSync()) - return; -} - -/* ========================================================================== */ - -/** Agent library initialization. */ -jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { - jvmtiEnv* jvmti = NULL; - jvmtiCapabilities caps; - jvmtiEventCallbacks callbacks; - const char* optValue; - - NSK_DISPLAY0("Agent_OnLoad\n"); - - /* init framework and parse options */ - if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) - return JNI_ERR; - - timeout = nsk_jvmti_getWaitTime() * 60 * 1000; - - /* get options */ - number_of_samples = nsk_jvmti_findOptionIntValue("samples", - DEFAULT_NUMBER_OF_SAMPLES); - if (!NSK_VERIFY(number_of_samples > 0)) - return JNI_ERR; - NSK_DISPLAY1("samples: %d\n", number_of_samples); - - sampling_interval = nsk_jvmti_findOptionIntValue("interval", - DEFAULT_SAMPLING_INTERVAL); - if (!NSK_VERIFY(sampling_interval > 0)) - return JNI_ERR; - NSK_DISPLAY1("interval: %d\n", sampling_interval); - - package_name = nsk_jvmti_findOptionStringValue("package", - DEFAULT_PACKAGE_NAME); - if (!NSK_VERIFY(package_name != NULL)) - return JNI_ERR; - NSK_DISPLAY1("package: %s\n", package_name); - - package_name_length = strlen(package_name); - if (!NSK_VERIFY(package_name_length > 0)) - return JNI_ERR; - - max_classes = nsk_jvmti_findOptionIntValue("classes", - DEFAULT_MAX_NUMBER_OF_CLASSES); - if (!NSK_VERIFY(max_classes > 0)) - return JNI_ERR; - NSK_DISPLAY1("classes: %d\n", max_classes); - - optValue = nsk_jvmti_findOptionValue("mode"); - if (optValue != NULL) { - if (strcmp(optValue, "compiled") == 0) - vm_mode = VM_MODE_COMPILED; - else if (strcmp(optValue, "interpreted") == 0) - vm_mode = VM_MODE_INTERPRETED; - else if (strcmp(optValue, "mixed") == 0) - vm_mode = VM_MODE_MIXED; - else { - NSK_COMPLAIN1("Unknown option value: mode=%s\n", optValue); - return JNI_ERR; - } - } - - optValue = nsk_jvmti_findOptionValue("bci"); - if (optValue != NULL) { - if (strcmp(optValue, "emcp") == 0) - bci_mode = BCI_MODE_EMCP; - else if (strcmp(optValue, "call") == 0) - bci_mode = BCI_MODE_CALL; - else if (strcmp(optValue, "alloc") == 0) - bci_mode = BCI_MODE_ALLOC; - else { - NSK_COMPLAIN1("Unknown option value: bci=%s\n", optValue); - return JNI_ERR; - } - } - - sync_freq = nsk_jvmti_findOptionIntValue("sync", 0); - if (!NSK_VERIFY(sync_freq >= 0)) - return JNI_ERR; - NSK_DISPLAY1("sync: %d\n", sync_freq); - - /* create JVMTI environment */ - if (!NSK_VERIFY((jvmti = - nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) - return JNI_ERR; - - /* allocate tables for classes */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, - max_classes * sizeof(char*), (unsigned char**) &names))) - return JNI_ERR; - - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, - max_classes * sizeof(jvmtiClassDefinition), - (unsigned char**) &old_class_def))) - return JNI_ERR; - - /* add capabilities */ - memset(&caps, 0, sizeof(caps)); - caps.can_redefine_classes = 1; - caps.can_generate_compiled_method_load_events = 1; - if (vm_mode != VM_MODE_COMPILED) { - caps.can_generate_single_step_events = 1; - } - if (sync_freq) { - caps.can_generate_exception_events = 1; - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) - return JNI_ERR; - - if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) - return JNI_ERR; - - /* set event callbacks */ - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ClassFileLoadHook = &ClassFileLoadHook; - callbacks.CompiledMethodLoad = &CompiledMethodLoad; - if (vm_mode != VM_MODE_COMPILED) { - callbacks.SingleStep = &SingleStep; - } - if (sync_freq) { - callbacks.Exception = &Exception; - } - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, - jvmti, &callbacks, sizeof(callbacks)))) - return JNI_ERR; - - /* enable events */ - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) - return JNI_ERR; - if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, - jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL))) - return JNI_ERR; - - return JNI_OK; -} - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/HotSwap.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/HotSwap.cpp new file mode 100644 index 00000000000..d56f443f83e --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/HotSwap.cpp @@ -0,0 +1,505 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "Injector.h" +#include "agent_common.h" + +#define PASSED 0 + +#ifdef __cplusplus +extern "C" { +#endif + +/* ========================================================================== */ + +#define DEFAULT_MAX_NUMBER_OF_CLASSES 100 +#define DEFAULT_NUMBER_OF_SAMPLES 10 +#define DEFAULT_SAMPLING_INTERVAL 100 +#define DEFAULT_PACKAGE_NAME "nsk/jvmti/scenarios/hotswap" +#define PROFILE_CLASS_NAME "nsk/share/jvmti/ProfileCollector" + +enum { + VM_MODE_COMPILED = 0, + VM_MODE_INTERPRETED = 1, + VM_MODE_MIXED = 2 +}; + +/* scaffold objects */ +static jlong timeout = 0; + +/* test options */ +static int number_of_samples; +static jlong sampling_interval; +static const char* package_name; +static size_t package_name_length; +static int vm_mode = VM_MODE_COMPILED; +static int bci_mode = BCI_MODE_EMCP; +static int sync_freq = 0; + +static jclass profile_klass = NULL; +static jfieldID count_field = NULL; + +/* test objects */ +static int max_classes; +static char** names = NULL; +static jvmtiClassDefinition* old_class_def = NULL; +static jvmtiClassDefinition* new_class_def = NULL; +static int classCount = 0; +static int newFlag = NSK_FALSE; + +/* ========================================================================== */ + +static int redefine(jvmtiEnv* jvmti, jvmtiClassDefinition* class_def) { + + if (!NSK_VERIFY(classCount != 0)) + return NSK_FALSE; + + NSK_DISPLAY1("Redefining %d classes...\n", classCount); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses, + jvmti, classCount, class_def))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/** callback functions **/ + +static void JNICALL +ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env, + jclass class_being_redefined, jobject loader, + const char* name, jobject protection_domain, + jint class_data_len, const unsigned char* class_data, + jint *new_class_data_len, unsigned char** new_class_data) { + jint name_len; + + if (name != NULL && classCount < max_classes && + class_being_redefined == NULL && + (strcmp(name, PROFILE_CLASS_NAME) != 0) && + (strncmp(name, package_name, package_name_length) == 0)) { + NSK_DISPLAY1("ClassFileLoadHook: %s\n", name); + name_len = (jint) strlen(name) + 1; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti_env, + name_len, (unsigned char**) &names[classCount]))) { + nsk_jvmti_setFailStatus(); + return; + } + memcpy(names[classCount], name, name_len); + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, + jvmti_env, class_data_len, (unsigned char**) + &old_class_def[classCount].class_bytes))) { + nsk_jvmti_setFailStatus(); + return; + } + memcpy((unsigned char*) old_class_def[classCount].class_bytes, + class_data, class_data_len); + old_class_def[classCount].class_byte_count = class_data_len; + classCount++; + } +} + +static int CompiledMethodLoadEventsCount = 0; + +static void JNICALL +CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, + jint code_size, const void* code_addr, jint map_length, + const jvmtiAddrLocationMap* map, const void* compile_info) { + char *name = NULL; + char *signature = NULL; + + CompiledMethodLoadEventsCount++; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, + jvmti_env, method, &name, &signature, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY3("CompiledMethodLoad event: %s%s (0x%p)\n", + name, signature, code_addr); + if (name != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name); + if (signature != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); +} + +static int SingleStepEventsCount = 0; + +static void JNICALL +SingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, + jmethodID method, jlocation location) { + + SingleStepEventsCount++; +} + +static int ExceptionEventsCount = 0; + +static void JNICALL +Exception(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread, + jmethodID method, jlocation location, jobject exception, + jmethodID catch_method, jlocation catch_location) { + + if (sync_freq && ((ExceptionEventsCount % sync_freq) == 0)) { + + if (nsk_getVerboseMode()) { + jclass klass = NULL; + char *signature = NULL; + + if (!NSK_JNI_VERIFY(jni_env, (klass = + NSK_CPP_STUB2(GetObjectClass, jni_env, exception)) != NULL)) { + nsk_jvmti_setFailStatus(); + return; + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti_env, + klass, &signature, NULL))) { + nsk_jvmti_setFailStatus(); + return; + } + NSK_DISPLAY2("Exception event %d: %s\n", + ExceptionEventsCount, signature); + if (signature != NULL) + NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature); + } + + if (!redefine(jvmti_env, (bci_mode != BCI_MODE_EMCP && newFlag) ? + new_class_def : old_class_def)) + nsk_jvmti_setFailStatus(); + + NSK_DISPLAY1("SingleStepEventsCount: %d\n", SingleStepEventsCount); + if (vm_mode == VM_MODE_MIXED) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti_env, ((newFlag) ? JVMTI_DISABLE : JVMTI_ENABLE), + JVMTI_EVENT_SINGLE_STEP, NULL))) + nsk_jvmti_setFailStatus(); + } + + if (nsk_getVerboseMode() && bci_mode != BCI_MODE_EMCP) { + jint profileCount = NSK_CPP_STUB3(GetStaticIntField, jni_env, + profile_klass, count_field); + NSK_DISPLAY1("profileCount: %d\n", profileCount); + } + + newFlag = (newFlag) ? NSK_FALSE : NSK_TRUE; + } + + ExceptionEventsCount++; +} + +/* ========================================================================== */ + +static jrawMonitorID waitLock = NULL; + +static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) { + int i; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) + return NSK_FALSE; + + if (vm_mode != VM_MODE_COMPILED) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL))) + return NSK_FALSE; + } + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, + jvmti, "waitLock", &waitLock))) + return NSK_FALSE; + + for (i = 0; i < classCount; i++) { + NSK_DISPLAY1("Find class: %s\n", names[i]); + if (!NSK_JNI_VERIFY(jni, (old_class_def[i].klass = + NSK_CPP_STUB2(FindClass, jni, names[i])) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (old_class_def[i].klass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, + old_class_def[i].klass)) != NULL)) + return NSK_FALSE; + } + + if (bci_mode != BCI_MODE_EMCP) { + NSK_DISPLAY1("Find class: %s\n", PROFILE_CLASS_NAME); + if (!NSK_JNI_VERIFY(jni, (profile_klass = + NSK_CPP_STUB2(FindClass, jni, PROFILE_CLASS_NAME)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (profile_klass = (jclass) + NSK_CPP_STUB2(NewGlobalRef, jni, profile_klass)) != NULL)) + return NSK_FALSE; + + if (!NSK_JNI_VERIFY(jni, (count_field = + NSK_CPP_STUB4(GetStaticFieldID, jni, profile_klass, + (bci_mode == BCI_MODE_CALL) ? "callCount" : "allocCount", + "I")) != NULL)) + return NSK_FALSE; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, + classCount * sizeof(jvmtiClassDefinition), + (unsigned char**) &new_class_def))) + return NSK_FALSE; + + for (i = 0; i < classCount; i++) { + new_class_def[i].klass = old_class_def[i].klass; + if (!Inject(old_class_def[i].class_bytes, + old_class_def[i].class_byte_count, + (unsigned char**) &new_class_def[i].class_bytes, + &new_class_def[i].class_byte_count, bci_mode)) + return NSK_FALSE; + } + } + + if (sync_freq) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_EXCEPTION, NULL))) + return NSK_FALSE; + } + + return NSK_TRUE; +} + +/* ========================================================================== */ + +static int wait_for(jvmtiEnv* jvmti, jlong millis) { + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, waitLock))) + return NSK_FALSE; + + if (!NSK_JVMTI_VERIFY( + NSK_CPP_STUB3(RawMonitorWait, jvmti, waitLock, millis))) + nsk_jvmti_setFailStatus(); + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, waitLock))) + return NSK_FALSE; + + return NSK_TRUE; +} + +/* ========================================================================== */ + +/** Agent algorithm. */ +static void JNICALL +agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { + int i; + + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (!prepare(jvmti, jni)) { + nsk_jvmti_setFailStatus(); + return; + } + + /* resume debugee and wait for sync */ + if (!nsk_jvmti_resumeSync()) + return; + if (!nsk_jvmti_waitForSync(timeout)) + return; + + if (sync_freq) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_DISABLE, JVMTI_EVENT_EXCEPTION, NULL))) + nsk_jvmti_setFailStatus(); + } else { + + for (i = 0; i < number_of_samples && !nsk_jvmti_isFailStatus(); i++) { + wait_for(jvmti, sampling_interval); + + if (!redefine(jvmti, (bci_mode != BCI_MODE_EMCP && newFlag) ? + new_class_def : old_class_def)) + nsk_jvmti_setFailStatus(); + + NSK_DISPLAY1("SingleStepEventsCount: %d\n", SingleStepEventsCount); + if (vm_mode == VM_MODE_MIXED) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, (((i % 2)==0) ? JVMTI_DISABLE : JVMTI_ENABLE), + JVMTI_EVENT_SINGLE_STEP, NULL))) + nsk_jvmti_setFailStatus(); + } + + if (nsk_getVerboseMode() && bci_mode != BCI_MODE_EMCP) { + jint profileCount = NSK_CPP_STUB3(GetStaticIntField, jni, + profile_klass, count_field); + NSK_DISPLAY1("profileCount: %d\n", profileCount); + } + + newFlag = (newFlag) ? NSK_FALSE : NSK_TRUE; + } + + } + + if (vm_mode != VM_MODE_COMPILED) { + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, NULL))) + nsk_jvmti_setFailStatus(); + } + + if (!nsk_jvmti_resumeSync()) + return; +} + +/* ========================================================================== */ + +/** Agent library initialization. */ +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiEnv* jvmti = NULL; + jvmtiCapabilities caps; + jvmtiEventCallbacks callbacks; + const char* optValue; + + NSK_DISPLAY0("Agent_OnLoad\n"); + + /* init framework and parse options */ + if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) + return JNI_ERR; + + timeout = nsk_jvmti_getWaitTime() * 60 * 1000; + + /* get options */ + number_of_samples = nsk_jvmti_findOptionIntValue("samples", + DEFAULT_NUMBER_OF_SAMPLES); + if (!NSK_VERIFY(number_of_samples > 0)) + return JNI_ERR; + NSK_DISPLAY1("samples: %d\n", number_of_samples); + + sampling_interval = nsk_jvmti_findOptionIntValue("interval", + DEFAULT_SAMPLING_INTERVAL); + if (!NSK_VERIFY(sampling_interval > 0)) + return JNI_ERR; + NSK_DISPLAY1("interval: %d\n", sampling_interval); + + package_name = nsk_jvmti_findOptionStringValue("package", + DEFAULT_PACKAGE_NAME); + if (!NSK_VERIFY(package_name != NULL)) + return JNI_ERR; + NSK_DISPLAY1("package: %s\n", package_name); + + package_name_length = strlen(package_name); + if (!NSK_VERIFY(package_name_length > 0)) + return JNI_ERR; + + max_classes = nsk_jvmti_findOptionIntValue("classes", + DEFAULT_MAX_NUMBER_OF_CLASSES); + if (!NSK_VERIFY(max_classes > 0)) + return JNI_ERR; + NSK_DISPLAY1("classes: %d\n", max_classes); + + optValue = nsk_jvmti_findOptionValue("mode"); + if (optValue != NULL) { + if (strcmp(optValue, "compiled") == 0) + vm_mode = VM_MODE_COMPILED; + else if (strcmp(optValue, "interpreted") == 0) + vm_mode = VM_MODE_INTERPRETED; + else if (strcmp(optValue, "mixed") == 0) + vm_mode = VM_MODE_MIXED; + else { + NSK_COMPLAIN1("Unknown option value: mode=%s\n", optValue); + return JNI_ERR; + } + } + + optValue = nsk_jvmti_findOptionValue("bci"); + if (optValue != NULL) { + if (strcmp(optValue, "emcp") == 0) + bci_mode = BCI_MODE_EMCP; + else if (strcmp(optValue, "call") == 0) + bci_mode = BCI_MODE_CALL; + else if (strcmp(optValue, "alloc") == 0) + bci_mode = BCI_MODE_ALLOC; + else { + NSK_COMPLAIN1("Unknown option value: bci=%s\n", optValue); + return JNI_ERR; + } + } + + sync_freq = nsk_jvmti_findOptionIntValue("sync", 0); + if (!NSK_VERIFY(sync_freq >= 0)) + return JNI_ERR; + NSK_DISPLAY1("sync: %d\n", sync_freq); + + /* create JVMTI environment */ + if (!NSK_VERIFY((jvmti = + nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) + return JNI_ERR; + + /* allocate tables for classes */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, + max_classes * sizeof(char*), (unsigned char**) &names))) + return JNI_ERR; + + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate, jvmti, + max_classes * sizeof(jvmtiClassDefinition), + (unsigned char**) &old_class_def))) + return JNI_ERR; + + /* add capabilities */ + memset(&caps, 0, sizeof(caps)); + caps.can_redefine_classes = 1; + caps.can_generate_compiled_method_load_events = 1; + if (vm_mode != VM_MODE_COMPILED) { + caps.can_generate_single_step_events = 1; + } + if (sync_freq) { + caps.can_generate_exception_events = 1; + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) + return JNI_ERR; + + if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) + return JNI_ERR; + + /* set event callbacks */ + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ClassFileLoadHook = &ClassFileLoadHook; + callbacks.CompiledMethodLoad = &CompiledMethodLoad; + if (vm_mode != VM_MODE_COMPILED) { + callbacks.SingleStep = &SingleStep; + } + if (sync_freq) { + callbacks.Exception = &Exception; + } + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, + jvmti, &callbacks, sizeof(callbacks)))) + return JNI_ERR; + + /* enable events */ + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL))) + return JNI_ERR; + if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, + jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL))) + return JNI_ERR; + + return JNI_OK; +} + +/* ========================================================================== */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/libHotSwap.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/libHotSwap.c deleted file mode 100644 index 3bcbca60df5..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/libHotSwap.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "HotSwap.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/libHotSwap.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/libHotSwap.cpp new file mode 100644 index 00000000000..a44c3d88f1a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/libHotSwap.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "HotSwap.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_FollowRefObjects.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_FollowRefObjects.c deleted file mode 100644 index fbf306a3da0..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_FollowRefObjects.c +++ /dev/null @@ -1,397 +0,0 @@ -/* - * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "jvmti_FollowRefObjects.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* ============================================================================= */ - -int g_fakeUserData = 0; -int g_userDataError = 0; -jvmtiHeapCallbacks g_wrongHeapCallbacks = { 0 }; - -/* This array has to be up-to-date with the jvmtiHeapReferenceKind enum */ -const char * const g_refKindStr[28] = { - "unknown_0", - "JVMTI_HEAP_REFERENCE_CLASS", - "JVMTI_HEAP_REFERENCE_FIELD", - "JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT", - "JVMTI_HEAP_REFERENCE_CLASS_LOADER", - "JVMTI_HEAP_REFERENCE_SIGNERS", - "JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN", - "JVMTI_HEAP_REFERENCE_INTERFACE", - "JVMTI_HEAP_REFERENCE_STATIC_FIELD", - "JVMTI_HEAP_REFERENCE_CONSTANT_POOL", - "JVMTI_HEAP_REFERENCE_SUPERCLASS", - "unknown_11", "unknown_12", "unknown_13", "unknown_14", "unknown_15", - "unknown_16", "unknown_17", "unknown_18", "unknown_19", "unknown_20", - "JVMTI_HEAP_REFERENCE_JNI_GLOBAL", - "JVMTI_HEAP_REFERENCE_SYSTEM_CLASS", - "JVMTI_HEAP_REFERENCE_MONITOR", - "JVMTI_HEAP_REFERENCE_STACK_LOCAL", - "JVMTI_HEAP_REFERENCE_JNI_LOCAL", - "JVMTI_HEAP_REFERENCE_THREAD", - "JVMTI_HEAP_REFERENCE_OTHER" -}; - -/* ============================================================================= */ - -char * g_szTagInfo[MAX_TAG]; -char g_tagFlags[MAX_TAG]; -int g_tagVisitCount[MAX_TAG]; - -/* ============================================================================= */ - -void markTagSet(jlong tag_val) -{ - if ( tag_val > 0 && tag_val < MAX_TAG ) - g_tagFlags[tag_val] |= FLAG_TAG_SET; -} - -void markTagVisited(jlong tag_val) -{ - if ( tag_val > 0 && tag_val < MAX_TAG ) { - g_tagVisitCount[tag_val]++; - } -} - -jboolean checkThatAllTagsVisited() -{ - jboolean ok = JNI_TRUE; - jlong i; - - NSK_DISPLAY0("Checking that all set tags have been visited\n"); - - for ( i = 1; i < MAX_TAG; i++ ) { - char flags = g_tagFlags[i]; - - if ( (g_tagFlags[i] & FLAG_TAG_SET) ) { - if ( g_tagVisitCount[i] == 0 ) { - NSK_COMPLAIN1("Tag %" LL "d has not been visited: %x\n", i); - ok = JNI_FALSE; - } - - DBG(printf(">>> Tag %" LL "d has been visited %i times: %s\n", i, g_tagVisitCount[i], g_szTagInfo[i])); - } - } - - return ok; -} - -JNIEXPORT void JNICALL Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_resetTags(JNIEnv* jni, jclass klass) -{ - memset(g_szTagInfo, 0, sizeof(g_szTagInfo)); - memset(g_tagFlags, 0, sizeof(g_tagFlags)); - memset(g_tagVisitCount, 0, sizeof(g_tagVisitCount)); -} - -JNIEXPORT jboolean JNICALL Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_setTag(JNIEnv* jni, jclass klass, jobject o, jlong tag, jstring sInfo) -{ - jvmtiEnv * jvmti = nsk_jvmti_getAgentJVMTIEnv(); - jint hashCode; - - if ( ! NSK_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, o, tag) == JVMTI_ERROR_NONE) ) { - NSK_COMPLAIN2("Can't set tag %li for object %lx\n", tag, o); - return JNI_FALSE; - } - - if ( ! NSK_VERIFY(NSK_CPP_STUB3(GetObjectHashCode, jvmti, o, &hashCode) == JVMTI_ERROR_NONE) ) { - NSK_COMPLAIN1("Can't get hash object %lx\n", o); - return JNI_FALSE; - } - - NSK_DISPLAY2("setTag: %08x <- % 3li", hashCode, tag); - - if ( tag > 0 && tag < MAX_TAG ) { - jboolean fCopy; - const char * s; - - if ( ! NSK_VERIFY((s = NSK_CPP_STUB3(GetStringUTFChars, jni, sInfo, &fCopy)) != NULL) ) { - NSK_COMPLAIN1("Can't get string at %#p\n", sInfo); - return JNI_FALSE; - } - - if ( ! s ) { - NSK_COMPLAIN1("Can't get string at %#p: NULL\n", sInfo); - return JNI_FALSE; - } - - g_szTagInfo[tag] = strdup(s); - - NSK_CPP_STUB3(ReleaseStringUTFChars, jni, sInfo, s); - - NSK_DISPLAY1(" // %s", g_szTagInfo[tag]); - - } - - markTagSet(tag); - - return JNI_TRUE; -} - -JNIEXPORT jlong JNICALL Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_getTag(JNIEnv* jni, jclass klass, jobject o) -{ - jvmtiEnv * jvmti = nsk_jvmti_getAgentJVMTIEnv(); - - jlong tag; - jvmtiError r; - if ( ! NSK_VERIFY((r = NSK_CPP_STUB3(GetTag, jvmti, o, &tag)) == JVMTI_ERROR_NONE) ) { - NSK_COMPLAIN2("Can't GetTag for object %lx. Return code: %i\n", o, r); - return -1; - } - - return tag; -} - -/* ============================================================================= */ - -int g_refsToVerifyCnt; - -RefToVerify g_refsToVerify[MAX_REFS]; - -/* ============================================================================= */ - -JNIEXPORT void JNICALL Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_resetRefsToVerify(JNIEnv* jni, jclass klass) -{ - g_refsToVerifyCnt = 0; -} - -static RefToVerify * findRefToVerify(jlong tagFrom, jlong tagTo, jint refKind) -{ - int i; - RefToVerify * pRefRec = g_refsToVerify; - - for ( i = g_refsToVerifyCnt; i > 0; i--, pRefRec++ ) { - pRefRec = &g_refsToVerify[i]; - if ( pRefRec->_tagFrom == tagFrom && pRefRec->_tagTo == tagTo && pRefRec->_refKind == refKind ) { - return pRefRec; - } - } - - return NULL; -} - -static jboolean addRefToVerify(jlong tagFrom, jlong tagTo, jint refKind, int expectedCount, int actualCount) -{ - RefToVerify * pRefRec; - - if ( g_refsToVerifyCnt >= MAX_REFS ) { - NSK_COMPLAIN0("TEST_BUG: Max. number of refs reached!"); - nsk_jvmti_setFailStatus(); - return JNI_FALSE; - } - - pRefRec = &g_refsToVerify[g_refsToVerifyCnt++]; - - pRefRec->_tagFrom = tagFrom; - pRefRec->_tagTo = tagTo; - pRefRec->_refKind = refKind; - pRefRec->_expectedCount = expectedCount; - pRefRec->_actualCount = actualCount; - - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_addRefToVerify(JNIEnv* jni, jclass klass, jobject from, jobject to, jint refKind, jint count) -{ - jvmtiEnv * jvmti = nsk_jvmti_getAgentJVMTIEnv(); - jvmtiError r; - jlong tagFrom, tagTo; - RefToVerify * pRefRec; - - if ( ! NSK_VERIFY((r = NSK_CPP_STUB3(GetTag, jvmti, from, &tagFrom)) == JVMTI_ERROR_NONE) ) { - NSK_COMPLAIN2("TEST_BUG: Can't GetTag for object %lx. Return code: %i\n", from, r); - nsk_jvmti_setFailStatus(); - return JNI_FALSE; - } - - - if ( ! NSK_VERIFY((r = NSK_CPP_STUB3(GetTag, jvmti, to, &tagTo)) == JVMTI_ERROR_NONE) ) { - NSK_COMPLAIN2("TEST_BUG: Can't GetTag for object %lx. Return code: %i\n", to, r); - nsk_jvmti_setFailStatus(); - return JNI_FALSE; - } - - if ( (pRefRec = findRefToVerify(tagFrom, tagTo, refKind)) != NULL ) { - pRefRec->_expectedCount += count; - return JNI_TRUE; - } - - return addRefToVerify(tagFrom, tagTo, refKind, count, 0); -} - -jboolean markRefToVerify(jlong tagFrom, jlong tagTo, int refKind) -{ - RefToVerify * pRefRec; - - if ( (pRefRec = findRefToVerify(tagFrom, tagTo, refKind)) != NULL ) { - pRefRec->_actualCount++; - return JNI_TRUE; - } - - return addRefToVerify(tagFrom, tagTo, refKind, 0, 1); -} - -/* ============================================================================= */ - -void checkUserData(const char * szFile, const int line, void * user_data) -{ - if (user_data != &g_fakeUserData && !g_userDataError) { - NSK_COMPLAIN4("%s, %i: Unexpected user_data is passed" - " to heapReferenceCallback:\n" - " expected: 0x%p\n" - " actual: 0x%p\n", - szFile, line, - &g_fakeUserData, - user_data); - g_userDataError++; - } -} - -#define CHECK_USER_DATA(p) checkUserData(__FILE__, __LINE__, (p)) - -void printHeapRefCallbackInfo( - jvmtiHeapReferenceKind reference_kind, - const jvmtiHeapReferenceInfo* reference_info, - jlong class_tag, - jlong referrer_class_tag, - jlong size, - jlong* tag_ptr, - jlong* referrer_tag_ptr, - jint length) -{ - const char * szInfo, * szRefInfo; - jlong tag_val = tag_ptr ? *tag_ptr : 0; - - NSK_DISPLAY1("heapReferenceCallback: %s", g_refKindStr[reference_kind]); - - NSK_DISPLAY3(" reference_info: %#lx, class_tag: %#" LL "d, referrer_class_tag: %#" LL "d\n", - reference_info, class_tag, referrer_class_tag); - - NSK_DISPLAY4(" size: %" LL "d, tag_ptr: %p, referrer_tag_ptr: %p, length: %-ld\n", - size, tag_ptr, referrer_tag_ptr, length); - - NSK_DISPLAY2(" tag: %" LL "d, referrer_tag: %" LL "d\n", - tag_val, DEREF(referrer_tag_ptr)); - - szInfo = ( tag_val > 0 && tag_val < MAX_TAG ) ? g_szTagInfo[tag_val] : ""; - szRefInfo = ( referrer_tag_ptr && *referrer_tag_ptr > 0 && *referrer_tag_ptr < MAX_TAG ) ? g_szTagInfo[*referrer_tag_ptr] : ""; - - NSK_DISPLAY3(" summary: %s: %s <- %s\n", - g_refKindStr[reference_kind], szInfo, szRefInfo); -} - -/* ============================================================================= */ - -jint JNICALL wrongHeapReferenceCallback( - jvmtiHeapReferenceKind reference_kind, - const jvmtiHeapReferenceInfo* reference_info, - jlong class_tag, - jlong referrer_class_tag, - jlong size, - jlong* tag_ptr, - jlong* referrer_tag_ptr, - jint length, - void* user_data) -{ - CHECK_USER_DATA(user_data); - NSK_COMPLAIN0("heap reference callback was called, where it should not be\n"); - nsk_jvmti_setFailStatus(); - printHeapRefCallbackInfo(reference_kind, reference_info, class_tag, referrer_class_tag, size, tag_ptr, referrer_tag_ptr, length); - - return JVMTI_VISIT_OBJECTS; -} - -jint JNICALL wrongPrimitiveFieldCallback( - jvmtiHeapReferenceKind reference_kind, - const jvmtiHeapReferenceInfo* reference_info, - jlong class_tag, - jlong* tag_ptr, - jvalue value, - jvmtiPrimitiveType value_type, - void* user_data) -{ - CHECK_USER_DATA(user_data); - NSK_COMPLAIN0("primitive field callback was called, where it should not be\n"); - nsk_jvmti_setFailStatus(); - - return JVMTI_VISIT_OBJECTS; -} - -jint JNICALL wrongArrayPrimitiveValueCallback( - jlong class_tag, - jlong size, - jlong* tag_ptr, - jint element_count, - jvmtiPrimitiveType element_type, - const void* elements, - void* user_data) -{ - CHECK_USER_DATA(user_data); - NSK_COMPLAIN0("array primitive value callback was called, where it should not be\n"); - nsk_jvmti_setFailStatus(); - - return JVMTI_VISIT_OBJECTS; -} - -jint JNICALL wrongStringPrimitiveValueCallback( - jlong class_tag, - jlong size, - jlong* tag_ptr, - const jchar* value, - jint value_length, - void* user_data) -{ - CHECK_USER_DATA(user_data); - NSK_COMPLAIN0("string primitive value callback was called, where it should not be\n"); - nsk_jvmti_setFailStatus(); - - return JVMTI_VISIT_OBJECTS; -} - -/* ============================================================================= */ - -void jvmti_FollowRefObject_init() -{ - g_wrongHeapCallbacks.heap_iteration_callback = NULL; - g_wrongHeapCallbacks.heap_reference_callback = wrongHeapReferenceCallback; - g_wrongHeapCallbacks.primitive_field_callback = wrongPrimitiveFieldCallback; - g_wrongHeapCallbacks.array_primitive_value_callback = wrongArrayPrimitiveValueCallback; - g_wrongHeapCallbacks.string_primitive_value_callback = wrongStringPrimitiveValueCallback; - - Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_resetTags(NULL, NULL); - Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_resetRefsToVerify(NULL, NULL); -} - -/* ============================================================================= */ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_FollowRefObjects.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_FollowRefObjects.cpp new file mode 100644 index 00000000000..abab6f4c11b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_FollowRefObjects.cpp @@ -0,0 +1,397 @@ +/* + * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "jvmti_FollowRefObjects.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= */ + +int g_fakeUserData = 0; +int g_userDataError = 0; +jvmtiHeapCallbacks g_wrongHeapCallbacks = {}; + +/* This array has to be up-to-date with the jvmtiHeapReferenceKind enum */ +const char * const g_refKindStr[28] = { + "unknown_0", + "JVMTI_HEAP_REFERENCE_CLASS", + "JVMTI_HEAP_REFERENCE_FIELD", + "JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT", + "JVMTI_HEAP_REFERENCE_CLASS_LOADER", + "JVMTI_HEAP_REFERENCE_SIGNERS", + "JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN", + "JVMTI_HEAP_REFERENCE_INTERFACE", + "JVMTI_HEAP_REFERENCE_STATIC_FIELD", + "JVMTI_HEAP_REFERENCE_CONSTANT_POOL", + "JVMTI_HEAP_REFERENCE_SUPERCLASS", + "unknown_11", "unknown_12", "unknown_13", "unknown_14", "unknown_15", + "unknown_16", "unknown_17", "unknown_18", "unknown_19", "unknown_20", + "JVMTI_HEAP_REFERENCE_JNI_GLOBAL", + "JVMTI_HEAP_REFERENCE_SYSTEM_CLASS", + "JVMTI_HEAP_REFERENCE_MONITOR", + "JVMTI_HEAP_REFERENCE_STACK_LOCAL", + "JVMTI_HEAP_REFERENCE_JNI_LOCAL", + "JVMTI_HEAP_REFERENCE_THREAD", + "JVMTI_HEAP_REFERENCE_OTHER" +}; + +/* ============================================================================= */ + +char * g_szTagInfo[MAX_TAG]; +char g_tagFlags[MAX_TAG]; +int g_tagVisitCount[MAX_TAG]; + +/* ============================================================================= */ + +void markTagSet(jlong tag_val) +{ + if ( tag_val > 0 && tag_val < MAX_TAG ) + g_tagFlags[tag_val] |= FLAG_TAG_SET; +} + +void markTagVisited(jlong tag_val) +{ + if ( tag_val > 0 && tag_val < MAX_TAG ) { + g_tagVisitCount[tag_val]++; + } +} + +jboolean checkThatAllTagsVisited() +{ + jboolean ok = JNI_TRUE; + jlong i; + + NSK_DISPLAY0("Checking that all set tags have been visited\n"); + + for ( i = 1; i < MAX_TAG; i++ ) { + char flags = g_tagFlags[i]; + + if ( (g_tagFlags[i] & FLAG_TAG_SET) ) { + if ( g_tagVisitCount[i] == 0 ) { + NSK_COMPLAIN1("Tag %" LL "d has not been visited: %x\n", i); + ok = JNI_FALSE; + } + + DBG(printf(">>> Tag %" LL "d has been visited %i times: %s\n", i, g_tagVisitCount[i], g_szTagInfo[i])); + } + } + + return ok; +} + +JNIEXPORT void JNICALL Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_resetTags(JNIEnv* jni, jclass klass) +{ + memset(g_szTagInfo, 0, sizeof(g_szTagInfo)); + memset(g_tagFlags, 0, sizeof(g_tagFlags)); + memset(g_tagVisitCount, 0, sizeof(g_tagVisitCount)); +} + +JNIEXPORT jboolean JNICALL Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_setTag(JNIEnv* jni, jclass klass, jobject o, jlong tag, jstring sInfo) +{ + jvmtiEnv * jvmti = nsk_jvmti_getAgentJVMTIEnv(); + jint hashCode; + + if ( ! NSK_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, o, tag) == JVMTI_ERROR_NONE) ) { + NSK_COMPLAIN2("Can't set tag %li for object %lx\n", tag, o); + return JNI_FALSE; + } + + if ( ! NSK_VERIFY(NSK_CPP_STUB3(GetObjectHashCode, jvmti, o, &hashCode) == JVMTI_ERROR_NONE) ) { + NSK_COMPLAIN1("Can't get hash object %lx\n", o); + return JNI_FALSE; + } + + NSK_DISPLAY2("setTag: %08x <- % 3li", hashCode, tag); + + if ( tag > 0 && tag < MAX_TAG ) { + jboolean fCopy; + const char * s; + + if ( ! NSK_VERIFY((s = NSK_CPP_STUB3(GetStringUTFChars, jni, sInfo, &fCopy)) != NULL) ) { + NSK_COMPLAIN1("Can't get string at %#p\n", sInfo); + return JNI_FALSE; + } + + if ( ! s ) { + NSK_COMPLAIN1("Can't get string at %#p: NULL\n", sInfo); + return JNI_FALSE; + } + + g_szTagInfo[tag] = strdup(s); + + NSK_CPP_STUB3(ReleaseStringUTFChars, jni, sInfo, s); + + NSK_DISPLAY1(" // %s", g_szTagInfo[tag]); + + } + + markTagSet(tag); + + return JNI_TRUE; +} + +JNIEXPORT jlong JNICALL Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_getTag(JNIEnv* jni, jclass klass, jobject o) +{ + jvmtiEnv * jvmti = nsk_jvmti_getAgentJVMTIEnv(); + + jlong tag; + jvmtiError r; + if ( ! NSK_VERIFY((r = NSK_CPP_STUB3(GetTag, jvmti, o, &tag)) == JVMTI_ERROR_NONE) ) { + NSK_COMPLAIN2("Can't GetTag for object %lx. Return code: %i\n", o, r); + return -1; + } + + return tag; +} + +/* ============================================================================= */ + +int g_refsToVerifyCnt; + +RefToVerify g_refsToVerify[MAX_REFS]; + +/* ============================================================================= */ + +JNIEXPORT void JNICALL Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_resetRefsToVerify(JNIEnv* jni, jclass klass) +{ + g_refsToVerifyCnt = 0; +} + +static RefToVerify * findRefToVerify(jlong tagFrom, jlong tagTo, jint refKind) +{ + int i; + RefToVerify * pRefRec = g_refsToVerify; + + for ( i = g_refsToVerifyCnt; i > 0; i--, pRefRec++ ) { + pRefRec = &g_refsToVerify[i]; + if ( pRefRec->_tagFrom == tagFrom && pRefRec->_tagTo == tagTo && pRefRec->_refKind == refKind ) { + return pRefRec; + } + } + + return NULL; +} + +static jboolean addRefToVerify(jlong tagFrom, jlong tagTo, jint refKind, int expectedCount, int actualCount) +{ + RefToVerify * pRefRec; + + if ( g_refsToVerifyCnt >= MAX_REFS ) { + NSK_COMPLAIN0("TEST_BUG: Max. number of refs reached!"); + nsk_jvmti_setFailStatus(); + return JNI_FALSE; + } + + pRefRec = &g_refsToVerify[g_refsToVerifyCnt++]; + + pRefRec->_tagFrom = tagFrom; + pRefRec->_tagTo = tagTo; + pRefRec->_refKind = refKind; + pRefRec->_expectedCount = expectedCount; + pRefRec->_actualCount = actualCount; + + return JNI_TRUE; +} + +JNIEXPORT jboolean JNICALL Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_addRefToVerify(JNIEnv* jni, jclass klass, jobject from, jobject to, jint refKind, jint count) +{ + jvmtiEnv * jvmti = nsk_jvmti_getAgentJVMTIEnv(); + jvmtiError r; + jlong tagFrom, tagTo; + RefToVerify * pRefRec; + + if ( ! NSK_VERIFY((r = NSK_CPP_STUB3(GetTag, jvmti, from, &tagFrom)) == JVMTI_ERROR_NONE) ) { + NSK_COMPLAIN2("TEST_BUG: Can't GetTag for object %lx. Return code: %i\n", from, r); + nsk_jvmti_setFailStatus(); + return JNI_FALSE; + } + + + if ( ! NSK_VERIFY((r = NSK_CPP_STUB3(GetTag, jvmti, to, &tagTo)) == JVMTI_ERROR_NONE) ) { + NSK_COMPLAIN2("TEST_BUG: Can't GetTag for object %lx. Return code: %i\n", to, r); + nsk_jvmti_setFailStatus(); + return JNI_FALSE; + } + + if ( (pRefRec = findRefToVerify(tagFrom, tagTo, refKind)) != NULL ) { + pRefRec->_expectedCount += count; + return JNI_TRUE; + } + + return addRefToVerify(tagFrom, tagTo, refKind, count, 0); +} + +jboolean markRefToVerify(jlong tagFrom, jlong tagTo, int refKind) +{ + RefToVerify * pRefRec; + + if ( (pRefRec = findRefToVerify(tagFrom, tagTo, refKind)) != NULL ) { + pRefRec->_actualCount++; + return JNI_TRUE; + } + + return addRefToVerify(tagFrom, tagTo, refKind, 0, 1); +} + +/* ============================================================================= */ + +void checkUserData(const char * szFile, const int line, void * user_data) +{ + if (user_data != &g_fakeUserData && !g_userDataError) { + NSK_COMPLAIN4("%s, %i: Unexpected user_data is passed" + " to heapReferenceCallback:\n" + " expected: 0x%p\n" + " actual: 0x%p\n", + szFile, line, + &g_fakeUserData, + user_data); + g_userDataError++; + } +} + +#define CHECK_USER_DATA(p) checkUserData(__FILE__, __LINE__, (p)) + +void printHeapRefCallbackInfo( + jvmtiHeapReferenceKind reference_kind, + const jvmtiHeapReferenceInfo* reference_info, + jlong class_tag, + jlong referrer_class_tag, + jlong size, + jlong* tag_ptr, + jlong* referrer_tag_ptr, + jint length) +{ + const char * szInfo, * szRefInfo; + jlong tag_val = tag_ptr ? *tag_ptr : 0; + + NSK_DISPLAY1("heapReferenceCallback: %s", g_refKindStr[reference_kind]); + + NSK_DISPLAY3(" reference_info: %#lx, class_tag: %#" LL "d, referrer_class_tag: %#" LL "d\n", + reference_info, class_tag, referrer_class_tag); + + NSK_DISPLAY4(" size: %" LL "d, tag_ptr: %p, referrer_tag_ptr: %p, length: %-ld\n", + size, tag_ptr, referrer_tag_ptr, length); + + NSK_DISPLAY2(" tag: %" LL "d, referrer_tag: %" LL "d\n", + tag_val, DEREF(referrer_tag_ptr)); + + szInfo = ( tag_val > 0 && tag_val < MAX_TAG ) ? g_szTagInfo[tag_val] : ""; + szRefInfo = ( referrer_tag_ptr && *referrer_tag_ptr > 0 && *referrer_tag_ptr < MAX_TAG ) ? g_szTagInfo[*referrer_tag_ptr] : ""; + + NSK_DISPLAY3(" summary: %s: %s <- %s\n", + g_refKindStr[reference_kind], szInfo, szRefInfo); +} + +/* ============================================================================= */ + +jint JNICALL wrongHeapReferenceCallback( + jvmtiHeapReferenceKind reference_kind, + const jvmtiHeapReferenceInfo* reference_info, + jlong class_tag, + jlong referrer_class_tag, + jlong size, + jlong* tag_ptr, + jlong* referrer_tag_ptr, + jint length, + void* user_data) +{ + CHECK_USER_DATA(user_data); + NSK_COMPLAIN0("heap reference callback was called, where it should not be\n"); + nsk_jvmti_setFailStatus(); + printHeapRefCallbackInfo(reference_kind, reference_info, class_tag, referrer_class_tag, size, tag_ptr, referrer_tag_ptr, length); + + return JVMTI_VISIT_OBJECTS; +} + +jint JNICALL wrongPrimitiveFieldCallback( + jvmtiHeapReferenceKind reference_kind, + const jvmtiHeapReferenceInfo* reference_info, + jlong class_tag, + jlong* tag_ptr, + jvalue value, + jvmtiPrimitiveType value_type, + void* user_data) +{ + CHECK_USER_DATA(user_data); + NSK_COMPLAIN0("primitive field callback was called, where it should not be\n"); + nsk_jvmti_setFailStatus(); + + return JVMTI_VISIT_OBJECTS; +} + +jint JNICALL wrongArrayPrimitiveValueCallback( + jlong class_tag, + jlong size, + jlong* tag_ptr, + jint element_count, + jvmtiPrimitiveType element_type, + const void* elements, + void* user_data) +{ + CHECK_USER_DATA(user_data); + NSK_COMPLAIN0("array primitive value callback was called, where it should not be\n"); + nsk_jvmti_setFailStatus(); + + return JVMTI_VISIT_OBJECTS; +} + +jint JNICALL wrongStringPrimitiveValueCallback( + jlong class_tag, + jlong size, + jlong* tag_ptr, + const jchar* value, + jint value_length, + void* user_data) +{ + CHECK_USER_DATA(user_data); + NSK_COMPLAIN0("string primitive value callback was called, where it should not be\n"); + nsk_jvmti_setFailStatus(); + + return JVMTI_VISIT_OBJECTS; +} + +/* ============================================================================= */ + +void jvmti_FollowRefObject_init() +{ + g_wrongHeapCallbacks.heap_iteration_callback = NULL; + g_wrongHeapCallbacks.heap_reference_callback = wrongHeapReferenceCallback; + g_wrongHeapCallbacks.primitive_field_callback = wrongPrimitiveFieldCallback; + g_wrongHeapCallbacks.array_primitive_value_callback = wrongArrayPrimitiveValueCallback; + g_wrongHeapCallbacks.string_primitive_value_callback = wrongStringPrimitiveValueCallback; + + Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_resetTags(NULL, NULL); + Java_nsk_jvmti_unit_FollowReferences_FollowRefObjects_resetRefsToVerify(NULL, NULL); +} + +/* ============================================================================= */ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_tools.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_tools.c deleted file mode 100644 index 2eadb09b24e..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_tools.c +++ /dev/null @@ -1,692 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include -#include - -/*************************************************************/ - -#include "jvmti.h" - -/*************************************************************/ - -#include "nsk_tools.h" -#include "jni_tools.h" -#include "jvmti_tools.h" -#include "JVMTITools.h" - -/*************************************************************/ - -#ifdef __cplusplus -extern "C" { -#endif - -/*************************************************************/ - -#define NSK_JVMTI_WAITTIME 2 - -#define NSK_JVMTI_MAX_OPTIONS 10 -#define NSK_JVMTI_OPTION_START '-' -#define NSK_JVMTI_OPTION_VAL_SEP '=' - -#define NSK_JVMTI_OPT_PATH_TO_NEW_BYTE_CODE "pathToNewByteCode" -#define PATH_FORMAT "%s%02d/%s" -#define DIR_NAME "newclass" - -static volatile int redefineAttempted = NSK_FALSE; -static volatile int redefineSucceed = NSK_FALSE; -static volatile int agentFailed = NSK_FALSE; - -static struct { - struct { - int count; - char* names[NSK_JVMTI_MAX_OPTIONS]; - char* values[NSK_JVMTI_MAX_OPTIONS]; - char* string; - } options; - int waittime; -} context; - -/*************************************************************/ - -static int check_option(int dashed, const char name[], const char value[]) { - if (strcmp("verbose", name) == 0) { - if (strlen(value) > 0) { - nsk_complain("nsk_jvmti_parseOptions(): unexpected value in option: %s=%s\n", name, value); - return NSK_FALSE; - } - nsk_setVerboseMode(NSK_TRUE); - } else if (strcmp("trace", name) == 0) { - if (strlen(value) <= 0) { - nsk_complain("nsk_jvmti_parseOptions(): no value for option: %s\n", name); - return NSK_FALSE; - } - if (strcmp("none", value) == 0) { - nsk_setTraceMode(NSK_TRACE_NONE); - } else if (strcmp("before", value) == 0) { - nsk_setTraceMode(NSK_TRACE_BEFORE); - } else if (strcmp("after", value) == 0) { - nsk_setTraceMode(NSK_TRACE_AFTER); - } else if (strcmp("all", value) == 0) { - nsk_setTraceMode(NSK_TRACE_ALL); - } else { - nsk_complain("nsk_jvmti_parseOptions(): uexpected value in option: %s=%s\n", name, value); - return NSK_FALSE; - } - nsk_setVerboseMode(NSK_TRUE); - } else if (strcmp("waittime", name) == 0) { - if (strlen(value) <= 0) { - nsk_complain("nsk_jvmti_parseOptions(): no value for option: %s\n", name); - return NSK_FALSE; - } - { - char* end = NULL; - long n = strtol(value, &end, 10); - if (end == NULL || end == value || *end != '\0') { - nsk_complain("nsk_jvmti_parseOptions(): not integer value in option: %s=%s\n", name, value); - return NSK_FALSE; - } - if (n < 0) { - nsk_complain("nsk_jvmti_parseOptions(): negative value in option: %s=%s\n", name, value); - return NSK_FALSE; - } - context.waittime = (int)n; - } - } else if (dashed) { - nsk_complain("nsk_jvmti_parseOptions(): unknown option: %c%s\n", - NSK_JVMTI_OPTION_START, name); - return NSK_FALSE; - } - return NSK_TRUE; -} - -static int add_option(const char opt[], int opt_len, const char val[], int val_len) { - char* name; - char* value; - - int success = NSK_TRUE; - int dashed_opt = NSK_FALSE; - - if (opt[0] == NSK_JVMTI_OPTION_START) { - dashed_opt = NSK_TRUE; - opt++; - opt_len--; - } - if (opt_len <= 0) { - nsk_complain("nsk_jvmti_parseOptions(): found empty option\n"); - return NSK_FALSE; - } - - name = (char*)malloc(opt_len + 1); - value = (char*)malloc(val_len + 1); - - if (name == NULL || value == NULL) { - nsk_complain("nsk_jvmti_parseOptions(): out of memory\n"); - success = NSK_FALSE; - } else { - strncpy(name, opt, opt_len); - name[opt_len] = '\0'; - strncpy(value, val, val_len); - value[val_len] = '\0'; - - if (!check_option(dashed_opt, name, value)) { - success = NSK_FALSE; - } - } - - if (success) { - if (context.options.count >= NSK_JVMTI_MAX_OPTIONS) { - nsk_complain("nsk_jvmti_parseOptions(): too many options for parsing\n"); - success = NSK_FALSE; - } else { - context.options.names[context.options.count] = name; - context.options.values[context.options.count] = value; - context.options.count++; - } - } - - if (!success) { - if (name != NULL) - free(name); - if (value != NULL) - free(value); - } - - return success; -} - -static void nsk_jvmti_free() { - if (context.options.count > 0) { - int i; - for (i = 0; i < context.options.count; i++) { - free(context.options.names[i]); - free(context.options.values[i]); - } - context.options.count = 0; - } - if (context.options.string != NULL) { - free(context.options.string); - context.options.string = NULL; - } -} - -int isOptSep(char c) { - return isspace(c) || c == '~'; -} - - -/** - * - * The current option will not perform more than one - * single option which given, this is due to places explained - * in this question. - * - **/ - - /* - * This whole play can be reduced with simple StringTokenizer (strtok). - * - */ - -#if !defined(__clang_major__) && defined(__GNUC__) && (__GNUC__ >= 8) -_Pragma("GCC diagnostic push") -_Pragma("GCC diagnostic ignored \"-Wstringop-truncation\"") -#endif - -int nsk_jvmti_parseOptions(const char options[]) { - size_t len; - const char* opt; - int success = NSK_TRUE; - - context.options.string = NULL; - context.options.count = 0; - context.waittime = 2; - - if (options == NULL) - return NSK_TRUE; - - len = strlen(options); - context.options.string = (char*)malloc(len + 2); - - if (context.options.string == NULL) { - nsk_complain("nsk_jvmti_parseOptions(): out of memory\n"); - return NSK_FALSE; - } - strncpy(context.options.string, options, len); - context.options.string[len] = '\0'; - context.options.string[len+1] = '\0'; - - for (opt = context.options.string; ; ) { - const char* opt_end; - const char* val_sep; - int opt_len=0; - int val_len=0; - int exit=1; - - while (*opt != '\0' && isOptSep(*opt)) opt++; - if (*opt == '\0') break; - - val_sep = NULL; - /* - This should break when the first option it encounters other wise - */ - for (opt_end = opt, opt_len=0; !(*opt_end == '\0' || isOptSep(*opt_end)); opt_end++,opt_len++) { - if (*opt_end == NSK_JVMTI_OPTION_VAL_SEP) { - val_sep = opt_end; - exit=0; - break; - } - } - - if (exit == 1) break; - - /* now scan for the search for the option value end. - - */ - exit =1; - opt_end++; - val_sep++; - /** - * I was expecting this jvmti_parseOptions(), - * should be for multiple options as well. - * If this break is not there then It will expects - * to have. so a space should be sufficient as well. - */ - for(val_len=0; !(*opt_end == '\0' || isOptSep(*opt_end)); opt_end++,val_len++) { - //if (*opt_end == NSK_JVMTI_OPTION_START) { - // break; - //} - } - - if (!add_option(opt, opt_len, val_sep, val_len)) { - success = NSK_FALSE; - break; - } - opt_end++; - opt = opt_end; - } - - if (!success) { - nsk_jvmti_free(); - } - - return success; -} - -#if !defined(__clang_major__) && defined(__GNUC__) && (__GNUC__ >= 8) -_Pragma("GCC diagnostic pop") -#endif - -/*************************************************************/ - -/** - * Returns value of given option name; or NULL if no such option found. - * If search name is NULL then complains an error and returns NULL. - */ -const char* nsk_jvmti_findOptionValue(const char name[]) { - int i; - - if (name == NULL) { - nsk_complain("nsk_jvmti_findOptionValue(): option name is NULL\n"); - return NULL; - } - - for (i = 0; i < context.options.count; i++) { - if (strcmp(name, context.options.names[i]) == 0) - return context.options.values[i]; - } - return NULL; -} - -/** - * Returns string value of given option; or defaultValue if no such option found. - * If options is specified but has empty value then complains an error and returns NULL. - */ -const char* nsk_jvmti_findOptionStringValue(const char name[], const char* defaultValue) { - const char* value; - - if (name == NULL) { - nsk_complain("nsk_jvmti_findOptionStringValue(): option name is NULL\n"); - return NULL; - } - - value = nsk_jvmti_findOptionValue(name); - if (value == NULL) { - return defaultValue; - } - - if (strlen(value) <= 0) { - nsk_complain("nsk_jvmti_findOptionStringValue(): empty value of option: %s=%s\n", - name, value); - return NULL; - } - return value; -} - -/** - * Returns integer value of given option; or defaultValue if no such option found. - * If options is specified but has no integer value then complains an error and returns -1. - */ -int nsk_jvmti_findOptionIntValue(const char name[], int defaultValue) { - const char* value; - - if (name == NULL) { - nsk_complain("nsk_jvmti_findOptionIntValue(): option name is NULL\n"); - return -1; - } - - value = nsk_jvmti_findOptionValue(name); - if (value == NULL) { - return defaultValue; - } - - if (strlen(value) <= 0) { - nsk_complain("nsk_jvmti_findOptionIntValue(): empty value of option: %s=%s\n", - name, value); - return -1; - } - - { - char* endptr = NULL; - int n = strtol(value, &endptr, 10); - - if (endptr == NULL || *endptr != '\0') { - nsk_complain("nsk_jvmti_findOptionIntValue(): not integer value of option: %s=%s\n", - name, value); - return -1; - } - return n; - } -} - -/** - * Returns number of parsed options. - */ -int nsk_jvmti_getOptionsCount() { - return context.options.count; -} - -/** - * Returns name of i-th parsed option. - * If no such option then complains an error and returns NULL. - */ -const char* nsk_jvmti_getOptionName(int i) { - if (i < 0 || i >= context.options.count) { - nsk_complain("nsk_jvmti_getOptionName(): option index out of bounds: %d\n", i); - return NULL; - } - return context.options.names[i]; -} - -/** - * Returns value of i-th parsed option. - * If no such option then complains an error and returns NULL. - */ -const char* nsk_jvmti_getOptionValue(int i) { - if (i < 0 || i >= context.options.count) { - nsk_complain("nsk_jvmti_getOptionValue(): option index out of bounds: %d\n", i); - return NULL; - } - return context.options.values[i]; -} - -/*************************************************************/ - -/** - * Returns value of -waittime option or default value if not specified. - */ -int nsk_jvmti_getWaitTime() { - return context.waittime; -} - -/** - * Sets specified waittime value. - */ -void nsk_jvmti_setWaitTime(int waittime) { - context.waittime = waittime; -} - -/*************************************************************/ - -int nsk_jvmti_lverify(int positive, jvmtiError error, jvmtiError expected, - const char file[], int line, const char format[], ...) -{ - int failure=0; - int negative = !positive; - int errorCode = (int)error; - const char* errorName = TranslateError(error); - va_list ap; - va_start(ap,format); - nsk_lvtrace(NSK_TRACE_AFTER,file,line,format,ap); - if (negative || expected != JVMTI_ERROR_NONE) - nsk_ltrace(NSK_TRACE_AFTER,file,line, - " jvmti error: code=%d, name=%s\n",errorCode,errorName); - if ((error == expected) == negative) { - nsk_lvcomplain(file,line,format,ap); - nsk_printf("# jvmti error: code=%d, name=%s\n",errorCode,errorName); - if (expected != JVMTI_ERROR_NONE) - nsk_printf("# error expected: code=%d, name=%s\n", - expected, TranslateError(expected)); - failure=1; - }; - va_end(ap); - return !failure; -} - -/*************************************************************/ - -JNIEXPORT jstring JNICALL -Java_nsk_share_jvmti_ArgumentHandler_getAgentOptionsString(JNIEnv *jni, jobject obj) { - jstring str_obj = NULL; - - if (!NSK_JNI_VERIFY(jni, (str_obj = - NSK_CPP_STUB2(NewStringUTF, jni, context.options.string)) != NULL)) { - return NULL; - } - return str_obj; -} - -/*************************************************************/ - -/** - * This method will try to redefine the class (classToRedefine) by loading - * physical file. pathToNewByteCode option which is passed - * on OnLoad Phase also used. - * - * So This method will do a file read pathToByteCode+fileName+.class (total path). - * Constrcuts a class objects and does a redefine of the class. - * On successfull redefine this method will return eaither JNI_TRUE or JNI_FALSE - * - * Hint:: - * 1) - * If there are many redefine on same testcase, then please try to use - * integer value (newclass00, newclass01, newclass02 , ....) way. - * - * 2) When you compile these please do keep, a metatag on testcase as - * # build : native classes classes.redef - * - * 3) When you do build these classes are psysically located in build as. - * - * TESTBASE/bin/newclass0* directory. - * eg: for nks/jvmti/scenarios/hotswap/HS204/hs204t001 you should see - * TESTBASE/bin/newclass0* /nsk/hotswap/HS204/hs204t001/MyClass.class - * - */ - -int nsk_jvmti_redefineClass(jvmtiEnv * jvmti, - jclass classToRedefine, - const char * fileName) { - redefineAttempted = NSK_TRUE; - if ( nsk_jvmti_findOptionValue(NSK_JVMTI_OPT_PATH_TO_NEW_BYTE_CODE) - == NULL ) { - nsk_printf("# error expected: %s \n", - NSK_JVMTI_OPT_PATH_TO_NEW_BYTE_CODE ); - nsk_printf("Hint :: missing java -agentlib:agentlib=%s=DirName, ($TESTBASE/bin) \n", - NSK_JVMTI_OPT_PATH_TO_NEW_BYTE_CODE ); - return NSK_FALSE; - } - if ( fileName == NULL) { - nsk_printf("# error file name expected did not found \n"); - return NSK_FALSE; - } - { - char file [1024]; - //= "DEFAULT"; - sprintf(file,"%s/%s.class", - nsk_jvmti_findOptionValue(NSK_JVMTI_OPT_PATH_TO_NEW_BYTE_CODE), - fileName); - nsk_printf("# info :: File = %s \n",file); - - { - FILE *bytecode; - unsigned char * classBytes; - jvmtiError error; - jint size; - - bytecode = fopen(file, "rb"); - error= JVMTI_ERROR_NONE; - if ( bytecode == NULL ) { - nsk_printf("# error **Agent::error opening file %s \n",file); - return NSK_FALSE; - } - - nsk_printf("# info **Agent:: opening file %s \n",file); - fseek(bytecode, 0, SEEK_END); - size = ftell(bytecode); - nsk_printf("# info file size= %ld\n",ftell(bytecode)); - rewind(bytecode); - error = (*jvmti)->Allocate(jvmti, size,&classBytes); - if ( error != JVMTI_ERROR_NONE) { - nsk_printf(" Failed to create memory %s \n",TranslateError(error)); - return NSK_FALSE; - } - - if ( ((jint) fread( classBytes, 1,size,bytecode )) != size ) { - nsk_printf(" # error failed to read all the bytes , could be less or more \n"); - return NSK_FALSE; - } else { - nsk_printf(" File red completely \n"); - } - fclose(bytecode); - { - jvmtiClassDefinition classDef; - classDef.klass = classToRedefine; - classDef.class_byte_count= size; - classDef.class_bytes = classBytes; - error = (*jvmti)->RedefineClasses(jvmti,1,&classDef); - if ( error != JVMTI_ERROR_NONE ) { - nsk_printf("# error occured while redefining %s ", - TranslateError(error) ); - return NSK_FALSE; - } - } - } - } - redefineSucceed= NSK_TRUE; - return NSK_TRUE; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_share_jvmti_RedefineAgent_redefineAttempted(JNIEnv *jni, jobject obj) { - - if (redefineAttempted == NSK_TRUE) { - return JNI_TRUE; - }else { - return JNI_FALSE; - } -} - - -JNIEXPORT jboolean JNICALL -Java_nsk_share_jvmti_RedefineAgent_isRedefined(JNIEnv * jni, jobject obj ) { - - if (redefineSucceed == NSK_TRUE) { - return JNI_TRUE; - }else { - return JNI_FALSE; - } -} -/** - * This jni method is a Java wrapper for agent status. - */ -JNIEXPORT jboolean JNICALL -Java_nsk_share_jvmti_RedefineAgent_agentStatus(JNIEnv * jni, jobject obj ) { - if ( agentFailed == NSK_TRUE) { - return JNI_FALSE; - } else { - return JNI_TRUE; - } -} - -void nsk_jvmti_getFileName(int redefineCnt, const char * dir, char * buf, size_t bufsize) { - snprintf(buf, bufsize, PATH_FORMAT, DIR_NAME, redefineCnt, dir); - buf[bufsize-1] = '\0'; -} - -int nsk_jvmti_enableNotification(jvmtiEnv *jvmti,jvmtiEvent event, jthread thread) { - jvmtiError rc=JVMTI_ERROR_NONE; - rc = (*jvmti)->SetEventNotificationMode(jvmti,JVMTI_ENABLE, event, thread); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf("# error Failed to set Notification for Event \n "); - return NSK_FALSE; - } - return NSK_TRUE; -} - -int nsk_jvmti_disableNotification(jvmtiEnv *jvmti,jvmtiEvent event, jthread thread) { - jvmtiError rc=JVMTI_ERROR_NONE; - rc = (*jvmti)->SetEventNotificationMode(jvmti,JVMTI_DISABLE, event, thread); - if (rc != JVMTI_ERROR_NONE) { - nsk_printf(" Failed to disaable Notification for Event "); - return NSK_FALSE; - } - return NSK_TRUE; -} - -void nsk_jvmti_agentFailed() { - agentFailed = NSK_TRUE; -} - -int isThreadExpected(jvmtiEnv *jvmti, jthread thread) { - static const char *vm_jfr_buffer_thread_name = "VM JFR Buffer Thread"; - static const char *jfr_request_timer_thread_name = "JFR request timer"; - - jvmtiThreadInfo threadinfo; - NSK_JVMTI_VERIFY((*jvmti)->GetThreadInfo(jvmti, thread, &threadinfo)); - - if (strcmp(threadinfo.name, vm_jfr_buffer_thread_name) == 0) - return 0; - - if (strcmp(threadinfo.name, jfr_request_timer_thread_name) == 0) - return 0; - - return 1; -} - -jint createRawMonitor(jvmtiEnv *env, const char *name, jrawMonitorID *monitor) { - jvmtiError error = NSK_CPP_STUB3(CreateRawMonitor, env, name, monitor); - if (!NSK_JVMTI_VERIFY(error)) { - return JNI_ERR; - } - return JNI_OK; -} - -void exitOnError(jvmtiError error) { - if (!NSK_JVMTI_VERIFY(error)) { - exit(error); - } -} - -void rawMonitorEnter(jvmtiEnv *env, jrawMonitorID monitor) { - jvmtiError error = NSK_CPP_STUB2(RawMonitorEnter, env, monitor); - exitOnError(error); -} - -void rawMonitorExit(jvmtiEnv *env, jrawMonitorID monitor) { - jvmtiError error = NSK_CPP_STUB2(RawMonitorExit, env, monitor); - exitOnError(error); -} - -void rawMonitorNotify(jvmtiEnv *env, jrawMonitorID monitor) { - jvmtiError error = NSK_CPP_STUB2(RawMonitorNotify, env, monitor); - exitOnError(error); -} - -void rawMonitorWait(jvmtiEnv *env, jrawMonitorID monitor, jlong millis) { - jvmtiError error = NSK_CPP_STUB3(RawMonitorWait, env, monitor, millis); - exitOnError(error); -} - -void getPhase(jvmtiEnv *env, jvmtiPhase *phase) { - jvmtiError error = NSK_CPP_STUB2(GetPhase, env, phase); - exitOnError(error); -} - -/*************************************************************/ - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_tools.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_tools.cpp new file mode 100644 index 00000000000..013d9b993f8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/jvmti_tools.cpp @@ -0,0 +1,692 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include +#include + +/*************************************************************/ + +#include "jvmti.h" + +/*************************************************************/ + +#include "nsk_tools.h" +#include "jni_tools.h" +#include "jvmti_tools.h" +#include "JVMTITools.h" + +/*************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif + +/*************************************************************/ + +#define NSK_JVMTI_WAITTIME 2 + +#define NSK_JVMTI_MAX_OPTIONS 10 +#define NSK_JVMTI_OPTION_START '-' +#define NSK_JVMTI_OPTION_VAL_SEP '=' + +#define NSK_JVMTI_OPT_PATH_TO_NEW_BYTE_CODE "pathToNewByteCode" +#define PATH_FORMAT "%s%02d/%s" +#define DIR_NAME "newclass" + +static volatile int redefineAttempted = NSK_FALSE; +static volatile int redefineSucceed = NSK_FALSE; +static volatile int agentFailed = NSK_FALSE; + +static struct { + struct { + int count; + char* names[NSK_JVMTI_MAX_OPTIONS]; + char* values[NSK_JVMTI_MAX_OPTIONS]; + char* string; + } options; + int waittime; +} context; + +/*************************************************************/ + +static int check_option(int dashed, const char name[], const char value[]) { + if (strcmp("verbose", name) == 0) { + if (strlen(value) > 0) { + nsk_complain("nsk_jvmti_parseOptions(): unexpected value in option: %s=%s\n", name, value); + return NSK_FALSE; + } + nsk_setVerboseMode(NSK_TRUE); + } else if (strcmp("trace", name) == 0) { + if (strlen(value) <= 0) { + nsk_complain("nsk_jvmti_parseOptions(): no value for option: %s\n", name); + return NSK_FALSE; + } + if (strcmp("none", value) == 0) { + nsk_setTraceMode(NSK_TRACE_NONE); + } else if (strcmp("before", value) == 0) { + nsk_setTraceMode(NSK_TRACE_BEFORE); + } else if (strcmp("after", value) == 0) { + nsk_setTraceMode(NSK_TRACE_AFTER); + } else if (strcmp("all", value) == 0) { + nsk_setTraceMode(NSK_TRACE_ALL); + } else { + nsk_complain("nsk_jvmti_parseOptions(): uexpected value in option: %s=%s\n", name, value); + return NSK_FALSE; + } + nsk_setVerboseMode(NSK_TRUE); + } else if (strcmp("waittime", name) == 0) { + if (strlen(value) <= 0) { + nsk_complain("nsk_jvmti_parseOptions(): no value for option: %s\n", name); + return NSK_FALSE; + } + { + char* end = NULL; + long n = strtol(value, &end, 10); + if (end == NULL || end == value || *end != '\0') { + nsk_complain("nsk_jvmti_parseOptions(): not integer value in option: %s=%s\n", name, value); + return NSK_FALSE; + } + if (n < 0) { + nsk_complain("nsk_jvmti_parseOptions(): negative value in option: %s=%s\n", name, value); + return NSK_FALSE; + } + context.waittime = (int)n; + } + } else if (dashed) { + nsk_complain("nsk_jvmti_parseOptions(): unknown option: %c%s\n", + NSK_JVMTI_OPTION_START, name); + return NSK_FALSE; + } + return NSK_TRUE; +} + +static int add_option(const char opt[], int opt_len, const char val[], int val_len) { + char* name; + char* value; + + int success = NSK_TRUE; + int dashed_opt = NSK_FALSE; + + if (opt[0] == NSK_JVMTI_OPTION_START) { + dashed_opt = NSK_TRUE; + opt++; + opt_len--; + } + if (opt_len <= 0) { + nsk_complain("nsk_jvmti_parseOptions(): found empty option\n"); + return NSK_FALSE; + } + + name = (char*)malloc(opt_len + 1); + value = (char*)malloc(val_len + 1); + + if (name == NULL || value == NULL) { + nsk_complain("nsk_jvmti_parseOptions(): out of memory\n"); + success = NSK_FALSE; + } else { + strncpy(name, opt, opt_len); + name[opt_len] = '\0'; + strncpy(value, val, val_len); + value[val_len] = '\0'; + + if (!check_option(dashed_opt, name, value)) { + success = NSK_FALSE; + } + } + + if (success) { + if (context.options.count >= NSK_JVMTI_MAX_OPTIONS) { + nsk_complain("nsk_jvmti_parseOptions(): too many options for parsing\n"); + success = NSK_FALSE; + } else { + context.options.names[context.options.count] = name; + context.options.values[context.options.count] = value; + context.options.count++; + } + } + + if (!success) { + if (name != NULL) + free(name); + if (value != NULL) + free(value); + } + + return success; +} + +static void nsk_jvmti_free() { + if (context.options.count > 0) { + int i; + for (i = 0; i < context.options.count; i++) { + free(context.options.names[i]); + free(context.options.values[i]); + } + context.options.count = 0; + } + if (context.options.string != NULL) { + free(context.options.string); + context.options.string = NULL; + } +} + +int isOptSep(char c) { + return isspace(c) || c == '~'; +} + + +/** + * + * The current option will not perform more than one + * single option which given, this is due to places explained + * in this question. + * + **/ + + /* + * This whole play can be reduced with simple StringTokenizer (strtok). + * + */ + +#if !defined(__clang_major__) && defined(__GNUC__) && (__GNUC__ >= 8) +_Pragma("GCC diagnostic push") +_Pragma("GCC diagnostic ignored \"-Wstringop-truncation\"") +#endif + +int nsk_jvmti_parseOptions(const char options[]) { + size_t len; + const char* opt; + int success = NSK_TRUE; + + context.options.string = NULL; + context.options.count = 0; + context.waittime = 2; + + if (options == NULL) + return NSK_TRUE; + + len = strlen(options); + context.options.string = (char*)malloc(len + 2); + + if (context.options.string == NULL) { + nsk_complain("nsk_jvmti_parseOptions(): out of memory\n"); + return NSK_FALSE; + } + strncpy(context.options.string, options, len); + context.options.string[len] = '\0'; + context.options.string[len+1] = '\0'; + + for (opt = context.options.string; ; ) { + const char* opt_end; + const char* val_sep; + int opt_len=0; + int val_len=0; + int exit=1; + + while (*opt != '\0' && isOptSep(*opt)) opt++; + if (*opt == '\0') break; + + val_sep = NULL; + /* + This should break when the first option it encounters other wise + */ + for (opt_end = opt, opt_len=0; !(*opt_end == '\0' || isOptSep(*opt_end)); opt_end++,opt_len++) { + if (*opt_end == NSK_JVMTI_OPTION_VAL_SEP) { + val_sep = opt_end; + exit=0; + break; + } + } + + if (exit == 1) break; + + /* now scan for the search for the option value end. + + */ + exit =1; + opt_end++; + val_sep++; + /** + * I was expecting this jvmti_parseOptions(), + * should be for multiple options as well. + * If this break is not there then It will expects + * to have. so a space should be sufficient as well. + */ + for(val_len=0; !(*opt_end == '\0' || isOptSep(*opt_end)); opt_end++,val_len++) { + //if (*opt_end == NSK_JVMTI_OPTION_START) { + // break; + //} + } + + if (!add_option(opt, opt_len, val_sep, val_len)) { + success = NSK_FALSE; + break; + } + opt_end++; + opt = opt_end; + } + + if (!success) { + nsk_jvmti_free(); + } + + return success; +} + +#if !defined(__clang_major__) && defined(__GNUC__) && (__GNUC__ >= 8) +_Pragma("GCC diagnostic pop") +#endif + +/*************************************************************/ + +/** + * Returns value of given option name; or NULL if no such option found. + * If search name is NULL then complains an error and returns NULL. + */ +const char* nsk_jvmti_findOptionValue(const char name[]) { + int i; + + if (name == NULL) { + nsk_complain("nsk_jvmti_findOptionValue(): option name is NULL\n"); + return NULL; + } + + for (i = 0; i < context.options.count; i++) { + if (strcmp(name, context.options.names[i]) == 0) + return context.options.values[i]; + } + return NULL; +} + +/** + * Returns string value of given option; or defaultValue if no such option found. + * If options is specified but has empty value then complains an error and returns NULL. + */ +const char* nsk_jvmti_findOptionStringValue(const char name[], const char* defaultValue) { + const char* value; + + if (name == NULL) { + nsk_complain("nsk_jvmti_findOptionStringValue(): option name is NULL\n"); + return NULL; + } + + value = nsk_jvmti_findOptionValue(name); + if (value == NULL) { + return defaultValue; + } + + if (strlen(value) <= 0) { + nsk_complain("nsk_jvmti_findOptionStringValue(): empty value of option: %s=%s\n", + name, value); + return NULL; + } + return value; +} + +/** + * Returns integer value of given option; or defaultValue if no such option found. + * If options is specified but has no integer value then complains an error and returns -1. + */ +int nsk_jvmti_findOptionIntValue(const char name[], int defaultValue) { + const char* value; + + if (name == NULL) { + nsk_complain("nsk_jvmti_findOptionIntValue(): option name is NULL\n"); + return -1; + } + + value = nsk_jvmti_findOptionValue(name); + if (value == NULL) { + return defaultValue; + } + + if (strlen(value) <= 0) { + nsk_complain("nsk_jvmti_findOptionIntValue(): empty value of option: %s=%s\n", + name, value); + return -1; + } + + { + char* endptr = NULL; + int n = strtol(value, &endptr, 10); + + if (endptr == NULL || *endptr != '\0') { + nsk_complain("nsk_jvmti_findOptionIntValue(): not integer value of option: %s=%s\n", + name, value); + return -1; + } + return n; + } +} + +/** + * Returns number of parsed options. + */ +int nsk_jvmti_getOptionsCount() { + return context.options.count; +} + +/** + * Returns name of i-th parsed option. + * If no such option then complains an error and returns NULL. + */ +const char* nsk_jvmti_getOptionName(int i) { + if (i < 0 || i >= context.options.count) { + nsk_complain("nsk_jvmti_getOptionName(): option index out of bounds: %d\n", i); + return NULL; + } + return context.options.names[i]; +} + +/** + * Returns value of i-th parsed option. + * If no such option then complains an error and returns NULL. + */ +const char* nsk_jvmti_getOptionValue(int i) { + if (i < 0 || i >= context.options.count) { + nsk_complain("nsk_jvmti_getOptionValue(): option index out of bounds: %d\n", i); + return NULL; + } + return context.options.values[i]; +} + +/*************************************************************/ + +/** + * Returns value of -waittime option or default value if not specified. + */ +int nsk_jvmti_getWaitTime() { + return context.waittime; +} + +/** + * Sets specified waittime value. + */ +void nsk_jvmti_setWaitTime(int waittime) { + context.waittime = waittime; +} + +/*************************************************************/ + +int nsk_jvmti_lverify(int positive, jvmtiError error, jvmtiError expected, + const char file[], int line, const char format[], ...) +{ + int failure=0; + int negative = !positive; + int errorCode = (int)error; + const char* errorName = TranslateError(error); + va_list ap; + va_start(ap,format); + nsk_lvtrace(NSK_TRACE_AFTER,file,line,format,ap); + if (negative || expected != JVMTI_ERROR_NONE) + nsk_ltrace(NSK_TRACE_AFTER,file,line, + " jvmti error: code=%d, name=%s\n",errorCode,errorName); + if ((error == expected) == negative) { + nsk_lvcomplain(file,line,format,ap); + nsk_printf("# jvmti error: code=%d, name=%s\n",errorCode,errorName); + if (expected != JVMTI_ERROR_NONE) + nsk_printf("# error expected: code=%d, name=%s\n", + expected, TranslateError(expected)); + failure=1; + }; + va_end(ap); + return !failure; +} + +/*************************************************************/ + +JNIEXPORT jstring JNICALL +Java_nsk_share_jvmti_ArgumentHandler_getAgentOptionsString(JNIEnv *jni, jobject obj) { + jstring str_obj = NULL; + + if (!NSK_JNI_VERIFY(jni, (str_obj = + NSK_CPP_STUB2(NewStringUTF, jni, context.options.string)) != NULL)) { + return NULL; + } + return str_obj; +} + +/*************************************************************/ + +/** + * This method will try to redefine the class (classToRedefine) by loading + * physical file. pathToNewByteCode option which is passed + * on OnLoad Phase also used. + * + * So This method will do a file read pathToByteCode+fileName+.class (total path). + * Constrcuts a class objects and does a redefine of the class. + * On successfull redefine this method will return eaither JNI_TRUE or JNI_FALSE + * + * Hint:: + * 1) + * If there are many redefine on same testcase, then please try to use + * integer value (newclass00, newclass01, newclass02 , ....) way. + * + * 2) When you compile these please do keep, a metatag on testcase as + * # build : native classes classes.redef + * + * 3) When you do build these classes are psysically located in build as. + * + * TESTBASE/bin/newclass0* directory. + * eg: for nks/jvmti/scenarios/hotswap/HS204/hs204t001 you should see + * TESTBASE/bin/newclass0* /nsk/hotswap/HS204/hs204t001/MyClass.class + * + */ + +int nsk_jvmti_redefineClass(jvmtiEnv * jvmti, + jclass classToRedefine, + const char * fileName) { + redefineAttempted = NSK_TRUE; + if ( nsk_jvmti_findOptionValue(NSK_JVMTI_OPT_PATH_TO_NEW_BYTE_CODE) + == NULL ) { + nsk_printf("# error expected: %s \n", + NSK_JVMTI_OPT_PATH_TO_NEW_BYTE_CODE ); + nsk_printf("Hint :: missing java -agentlib:agentlib=%s=DirName, ($TESTBASE/bin) \n", + NSK_JVMTI_OPT_PATH_TO_NEW_BYTE_CODE ); + return NSK_FALSE; + } + if ( fileName == NULL) { + nsk_printf("# error file name expected did not found \n"); + return NSK_FALSE; + } + { + char file [1024]; + //= "DEFAULT"; + sprintf(file,"%s/%s.class", + nsk_jvmti_findOptionValue(NSK_JVMTI_OPT_PATH_TO_NEW_BYTE_CODE), + fileName); + nsk_printf("# info :: File = %s \n",file); + + { + FILE *bytecode; + unsigned char * classBytes; + jvmtiError error; + jint size; + + bytecode = fopen(file, "rb"); + error= JVMTI_ERROR_NONE; + if ( bytecode == NULL ) { + nsk_printf("# error **Agent::error opening file %s \n",file); + return NSK_FALSE; + } + + nsk_printf("# info **Agent:: opening file %s \n",file); + fseek(bytecode, 0, SEEK_END); + size = ftell(bytecode); + nsk_printf("# info file size= %ld\n",ftell(bytecode)); + rewind(bytecode); + error = jvmti->Allocate(size,&classBytes); + if ( error != JVMTI_ERROR_NONE) { + nsk_printf(" Failed to create memory %s \n",TranslateError(error)); + return NSK_FALSE; + } + + if ( ((jint) fread( classBytes, 1,size,bytecode )) != size ) { + nsk_printf(" # error failed to read all the bytes , could be less or more \n"); + return NSK_FALSE; + } else { + nsk_printf(" File red completely \n"); + } + fclose(bytecode); + { + jvmtiClassDefinition classDef; + classDef.klass = classToRedefine; + classDef.class_byte_count= size; + classDef.class_bytes = classBytes; + error = jvmti->RedefineClasses(1,&classDef); + if ( error != JVMTI_ERROR_NONE ) { + nsk_printf("# error occured while redefining %s ", + TranslateError(error) ); + return NSK_FALSE; + } + } + } + } + redefineSucceed= NSK_TRUE; + return NSK_TRUE; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_share_jvmti_RedefineAgent_redefineAttempted(JNIEnv *jni, jobject obj) { + + if (redefineAttempted == NSK_TRUE) { + return JNI_TRUE; + }else { + return JNI_FALSE; + } +} + + +JNIEXPORT jboolean JNICALL +Java_nsk_share_jvmti_RedefineAgent_isRedefined(JNIEnv * jni, jobject obj ) { + + if (redefineSucceed == NSK_TRUE) { + return JNI_TRUE; + }else { + return JNI_FALSE; + } +} +/** + * This jni method is a Java wrapper for agent status. + */ +JNIEXPORT jboolean JNICALL +Java_nsk_share_jvmti_RedefineAgent_agentStatus(JNIEnv * jni, jobject obj ) { + if ( agentFailed == NSK_TRUE) { + return JNI_FALSE; + } else { + return JNI_TRUE; + } +} + +void nsk_jvmti_getFileName(int redefineCnt, const char * dir, char * buf, size_t bufsize) { + snprintf(buf, bufsize, PATH_FORMAT, DIR_NAME, redefineCnt, dir); + buf[bufsize-1] = '\0'; +} + +int nsk_jvmti_enableNotification(jvmtiEnv *jvmti,jvmtiEvent event, jthread thread) { + jvmtiError rc=JVMTI_ERROR_NONE; + rc = jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, thread); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf("# error Failed to set Notification for Event \n "); + return NSK_FALSE; + } + return NSK_TRUE; +} + +int nsk_jvmti_disableNotification(jvmtiEnv *jvmti,jvmtiEvent event, jthread thread) { + jvmtiError rc=JVMTI_ERROR_NONE; + rc = jvmti->SetEventNotificationMode(JVMTI_DISABLE, event, thread); + if (rc != JVMTI_ERROR_NONE) { + nsk_printf(" Failed to disaable Notification for Event "); + return NSK_FALSE; + } + return NSK_TRUE; +} + +void nsk_jvmti_agentFailed() { + agentFailed = NSK_TRUE; +} + +int isThreadExpected(jvmtiEnv *jvmti, jthread thread) { + static const char *vm_jfr_buffer_thread_name = "VM JFR Buffer Thread"; + static const char *jfr_request_timer_thread_name = "JFR request timer"; + + jvmtiThreadInfo threadinfo; + NSK_JVMTI_VERIFY(jvmti->GetThreadInfo(thread, &threadinfo)); + + if (strcmp(threadinfo.name, vm_jfr_buffer_thread_name) == 0) + return 0; + + if (strcmp(threadinfo.name, jfr_request_timer_thread_name) == 0) + return 0; + + return 1; +} + +jint createRawMonitor(jvmtiEnv *env, const char *name, jrawMonitorID *monitor) { + jvmtiError error = NSK_CPP_STUB3(CreateRawMonitor, env, name, monitor); + if (!NSK_JVMTI_VERIFY(error)) { + return JNI_ERR; + } + return JNI_OK; +} + +void exitOnError(jvmtiError error) { + if (!NSK_JVMTI_VERIFY(error)) { + exit(error); + } +} + +void rawMonitorEnter(jvmtiEnv *env, jrawMonitorID monitor) { + jvmtiError error = NSK_CPP_STUB2(RawMonitorEnter, env, monitor); + exitOnError(error); +} + +void rawMonitorExit(jvmtiEnv *env, jrawMonitorID monitor) { + jvmtiError error = NSK_CPP_STUB2(RawMonitorExit, env, monitor); + exitOnError(error); +} + +void rawMonitorNotify(jvmtiEnv *env, jrawMonitorID monitor) { + jvmtiError error = NSK_CPP_STUB2(RawMonitorNotify, env, monitor); + exitOnError(error); +} + +void rawMonitorWait(jvmtiEnv *env, jrawMonitorID monitor, jlong millis) { + jvmtiError error = NSK_CPP_STUB3(RawMonitorWait, env, monitor, millis); + exitOnError(error); +} + +void getPhase(jvmtiEnv *env, jvmtiPhase *phase) { + jvmtiError error = NSK_CPP_STUB2(GetPhase, env, phase); + exitOnError(error); +} + +/*************************************************************/ + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/Heap.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/Heap.c deleted file mode 100644 index 638a364a9c7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/Heap.c +++ /dev/null @@ -1,467 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include - -#include "jni.h" -#include "jvmti.h" -#include "agent_common.h" - -static jvmtiEnv *jvmti; -static jint dummy_user_data; -static jboolean user_data_error_flag = JNI_FALSE; - -/* - * Default callbacks - */ - -static jvmtiEventObjectFree object_free_callback; - -static void JNICALL default_object_free(jvmtiEnv *env, jlong tag) { - if (object_free_callback != NULL) { - (*object_free_callback)(env, tag); - } -} - -static jvmtiIterationControl JNICALL default_heap_object_callback - (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) -{ - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - fprintf(stderr, "WARNING: (default) unexpected value of user_data\n"); - } - return JVMTI_ITERATION_ABORT; -} - -static jvmtiHeapObjectCallback heap_object_callback = default_heap_object_callback; -static jvmtiHeapRootCallback heap_root_callback = NULL; -static jvmtiStackReferenceCallback stack_ref_callback = NULL; -static jvmtiObjectReferenceCallback object_ref_callback = NULL; - -/* - * Basic tagging functions - */ - -JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_setTag0 - (JNIEnv *env, jclass cls, jobject o, jlong tag) -{ - return (*jvmti)->SetTag(jvmti, o, tag); -} - -JNIEXPORT jlong JNICALL Java_nsk_share_jvmti_unit_Heap_getTag0 - (JNIEnv *env, jclass cls, jobject o) -{ - jlong tag; - jvmtiError err = (*jvmti)->GetTag(jvmti, o, &tag); - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "ERORR: GetTag failed: JVMTI error=%d\n", err); - return 0; - } - return tag; -} - -JNIEXPORT jlong JNICALL Java_nsk_share_jvmti_unit_Heap_getObjectSize - (JNIEnv *env, jclass cls, jobject o) -{ - jlong size; - jvmtiError err = (*jvmti)->GetObjectSize(jvmti, o, &size); - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "ERORR: GetObjectSize failed: JVMTI error=%d\n", err); - return 0; - } - return size; -} - -/* - * Iterations functions - */ - -JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_iterateOverHeap0 - (JNIEnv *env, jclass cls, jint filter_kind) -{ - if (heap_object_callback == default_heap_object_callback) { - fprintf(stderr, "WARNING: default heap_object_callback set\n"); - } - user_data_error_flag = JNI_FALSE; - return (*jvmti)->IterateOverHeap(jvmti, - filter_kind, heap_object_callback, &dummy_user_data); -} - -JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_iterateOverInstancesOfClass0 - (JNIEnv *env, jclass this_cls, jclass target_cls, jint filter_kind) -{ - if (heap_object_callback == default_heap_object_callback) { - fprintf(stderr, "WARNING: default heap_object_callback set\n"); - } - user_data_error_flag = JNI_FALSE; - return (*jvmti)->IterateOverInstancesOfClass(jvmti, target_cls, - filter_kind, heap_object_callback, &dummy_user_data); -} - -JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_iterateOverReachableObjects0 - (JNIEnv *env, jclass this_cls) -{ - jvmtiError err; - user_data_error_flag = JNI_FALSE; - err = (*jvmti)->IterateOverReachableObjects(jvmti, heap_root_callback, - stack_ref_callback, object_ref_callback, &dummy_user_data); - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "IterateOverReachableObjects failed: jvmti error=%d", err); - } - return err; -} - -JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_iterateOverObjectsReachableFromObject0 - (JNIEnv *env, jclass this_cls, jobject o) -{ - jvmtiError err; - user_data_error_flag = JNI_FALSE; - err = (*jvmti)->IterateOverObjectsReachableFromObject(jvmti, o, - object_ref_callback, &dummy_user_data); - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "IterateOverObjectsReachableFromObject failed: jvmti error=%d", err); - } - return err; -} - - -/* - * GetObjectsWithTags tests - */ - -static jobject object_results_ref; -static jobject tag_results_ref; - -JNIEXPORT jlongArray JNICALL Java_nsk_share_jvmti_unit_Heap_tagResults - (JNIEnv *env, jclass this_cls) -{ - return (jlongArray)tag_results_ref; -} - -JNIEXPORT jobjectArray JNICALL Java_nsk_share_jvmti_unit_Heap_objectResults - (JNIEnv *env, jclass this_cls) -{ - return (jobjectArray)object_results_ref; -} - -JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_getObjectsWithTags - (JNIEnv *env, jclass this_cls, jint count, jlongArray array) -{ - jlong *tags; - jint i; - jvmtiError err; - jobject *object_results; - jlong *tag_results; - jclass cls; - jobjectArray object_array; - jlongArray tag_array; - - /* get rid of any arrays that we are holding from a previous call */ - - if (object_results_ref != NULL) { - (*env)->DeleteGlobalRef(env, object_results_ref); - object_results_ref = NULL; - } - if (tag_results_ref != NULL) { - (*env)->DeleteGlobalRef(env, tag_results_ref); - tag_results_ref = NULL; - } - - /* copy input list-of-tags from java into C */ - - tags = (jlong*)malloc(count * sizeof(jlong)); - (*env)->GetLongArrayRegion(env, array, 0, count, tags); - - err = (*jvmti)->GetObjectsWithTags(jvmti, count, tags, - &count, &object_results, &tag_results); - - /* free the input argument that we malloced */ - free(tags); - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "ERROR: GetObjectsWithTags failed: %d\n", err); - return err; - } - - /* copy output from C arrays into Java arrays */ - - cls = (*env)->FindClass(env, "java/lang/Object"); - - object_array = (*env)->NewObjectArray(env, count, cls, NULL); - tag_array = (*env)->NewLongArray(env, count); - - for (i=0; iSetObjectArrayElement(env, object_array, i, object_results[i]); - } - (*env)->SetLongArrayRegion(env, tag_array, 0, count, tag_results); - - /* create JNI global refs as the current refs are local */ - - object_results_ref = (*env)->NewGlobalRef(env, object_array); - tag_results_ref = (*env)->NewGlobalRef(env, tag_array); - - (*jvmti)->Deallocate(jvmti, (unsigned char*)object_results); - (*jvmti)->Deallocate(jvmti, (unsigned char*)tag_results); - - return count; -} - -/************* Basic Iteration Tests **************/ - -static jint object_count; - -static jvmtiIterationControl JNICALL tagged_object_count_callback - (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) -{ - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - fprintf(stderr, "WARNING: (tagged) unexpected value of user_data\n"); - } - if (*tag_ptr != 0) { - object_count++; - } - return JVMTI_ITERATION_CONTINUE; -} - -static jvmtiIterationControl JNICALL total_object_count_callback - (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) -{ - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - fprintf(stderr, "WARNING: (total) unexpected value of user_data\n"); - } - if (*tag_ptr != 0) { - object_count++; - } - return JVMTI_ITERATION_CONTINUE; -} - - -JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setTaggedObjectCountCallback - (JNIEnv *env, jclass cls) -{ - heap_object_callback = tagged_object_count_callback; - object_count = 0; -} - -JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setTotalObjectCountCallback - (JNIEnv *env, jclass cls) -{ - heap_object_callback = total_object_count_callback; - object_count = 0; -} - -JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_getObjectCount - (JNIEnv *env, jclass cls) -{ - return object_count; -} - -JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_zeroObjectCount - (JNIEnv *env, jclass cls) -{ - object_count = 0; -} - - -/************* Basic Iteration Tests *************/ - -static jvmtiIterationControl JNICALL klass_tag_test_callback - (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) -{ - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - fprintf(stderr, "WARNING: (klass) unexpected value of user_data\n"); - } - if (class_tag != 0) { - *tag_ptr = class_tag; - } - return JVMTI_ITERATION_CONTINUE; -} - -JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setKlassTagTestCallback - (JNIEnv *env, jclass cls) -{ - heap_object_callback = klass_tag_test_callback; -} - -/************* Heap Walking Tests *************/ - -JNIEXPORT jobject JNICALL Java_nsk_share_jvmti_unit_Heap_newGlobalRef - (JNIEnv *env, jclass cls, jobject o) -{ - return (*env)->NewGlobalRef(env, o); -} - -static jvmtiIterationControl JNICALL simple_heap_root_callback - (jvmtiHeapRootKind root_kind, jlong class_tag, jlong size, - jlong* tag_ptr, void* user_data) -{ - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - fprintf(stderr, "WARNING: (heap) unexpected value of user_data\n"); - } - *tag_ptr = root_kind; - return JVMTI_ITERATION_CONTINUE; -} - -static jvmtiIterationControl JNICALL simple_stack_ref_callback - (jvmtiHeapRootKind root_kind, jlong class_tag, jlong size, jlong* tag_ptr, - jlong thread_tag, jint depth, jmethodID method, jint slot, void* user_data) -{ - if (root_kind == JVMTI_HEAP_ROOT_STACK_LOCAL) { - if (method == NULL) { - fprintf(stderr, "WARNING: jmethodID missing for STACK_LOCAL\n"); - } - } - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - fprintf(stderr, "WARNING: (stack) unexpected value of user_data\n"); - } - *tag_ptr = thread_tag; - return JVMTI_ITERATION_CONTINUE; -} - -static jvmtiIterationControl JNICALL simple_object_ref_callback - (jvmtiObjectReferenceKind reference_kind, jlong class_tag, jlong size, jlong* tag_ptr, - jlong referrer_tag, jint referrer_index, void* user_data) -{ - if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { - user_data_error_flag = JNI_TRUE; - fprintf(stderr, "WARNING: (object) unexpected value of user_data\n"); - } - *tag_ptr = 777; - return JVMTI_ITERATION_CONTINUE; -} - - -JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setHeapRootCallback - (JNIEnv *env, jclass cls) -{ - heap_root_callback = simple_heap_root_callback; - stack_ref_callback = NULL; - object_ref_callback = NULL; -} - -JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setStackRefCallback - (JNIEnv *env, jclass cls) -{ - heap_root_callback = NULL; - stack_ref_callback = simple_stack_ref_callback; - object_ref_callback = NULL; -} - -JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setObjectRefCallback - (JNIEnv *env, jclass cls) -{ - heap_root_callback = NULL; - stack_ref_callback = NULL; - object_ref_callback = simple_object_ref_callback; -} - - - -/*************** OBJECT_FREE tests ************/ - -static jint object_free_count; - -static void JNICALL -object_free_count_callback(jvmtiEnv *env, jlong tag) { - if (tag == 0) { - fprintf(stderr, "WARNING: OBJECT_FREE event called with tag 0!!!\n"); - } - object_free_count++; -} - -JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setObjectFreeCallback - (JNIEnv *env, jclass cls) -{ - object_free_callback = object_free_count_callback; - object_free_count = 0; -} - -JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_getObjectFreeCount - (JNIEnv *env, jclass cls) -{ - return object_free_count; -} - -JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_zeroObjectFreeCount - (JNIEnv *env, jclass cls) -{ - object_free_count = 0; -} - -/* - * Agent_Initialize - add capabilities and enables OBJECT_FREE event - */ -jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) -{ - jint rc; - jvmtiError err; - jvmtiCapabilities capabilities; - jvmtiEventCallbacks callbacks; - - /* get JVMTI environment */ - - rc = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION); - if (rc != JNI_OK) { - fprintf(stderr, "Unable to create jvmtiEnv, GetEnv failed, error=%d\n", rc); - return -1; - } - - - /* add annotate object capability */ - err = (*jvmti)->GetCapabilities(jvmti, &capabilities); - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "GetCapabilities failed, error=%d\n", err); - } - capabilities.can_tag_objects = 1; - capabilities.can_generate_object_free_events = 1; - err = (*jvmti)->AddCapabilities(jvmti, &capabilities); - - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "AddCapabilities failed, error=%d\n", err); - return -1; - } - - - /* enable OBJECT_FREE events */ - err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL); - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "SetEventNotificationMode failed, error=%d\n", err); - return -1; - } - - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.ObjectFree = default_object_free; - err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); - if (err != JVMTI_ERROR_NONE) { - fprintf(stderr, "SetEventCallbacks failed, error=%d\n", err); - return -1; - } - - return 0; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/Heap.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/Heap.cpp new file mode 100644 index 00000000000..2b5484057b8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/Heap.cpp @@ -0,0 +1,475 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include + +#include "jni.h" +#include "jvmti.h" +#include "agent_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jvmtiEnv *jvmti; +static jint dummy_user_data; +static jboolean user_data_error_flag = JNI_FALSE; + +/* + * Default callbacks + */ + +static jvmtiEventObjectFree object_free_callback; + +static void JNICALL default_object_free(jvmtiEnv *env, jlong tag) { + if (object_free_callback != NULL) { + (*object_free_callback)(env, tag); + } +} + +static jvmtiIterationControl JNICALL default_heap_object_callback + (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) +{ + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + fprintf(stderr, "WARNING: (default) unexpected value of user_data\n"); + } + return JVMTI_ITERATION_ABORT; +} + +static jvmtiHeapObjectCallback heap_object_callback = default_heap_object_callback; +static jvmtiHeapRootCallback heap_root_callback = NULL; +static jvmtiStackReferenceCallback stack_ref_callback = NULL; +static jvmtiObjectReferenceCallback object_ref_callback = NULL; + +/* + * Basic tagging functions + */ + +JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_setTag0 + (JNIEnv *env, jclass cls, jobject o, jlong tag) +{ + return jvmti->SetTag(o, tag); +} + +JNIEXPORT jlong JNICALL Java_nsk_share_jvmti_unit_Heap_getTag0 + (JNIEnv *env, jclass cls, jobject o) +{ + jlong tag; + jvmtiError err = jvmti->GetTag(o, &tag); + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "ERORR: GetTag failed: JVMTI error=%d\n", err); + return 0; + } + return tag; +} + +JNIEXPORT jlong JNICALL Java_nsk_share_jvmti_unit_Heap_getObjectSize + (JNIEnv *env, jclass cls, jobject o) +{ + jlong size; + jvmtiError err = jvmti->GetObjectSize(o, &size); + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "ERORR: GetObjectSize failed: JVMTI error=%d\n", err); + return 0; + } + return size; +} + +/* + * Iterations functions + */ + +JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_iterateOverHeap0 + (JNIEnv *env, jclass cls, jint filter_kind) +{ + if (heap_object_callback == default_heap_object_callback) { + fprintf(stderr, "WARNING: default heap_object_callback set\n"); + } + user_data_error_flag = JNI_FALSE; + return jvmti->IterateOverHeap( + (jvmtiHeapObjectFilter) filter_kind, heap_object_callback, &dummy_user_data); +} + +JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_iterateOverInstancesOfClass0 + (JNIEnv *env, jclass this_cls, jclass target_cls, jint filter_kind) +{ + if (heap_object_callback == default_heap_object_callback) { + fprintf(stderr, "WARNING: default heap_object_callback set\n"); + } + user_data_error_flag = JNI_FALSE; + return jvmti->IterateOverInstancesOfClass(target_cls, + (jvmtiHeapObjectFilter) filter_kind, heap_object_callback, &dummy_user_data); +} + +JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_iterateOverReachableObjects0 + (JNIEnv *env, jclass this_cls) +{ + jvmtiError err; + user_data_error_flag = JNI_FALSE; + err = jvmti->IterateOverReachableObjects(heap_root_callback, + stack_ref_callback, object_ref_callback, &dummy_user_data); + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "IterateOverReachableObjects failed: jvmti error=%d", err); + } + return err; +} + +JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_iterateOverObjectsReachableFromObject0 + (JNIEnv *env, jclass this_cls, jobject o) +{ + jvmtiError err; + user_data_error_flag = JNI_FALSE; + err = jvmti->IterateOverObjectsReachableFromObject(o, + object_ref_callback, &dummy_user_data); + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "IterateOverObjectsReachableFromObject failed: jvmti error=%d", err); + } + return err; +} + + +/* + * GetObjectsWithTags tests + */ + +static jobject object_results_ref; +static jobject tag_results_ref; + +JNIEXPORT jlongArray JNICALL Java_nsk_share_jvmti_unit_Heap_tagResults + (JNIEnv *env, jclass this_cls) +{ + return (jlongArray)tag_results_ref; +} + +JNIEXPORT jobjectArray JNICALL Java_nsk_share_jvmti_unit_Heap_objectResults + (JNIEnv *env, jclass this_cls) +{ + return (jobjectArray)object_results_ref; +} + +JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_getObjectsWithTags + (JNIEnv *env, jclass this_cls, jint count, jlongArray array) +{ + jlong *tags; + jint i; + jvmtiError err; + jobject *object_results; + jlong *tag_results; + jclass cls; + jobjectArray object_array; + jlongArray tag_array; + + /* get rid of any arrays that we are holding from a previous call */ + + if (object_results_ref != NULL) { + env->DeleteGlobalRef(object_results_ref); + object_results_ref = NULL; + } + if (tag_results_ref != NULL) { + env->DeleteGlobalRef(tag_results_ref); + tag_results_ref = NULL; + } + + /* copy input list-of-tags from java into C */ + + tags = (jlong*)malloc(count * sizeof(jlong)); + env->GetLongArrayRegion(array, 0, count, tags); + + err = jvmti->GetObjectsWithTags(count, tags, + &count, &object_results, &tag_results); + + /* free the input argument that we malloced */ + free(tags); + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "ERROR: GetObjectsWithTags failed: %d\n", err); + return err; + } + + /* copy output from C arrays into Java arrays */ + + cls = env->FindClass("java/lang/Object"); + + object_array = env->NewObjectArray(count, cls, NULL); + tag_array = env->NewLongArray(count); + + for (i=0; iSetObjectArrayElement(object_array, i, object_results[i]); + } + env->SetLongArrayRegion(tag_array, 0, count, tag_results); + + /* create JNI global refs as the current refs are local */ + + object_results_ref = env->NewGlobalRef(object_array); + tag_results_ref = env->NewGlobalRef(tag_array); + + jvmti->Deallocate((unsigned char*)object_results); + jvmti->Deallocate((unsigned char*)tag_results); + + return count; +} + +/************* Basic Iteration Tests **************/ + +static jint object_count; + +static jvmtiIterationControl JNICALL tagged_object_count_callback + (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) +{ + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + fprintf(stderr, "WARNING: (tagged) unexpected value of user_data\n"); + } + if (*tag_ptr != 0) { + object_count++; + } + return JVMTI_ITERATION_CONTINUE; +} + +static jvmtiIterationControl JNICALL total_object_count_callback + (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) +{ + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + fprintf(stderr, "WARNING: (total) unexpected value of user_data\n"); + } + if (*tag_ptr != 0) { + object_count++; + } + return JVMTI_ITERATION_CONTINUE; +} + + +JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setTaggedObjectCountCallback + (JNIEnv *env, jclass cls) +{ + heap_object_callback = tagged_object_count_callback; + object_count = 0; +} + +JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setTotalObjectCountCallback + (JNIEnv *env, jclass cls) +{ + heap_object_callback = total_object_count_callback; + object_count = 0; +} + +JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_getObjectCount + (JNIEnv *env, jclass cls) +{ + return object_count; +} + +JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_zeroObjectCount + (JNIEnv *env, jclass cls) +{ + object_count = 0; +} + + +/************* Basic Iteration Tests *************/ + +static jvmtiIterationControl JNICALL klass_tag_test_callback + (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) +{ + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + fprintf(stderr, "WARNING: (klass) unexpected value of user_data\n"); + } + if (class_tag != 0) { + *tag_ptr = class_tag; + } + return JVMTI_ITERATION_CONTINUE; +} + +JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setKlassTagTestCallback + (JNIEnv *env, jclass cls) +{ + heap_object_callback = klass_tag_test_callback; +} + +/************* Heap Walking Tests *************/ + +JNIEXPORT jobject JNICALL Java_nsk_share_jvmti_unit_Heap_newGlobalRef + (JNIEnv *env, jclass cls, jobject o) +{ + return env->NewGlobalRef(o); +} + +static jvmtiIterationControl JNICALL simple_heap_root_callback + (jvmtiHeapRootKind root_kind, jlong class_tag, jlong size, + jlong* tag_ptr, void* user_data) +{ + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + fprintf(stderr, "WARNING: (heap) unexpected value of user_data\n"); + } + *tag_ptr = root_kind; + return JVMTI_ITERATION_CONTINUE; +} + +static jvmtiIterationControl JNICALL simple_stack_ref_callback + (jvmtiHeapRootKind root_kind, jlong class_tag, jlong size, jlong* tag_ptr, + jlong thread_tag, jint depth, jmethodID method, jint slot, void* user_data) +{ + if (root_kind == JVMTI_HEAP_ROOT_STACK_LOCAL) { + if (method == NULL) { + fprintf(stderr, "WARNING: jmethodID missing for STACK_LOCAL\n"); + } + } + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + fprintf(stderr, "WARNING: (stack) unexpected value of user_data\n"); + } + *tag_ptr = thread_tag; + return JVMTI_ITERATION_CONTINUE; +} + +static jvmtiIterationControl JNICALL simple_object_ref_callback + (jvmtiObjectReferenceKind reference_kind, jlong class_tag, jlong size, jlong* tag_ptr, + jlong referrer_tag, jint referrer_index, void* user_data) +{ + if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) { + user_data_error_flag = JNI_TRUE; + fprintf(stderr, "WARNING: (object) unexpected value of user_data\n"); + } + *tag_ptr = 777; + return JVMTI_ITERATION_CONTINUE; +} + + +JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setHeapRootCallback + (JNIEnv *env, jclass cls) +{ + heap_root_callback = simple_heap_root_callback; + stack_ref_callback = NULL; + object_ref_callback = NULL; +} + +JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setStackRefCallback + (JNIEnv *env, jclass cls) +{ + heap_root_callback = NULL; + stack_ref_callback = simple_stack_ref_callback; + object_ref_callback = NULL; +} + +JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setObjectRefCallback + (JNIEnv *env, jclass cls) +{ + heap_root_callback = NULL; + stack_ref_callback = NULL; + object_ref_callback = simple_object_ref_callback; +} + + + +/*************** OBJECT_FREE tests ************/ + +static jint object_free_count; + +static void JNICALL +object_free_count_callback(jvmtiEnv *env, jlong tag) { + if (tag == 0) { + fprintf(stderr, "WARNING: OBJECT_FREE event called with tag 0!!!\n"); + } + object_free_count++; +} + +JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_setObjectFreeCallback + (JNIEnv *env, jclass cls) +{ + object_free_callback = object_free_count_callback; + object_free_count = 0; +} + +JNIEXPORT jint JNICALL Java_nsk_share_jvmti_unit_Heap_getObjectFreeCount + (JNIEnv *env, jclass cls) +{ + return object_free_count; +} + +JNIEXPORT void JNICALL Java_nsk_share_jvmti_unit_Heap_zeroObjectFreeCount + (JNIEnv *env, jclass cls) +{ + object_free_count = 0; +} + +/* + * Agent_Initialize - add capabilities and enables OBJECT_FREE event + */ +jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) +{ + jint rc; + jvmtiError err; + jvmtiCapabilities capabilities; + jvmtiEventCallbacks callbacks; + + /* get JVMTI environment */ + + rc = vm->GetEnv((void **)&jvmti, JVMTI_VERSION); + if (rc != JNI_OK) { + fprintf(stderr, "Unable to create jvmtiEnv, GetEnv failed, error=%d\n", rc); + return -1; + } + + + /* add annotate object capability */ + err = jvmti->GetCapabilities(&capabilities); + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "GetCapabilities failed, error=%d\n", err); + } + capabilities.can_tag_objects = 1; + capabilities.can_generate_object_free_events = 1; + err = jvmti->AddCapabilities(&capabilities); + + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "AddCapabilities failed, error=%d\n", err); + return -1; + } + + + /* enable OBJECT_FREE events */ + err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL); + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "SetEventNotificationMode failed, error=%d\n", err); + return -1; + } + + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.ObjectFree = default_object_free; + err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); + if (err != JVMTI_ERROR_NONE) { + fprintf(stderr, "SetEventCallbacks failed, error=%d\n", err); + return -1; + } + + return 0; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/libHeap.c b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/libHeap.c deleted file mode 100644 index 65ba09d9a54..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/libHeap.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "native_thread.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "jvmti_FollowRefObjects.c" -#include "Injector.c" -#include "JVMTITools.c" -#include "agent_common.c" -#include "Heap.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/libHeap.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/libHeap.cpp new file mode 100644 index 00000000000..50c36c17229 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/unit/libHeap.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "native_thread.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "jvmti_FollowRefObjects.cpp" +#include "Injector.cpp" +#include "JVMTITools.cpp" +#include "agent_common.cpp" +#include "Heap.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/locks/JNIMonitorLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/locks/JNIMonitorLocker.c deleted file mode 100644 index aad97b32636..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/locks/JNIMonitorLocker.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include "jni.h" -#include "nsk_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef JNI_ENV_PTR - -#ifdef __cplusplus -#define JNI_ENV_ARG_2(x, y) y -#define JNI_ENV_ARG_3(x, y, z) y, z -#define JNI_ENV_ARG_4(x, y, z. a) y, z, a -#define JNI_ENV_PTR(x) x -#else -#define JNI_ENV_ARG_2(x,y) x, y -#define JNI_ENV_ARG_3(x, y, z) x, y, z -#define JNI_ENV_ARG_4(x, y, z, a) x, y, z, a -#define JNI_ENV_PTR(x) (*x) -#endif - -#endif - -JNIEXPORT void JNICALL -Java_nsk_share_locks_JNIMonitorLocker_doLock(JNIEnv *env, jobject thisObject) -{ -/* -This method executes JNI analog for following Java code: - - JNI_MonitorEnter(this); - - step1.unlockAll(); - step2.waitFor(); - readyWicket.unlock(); - inner.lock(); - - JNI_MonitorExit(this); -*/ - jint success; - jfieldID field; - jclass thisObjectClass; - - // fields 'step1' and 'step2' - jobject wicketObject; - - // class for fields 'step1', 'step2', 'readyWicket' - jclass wicketClass; - - // field 'inner' - jobject innerObject; - - // class for field 'inner' - jclass deadlockLockerClass; - - success = JNI_ENV_PTR(env)->MonitorEnter(JNI_ENV_ARG_2(env, thisObject)); - - if(success != 0) - { - NSK_COMPLAIN1("MonitorEnter return non-zero: %d\n", success); - - JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG_3(env, JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG_2(env, "nsk/share/TestJNIError")), "MonitorEnter return non-zero")); - } - - thisObjectClass = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG_2(env, thisObject)); - - // step1.unlockAll() - field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG_4(env, thisObjectClass, "step1", "Lnsk/share/Wicket;")); - - wicketObject = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG_3(env, thisObject, field)); - wicketClass = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG_2(env, wicketObject)); - - JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG_3(env, wicketObject, JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG_4(env, wicketClass, "unlockAll", "()V")))); - - // step2.waitFor() - field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG_4(env, thisObjectClass, "step2", "Lnsk/share/Wicket;")); - wicketObject = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG_3(env, thisObject, field)); - - JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG_3(env, wicketObject, JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG_4(env, wicketClass, "waitFor", "()V")))); - - // readyWicket.unlock() - field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG_4(env, thisObjectClass, "readyWicket", "Lnsk/share/Wicket;")); - wicketObject = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG_3(env, thisObject, field)); - - JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG_3(env, wicketObject, JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG_4(env, wicketClass, "unlock", "()V")))); - - // inner.lock() - field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG_4(env, thisObjectClass, "inner", "Lnsk/share/locks/DeadlockLocker;")); - innerObject = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG_3(env, thisObject, field)); - deadlockLockerClass = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG_2(env, innerObject)); - - JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG_3(env, innerObject, JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG_4(env, deadlockLockerClass, "lock", "()V")))); - - success = JNI_ENV_PTR(env)->MonitorExit(JNI_ENV_ARG_2(env, thisObject)); - - if(success != 0) - { - NSK_COMPLAIN1("MonitorExit return non-zero: %d\n", success); - - JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG_3(env, JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG_2(env, "nsk/share/TestJNIError")), "MonitorExit return non-zero")); - } -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/locks/JNIMonitorLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/locks/JNIMonitorLocker.cpp new file mode 100644 index 00000000000..1e0ea7c6fbd --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/locks/JNIMonitorLocker.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include "jni.h" +#include "nsk_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_PTR + +#ifdef __cplusplus +#define JNI_ENV_ARG_2(x, y) y +#define JNI_ENV_ARG_3(x, y, z) y, z +#define JNI_ENV_ARG_4(x, y, z, a) y, z, a +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG_2(x,y) x, y +#define JNI_ENV_ARG_3(x, y, z) x, y, z +#define JNI_ENV_ARG_4(x, y, z, a) x, y, z, a +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +JNIEXPORT void JNICALL +Java_nsk_share_locks_JNIMonitorLocker_doLock(JNIEnv *env, jobject thisObject) +{ +/* +This method executes JNI analog for following Java code: + + JNI_MonitorEnter(this); + + step1.unlockAll(); + step2.waitFor(); + readyWicket.unlock(); + inner.lock(); + + JNI_MonitorExit(this); +*/ + jint success; + jfieldID field; + jclass thisObjectClass; + + // fields 'step1' and 'step2' + jobject wicketObject; + + // class for fields 'step1', 'step2', 'readyWicket' + jclass wicketClass; + + // field 'inner' + jobject innerObject; + + // class for field 'inner' + jclass deadlockLockerClass; + + success = JNI_ENV_PTR(env)->MonitorEnter(JNI_ENV_ARG_2(env, thisObject)); + + if(success != 0) + { + NSK_COMPLAIN1("MonitorEnter return non-zero: %d\n", success); + + JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG_3(env, JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG_2(env, "nsk/share/TestJNIError")), "MonitorEnter return non-zero")); + } + + thisObjectClass = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG_2(env, thisObject)); + + // step1.unlockAll() + field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG_4(env, thisObjectClass, "step1", "Lnsk/share/Wicket;")); + + wicketObject = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG_3(env, thisObject, field)); + wicketClass = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG_2(env, wicketObject)); + + JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG_3(env, wicketObject, JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG_4(env, wicketClass, "unlockAll", "()V")))); + + // step2.waitFor() + field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG_4(env, thisObjectClass, "step2", "Lnsk/share/Wicket;")); + wicketObject = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG_3(env, thisObject, field)); + + JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG_3(env, wicketObject, JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG_4(env, wicketClass, "waitFor", "()V")))); + + // readyWicket.unlock() + field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG_4(env, thisObjectClass, "readyWicket", "Lnsk/share/Wicket;")); + wicketObject = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG_3(env, thisObject, field)); + + JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG_3(env, wicketObject, JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG_4(env, wicketClass, "unlock", "()V")))); + + // inner.lock() + field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG_4(env, thisObjectClass, "inner", "Lnsk/share/locks/DeadlockLocker;")); + innerObject = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG_3(env, thisObject, field)); + deadlockLockerClass = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG_2(env, innerObject)); + + JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG_3(env, innerObject, JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG_4(env, deadlockLockerClass, "lock", "()V")))); + + success = JNI_ENV_PTR(env)->MonitorExit(JNI_ENV_ARG_2(env, thisObject)); + + if(success != 0) + { + NSK_COMPLAIN1("MonitorExit return non-zero: %d\n", success); + + JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG_3(env, JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG_2(env, "nsk/share/TestJNIError")), "MonitorExit return non-zero")); + } +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/locks/LockingThread.c b/test/hotspot/jtreg/vmTestbase/nsk/share/locks/LockingThread.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/locks/LockingThread.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/locks/LockingThread.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/locks/libJNIMonitorLocker.c b/test/hotspot/jtreg/vmTestbase/nsk/share/locks/libJNIMonitorLocker.c deleted file mode 100644 index 85f46f45307..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/locks/libJNIMonitorLocker.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "nsk_tools.c" -#include "JNIMonitorLocker.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/locks/libJNIMonitorLocker.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/locks/libJNIMonitorLocker.cpp new file mode 100644 index 00000000000..062abd3117b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/locks/libJNIMonitorLocker.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "nsk_tools.cpp" +#include "JNIMonitorLocker.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/locks/libLockingThread.c b/test/hotspot/jtreg/vmTestbase/nsk/share/locks/libLockingThread.c deleted file mode 100644 index 0eef28071c3..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/locks/libLockingThread.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "LockingThread.c" -#include "nsk_tools.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/locks/libLockingThread.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/locks/libLockingThread.cpp new file mode 100644 index 00000000000..89fdaa79326 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/locks/libLockingThread.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "LockingThread.cpp" +#include "nsk_tools.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/native/native_thread.c b/test/hotspot/jtreg/vmTestbase/nsk/share/native/native_thread.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/native/native_thread.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/native/native_thread.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/native/native_utils.c b/test/hotspot/jtreg/vmTestbase/nsk/share/native/native_utils.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/native/native_utils.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/native/native_utils.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.c b/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.c deleted file mode 100644 index 8452592c269..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "nsk_list.h" -#include "nsk_tools.h" - -#define NSK_LIST_INIT_COUNT 20 - -typedef struct nsk_list_infoStruct { - const void **arr; - int elements_count; - int allocated_count; -} nsk_list_info; - - -static int nsk_list_size_void = sizeof(void *); - -/* ============================================================================= */ - -const void* nsk_list_create() { - - nsk_list_info *list_info; - - /* create nsk_list_info */ - list_info = (nsk_list_info *)malloc(sizeof(nsk_list_info)); - if (list_info == NULL) { - return NULL; - } - - list_info->allocated_count = NSK_LIST_INIT_COUNT; - list_info->elements_count = 0; - list_info->arr = (const void **)malloc(list_info->allocated_count * nsk_list_size_void); - if (list_info->arr == NULL) { - free(list_info); - return NULL; - } - - return list_info; -} - -/* ============================================================================= */ - -int nsk_list_destroy(const void *plist) { - - const nsk_list_info *list_info = (const nsk_list_info *)plist; - - free((void *)list_info->arr); - free((void *)plist); - - return NSK_TRUE; -} - -/* ============================================================================= */ - -int nsk_list_add(const void *plist, const void *p) { - - nsk_list_info *list_info = (nsk_list_info *)plist; - - if (list_info->elements_count >= list_info->allocated_count) { - list_info->allocated_count += NSK_LIST_INIT_COUNT; - list_info->arr = (const void **)realloc((void *)list_info->arr, list_info->allocated_count * nsk_list_size_void); - if (list_info->arr == NULL) { - return NSK_FALSE; - } - } - list_info->arr[list_info->elements_count++] = p; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -int nsk_list_remove(const void *plist, int ind) { - - nsk_list_info *list_info = (nsk_list_info *)plist; - - if ((list_info->elements_count <= 0) - || ((ind < 0) || (ind >= list_info->elements_count))) - return NSK_FALSE; - - { - int i; - for (i = ind+1; i < list_info->elements_count; i++) { - list_info->arr[i - 1] = list_info->arr[i]; - } - } - list_info->arr[--list_info->elements_count] = 0; - - return NSK_TRUE; -} - -/* ============================================================================= */ - -int nsk_list_getCount(const void *plist) { - - return ((const nsk_list_info *)plist)->elements_count; -} - -/* ============================================================================= */ - -const void* nsk_list_get(const void *plist, int i) { - - const nsk_list_info *list_info = (const nsk_list_info *)plist; - - if ((i >= 0) && (i < list_info->elements_count)) { - return list_info->arr[i]; - } - - return NULL; -} - -/* ============================================================================= */ diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.cpp new file mode 100644 index 00000000000..50a03d86321 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "nsk_list.h" +#include "nsk_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define NSK_LIST_INIT_COUNT 20 + +typedef struct nsk_list_infoStruct { + const void **arr; + int elements_count; + int allocated_count; +} nsk_list_info; + + +static int nsk_list_size_void = sizeof(void *); + +/* ============================================================================= */ + +const void* nsk_list_create() { + + nsk_list_info *list_info; + + /* create nsk_list_info */ + list_info = (nsk_list_info *)malloc(sizeof(nsk_list_info)); + if (list_info == NULL) { + return NULL; + } + + list_info->allocated_count = NSK_LIST_INIT_COUNT; + list_info->elements_count = 0; + list_info->arr = (const void **)malloc(list_info->allocated_count * nsk_list_size_void); + if (list_info->arr == NULL) { + free(list_info); + return NULL; + } + + return list_info; +} + +/* ============================================================================= */ + +int nsk_list_destroy(const void *plist) { + + const nsk_list_info *list_info = (const nsk_list_info *)plist; + + free((void *)list_info->arr); + free((void *)plist); + + return NSK_TRUE; +} + +/* ============================================================================= */ + +int nsk_list_add(const void *plist, const void *p) { + + nsk_list_info *list_info = (nsk_list_info *)plist; + + if (list_info->elements_count >= list_info->allocated_count) { + list_info->allocated_count += NSK_LIST_INIT_COUNT; + list_info->arr = (const void **)realloc((void *)list_info->arr, list_info->allocated_count * nsk_list_size_void); + if (list_info->arr == NULL) { + return NSK_FALSE; + } + } + list_info->arr[list_info->elements_count++] = p; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +int nsk_list_remove(const void *plist, int ind) { + + nsk_list_info *list_info = (nsk_list_info *)plist; + + if ((list_info->elements_count <= 0) + || ((ind < 0) || (ind >= list_info->elements_count))) + return NSK_FALSE; + + { + int i; + for (i = ind+1; i < list_info->elements_count; i++) { + list_info->arr[i - 1] = list_info->arr[i]; + } + } + list_info->arr[--list_info->elements_count] = 0; + + return NSK_TRUE; +} + +/* ============================================================================= */ + +int nsk_list_getCount(const void *plist) { + + return ((const nsk_list_info *)plist)->elements_count; +} + +/* ============================================================================= */ + +const void* nsk_list_get(const void *plist, int i) { + + const nsk_list_info *list_info = (const nsk_list_info *)plist; + + if ((i >= 0) && (i < list_info->elements_count)) { + return list_info->arr[i]; + } + + return NULL; +} + +#ifdef __cplusplus +} +#endif + +/* ============================================================================= */ diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.h b/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.h index 2563e4288c8..a4fde915931 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.h +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.h @@ -24,6 +24,10 @@ #ifndef NSK_LIST #define NSK_LIST +#ifdef __cplusplus +extern "C" { +#endif + /** * Prepares array of pointers which has fixed INITIAL_SIZE. * Memory for this array will be reallocated at the nsk_list_add() @@ -64,4 +68,8 @@ int nsk_list_add(const void *plist, const void *p); */ int nsk_list_remove(const void *plist, int i); +#ifdef __cplusplus +} +#endif + #endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_mutex.c b/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_mutex.c deleted file mode 100644 index 586e747b9d2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_mutex.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "nsk_mutex.h" - -#ifndef _WIN32 - -#include - -MUTEX* MUTEX_create() -{ - MUTEX* mutex = (MUTEX*)malloc(sizeof(pthread_mutex_t)); - if (mutex) - { - pthread_mutex_init((pthread_mutex_t*)mutex, NULL); - } - return mutex; -} - -void MUTEX_acquire(MUTEX* mutex) -{ - pthread_mutex_lock((pthread_mutex_t*)mutex); -} - -void MUTEX_release(MUTEX* mutex) -{ - pthread_mutex_unlock((pthread_mutex_t*)mutex); -} - -void MUTEX_destroy(MUTEX* mutex) -{ - pthread_mutex_destroy((pthread_mutex_t*)mutex); - - free(mutex); -} - -#else // _WIN32 - -#include - -MUTEX* MUTEX_create() -{ - MUTEX* mutex = (MUTEX*)malloc(sizeof(CRITICAL_SECTION)); - if (mutex) - { - InitializeCriticalSection((PCRITICAL_SECTION)mutex); - } - return mutex; -} - -void MUTEX_acquire(MUTEX* mutex) -{ - EnterCriticalSection((PCRITICAL_SECTION)mutex); -} - -void MUTEX_release(MUTEX* mutex) -{ - LeaveCriticalSection((PCRITICAL_SECTION)mutex); -} - -void MUTEX_destroy(MUTEX* mutex) -{ - DeleteCriticalSection((PCRITICAL_SECTION)mutex); - - free(mutex); -} - -#endif // _WIN32 diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_mutex.cpp b/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_mutex.cpp new file mode 100644 index 00000000000..04dcd1b2906 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_mutex.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "nsk_mutex.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _WIN32 + +#include + +MUTEX* MUTEX_create() +{ + MUTEX* mutex = (MUTEX*)malloc(sizeof(pthread_mutex_t)); + if (mutex) + { + pthread_mutex_init((pthread_mutex_t*)mutex, NULL); + } + return mutex; +} + +void MUTEX_acquire(MUTEX* mutex) +{ + pthread_mutex_lock((pthread_mutex_t*)mutex); +} + +void MUTEX_release(MUTEX* mutex) +{ + pthread_mutex_unlock((pthread_mutex_t*)mutex); +} + +void MUTEX_destroy(MUTEX* mutex) +{ + pthread_mutex_destroy((pthread_mutex_t*)mutex); + + free(mutex); +} + +#else // _WIN32 + +#include + +MUTEX* MUTEX_create() +{ + MUTEX* mutex = (MUTEX*)malloc(sizeof(CRITICAL_SECTION)); + if (mutex) + { + InitializeCriticalSection((PCRITICAL_SECTION)mutex); + } + return mutex; +} + +void MUTEX_acquire(MUTEX* mutex) +{ + EnterCriticalSection((PCRITICAL_SECTION)mutex); +} + +void MUTEX_release(MUTEX* mutex) +{ + LeaveCriticalSection((PCRITICAL_SECTION)mutex); +} + +void MUTEX_destroy(MUTEX* mutex) +{ + DeleteCriticalSection((PCRITICAL_SECTION)mutex); + + free(mutex); +} + +#endif // _WIN32 + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_tools.c b/test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_tools.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_tools.c rename to test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_tools.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/gclocker/libgcl001.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/gclocker/libgcl001.c deleted file mode 100644 index 9d37866b4e6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/gclocker/libgcl001.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "jnihelper.h" - -// compare most java primitive value types -#define COMP(type) \ -int type##comp(const void *s1, const void *s2)\ -{\ - type st1 = *((type *)s1);\ - type st2 = *((type *)s2);\ - if (st1 < st2)\ - return -1;\ - else if (st1 > st2)\ - return 1;\ - else\ - return 0;\ -} - -// basic routine: provide critical sections and calculations - // enter array CS - // check isCopy for native referencing - // enter first string CS - // leave first string CS - // enter second string CS - // leave array CS - // enter second string CS - -#define BODY(type) \ -int hash = 0; int i; jboolean isCopy = JNI_FALSE; jchar *nativeStr; jsize size; type *nativeArray; \ -size = (*env)->GetArrayLength(env, array); CE \ -nativeArray = (type *)(*env)->GetPrimitiveArrayCritical(env, array, &isCopy); CE \ -EnterCS(env); \ -if (isCopy == JNI_TRUE) return 0;\ -qsort(nativeArray, size, sizeof(type), *type##comp);\ -\ -size = (*env)->GetStringLength(env, str); CE \ -nativeStr = (jchar *)(*env)->GetStringCritical(env, str, &isCopy); CE \ -if (isCopy == JNI_TRUE) return 0;\ -for (i = 0; i < size; ++i)\ - hash += (int)nativeStr[i];\ -\ -(*env)->ReleasePrimitiveArrayCritical(env, array, nativeArray, 0); CE \ -LeaveCS(env); \ -(*env)->ReleaseStringCritical(env, str, nativeStr); CE \ -\ -hash = 0;\ -size = (*env)->GetStringLength(env, str); CE \ -nativeStr = (jchar *)(*env)->GetStringCritical(env, str, &isCopy); CE \ -EnterCS(env); \ -if (isCopy == JNI_TRUE) return 0;\ -for (i = 0; i < size; ++i)\ - hash += (int)nativeStr[i];\ -LeaveCS(env); \ -(*env)->ReleaseStringCritical(env, str, nativeStr); CE \ -return hash; - -static int CSEntered = 0; -static int CSLeft = 0; - -void EnterCS(JNIEnv *env) -{ - // unsafe but where are no better ideas - //++CSEntered; - //printf("CS Entered -> Entered: %d\n", CSEntered); -// jclass trace = 0; jmethodID method = 0; -// trace = (*env)->FindClass(env, "nsk/stress/jni/gclocker/Trace"); CE -// method = (*env)->GetStaticMethodID(env, trace, "EnterCS", "()V"); CE -// (*env)->CallStaticVoidMethod(env, trace, method); CE -} - -void LeaveCS(JNIEnv *env) -{ - // unsafe but where are no better ideas - //++CSLeft; - //printf("CS Left -> Completed: %d\tActive: %d\n", CSLeft, CSEntered - CSLeft); -// jclass trace = 0; jmethodID method = 0; -// trace = (*env)->FindClass(env, "nsk/stress/jni/gclocker/Trace"); CE -// method = (*env)->GetStaticMethodID(env, trace, "LeaveCS", "()V"); CE -// (*env)->CallStaticVoidMethod(env, trace, method); CE -} - -COMP(jint) -COMP(jboolean) -COMP(jchar) -COMP(jshort) -COMP(jbyte) -COMP(jdouble) -COMP(jfloat) -COMP(jlong) - -/* - * Class: JNIWorker - * Method: NativeCall - * Signature: ([ZLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3ZLjava_lang_String_2 - (JNIEnv * env, jobject obj, jbooleanArray array, jstring str) -{ - BODY(jboolean) -} - -/* - * Class: JNIWorker - * Method: NativeCall - * Signature: ([BLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3BLjava_lang_String_2 - (JNIEnv * env, jobject obj, jbyteArray array, jstring str) -{ - BODY(jbyte) -} - -/* - * Class: JNIWorker - * Method: NativeCall - * Signature: ([CLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3CLjava_lang_String_2 - (JNIEnv *env, jobject obj, jcharArray array, jstring str) -{ - BODY(jchar) -} - -/* - * Class: JNIWorker - * Method: NativeCall - * Signature: ([SLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3SLjava_lang_String_2 - (JNIEnv *env, jobject obj, jshortArray array, jstring str) -{ - BODY(jshort) -} - -/* - * Class: JNIWorker - * Method: NativeCall - * Signature: ([ILjava/lang/String;)I - */ -JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3ILjava_lang_String_2 - (JNIEnv *env, jobject obj, jintArray array, jstring str) -{ - BODY(jint) -} - -/* - * Class: JNIWorker - * Method: NativeCall - * Signature: ([JLjava/lang/String;)I - */ - -JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3JLjava_lang_String_2 - (JNIEnv *env, jobject obj, jlongArray array, jstring str) -{ - BODY(jlong) -} - -/* - * Class: JNIWorker - * Method: NativeCall - * Signature: ([FLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3FLjava_lang_String_2 - (JNIEnv *env, jobject obj, jfloatArray array, jstring str) -{ - BODY(jfloat) -} - -/* - * Class: JNIWorker - * Method: NativeCall - * Signature: ([DLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3DLjava_lang_String_2 - (JNIEnv *env, jobject obj, jdoubleArray array, jstring str) -{ - BODY(jdouble) -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/gclocker/libgcl001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/gclocker/libgcl001.cpp new file mode 100644 index 00000000000..0e0aa5a2ce1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/gclocker/libgcl001.cpp @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include +#include "jnihelper.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// compare most java primitive value types +#define COMP(type) \ +int type##comp(const void *s1, const void *s2)\ +{\ + type st1 = *((type *)s1);\ + type st2 = *((type *)s2);\ + if (st1 < st2)\ + return -1;\ + else if (st1 > st2)\ + return 1;\ + else\ + return 0;\ +} + +// basic routine: provide critical sections and calculations + // enter array CS + // check isCopy for native referencing + // enter first string CS + // leave first string CS + // enter second string CS + // leave array CS + // enter second string CS + +#define BODY(type) \ +int hash = 0; int i; jboolean isCopy = JNI_FALSE; jchar *nativeStr; jsize size; type *nativeArray; \ +size = env->GetArrayLength(array); CE \ +nativeArray = (type *)env->GetPrimitiveArrayCritical(array, &isCopy); CE \ +EnterCS(env); \ +if (isCopy == JNI_TRUE) return 0;\ +qsort(nativeArray, size, sizeof(type), *type##comp);\ +\ +size = env->GetStringLength(str); CE \ +nativeStr = (jchar *)env->GetStringCritical(str, &isCopy); CE \ +if (isCopy == JNI_TRUE) return 0;\ +for (i = 0; i < size; ++i)\ + hash += (int)nativeStr[i];\ +\ +env->ReleasePrimitiveArrayCritical(array, nativeArray, 0); CE \ +LeaveCS(env); \ +env->ReleaseStringCritical(str, nativeStr); CE \ +\ +hash = 0;\ +size = env->GetStringLength(str); CE \ +nativeStr = (jchar *)env->GetStringCritical(str, &isCopy); CE \ +EnterCS(env); \ +if (isCopy == JNI_TRUE) return 0;\ +for (i = 0; i < size; ++i)\ + hash += (int)nativeStr[i];\ +LeaveCS(env); \ +env->ReleaseStringCritical(str, nativeStr); CE \ +return hash; + +static int CSEntered = 0; +static int CSLeft = 0; + +void EnterCS(JNIEnv *env) +{ + // unsafe but where are no better ideas + //++CSEntered; + //printf("CS Entered -> Entered: %d\n", CSEntered); +// jclass trace = 0; jmethodID method = 0; +// trace = env->FindClass("nsk/stress/jni/gclocker/Trace"); CE +// method = env->GetStaticMethodID(trace, "EnterCS", "()V"); CE +// env->CallStaticVoidMethod(trace, method); CE +} + +void LeaveCS(JNIEnv *env) +{ + // unsafe but where are no better ideas + //++CSLeft; + //printf("CS Left -> Completed: %d\tActive: %d\n", CSLeft, CSEntered - CSLeft); +// jclass trace = 0; jmethodID method = 0; +// trace = env->FindClass("nsk/stress/jni/gclocker/Trace"); CE +// method = env->GetStaticMethodID(trace, "LeaveCS", "()V"); CE +// env->CallStaticVoidMethod(trace, method); CE +} + +COMP(jint) +COMP(jboolean) +COMP(jchar) +COMP(jshort) +COMP(jbyte) +COMP(jdouble) +COMP(jfloat) +COMP(jlong) + +/* + * Class: JNIWorker + * Method: NativeCall + * Signature: ([ZLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3ZLjava_lang_String_2 + (JNIEnv * env, jobject obj, jbooleanArray array, jstring str) +{ + BODY(jboolean) +} + +/* + * Class: JNIWorker + * Method: NativeCall + * Signature: ([BLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3BLjava_lang_String_2 + (JNIEnv * env, jobject obj, jbyteArray array, jstring str) +{ + BODY(jbyte) +} + +/* + * Class: JNIWorker + * Method: NativeCall + * Signature: ([CLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3CLjava_lang_String_2 + (JNIEnv *env, jobject obj, jcharArray array, jstring str) +{ + BODY(jchar) +} + +/* + * Class: JNIWorker + * Method: NativeCall + * Signature: ([SLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3SLjava_lang_String_2 + (JNIEnv *env, jobject obj, jshortArray array, jstring str) +{ + BODY(jshort) +} + +/* + * Class: JNIWorker + * Method: NativeCall + * Signature: ([ILjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3ILjava_lang_String_2 + (JNIEnv *env, jobject obj, jintArray array, jstring str) +{ + BODY(jint) +} + +/* + * Class: JNIWorker + * Method: NativeCall + * Signature: ([JLjava/lang/String;)I + */ + +JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3JLjava_lang_String_2 + (JNIEnv *env, jobject obj, jlongArray array, jstring str) +{ + BODY(jlong) +} + +/* + * Class: JNIWorker + * Method: NativeCall + * Signature: ([FLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3FLjava_lang_String_2 + (JNIEnv *env, jobject obj, jfloatArray array, jstring str) +{ + BODY(jfloat) +} + +/* + * Class: JNIWorker + * Method: NativeCall + * Signature: ([DLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_nsk_stress_jni_gclocker_JNIWorker_NativeCall___3DLjava_lang_String_2 + (JNIEnv *env, jobject obj, jdoubleArray array, jstring str) +{ + BODY(jdouble) +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/jnihelper.h b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/jnihelper.h index d5084b37c9d..753e3048f4d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/jnihelper.h +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/jnihelper.h @@ -23,11 +23,11 @@ // Asserts every exception as fatal one #define CE {\ - if ((*env)->ExceptionOccurred(env))\ + if (env->ExceptionOccurred())\ {\ - puts("Unexpected JNI exception. TEST FAIL."); \ - (*env)->ExceptionDescribe(env); \ - (*env)->ExceptionClear(env);\ - (*env)->FatalError(env, "Unexpected JNI Exception. TEST FAIL."); \ + puts("Unexpected JNI exception. TEST FAIL.");\ + env->ExceptionDescribe();\ + env->ExceptionClear();\ + env->FatalError("Unexpected JNI Exception. TEST FAIL.");\ }\ } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress001.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress001.c deleted file mode 100644 index 2c0745a8e38..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress001.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -/* Changed from strings.h to string.h for Windows. */ -#include -#include -#include "jnihelper.h" - -#define DIGESTLENGTH 16 - -typedef struct { - const char **str; - char **checkstr; -} CHAR_ARRAY; - -typedef struct { - const jchar **str; - char **checkstr; - int *size; -} JCHAR_ARRAY; - -JNIEXPORT jstring JNICALL -Java_nsk_stress_jni_JNIter001_jnistress (JNIEnv *env, jobject jobj, jstring jstr, - jint nstr, jint printperiod) { - - int i,j; - size_t k; - static CHAR_ARRAY *element; - unsigned char digest[DIGESTLENGTH]; - static int allocs=0; - static size_t strsize=0; - static unsigned int compared=1; - - const char *clsName = "nsk/stress/jni/JNIter001"; - const char *name="setpass"; - const char *sig="(Z)V"; - const char *halt="halt"; - const char *haltSig="()V"; - jstring tmpstr; - jclass clazz; - jmethodID methodID; - - (*env)->MonitorEnter(env, jobj); CE - if (!allocs) { - element = (CHAR_ARRAY *)malloc(sizeof(CHAR_ARRAY)); - element->str = (const char **)malloc(nstr*sizeof(const char *)); - element->checkstr = (char **)malloc(nstr*sizeof(char *)); - for (j=0;jcheckstr[j] = (char *)malloc(DIGESTLENGTH*sizeof(char)); - } - for(j=0;jstr[allocs] = (*env)->GetStringUTFChars(env,jstr,0); CE - if (strlen(element->str[allocs]) != - (size_t) (*env)->GetStringUTFLength(env, jstr)) - printf("Length is wrong in string No. %d\n",allocs); - else - strsize += strlen(element->str[allocs])+1; - for (k = 0; k < strlen(element->str[allocs]); k++) { - digest[k % DIGESTLENGTH] += element->str[allocs][k]; - } - memcpy(element->checkstr[allocs],digest,DIGESTLENGTH); - allocs++; - if (allocs%printperiod==0) { - printf("Check string for thread %s is ", element->str[allocs-1]); - for (j=0;jNewStringUTF(env,element->str[allocs-1]); CE - for (j=0; jstr[j]); k++) { - digest[k % DIGESTLENGTH] += element->str[j][k]; - } - if (memcmp(digest,element->checkstr[j],DIGESTLENGTH)==0) { - (*env)->ReleaseStringUTFChars(env,jstr,element->str[j]); CE - element->str[j] = NULL; - element->checkstr[j] = NULL; - } - else { - compared=0; - printf("The element No. %d has been corrupted %s vs %s\n",j, element->str[j],element->checkstr[j]); - printf("Digest string is %s [", element->str[j]); - for (i=0;icheckstr[j]); - free(element->checkstr); - free((void *)(element->str)); - free(element); - clazz=(*env)->FindClass(env, clsName); CE - if (!compared) { - methodID=(*env)->GetStaticMethodID(env, clazz, name, sig); CE - (*env)->CallStaticVoidMethod(env, clazz, methodID, JNI_FALSE); CE - } - //methodID=(*env)->GetStaticMethodID(env, clazz, halt, haltSig); CE - //(*env)->CallStaticVoidMethod(env, clazz, methodID); CE - return(tmpstr); - } - (*env)->MonitorExit(env, jobj); CE - return ((*env)->NewStringUTF(env,element->str[allocs-1])); -} - -JNIEXPORT jstring JNICALL -Java_nsk_stress_jni_JNIter001_jnistress1(JNIEnv *env, jobject jobj, jstring jstr, - jint nstr, jint printperiod) { - - int i,j; - static JCHAR_ARRAY *javachars; - unsigned char digest[DIGESTLENGTH]; - static int index=0; - static long len=0; - static unsigned int equal=1; - char *elem; - - const char *clsName = "nsk/stress/jni/JNIter001"; - const char *name="setpass"; - const char *sig="(Z)V"; - const char *halt="halt"; - const char *haltSig="()V"; - jstring tmpstr; - jclass clazz; - jmethodID methodID; - - (*env)->MonitorEnter(env, jobj); CE - if (!index) { - javachars = (JCHAR_ARRAY *)malloc(sizeof(JCHAR_ARRAY)); - javachars->str = (const jchar **)malloc(nstr*sizeof(const jchar *)); - javachars->checkstr = (char **)malloc(nstr*sizeof(char *)); - javachars->size = (int *)malloc(nstr*sizeof(int)); - for (j=0;jcheckstr[j] = (char *)malloc(DIGESTLENGTH*sizeof(char)); - } - for(j=0;jstr[index] = (*env)->GetStringChars(env,jstr,0); CE - javachars->size[index] = (*env)->GetStringUTFLength(env, jstr); CE - len += javachars->size[index]; - elem = (char*) malloc(javachars->size[index]*sizeof(char)); - for (j=0; j < javachars->size[index]; j++) { - elem[j] = (char) javachars->str[index][j]; - } - //memcpy(digest, elem, javachars->size[index]); - for(j=0;jsize[index]; j++) { - digest[j % DIGESTLENGTH]+=elem[j]; - } - memcpy(javachars->checkstr[index++],digest,DIGESTLENGTH); - if (index%printperiod==0) { - printf("Check string sum for thread %s is ",elem); - for (j=0;jNewString(env,javachars->str[index-1],javachars->size[index-1]); CE - for (j=0; jsize[j]*sizeof(char)); - for (i=0; i < javachars->size[j]; i++) { - elem[i] = (char) javachars->str[j][i]; - } - //memcpy(digest, elem, javachars->size[j]); - for(i=0;isize[j]; i++) { - digest[i % DIGESTLENGTH]+=elem[i]; - } - free(elem); - if (memcmp(digest,javachars->checkstr[j],javachars->size[j])==0) { - (*env)->ReleaseStringChars(env,jstr,javachars->str[j]); CE - javachars->str[j] = NULL; - javachars->checkstr[j] = NULL; - javachars->size[j] = 0; - } - else { - equal=0; - printf("The Unicode element No. %d has been corrupted\n",j); - for(i=0;icheckstr[j][i]); - } - } - } - index=0; - len = 0; - for (j=0;jcheckstr[j]); - free(javachars->checkstr); - free((void *)(javachars->str)); - free(javachars->size); - free(javachars); - clazz=(*env)->FindClass(env, clsName); CE - if (!equal) { - methodID=(*env)->GetStaticMethodID(env, clazz, name, sig); CE - (*env)->CallStaticVoidMethod(env, clazz, methodID, JNI_FALSE); CE - } - //methodID=(*env)->GetStaticMethodID(env, clazz, halt, haltSig); CE - //(*env)->CallStaticVoidMethod(env, clazz, methodID); CE - return(tmpstr); - } - (*env)->MonitorExit(env, jobj); CE - return((*env)->NewString(env,javachars->str[index-1],javachars->size[index-1])); -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress001.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress001.cpp new file mode 100644 index 00000000000..9dc3125ab21 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress001.cpp @@ -0,0 +1,247 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +/* Changed from strings.h to string.h for Windows. */ +#include +#include +#include "jnihelper.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define DIGESTLENGTH 16 + +typedef struct { + const char **str; + char **checkstr; +} CHAR_ARRAY; + +typedef struct { + const jchar **str; + char **checkstr; + int *size; +} JCHAR_ARRAY; + +JNIEXPORT jstring JNICALL +Java_nsk_stress_jni_JNIter001_jnistress (JNIEnv *env, jobject jobj, jstring jstr, + jint nstr, jint printperiod) { + + int i,j; + size_t k; + static CHAR_ARRAY *element; + unsigned char digest[DIGESTLENGTH]; + static int allocs=0; + static size_t strsize=0; + static unsigned int compared=1; + + const char *clsName = "nsk/stress/jni/JNIter001"; + const char *name="setpass"; + const char *sig="(Z)V"; + const char *halt="halt"; + const char *haltSig="()V"; + jstring tmpstr; + jclass clazz; + jmethodID methodID; + + env->MonitorEnter(jobj); CE + if (!allocs) { + element = (CHAR_ARRAY *)malloc(sizeof(CHAR_ARRAY)); + element->str = (const char **)malloc(nstr*sizeof(const char *)); + element->checkstr = (char **)malloc(nstr*sizeof(char *)); + for (j=0;jcheckstr[j] = (char *)malloc(DIGESTLENGTH*sizeof(char)); + } + for(j=0;jstr[allocs] = env->GetStringUTFChars(jstr,0); CE + if (strlen(element->str[allocs]) != + (size_t) env->GetStringUTFLength(jstr)) + printf("Length is wrong in string No. %d\n",allocs); + else + strsize += strlen(element->str[allocs])+1; + for (k = 0; k < strlen(element->str[allocs]); k++) { + digest[k % DIGESTLENGTH] += element->str[allocs][k]; + } + memcpy(element->checkstr[allocs],digest,DIGESTLENGTH); + allocs++; + if (allocs%printperiod==0) { + printf("Check string for thread %s is ", element->str[allocs-1]); + for (j=0;jNewStringUTF(element->str[allocs-1]); CE + for (j=0; jstr[j]); k++) { + digest[k % DIGESTLENGTH] += element->str[j][k]; + } + if (memcmp(digest,element->checkstr[j],DIGESTLENGTH)==0) { + env->ReleaseStringUTFChars(jstr,element->str[j]); CE + element->str[j] = NULL; + element->checkstr[j] = NULL; + } + else { + compared=0; + printf("The element No. %d has been corrupted %s vs %s\n",j, element->str[j],element->checkstr[j]); + printf("Digest string is %s [", element->str[j]); + for (i=0;icheckstr[j]); + free(element->checkstr); + free((void *)(element->str)); + free(element); + clazz=env->FindClass(clsName); CE + if (!compared) { + methodID=env->GetStaticMethodID(clazz, name, sig); CE + env->CallStaticVoidMethod(clazz, methodID, JNI_FALSE); CE + } + //methodID=env->GetStaticMethodID(clazz, halt, haltSig); CE + //env->CallStaticVoidMethod(clazz, methodID); CE + return(tmpstr); + } + env->MonitorExit(jobj); CE + return (env->NewStringUTF(element->str[allocs-1])); +} + +JNIEXPORT jstring JNICALL +Java_nsk_stress_jni_JNIter001_jnistress1(JNIEnv *env, jobject jobj, jstring jstr, + jint nstr, jint printperiod) { + + int i,j; + static JCHAR_ARRAY *javachars; + unsigned char digest[DIGESTLENGTH]; + static int index=0; + static long len=0; + static unsigned int equal=1; + char *elem; + + const char *clsName = "nsk/stress/jni/JNIter001"; + const char *name="setpass"; + const char *sig="(Z)V"; + const char *halt="halt"; + const char *haltSig="()V"; + jstring tmpstr; + jclass clazz; + jmethodID methodID; + + env->MonitorEnter(jobj); CE + if (!index) { + javachars = (JCHAR_ARRAY *)malloc(sizeof(JCHAR_ARRAY)); + javachars->str = (const jchar **)malloc(nstr*sizeof(const jchar *)); + javachars->checkstr = (char **)malloc(nstr*sizeof(char *)); + javachars->size = (int *)malloc(nstr*sizeof(int)); + for (j=0;jcheckstr[j] = (char *)malloc(DIGESTLENGTH*sizeof(char)); + } + for(j=0;jstr[index] = env->GetStringChars(jstr,0); CE + javachars->size[index] = env->GetStringUTFLength(jstr); CE + len += javachars->size[index]; + elem = (char*) malloc(javachars->size[index]*sizeof(char)); + for (j=0; j < javachars->size[index]; j++) { + elem[j] = (char) javachars->str[index][j]; + } + //memcpy(digest, elem, javachars->size[index]); + for(j=0;jsize[index]; j++) { + digest[j % DIGESTLENGTH]+=elem[j]; + } + memcpy(javachars->checkstr[index++],digest,DIGESTLENGTH); + if (index%printperiod==0) { + printf("Check string sum for thread %s is ",elem); + for (j=0;jNewString(javachars->str[index-1],javachars->size[index-1]); CE + for (j=0; jsize[j]*sizeof(char)); + for (i=0; i < javachars->size[j]; i++) { + elem[i] = (char) javachars->str[j][i]; + } + //memcpy(digest, elem, javachars->size[j]); + for(i=0;isize[j]; i++) { + digest[i % DIGESTLENGTH]+=elem[i]; + } + free(elem); + if (memcmp(digest,javachars->checkstr[j],javachars->size[j])==0) { + env->ReleaseStringChars(jstr,javachars->str[j]); CE + javachars->str[j] = NULL; + javachars->checkstr[j] = NULL; + javachars->size[j] = 0; + } + else { + equal=0; + printf("The Unicode element No. %d has been corrupted\n",j); + for(i=0;icheckstr[j][i]); + } + } + } + index=0; + len = 0; + for (j=0;jcheckstr[j]); + free(javachars->checkstr); + free((void *)(javachars->str)); + free(javachars->size); + free(javachars); + clazz=env->FindClass(clsName); CE + if (!equal) { + methodID=env->GetStaticMethodID(clazz, name, sig); CE + env->CallStaticVoidMethod(clazz, methodID, JNI_FALSE); CE + } + //methodID=env->GetStaticMethodID(clazz, halt, haltSig); CE + //env->CallStaticVoidMethod(clazz, methodID); CE + return(tmpstr); + } + env->MonitorExit(jobj); CE + return(env->NewString(javachars->str[index-1],javachars->size[index-1])); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress002.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress002.c deleted file mode 100644 index b907804ded8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress002.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jnihelper.h" - -jobject NewObjectWrapper(JNIEnv *env, jclass clazz, jmethodID methodID, ...) { - va_list ap; - jobject tmp; - - va_start(ap,methodID); - tmp=(*env)->NewObjectV(env, clazz, methodID, ap); - va_end(ap); - return(tmp); -} - -JNIEXPORT jobjectArray JNICALL -Java_nsk_stress_jni_JNIter002_jniobjects (JNIEnv *env, jobject jobj, jstring jstr, jint intgr, - jlong lng, jcharArray jChArr, jfloat flt, jdouble dbl) { - - static int classCount = 0; - jobjectArray obj; - jobject element; - jclass clazz, clazzUp; - jmethodID methodID; - const char *classname="nsk/stress/jni/objectsJNI"; - const char *name=""; - const char *sig="(Ljava/lang/String;IJ[CFD)V"; - const char *upperClassName="nsk/stress/jni/jnistress002"; - const char *fieldName="jniStringAllocSize"; - const char *fieldSig="I"; - const char *setpass="halt"; - const char *setpassSig="()V"; - jvalue paramArr [6]; - - (*env)->MonitorEnter(env, jobj); CE - ++classCount; - (*env)->MonitorExit(env, jobj); CE - paramArr[0].l=jstr; - paramArr[1].i=intgr; - paramArr[2].j=lng; - paramArr[3].l=jChArr; - paramArr[4].f=flt; - paramArr[5].d=dbl; - - clazz=(*env)->FindClass(env,classname); CE - obj=(*env)->NewObjectArray(env,(jsize)3,clazz, - (*env)->AllocObject(env, clazz)); CE - if (obj==NULL) { - fprintf(stderr,"Can not construct the object Array for %s\n", classname); - return(NULL); - } - - methodID=(*env)->GetMethodID(env,clazz,name,sig); CE - if (methodID==NULL) { - fprintf(stderr,"Can not get the ID of for %s\n", classname); - return(NULL); - } - - element=(*env)->NewObject(env,clazz,methodID, - jstr, intgr, lng, jChArr, flt, dbl); CE - (*env)->SetObjectArrayElement(env,obj,0,element); CE - element=(*env)->NewObjectA(env,clazz,methodID,paramArr); CE - (*env)->SetObjectArrayElement(env,obj,1,element); CE - element= NewObjectWrapper(env, clazz, methodID, - jstr, intgr, lng, jChArr, flt, dbl); CE - (*env)->SetObjectArrayElement(env,obj,2,element); CE - - clazzUp=(*env)->FindClass(env, upperClassName); CE - if (classCount == (*env)->GetStaticIntField(env, clazzUp, - (*env)->GetStaticFieldID(env,clazzUp,fieldName,fieldSig))) { - classname="nsk/stress/jni/JNIter002"; - clazz=(*env)->FindClass(env, classname); CE - methodID=(*env)->GetStaticMethodID(env,clazz, setpass, setpassSig); CE - (*env)->CallStaticVoidMethod(env, clazz, methodID); CE - } - - CE - - return obj; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress002.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress002.cpp new file mode 100644 index 00000000000..160fd2f51b5 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress002.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jnihelper.h" + +#ifdef __cplusplus +extern "C" { +#endif + +jobject NewObjectWrapper(JNIEnv *env, jclass clazz, jmethodID methodID, ...) { + va_list ap; + jobject tmp; + + va_start(ap,methodID); + tmp=env->NewObjectV(clazz, methodID, ap); + va_end(ap); + return(tmp); +} + +JNIEXPORT jobjectArray JNICALL +Java_nsk_stress_jni_JNIter002_jniobjects (JNIEnv *env, jobject jobj, jstring jstr, jint intgr, + jlong lng, jcharArray jChArr, jfloat flt, jdouble dbl) { + + static int classCount = 0; + jobjectArray obj; + jobject element; + jclass clazz, clazzUp; + jmethodID methodID; + const char *classname="nsk/stress/jni/objectsJNI"; + const char *name=""; + const char *sig="(Ljava/lang/String;IJ[CFD)V"; + const char *upperClassName="nsk/stress/jni/jnistress002"; + const char *fieldName="jniStringAllocSize"; + const char *fieldSig="I"; + const char *setpass="halt"; + const char *setpassSig="()V"; + jvalue paramArr [6]; + + env->MonitorEnter(jobj); CE + ++classCount; + env->MonitorExit(jobj); CE + paramArr[0].l=jstr; + paramArr[1].i=intgr; + paramArr[2].j=lng; + paramArr[3].l=jChArr; + paramArr[4].f=flt; + paramArr[5].d=dbl; + + clazz=env->FindClass(classname); CE + obj=env->NewObjectArray((jsize)3,clazz, + env->AllocObject(clazz)); CE + if (obj==NULL) { + fprintf(stderr,"Can not construct the object Array for %s\n", classname); + return(NULL); + } + + methodID=env->GetMethodID(clazz,name,sig); CE + if (methodID==NULL) { + fprintf(stderr,"Can not get the ID of for %s\n", classname); + return(NULL); + } + + element=env->NewObject(clazz,methodID, + jstr, intgr, lng, jChArr, flt, dbl); CE + env->SetObjectArrayElement(obj,0,element); CE + element=env->NewObjectA(clazz,methodID,paramArr); CE + env->SetObjectArrayElement(obj,1,element); CE + element= NewObjectWrapper(env, clazz, methodID, + jstr, intgr, lng, jChArr, flt, dbl); CE + env->SetObjectArrayElement(obj,2,element); CE + + clazzUp=env->FindClass(upperClassName); CE + if (classCount == env->GetStaticIntField(clazzUp, + env->GetStaticFieldID(clazzUp,fieldName,fieldSig))) { + classname="nsk/stress/jni/JNIter002"; + clazz=env->FindClass(classname); CE + methodID=env->GetStaticMethodID(clazz, setpass, setpassSig); CE + env->CallStaticVoidMethod(clazz, methodID); CE + } + + CE + + return obj; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress003.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress003.c deleted file mode 100644 index 4a1a8335867..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress003.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jnihelper.h" - -#define BOOL 0 -#define BYTE 1 -#define CHAR 2 -#define SHORT 3 -#define INT 4 -#define LONG 5 -#define FLOAT 6 -#define DOUBLE 7 - -JNIEXPORT jobjectArray JNICALL -Java_nsk_stress_jni_JNIter003_jniInitArrays (JNIEnv *env, jobject jobj, jint size) { - - jobject *arrayArray; - jboolean *boolBuf; - jbyte *byteBuf; - jchar *charBuf; - jshort *shortBuf; - jint *intBuf; - jlong *longBuf; - jfloat *floatBuf; - jdouble *doubleBuf; - jobjectArray objectsArray; - - int i; - int SIZE=size; - const char *classname="java/lang/Object"; - jclass clazz = (*env)->FindClass(env,classname); CE - objectsArray = (*env)->NewObjectArray(env,8,clazz,(*env)->AllocObject(env,clazz)); - - arrayArray=(jobject *)malloc(8*sizeof(jobject)); CE - arrayArray[BOOL]=(*env)->NewBooleanArray(env,SIZE); CE - arrayArray[BYTE]=(*env)->NewByteArray(env, SIZE); CE - arrayArray[CHAR]=(*env)->NewCharArray(env, SIZE); CE - arrayArray[SHORT]=(*env)->NewShortArray(env, SIZE); CE - arrayArray[INT]=(*env)->NewIntArray(env, SIZE); CE - arrayArray[LONG]=(*env)->NewLongArray(env, SIZE); CE - arrayArray[FLOAT]=(*env)->NewFloatArray(env, SIZE); CE - arrayArray[DOUBLE]=(*env)->NewDoubleArray(env, SIZE); CE - - for(i=0;i<8;i++) - {(*env)->SetObjectArrayElement(env,objectsArray,i,arrayArray[i]); CE } - - boolBuf=(jboolean *)malloc(SIZE*sizeof(jboolean)); - byteBuf=(jbyte *)malloc(SIZE*sizeof(jbyte)); - charBuf=(jchar *)malloc(SIZE*sizeof(jchar)); - shortBuf=(jshort *)malloc(SIZE*sizeof(jshort)); - intBuf=(jint *)malloc(SIZE*sizeof(jint)); - longBuf=(jlong *)malloc(SIZE*sizeof(jlong)); - floatBuf=(jfloat *)malloc(SIZE*sizeof(jfloat)); - doubleBuf=(jdouble *)malloc(SIZE*sizeof(jdouble)); - - for (i=0;iSetBooleanArrayRegion(env,arrayArray[BOOL],0,i,boolBuf); CE - (*env)->SetByteArrayRegion(env,arrayArray[BYTE],0,i,byteBuf); CE - (*env)->SetCharArrayRegion(env,arrayArray[CHAR],0,i,charBuf); CE - (*env)->SetShortArrayRegion(env,arrayArray[SHORT],0,i,shortBuf); CE - (*env)->SetIntArrayRegion(env,arrayArray[INT],0,i,intBuf); CE - (*env)->SetLongArrayRegion(env,arrayArray[LONG],0,i,longBuf); CE - (*env)->SetFloatArrayRegion(env,arrayArray[FLOAT],0,i,floatBuf); CE - (*env)->SetDoubleArrayRegion(env,arrayArray[DOUBLE],0,i,doubleBuf); CE - - free(doubleBuf); - free(floatBuf); - free(longBuf); - free(intBuf); - free(shortBuf); - free(byteBuf); - free(charBuf); - free(boolBuf); - free(arrayArray); - - return objectsArray; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_stress_jni_JNIter003_jniBodyChangeArray (JNIEnv *env, jobject jobj, - jobjectArray orig, jobjectArray clone, jint limit) { - -#define SWAP(param1, param2) tmparr=param2; param2=param1; param1=tmparr; -#define SIZE(type) (*env)->GetArrayLength(env,arrayClone[type]) - - static volatile long count=0; - jobject *arrayOrig, *arrayClone; - jboolean *boolOrig, *boolClone; - jbyte *byteOrig, *byteClone; - jchar *charOrig, *charClone; - jshort *shortOrig, *shortClone; - jint *intOrig, *intClone; - jlong *longOrig, *longClone; - jfloat *floatOrig, *floatClone; - jdouble *doubleOrig, *doubleClone; - int i; - - if ((orig==NULL) || (clone==NULL)) { - fprintf(stderr,"JNI received a NULL array from Java\n"); - return JNI_FALSE; - } - if (count == limit) { - jclass clazz; - const char *classname = "nsk/stress/jni/JNIter003"; - const char *setdone = "halt"; - const char *setdonesig = "()V"; - jmethodID jmethod; - - fprintf(stderr, "Count and limit are: %ld\t%d cons.\n", count, limit); - clazz=(*env)->FindClass(env, classname); CE - jmethod=(*env)->GetMethodID(env, clazz, setdone, setdonesig); CE - (*env)->CallVoidMethod(env, jobj, jmethod); CE - - return JNI_TRUE; - } - (*env)->MonitorEnter(env, jobj); CE - ++count; - (*env)->MonitorExit(env, jobj); CE - arrayOrig=(jobject *)malloc(8*sizeof(jobject)); - arrayClone=(jobject *)malloc(8*sizeof(jobject)); - for(i=0;i<8;i++) { - arrayOrig[i]=(*env)->GetObjectArrayElement(env,orig,i); CE - arrayClone[i]=(*env)->GetObjectArrayElement(env,clone,i); CE - } - - /* Take the elements from Java arrays into native buffers */ - /* Use GetArrayElements */ - boolOrig = (*env)->GetBooleanArrayElements(env,arrayOrig[BOOL],0); CE - byteOrig = (*env)->GetByteArrayElements(env,arrayOrig[BYTE],0); CE - charOrig = (*env)->GetCharArrayElements(env,arrayOrig[CHAR],0); CE - shortOrig = (*env)->GetShortArrayElements(env,arrayOrig[SHORT],0); CE - intOrig = (*env)->GetIntArrayElements(env,arrayOrig[INT],0); CE - longOrig = (*env)->GetLongArrayElements(env,arrayOrig[LONG],0); CE - floatOrig = (*env)->GetFloatArrayElements(env,arrayOrig[FLOAT],0); CE - doubleOrig = (*env)->GetDoubleArrayElements(env,arrayOrig[DOUBLE],0); CE - - /* Alloc some memory for cloned arrays buffers */ - boolClone=(jboolean *)malloc(SIZE(BOOL)*sizeof(jboolean)); - byteClone=(jbyte *)malloc(SIZE(BYTE)*sizeof(jbyte)); - charClone=(jchar *)malloc(SIZE(CHAR)*sizeof(jchar)); - shortClone=(jshort *)malloc(SIZE(SHORT)*sizeof(jshort)); - intClone=(jint *)malloc(SIZE(INT)*sizeof(jint)); - longClone=(jlong *)malloc(SIZE(LONG)*sizeof(jlong)); - floatClone=(jfloat *)malloc(SIZE(FLOAT)*sizeof(jfloat)); - doubleClone=(jdouble *)malloc(SIZE(DOUBLE)*sizeof(jdouble)); - - /* Take the elements from cloned Java arrays into native buffers */ - /* Use GetArrayRegion */ - (*env)->GetBooleanArrayRegion(env,arrayClone[BOOL],0,SIZE(BOOL),boolClone); CE - (*env)->GetByteArrayRegion(env,arrayClone[BYTE],0,SIZE(BYTE),byteClone); CE - (*env)->GetCharArrayRegion(env,arrayClone[CHAR],0,SIZE(CHAR),charClone); CE - (*env)->GetShortArrayRegion(env,arrayClone[SHORT],0,SIZE(SHORT),shortClone); CE - (*env)->GetIntArrayRegion(env,arrayClone[INT],0,SIZE(INT),intClone); CE - (*env)->GetLongArrayRegion(env,arrayClone[LONG],0,SIZE(LONG),longClone); CE - (*env)->GetFloatArrayRegion(env,arrayClone[FLOAT],0,SIZE(FLOAT),floatClone); CE - (*env)->GetDoubleArrayRegion(env,arrayClone[DOUBLE],0,SIZE(DOUBLE),doubleClone); CE - - /* In this code section I should make some changes for elements into both */ - /* (original and cloned) arrays and than copied new values back to Java */ - -/* -Can't change the pointer into the Java structure. It's illegal JNI. - SWAP(boolOrig,boolClone) - SWAP(byteOrig,byteClone) - SWAP(charOrig,charClone) - SWAP(shortOrig,shortClone) - SWAP(intOrig,intClone) - SWAP(longOrig,longClone) - SWAP(floatOrig,floatClone) - SWAP(doubleOrig,doubleClone) -*/ - - /* Coping new values of elements back to Java and releasing native buffers */ - /* Use SetArrayRegion */ -/* -Use Orig pointers to get the original effect of the test. - (*env)->SetBooleanArrayRegion(env,arrayClone[BOOL],0,SIZE(BOOL),boolClone); - (*env)->SetByteArrayRegion(env,arrayClone[BYTE],0,SIZE(BYTE),byteClone); - (*env)->SetCharArrayRegion(env,arrayClone[CHAR],0,SIZE(CHAR),charClone); - (*env)->SetShortArrayRegion(env,arrayClone[SHORT],0,SIZE(SHORT),shortClone); - (*env)->SetIntArrayRegion(env,arrayClone[INT],0,SIZE(INT),intClone); - (*env)->SetLongArrayRegion(env,arrayClone[LONG],0,SIZE(LONG),longClone); - (*env)->SetFloatArrayRegion(env,arrayClone[FLOAT],0,SIZE(FLOAT),floatClone); - (*env)->SetDoubleArrayRegion(env,arrayClone[DOUBLE],0,SIZE(DOUBLE),doubleClone); -*/ - (*env)->SetBooleanArrayRegion(env,arrayClone[BOOL],0,SIZE(BOOL),boolOrig); CE - (*env)->SetByteArrayRegion(env,arrayClone[BYTE],0,SIZE(BYTE),byteOrig); CE - (*env)->SetCharArrayRegion(env,arrayClone[CHAR],0,SIZE(CHAR),charOrig); CE - (*env)->SetShortArrayRegion(env,arrayClone[SHORT],0,SIZE(SHORT),shortOrig); CE - (*env)->SetIntArrayRegion(env,arrayClone[INT],0,SIZE(INT),intOrig); CE - (*env)->SetLongArrayRegion(env,arrayClone[LONG],0,SIZE(LONG),longOrig); CE - (*env)->SetFloatArrayRegion(env,arrayClone[FLOAT],0,SIZE(FLOAT),floatOrig); CE - (*env)->SetDoubleArrayRegion(env,arrayClone[DOUBLE],0,SIZE(DOUBLE),doubleOrig); CE - - /* Use ReleaseArrayElements */ - (*env)->ReleaseDoubleArrayElements(env,arrayOrig[DOUBLE],doubleOrig,0); CE - (*env)->ReleaseFloatArrayElements(env,arrayOrig[FLOAT],floatOrig,0); CE - (*env)->ReleaseLongArrayElements(env,arrayOrig[LONG],longOrig,0); CE - (*env)->ReleaseIntArrayElements(env,arrayOrig[INT],intOrig,0); CE - (*env)->ReleaseShortArrayElements(env,arrayOrig[SHORT],shortOrig,0); CE - (*env)->ReleaseCharArrayElements(env,arrayOrig[CHAR],charOrig,0); CE - (*env)->ReleaseByteArrayElements(env,arrayOrig[BYTE],byteOrig,0); CE - (*env)->ReleaseBooleanArrayElements(env,arrayOrig[BOOL],boolOrig,0); CE - free(arrayOrig); - - free(doubleClone); - free(floatClone); - free(longClone); - free(intClone); - free(shortClone); - free(byteClone); - free(charClone); - free(boolClone); - free(arrayClone); - - return JNI_TRUE; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress003.cpp new file mode 100644 index 00000000000..cb5d18d2369 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress003.cpp @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jnihelper.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define BOOL 0 +#define BYTE 1 +#define CHAR 2 +#define SHORT 3 +#define INT 4 +#define LONG 5 +#define FLOAT 6 +#define DOUBLE 7 + +JNIEXPORT jobjectArray JNICALL +Java_nsk_stress_jni_JNIter003_jniInitArrays (JNIEnv *env, jobject jobj, jint size) { + + jarray *arrayArray; + jboolean *boolBuf; + jbyte *byteBuf; + jchar *charBuf; + jshort *shortBuf; + jint *intBuf; + jlong *longBuf; + jfloat *floatBuf; + jdouble *doubleBuf; + jobjectArray objectsArray; + + int i; + int SIZE=size; + const char *classname="java/lang/Object"; + jclass clazz = env->FindClass(classname); CE + objectsArray = env->NewObjectArray(8,clazz, env->AllocObject(clazz)); + + arrayArray=(jarray *)malloc(8*sizeof(jarray)); CE + arrayArray[BOOL]=env->NewBooleanArray(SIZE); CE + arrayArray[BYTE]=env->NewByteArray(SIZE); CE + arrayArray[CHAR]=env->NewCharArray(SIZE); CE + arrayArray[SHORT]=env->NewShortArray(SIZE); CE + arrayArray[INT]=env->NewIntArray(SIZE); CE + arrayArray[LONG]=env->NewLongArray(SIZE); CE + arrayArray[FLOAT]=env->NewFloatArray(SIZE); CE + arrayArray[DOUBLE]=env->NewDoubleArray(SIZE); CE + + for(i=0;i<8;i++) + {env->SetObjectArrayElement(objectsArray,i,arrayArray[i]); CE } + + boolBuf=(jboolean *)malloc(SIZE*sizeof(jboolean)); + byteBuf=(jbyte *)malloc(SIZE*sizeof(jbyte)); + charBuf=(jchar *)malloc(SIZE*sizeof(jchar)); + shortBuf=(jshort *)malloc(SIZE*sizeof(jshort)); + intBuf=(jint *)malloc(SIZE*sizeof(jint)); + longBuf=(jlong *)malloc(SIZE*sizeof(jlong)); + floatBuf=(jfloat *)malloc(SIZE*sizeof(jfloat)); + doubleBuf=(jdouble *)malloc(SIZE*sizeof(jdouble)); + + for (i=0;iSetBooleanArrayRegion((jbooleanArray) arrayArray[BOOL],0,i,boolBuf); CE + env->SetByteArrayRegion((jbyteArray) arrayArray[BYTE],0,i,byteBuf); CE + env->SetCharArrayRegion((jcharArray) arrayArray[CHAR],0,i,charBuf); CE + env->SetShortArrayRegion((jshortArray) arrayArray[SHORT],0,i,shortBuf); CE + env->SetIntArrayRegion((jintArray) arrayArray[INT],0,i,intBuf); CE + env->SetLongArrayRegion((jlongArray) arrayArray[LONG],0,i,longBuf); CE + env->SetFloatArrayRegion((jfloatArray) arrayArray[FLOAT],0,i,floatBuf); CE + env->SetDoubleArrayRegion((jdoubleArray) arrayArray[DOUBLE],0,i,doubleBuf); CE + + free(doubleBuf); + free(floatBuf); + free(longBuf); + free(intBuf); + free(shortBuf); + free(byteBuf); + free(charBuf); + free(boolBuf); + free(arrayArray); + + return objectsArray; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_stress_jni_JNIter003_jniBodyChangeArray (JNIEnv *env, jobject jobj, + jobjectArray orig, jobjectArray clone, jint limit) { + +#define SWAP(param1, param2) tmparr=param2; param2=param1; param1=tmparr; +#define SIZE(type) env->GetArrayLength(arrayClone[type]) + + static volatile long count=0; + jarray *arrayOrig, *arrayClone; + jboolean *boolOrig, *boolClone; + jbyte *byteOrig, *byteClone; + jchar *charOrig, *charClone; + jshort *shortOrig, *shortClone; + jint *intOrig, *intClone; + jlong *longOrig, *longClone; + jfloat *floatOrig, *floatClone; + jdouble *doubleOrig, *doubleClone; + int i; + + if ((orig==NULL) || (clone==NULL)) { + fprintf(stderr,"JNI received a NULL array from Java\n"); + return JNI_FALSE; + } + if (count == limit) { + jclass clazz; + const char *classname = "nsk/stress/jni/JNIter003"; + const char *setdone = "halt"; + const char *setdonesig = "()V"; + jmethodID jmethod; + + fprintf(stderr, "Count and limit are: %ld\t%d cons.\n", count, limit); + clazz=env->FindClass(classname); CE + jmethod=env->GetMethodID(clazz, setdone, setdonesig); CE + env->CallVoidMethod(jobj, jmethod); CE + + return JNI_TRUE; + } + env->MonitorEnter(jobj); CE + ++count; + env->MonitorExit(jobj); CE + arrayOrig=(jarray *)malloc(8*sizeof(jarray)); + arrayClone=(jarray *)malloc(8*sizeof(jarray)); + for(i=0;i<8;i++) { + arrayOrig[i]=(jarray) env->GetObjectArrayElement(orig,i); CE + arrayClone[i]=(jarray) env->GetObjectArrayElement(clone,i); CE + } + + /* Take the elements from Java arrays into native buffers */ + /* Use GetArrayElements */ + boolOrig = env->GetBooleanArrayElements((jbooleanArray) arrayOrig[BOOL],0); CE + byteOrig = env->GetByteArrayElements((jbyteArray) arrayOrig[BYTE],0); CE + charOrig = env->GetCharArrayElements((jcharArray) arrayOrig[CHAR],0); CE + shortOrig = env->GetShortArrayElements((jshortArray) arrayOrig[SHORT],0); CE + intOrig = env->GetIntArrayElements((jintArray) arrayOrig[INT],0); CE + longOrig = env->GetLongArrayElements((jlongArray) arrayOrig[LONG],0); CE + floatOrig = env->GetFloatArrayElements((jfloatArray) arrayOrig[FLOAT],0); CE + doubleOrig = env->GetDoubleArrayElements((jdoubleArray) arrayOrig[DOUBLE],0); CE + + /* Alloc some memory for cloned arrays buffers */ + boolClone=(jboolean *)malloc(SIZE(BOOL)*sizeof(jboolean)); + byteClone=(jbyte *)malloc(SIZE(BYTE)*sizeof(jbyte)); + charClone=(jchar *)malloc(SIZE(CHAR)*sizeof(jchar)); + shortClone=(jshort *)malloc(SIZE(SHORT)*sizeof(jshort)); + intClone=(jint *)malloc(SIZE(INT)*sizeof(jint)); + longClone=(jlong *)malloc(SIZE(LONG)*sizeof(jlong)); + floatClone=(jfloat *)malloc(SIZE(FLOAT)*sizeof(jfloat)); + doubleClone=(jdouble *)malloc(SIZE(DOUBLE)*sizeof(jdouble)); + + /* Take the elements from cloned Java arrays into native buffers */ + /* Use GetArrayRegion */ + env->GetBooleanArrayRegion((jbooleanArray) arrayClone[BOOL],0,SIZE(BOOL),boolClone); CE + env->GetByteArrayRegion((jbyteArray) arrayClone[BYTE],0,SIZE(BYTE),byteClone); CE + env->GetCharArrayRegion((jcharArray) arrayClone[CHAR],0,SIZE(CHAR),charClone); CE + env->GetShortArrayRegion((jshortArray) arrayClone[SHORT],0,SIZE(SHORT),shortClone); CE + env->GetIntArrayRegion((jintArray) arrayClone[INT],0,SIZE(INT),intClone); CE + env->GetLongArrayRegion((jlongArray) arrayClone[LONG],0,SIZE(LONG),longClone); CE + env->GetFloatArrayRegion((jfloatArray) arrayClone[FLOAT],0,SIZE(FLOAT),floatClone); CE + env->GetDoubleArrayRegion((jdoubleArray) arrayClone[DOUBLE],0,SIZE(DOUBLE),doubleClone); CE + + /* In this code section I should make some changes for elements into both */ + /* (original and cloned) arrays and than copied new values back to Java */ + +/* +Can't change the pointer into the Java structure. It's illegal JNI. + SWAP(boolOrig,boolClone) + SWAP(byteOrig,byteClone) + SWAP(charOrig,charClone) + SWAP(shortOrig,shortClone) + SWAP(intOrig,intClone) + SWAP(longOrig,longClone) + SWAP(floatOrig,floatClone) + SWAP(doubleOrig,doubleClone) +*/ + + /* Coping new values of elements back to Java and releasing native buffers */ + /* Use SetArrayRegion */ +/* +Use Orig pointers to get the original effect of the test. + env->SetBooleanArrayRegion(arrayClone[BOOL],0,SIZE(BOOL),boolClone); + env->SetByteArrayRegion(arrayClone[BYTE],0,SIZE(BYTE),byteClone); + env->SetCharArrayRegion(arrayClone[CHAR],0,SIZE(CHAR),charClone); + env->SetShortArrayRegion(arrayClone[SHORT],0,SIZE(SHORT),shortClone); + env->SetIntArrayRegion(arrayClone[INT],0,SIZE(INT),intClone); + env->SetLongArrayRegion(arrayClone[LONG],0,SIZE(LONG),longClone); + env->SetFloatArrayRegion(arrayClone[FLOAT],0,SIZE(FLOAT),floatClone); + env->SetDoubleArrayRegion(arrayClone[DOUBLE],0,SIZE(DOUBLE),doubleClone); +*/ + env->SetBooleanArrayRegion((jbooleanArray) arrayClone[BOOL],0,SIZE(BOOL),boolOrig); CE + env->SetByteArrayRegion((jbyteArray) arrayClone[BYTE],0,SIZE(BYTE),byteOrig); CE + env->SetCharArrayRegion((jcharArray) arrayClone[CHAR],0,SIZE(CHAR),charOrig); CE + env->SetShortArrayRegion((jshortArray) arrayClone[SHORT],0,SIZE(SHORT),shortOrig); CE + env->SetIntArrayRegion((jintArray) arrayClone[INT],0,SIZE(INT),intOrig); CE + env->SetLongArrayRegion((jlongArray) arrayClone[LONG],0,SIZE(LONG),longOrig); CE + env->SetFloatArrayRegion((jfloatArray) arrayClone[FLOAT],0,SIZE(FLOAT),floatOrig); CE + env->SetDoubleArrayRegion((jdoubleArray) arrayClone[DOUBLE],0,SIZE(DOUBLE),doubleOrig); CE + + /* Use ReleaseArrayElements */ + env->ReleaseDoubleArrayElements((jdoubleArray) arrayOrig[DOUBLE],doubleOrig,0); CE + env->ReleaseFloatArrayElements((jfloatArray) arrayOrig[FLOAT],floatOrig,0); CE + env->ReleaseLongArrayElements((jlongArray) arrayOrig[LONG],longOrig,0); CE + env->ReleaseIntArrayElements((jintArray) arrayOrig[INT],intOrig,0); CE + env->ReleaseShortArrayElements((jshortArray) arrayOrig[SHORT],shortOrig,0); CE + env->ReleaseCharArrayElements((jcharArray) arrayOrig[CHAR],charOrig,0); CE + env->ReleaseByteArrayElements((jbyteArray) arrayOrig[BYTE],byteOrig,0); CE + env->ReleaseBooleanArrayElements((jbooleanArray) arrayOrig[BOOL],boolOrig,0); CE + free(arrayOrig); + + free(doubleClone); + free(floatClone); + free(longClone); + free(intClone); + free(shortClone); + free(byteClone); + free(charClone); + free(boolClone); + free(arrayClone); + + return JNI_TRUE; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress004.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress004.c deleted file mode 100644 index e1f5f7dcab1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress004.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include -#include "jnihelper.h" - -#define DIGESTLENGTH 16 - -JNIEXPORT jcharArray JNICALL -Java_nsk_stress_jni_JNIter004_CheckSum (JNIEnv *env, jobject jobj, jstring jstr) { - - unsigned char digest[DIGESTLENGTH]; - jchar *tmp; - static jint upper = 0; - jcharArray jArr; - int i; - const jchar *critstr; - char *str; - jint len=(*env)->GetStringUTFLength(env,jstr); CE - - for(i=0;iGetStringUTFChars(env, jstr, 0); */ - - (*env)->MonitorEnter(env, jobj); CE - if (upper==0) tmp=(jchar *)malloc(DIGESTLENGTH*sizeof(char)); - if ((*env)->ExceptionOccurred(env)) { - (*env)->ExceptionDescribe(env); - (*env)->ExceptionClear(env); - } - critstr=(*env)->GetStringCritical(env, jstr, 0); CE - for(i=0;iReleaseStringCritical(env,jstr,critstr); CE - for(i=0;iExceptionOccurred(env)) { - (*env)->ExceptionDescribe(env); - (*env)->ExceptionClear(env); - } - memcpy(tmp,digest,DIGESTLENGTH); - jArr=(*env)->NewCharArray(env,DIGESTLENGTH/sizeof(jchar)); CE - len=(*env)->GetArrayLength(env,jArr); CE - (*env)->SetCharArrayRegion(env,jArr,0,len,tmp); CE -/* ++upper; */ - (*env)->MonitorExit(env, jobj); CE - return jArr; -} - -JNIEXPORT jboolean JNICALL -Java_nsk_stress_jni_JNIter004_CheckCompare (JNIEnv *env, jobject jobj, jstring jstr, - jcharArray cArr, jint limit) { - - unsigned char digest[DIGESTLENGTH]; - jchar *tmp; -/* jcharArray jArr; */ - const jchar *critstr; - jint strlen; - char *str; - jboolean ret=JNI_TRUE; - int i; - static jint upper = 0; - jint len; - jchar *ch; - - for(i=0;iGetStringUTFLength(env,jstr); CE - str = (char *)malloc(strlen*sizeof(char)); - - len =(*env)->GetArrayLength(env,cArr); CE - - (*env)->MonitorEnter(env, jobj); CE - if (upper>limit) { - (*env)->MonitorExit(env, jobj); CE - return JNI_FALSE; - } - tmp=(jchar *)malloc(DIGESTLENGTH*sizeof(char)); - if ((*env)->ExceptionOccurred(env)) { - (*env)->ExceptionDescribe(env); - (*env)->ExceptionClear(env); - } - critstr=(*env)->GetStringCritical(env, jstr, 0); CE - for(i=0;iReleaseStringCritical(env,jstr,critstr); CE - for(i=0;iExceptionOccurred(env)) { - (*env)->ExceptionDescribe(env); - (*env)->ExceptionClear(env); - } - memcpy(tmp,digest,DIGESTLENGTH); - -/* jArr=(*env)->NewCharArray(env,DIGESTLENGTH/sizeof(jchar)); */ -/* len=(*env)->GetArrayLength(env,jArr); */ -/* (*env)->SetCharArrayRegion(env,jArr,0,len,tmp); */ -/* ++upper; */ -/* (*env)->MonitorExit(env, jobj); */ - -/* Compare */ -/* (*env)->MonitorEnter(env, jobj); */ - - ch=(jchar *)(*env)->GetPrimitiveArrayCritical(env,cArr,0); CE - - printf("Comparing: "); - for(i=0;iReleasePrimitiveArrayCritical(env,cArr,ch,0); CE - ++upper; - if (!(upper % 500)) - fprintf(stderr,"There are %d elements now.\n", upper); - if (upper==limit) { - jclass clazz; - jmethodID methodID; - char *name="halt"; - char *sig="()V"; - - clazz=(*env)->GetObjectClass(env, jobj); CE - methodID=(*env)->GetStaticMethodID(env, clazz, name, sig); CE - (*env)->CallStaticVoidMethod(env, clazz, methodID); CE - free(tmp); - ret=JNI_TRUE; - } - (*env)->MonitorExit(env, jobj); CE - return ret; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress004.cpp new file mode 100644 index 00000000000..e2e5834cce8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress004.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include +#include "jnihelper.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define DIGESTLENGTH 16 + +JNIEXPORT jcharArray JNICALL +Java_nsk_stress_jni_JNIter004_CheckSum (JNIEnv *env, jobject jobj, jstring jstr) { + + unsigned char digest[DIGESTLENGTH]; + jchar *tmp; + static jint upper = 0; + jcharArray jArr; + int i; + const jchar *critstr; + char *str; + jint len=env->GetStringUTFLength(jstr); CE + + for(i=0;iGetStringUTFChars(jstr, 0); */ + + env->MonitorEnter(jobj); CE + if (upper==0) tmp=(jchar *)malloc(DIGESTLENGTH*sizeof(char)); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + } + critstr=env->GetStringCritical(jstr, 0); CE + for(i=0;iReleaseStringCritical(jstr,critstr); CE + for(i=0;iExceptionOccurred()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + } + memcpy(tmp,digest,DIGESTLENGTH); + jArr=env->NewCharArray(DIGESTLENGTH/sizeof(jchar)); CE + len=env->GetArrayLength(jArr); CE + env->SetCharArrayRegion(jArr,0,len,tmp); CE +/* ++upper; */ + env->MonitorExit(jobj); CE + return jArr; +} + +JNIEXPORT jboolean JNICALL +Java_nsk_stress_jni_JNIter004_CheckCompare (JNIEnv *env, jobject jobj, jstring jstr, + jcharArray cArr, jint limit) { + + unsigned char digest[DIGESTLENGTH]; + jchar *tmp; +/* jcharArray jArr; */ + const jchar *critstr; + jint strlen; + char *str; + jboolean ret=JNI_TRUE; + int i; + static jint upper = 0; + jint len; + jchar *ch; + + for(i=0;iGetStringUTFLength(jstr); CE + str = (char *)malloc(strlen*sizeof(char)); + + len =env->GetArrayLength(cArr); CE + + env->MonitorEnter(jobj); CE + if (upper>limit) { + env->MonitorExit(jobj); CE + return JNI_FALSE; + } + tmp=(jchar *)malloc(DIGESTLENGTH*sizeof(char)); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + } + critstr=env->GetStringCritical(jstr, 0); CE + for(i=0;iReleaseStringCritical(jstr,critstr); CE + for(i=0;iExceptionOccurred()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + } + memcpy(tmp,digest,DIGESTLENGTH); + +/* jArr=env->NewCharArray(DIGESTLENGTH/sizeof(jchar)); */ +/* len=env->GetArrayLength(jArr); */ +/* env->SetCharArrayRegion(jArr,0,len,tmp); */ +/* ++upper; */ +/* env->MonitorExit(jobj); */ + +/* Compare */ +/* env->MonitorEnter(jobj); */ + + ch=(jchar *)env->GetPrimitiveArrayCritical(cArr,0); CE + + printf("Comparing: "); + for(i=0;iReleasePrimitiveArrayCritical(cArr,ch,0); CE + ++upper; + if (!(upper % 500)) + fprintf(stderr,"There are %d elements now.\n", upper); + if (upper==limit) { + jclass clazz; + jmethodID methodID; + char *name = (char*) "halt"; + char *sig = (char*) "()V"; + + clazz=env->GetObjectClass(jobj); CE + methodID=env->GetStaticMethodID(clazz, name, sig); CE + env->CallStaticVoidMethod(clazz, methodID); CE + free(tmp); + ret=JNI_TRUE; + } + env->MonitorExit(jobj); CE + return ret; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress005.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress005.c deleted file mode 100644 index f1c6b94448f..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress005.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include - -#define CHECK_EXCEPTION { if ((*env)->ExceptionOccurred(env)) { fprintf(stderr, "Unexpected exception:\n"); (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); exit(97); } } - -JNIEXPORT void JNICALL -Java_nsk_stress_jni_JNIter005_except (JNIEnv *env, jobject jobj, jthrowable tobj) { - jclass clazz; - static int Exceptcalls=0; - const char *name; - const char *mess; - jmethodID jmethod; - const char *iter = "nsk/stress/jni/JNIter005"; -// const char *inc = "nsk/stress/jni/jnistress005/incCount"; - const char *incSig = "()V"; - const char *fldName = "counts"; - const char *fldSig = "I"; - -/* incClazz = (*env)->FindClass(env, iter); */ -/* CHECK_EXCEPTION */ -/* jmethod=(*env)->GetStaticMethodID(env, incClazz, inc, incSig); */ -/* CHECK_EXCEPTION */ -/* (*env)->CallStaticVoidMethod(env, incClazz, jmethod); */ -/* CHECK_EXCEPTION */ -/* jfld = (*env)->GetFieldID(env, incClazz, fldName, fldSig); */ -/* printf("JNI: Count is %d\n", (*env)->GetIntField(env, jobj, jfld)); */ -/* CHECK_EXCEPTION */ - - (*env)->MonitorEnter(env, jobj); - CHECK_EXCEPTION - if (!(*env)->Throw(env, tobj)) { - if((*env)->ExceptionOccurred(env)) - if (Exceptcalls%1000==0) - fprintf(stderr, "NATIVE: Throw has been catched in native\n"); - (*env)->ExceptionClear(env); - ++Exceptcalls; - } else fprintf(stderr, "Throw failed\n"); - - (*env)->MonitorExit(env, jobj); - CHECK_EXCEPTION - - switch (Exceptcalls%23) { - case 0: name="java/lang/ArithmeticException"; break; - case 1: name="java/lang/ArrayIndexOutOfBoundsException"; break; - case 2: name="java/lang/ArrayStoreException"; break; - case 3: name="java/lang/ClassCastException"; break; - case 4: name="java/lang/ClassNotFoundException"; break; - case 5: name="java/lang/CloneNotSupportedException"; break; - case 6: name="java/lang/IllegalAccessException"; break; - case 7: name="java/lang/IllegalArgumentException"; break; - case 8: name="java/lang/IllegalMonitorStateException"; break; - case 9: name="java/lang/IllegalStateException"; break; - case 10: name="java/lang/IllegalThreadStateException"; break; - case 11: name="java/lang/IndexOutOfBoundsException"; break; - case 12: name="java/lang/InstantiationException"; break; - case 13: name="java/lang/InterruptedException"; break; - case 14: name="java/lang/NegativeArraySizeException"; break; - case 15: name="java/lang/NoSuchFieldException"; break; - case 16: name="java/lang/NoSuchMethodException"; break; - case 17: name="java/lang/NullPointerException"; break; - case 18: name="java/lang/NumberFormatException"; break; - case 19: name="java/lang/RuntimeException"; break; - case 20: name="java/lang/SecurityException"; break; - case 21: name="java/lang/StringIndexOutOfBoundsException"; break; - case 22: name="java/lang/UnsupportedOperationException"; break; - default: name="java/lang/Exception"; - } - mess=name; - - CHECK_EXCEPTION - clazz = (*env)->FindClass(env, name); - CHECK_EXCEPTION - if ((*env)->ThrowNew(env, clazz, mess)) { - const char *pass = "setpass"; - const char *passSig = "(Z)V"; - jclass incClazz; - fprintf(stderr, "ThrowNew failed\n"); - CHECK_EXCEPTION; - incClazz = (*env)->FindClass(env, iter); - CHECK_EXCEPTION; - jmethod=(*env)->GetStaticMethodID(env, incClazz, pass, passSig); - CHECK_EXCEPTION - (*env)->CallStaticVoidMethod(env, incClazz, jmethod, JNI_FALSE); - CHECK_EXCEPTION - } -/* printf("JNI: count %d\n", Exceptcalls); */ -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress005.cpp new file mode 100644 index 00000000000..2d387688838 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress005.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define CHECK_EXCEPTION { if (env->ExceptionOccurred()) { fprintf(stderr, "Unexpected exception:\n"); env->ExceptionDescribe(); env->ExceptionClear(); exit(97); } } + +JNIEXPORT void JNICALL +Java_nsk_stress_jni_JNIter005_except (JNIEnv *env, jobject jobj, jthrowable tobj) { + jclass clazz; + static int Exceptcalls=0; + const char *name; + const char *mess; + jmethodID jmethod; + const char *iter = "nsk/stress/jni/JNIter005"; +// const char *inc = "nsk/stress/jni/jnistress005/incCount"; + const char *incSig = "()V"; + const char *fldName = "counts"; + const char *fldSig = "I"; + +/* incClazz = env->FindClass(iter); */ +/* CHECK_EXCEPTION */ +/* jmethod=env->GetStaticMethodID(incClazz, inc, incSig); */ +/* CHECK_EXCEPTION */ +/* env->CallStaticVoidMethod(incClazz, jmethod); */ +/* CHECK_EXCEPTION */ +/* jfld = env->GetFieldID(incClazz, fldName, fldSig); */ +/* printf("JNI: Count is %d\n", env->GetIntField(jobj, jfld)); */ +/* CHECK_EXCEPTION */ + + env->MonitorEnter(jobj); + CHECK_EXCEPTION + if (!env->Throw(tobj)) { + if(env->ExceptionOccurred()) + if (Exceptcalls%1000==0) + fprintf(stderr, "NATIVE: Throw has been catched in native\n"); + env->ExceptionClear(); + ++Exceptcalls; + } else fprintf(stderr, "Throw failed\n"); + + env->MonitorExit(jobj); + CHECK_EXCEPTION + + switch (Exceptcalls%23) { + case 0: name="java/lang/ArithmeticException"; break; + case 1: name="java/lang/ArrayIndexOutOfBoundsException"; break; + case 2: name="java/lang/ArrayStoreException"; break; + case 3: name="java/lang/ClassCastException"; break; + case 4: name="java/lang/ClassNotFoundException"; break; + case 5: name="java/lang/CloneNotSupportedException"; break; + case 6: name="java/lang/IllegalAccessException"; break; + case 7: name="java/lang/IllegalArgumentException"; break; + case 8: name="java/lang/IllegalMonitorStateException"; break; + case 9: name="java/lang/IllegalStateException"; break; + case 10: name="java/lang/IllegalThreadStateException"; break; + case 11: name="java/lang/IndexOutOfBoundsException"; break; + case 12: name="java/lang/InstantiationException"; break; + case 13: name="java/lang/InterruptedException"; break; + case 14: name="java/lang/NegativeArraySizeException"; break; + case 15: name="java/lang/NoSuchFieldException"; break; + case 16: name="java/lang/NoSuchMethodException"; break; + case 17: name="java/lang/NullPointerException"; break; + case 18: name="java/lang/NumberFormatException"; break; + case 19: name="java/lang/RuntimeException"; break; + case 20: name="java/lang/SecurityException"; break; + case 21: name="java/lang/StringIndexOutOfBoundsException"; break; + case 22: name="java/lang/UnsupportedOperationException"; break; + default: name="java/lang/Exception"; + } + mess=name; + + CHECK_EXCEPTION + clazz = env->FindClass(name); + CHECK_EXCEPTION + if (env->ThrowNew(clazz, mess)) { + const char *pass = "setpass"; + const char *passSig = "(Z)V"; + jclass incClazz; + fprintf(stderr, "ThrowNew failed\n"); + CHECK_EXCEPTION; + incClazz = env->FindClass(iter); + CHECK_EXCEPTION; + jmethod=env->GetStaticMethodID(incClazz, pass, passSig); + CHECK_EXCEPTION + env->CallStaticVoidMethod(incClazz, jmethod, JNI_FALSE); + CHECK_EXCEPTION + } +/* printf("JNI: count %d\n", Exceptcalls); */ +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress006.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress006.c deleted file mode 100644 index d4d1eecbef8..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress006.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jnihelper.h" - -JNIEXPORT jboolean JNICALL -Java_nsk_stress_jni_JNIter006_refs (JNIEnv *env, jobject jobj, jobject tobj, jint LIMIT) { - - static jobject *globRefsArray = 0; - static int upper = 0; - - jclass clazz; - jmethodID jmethod; - jboolean res=JNI_FALSE; - const char *classname = "nsk/stress/jni/JNIter006"; - const char *getmethodname="get_i"; - const char *setmethodname="set_i"; - const char *getsig="()I"; - const char *setsig="(I)V"; - const char *setdone = "halt"; - const char *setdonesig = "()V"; - int i = 0; - - if (upper >= LIMIT) return JNI_TRUE; - - if (upper==0) - globRefsArray=(jobject*)(malloc(LIMIT*sizeof(jobject))); - - globRefsArray[upper]=(*env)->NewGlobalRef(env, tobj); CE - if ((*env)->IsSameObject(env, tobj, globRefsArray[upper])) { - (*env)->DeleteLocalRef(env, tobj); CE - clazz=(*env)->GetObjectClass(env, globRefsArray[upper]); CE - } - else { - fprintf(stderr,"Objects are different\n"); - (*env)->MonitorExit(env, jobj); CE - return res; - } - jmethod=(*env)->GetStaticMethodID(env, clazz, setmethodname, setsig); CE - (*env)->CallStaticVoidMethod(env, clazz, jmethod, (jint)upper); CE - (*env)->MonitorEnter(env, jobj); CE - ++upper; - res=JNI_TRUE; - (*env)->MonitorExit(env, jobj); CE -/* If upper == LIMIT than flush ref's array and set */ -/* 'done' flag in JNIter006 class to JNI_TRUE */ - if (upper == LIMIT) { - fprintf(stderr,"\n\tTotal memory allocated: %zd bytes\n", - LIMIT*sizeof(jobject)); - clazz=(*env)->FindClass(env, classname); CE - jmethod=(*env)->GetMethodID(env, clazz, setdone, setdonesig); CE - (*env)->CallVoidMethod(env, jobj, jmethod); CE - - for (i=0;iDeleteGlobalRef(env, globRefsArray[i]); CE - } - free(globRefsArray); - } - return res; -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress006.cpp new file mode 100644 index 00000000000..3e2bfd6d0ee --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress006.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jnihelper.h" + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT jboolean JNICALL +Java_nsk_stress_jni_JNIter006_refs (JNIEnv *env, jobject jobj, jobject tobj, jint LIMIT) { + + static jobject *globRefsArray = 0; + static int upper = 0; + + jclass clazz; + jmethodID jmethod; + jboolean res=JNI_FALSE; + const char *classname = "nsk/stress/jni/JNIter006"; + const char *getmethodname="get_i"; + const char *setmethodname="set_i"; + const char *getsig="()I"; + const char *setsig="(I)V"; + const char *setdone = "halt"; + const char *setdonesig = "()V"; + int i = 0; + + if (upper >= LIMIT) return JNI_TRUE; + + if (upper==0) + globRefsArray=(jobject*)(malloc(LIMIT*sizeof(jobject))); + + globRefsArray[upper]=env->NewGlobalRef(tobj); CE + if (env->IsSameObject(tobj, globRefsArray[upper])) { + env->DeleteLocalRef(tobj); CE + clazz=env->GetObjectClass(globRefsArray[upper]); CE + } + else { + fprintf(stderr,"Objects are different\n"); + env->MonitorExit(jobj); CE + return res; + } + jmethod=env->GetStaticMethodID(clazz, setmethodname, setsig); CE + env->CallStaticVoidMethod(clazz, jmethod, (jint)upper); CE + env->MonitorEnter(jobj); CE + ++upper; + res=JNI_TRUE; + env->MonitorExit(jobj); CE +/* If upper == LIMIT than flush ref's array and set */ +/* 'done' flag in JNIter006 class to JNI_TRUE */ + if (upper == LIMIT) { + fprintf(stderr,"\n\tTotal memory allocated: %zd bytes\n", + LIMIT*sizeof(jobject)); + clazz=env->FindClass(classname); CE + jmethod=env->GetMethodID(clazz, setdone, setdonesig); CE + env->CallVoidMethod(jobj, jmethod); CE + + for (i=0;iDeleteGlobalRef(globRefsArray[i]); CE + } + free(globRefsArray); + } + return res; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress007.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress007.c deleted file mode 100644 index dad8f8d3aa4..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress007.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "jnihelper.h" - -JNIEXPORT void JNICALL -Java_nsk_stress_jni_JNIter007_incCount (JNIEnv *env, jobject jobj, jstring name) { - jclass clazz; - jfieldID fld; - jint value; - const char *str = (*env)->GetStringUTFChars(env, name, 0); CE - - if ((*env)->MonitorEnter(env, jobj)) - printf("Error in monitor lock\n"); - clazz = (*env)->GetObjectClass(env, jobj); CE - fld = (*env)->GetStaticFieldID(env, clazz, "nativeCount", "I"); CE - value = (*env)->GetStaticIntField(env, clazz, fld); CE - (*env)->SetStaticIntField(env, clazz, fld, (jint)(++value)); CE - (*env)->MonitorExit(env, jobj); CE - if (value%1000 == 0 ) - printf("in %s Count after %u\n", str, value); -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress007.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress007.cpp new file mode 100644 index 00000000000..561aa2180a7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress007.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include "jnihelper.h" + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT void JNICALL +Java_nsk_stress_jni_JNIter007_incCount (JNIEnv *env, jobject jobj, jstring name) { + jclass clazz; + jfieldID fld; + jint value; + const char *str = env->GetStringUTFChars(name, 0); CE + + if (env->MonitorEnter(jobj)) + printf("Error in monitor lock\n"); + clazz = env->GetObjectClass(jobj); CE + fld = env->GetStaticFieldID(clazz, "nativeCount", "I"); CE + value = env->GetStaticIntField(clazz, fld); CE + env->SetStaticIntField(clazz, fld, (jint)(++value)); CE + env->MonitorExit(jobj); CE + if (value%1000 == 0 ) + printf("in %s Count after %u\n", str, value); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace003.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace003.c deleted file mode 100644 index fbf6e224451..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace003.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_tools.c" -#include "nsk_tools.c" -#include "strace003.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace003.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace003.cpp new file mode 100644 index 00000000000..f6aeecec9da --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace003.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "strace003.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace004.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace004.c deleted file mode 100644 index f0b30df1f07..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace004.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_tools.c" -#include "nsk_tools.c" -#include "strace004.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace004.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace004.cpp new file mode 100644 index 00000000000..bf215126612 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace004.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "strace004.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace005.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace005.c deleted file mode 100644 index 1468d6ad7a7..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace005.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_tools.c" -#include "nsk_tools.c" -#include "strace005.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace005.cpp new file mode 100644 index 00000000000..2cd0e47d0b1 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace005.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "strace005.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace006.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace006.c deleted file mode 100644 index 264275d4fa2..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace006.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_tools.c" -#include "nsk_tools.c" -#include "strace006.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace006.cpp new file mode 100644 index 00000000000..1c964da0e7f --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace006.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "strace006.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace008.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace008.c deleted file mode 100644 index d164192a912..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace008.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_tools.c" -#include "nsk_tools.c" -#include "strace008.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace008.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace008.cpp new file mode 100644 index 00000000000..af70b5523d0 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace008.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "strace008.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace009.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace009.c deleted file mode 100644 index d933cf6475c..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace009.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_tools.c" -#include "nsk_tools.c" -#include "strace009.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace009.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace009.cpp new file mode 100644 index 00000000000..332ee3f4f71 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace009.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "strace009.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace011.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace011.c deleted file mode 100644 index 6bf1ed9106a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace011.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_tools.c" -#include "nsk_tools.c" -#include "strace011.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace011.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace011.cpp new file mode 100644 index 00000000000..dd9529a0a60 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace011.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "strace011.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace012.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace012.c deleted file mode 100644 index 0c8092d2363..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace012.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_tools.c" -#include "nsk_tools.c" -#include "strace012.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace012.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace012.cpp new file mode 100644 index 00000000000..a51907bd2fe --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace012.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "strace012.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace014.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace014.c deleted file mode 100644 index c436f7b5e90..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace014.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_tools.c" -#include "nsk_tools.c" -#include "strace014.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace014.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace014.cpp new file mode 100644 index 00000000000..bd8342282cc --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace014.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "strace014.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace015.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace015.c deleted file mode 100644 index 22b7ccb89b9..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace015.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_tools.c" -#include "nsk_tools.c" -#include "strace015.c" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace015.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace015.cpp new file mode 100644 index 00000000000..4a135eba29a --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/libstrace015.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "strace015.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/nsk_strace.h b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/nsk_strace.h index 0f6644e6f5e..4a024e061c6 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/nsk_strace.h +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/nsk_strace.h @@ -29,8 +29,8 @@ #define JNI_VERSION JNI_VERSION_1_1 -#define EXCEPTION_CLEAR (*env)->ExceptionClear(env) -#define EXCEPTION_OCCURRED (*env)->ExceptionOccurred(env) +#define EXCEPTION_CLEAR NSK_CPP_STUB1(ExceptionClear, env) +#define EXCEPTION_OCCURRED NSK_CPP_STUB1(ExceptionOccurred, env) // Check for pending exception of the specified type // If it's present, then clear it diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace003.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace003.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace003.c rename to test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace003.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace004.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace004.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace004.c rename to test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace004.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.c deleted file mode 100644 index c61fe133fe6..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "nsk_strace.h" -#include "nsk_tools.h" - -#ifdef __cplusplus -extern "C" { -#endif - -static const char *Stest_cn="nsk/stress/strace/strace005"; -static jclass stackOverflowErrorClass; - -JNIEXPORT jint JNICALL -JNI_OnLoad(JavaVM *vm, void *reserved) -{ - JNIEnv *env; - - if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION) != JNI_OK) { - printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__); - return 0; - } - - FIND_CLASS(stackOverflowErrorClass, "java/lang/StackOverflowError"); - if ((stackOverflowErrorClass = (*env)->NewGlobalRef(env, stackOverflowErrorClass)) == NULL) { - printf("Can't create global ref for stack overflow class\n"); - return 0; - } - - return JNI_VERSION; -} - -JNIEXPORT void JNICALL -JNI_OnUnload(JavaVM *vm, void *reserved) -{ - JNIEnv *env; - - if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION) != JNI_OK) { - if (stackOverflowErrorClass != NULL) { - (*env)->DeleteGlobalRef(env, stackOverflowErrorClass); - } - } else { - printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__); - } - -} - -JNIEXPORT void JNICALL -Java_nsk_stress_strace_strace005Thread_recursiveMethod2(JNIEnv *env, jobject obj) -{ - jfieldID field; - jmethodID method; - jint currDepth; - jclass testClass, threadClass; - jint maxDepth; - - FIND_CLASS(testClass, Stest_cn); - GET_OBJECT_CLASS(threadClass, obj); - - GET_STATIC_INT_FIELD(maxDepth, testClass, "DEPTH"); - - /* currDepth++ */ - GET_INT_FIELD(currDepth, obj, threadClass, "currentDepth"); - currDepth++; - SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth); - - - if (maxDepth - currDepth > 0) - { - GET_STATIC_METHOD_ID(method, threadClass, "yield", "()V"); - NSK_CPP_STUB3(CallStaticVoidMethod, env, threadClass, method); - EXCEPTION_CHECK(stackOverflowErrorClass, currDepth); - - GET_METHOD_ID(method, threadClass, "recursiveMethod1", "()V"); - NSK_CPP_STUB3(CallVoidMethod, env, obj, method); - EXCEPTION_CHECK(stackOverflowErrorClass, currDepth); - } - - currDepth--; - GET_OBJECT_CLASS(threadClass, obj); - SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth); -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.cpp new file mode 100644 index 00000000000..b0a3ca3f1b3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "nsk_strace.h" +#include "nsk_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static const char *Stest_cn="nsk/stress/strace/strace005"; +static jclass stackOverflowErrorClass; + +JNIEXPORT jint JNICALL +JNI_OnLoad(JavaVM *vm, void *reserved) +{ + JNIEnv *env; + + if (vm->GetEnv((void **) &env, JNI_VERSION) != JNI_OK) { + printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__); + return 0; + } + + FIND_CLASS(stackOverflowErrorClass, "java/lang/StackOverflowError"); + if ((stackOverflowErrorClass = (jclass) env->NewGlobalRef(stackOverflowErrorClass)) == NULL) { + printf("Can't create global ref for stack overflow class\n"); + return 0; + } + + return JNI_VERSION; +} + +JNIEXPORT void JNICALL +JNI_OnUnload(JavaVM *vm, void *reserved) +{ + JNIEnv *env; + + if (vm->GetEnv((void **) &env, JNI_VERSION) != JNI_OK) { + if (stackOverflowErrorClass != NULL) { + env->DeleteGlobalRef(stackOverflowErrorClass); + } + } else { + printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__); + } + +} + +JNIEXPORT void JNICALL +Java_nsk_stress_strace_strace005Thread_recursiveMethod2(JNIEnv *env, jobject obj) +{ + jfieldID field; + jmethodID method; + jint currDepth; + jclass testClass, threadClass; + jint maxDepth; + + FIND_CLASS(testClass, Stest_cn); + GET_OBJECT_CLASS(threadClass, obj); + + GET_STATIC_INT_FIELD(maxDepth, testClass, "DEPTH"); + + /* currDepth++ */ + GET_INT_FIELD(currDepth, obj, threadClass, "currentDepth"); + currDepth++; + SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth); + + + if (maxDepth - currDepth > 0) + { + GET_STATIC_METHOD_ID(method, threadClass, "yield", "()V"); + NSK_CPP_STUB3(CallStaticVoidMethod, env, threadClass, method); + EXCEPTION_CHECK(stackOverflowErrorClass, currDepth); + + GET_METHOD_ID(method, threadClass, "recursiveMethod1", "()V"); + NSK_CPP_STUB3(CallVoidMethod, env, obj, method); + EXCEPTION_CHECK(stackOverflowErrorClass, currDepth); + } + + currDepth--; + GET_OBJECT_CLASS(threadClass, obj); + SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace006.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace006.c deleted file mode 100644 index 50b89cbe033..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace006.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "nsk_strace.h" - -#ifdef __cplusplus -extern "C" { -#endif - -static const char *Stest_cn="nsk/stress/strace/strace006"; - -static jclass testClass, threadClass; -static jint DEPTH; -static jclass stackOverflowErrorClass; - -JNIEXPORT jint JNICALL -JNI_OnLoad(JavaVM *vm, void *reserved) -{ - JNIEnv *env; - - if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION) != JNI_OK) { - printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__); - return 0; - } - - FIND_CLASS(stackOverflowErrorClass, "java/lang/StackOverflowError"); - if ((stackOverflowErrorClass = (*env)->NewGlobalRef(env, stackOverflowErrorClass)) == NULL) { - printf("Can't create global ref for stack overflow class\n"); - return 0; - } - - return JNI_VERSION; -} - -JNIEXPORT void JNICALL -JNI_OnUnload(JavaVM *vm, void *reserved) -{ - JNIEnv *env; - - if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION) != JNI_OK) { - if (stackOverflowErrorClass != NULL) { - (*env)->DeleteGlobalRef(env, stackOverflowErrorClass); - } - } else { - printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__); - } - -} - -JNIEXPORT void JNICALL -Java_nsk_stress_strace_strace006Thread_recursiveMethod2(JNIEnv *env, jobject obj) -{ - jfieldID field; - jmethodID method; - jint currDepth; - jclass testClass, threadClass; - jint maxDepth; - - FIND_CLASS(testClass, Stest_cn); - GET_OBJECT_CLASS(threadClass, obj); - - GET_STATIC_INT_FIELD(maxDepth, testClass, "DEPTH"); - - /* currDepth++ */ - GET_INT_FIELD(currDepth, obj, threadClass, "currentDepth"); - currDepth++; - SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth); - - if (maxDepth - currDepth > 0) - { - GET_STATIC_METHOD_ID(method, threadClass, "yield", "()V"); - NSK_CPP_STUB3(CallStaticVoidMethod, env, threadClass, method); - EXCEPTION_CHECK(stackOverflowErrorClass, currDepth); - - GET_METHOD_ID(method, threadClass, "recursiveMethod1", "()V"); - NSK_CPP_STUB3(CallVoidMethod, env, obj, method); - EXCEPTION_CHECK(stackOverflowErrorClass, currDepth); - } - - currDepth--; - GET_OBJECT_CLASS(threadClass, obj); - SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth); -} - -#ifdef __cplusplus -} -#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace006.cpp b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace006.cpp new file mode 100644 index 00000000000..34249808b15 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace006.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include "nsk_strace.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static const char *Stest_cn="nsk/stress/strace/strace006"; + +static jclass testClass, threadClass; +static jint DEPTH; +static jclass stackOverflowErrorClass; + +JNIEXPORT jint JNICALL +JNI_OnLoad(JavaVM *vm, void *reserved) +{ + JNIEnv *env; + + if (vm->GetEnv((void **) &env, JNI_VERSION) != JNI_OK) { + printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__); + return 0; + } + + FIND_CLASS(stackOverflowErrorClass, "java/lang/StackOverflowError"); + if ((stackOverflowErrorClass = (jclass) env->NewGlobalRef(stackOverflowErrorClass)) == NULL) { + printf("Can't create global ref for stack overflow class\n"); + return 0; + } + + return JNI_VERSION; +} + +JNIEXPORT void JNICALL +JNI_OnUnload(JavaVM *vm, void *reserved) +{ + JNIEnv *env; + + if (vm->GetEnv((void **) &env, JNI_VERSION) != JNI_OK) { + if (stackOverflowErrorClass != NULL) { + env->DeleteGlobalRef(stackOverflowErrorClass); + } + } else { + printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__); + } + +} + +JNIEXPORT void JNICALL +Java_nsk_stress_strace_strace006Thread_recursiveMethod2(JNIEnv *env, jobject obj) +{ + jfieldID field; + jmethodID method; + jint currDepth; + jclass testClass, threadClass; + jint maxDepth; + + FIND_CLASS(testClass, Stest_cn); + GET_OBJECT_CLASS(threadClass, obj); + + GET_STATIC_INT_FIELD(maxDepth, testClass, "DEPTH"); + + /* currDepth++ */ + GET_INT_FIELD(currDepth, obj, threadClass, "currentDepth"); + currDepth++; + SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth); + + if (maxDepth - currDepth > 0) + { + GET_STATIC_METHOD_ID(method, threadClass, "yield", "()V"); + NSK_CPP_STUB3(CallStaticVoidMethod, env, threadClass, method); + EXCEPTION_CHECK(stackOverflowErrorClass, currDepth); + + GET_METHOD_ID(method, threadClass, "recursiveMethod1", "()V"); + NSK_CPP_STUB3(CallVoidMethod, env, obj, method); + EXCEPTION_CHECK(stackOverflowErrorClass, currDepth); + } + + currDepth--; + GET_OBJECT_CLASS(threadClass, obj); + SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace008.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace008.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace008.c rename to test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace008.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace009.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace009.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace009.c rename to test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace009.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace011.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace011.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace011.c rename to test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace011.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace012.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace012.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace012.c rename to test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace012.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace014.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace014.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace014.c rename to test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace014.cpp diff --git a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace015.c b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace015.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace015.c rename to test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace015.cpp diff --git a/test/hotspot/jtreg/vmTestbase/vm/jit/LongTransitions/libLTTest.c b/test/hotspot/jtreg/vmTestbase/vm/jit/LongTransitions/libLTTest.c deleted file mode 100644 index d37f1e4da03..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/jit/LongTransitions/libLTTest.c +++ /dev/null @@ -1,3460 +0,0 @@ -/* - * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc1(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jfloat p5,jfloat p6,jfloat p7 - ,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jfloat p14 - ,jfloat p15,jfloat p16,jfloat p17,jfloat p18,jfloat p19,jfloat p20,jfloat p21 - ,jfloat p22,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jfloat p27,jfloat p28 - ,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jfloat p35 - ,jfloat p36,jfloat p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jfloat p42 - ,jfloat p43,jfloat p44,jfloat p45,jfloat p46,jfloat p47,jfloat p48,jfloat p49 - ,jfloat p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54,jfloat p55,jfloat p56 - ,jfloat p57,jfloat p58,jfloat p59,jfloat p60,jfloat p61,jfloat p62,jfloat p63 - ,jfloat p64,jfloat p65,jfloat p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 - ,jfloat p71,jfloat p72,jfloat p73,jfloat p74,jfloat p75,jfloat p76,jfloat p77 - ,jfloat p78,jfloat p79,jfloat p80,jfloat p81,jfloat p82,jfloat p83,jfloat p84 - ,jfloat p85,jfloat p86,jfloat p87,jfloat p88,jfloat p89,jfloat p90,jfloat p91 - ,jfloat p92,jfloat p93,jfloat p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98 - ,jfloat p99,jfloat p100,jfloat p101,jfloat p102,jfloat p103,jfloat p104 - ,jfloat p105,jfloat p106,jfloat p107,jfloat p108,jfloat p109,jfloat p110 - ,jfloat p111,jfloat p112,jfloat p113,jfloat p114,jfloat p115,jfloat p116 - ,jfloat p117,jfloat p118,jfloat p119,jfloat p120,jfloat p121,jfloat p122 - ,jfloat p123,jfloat p124,jfloat p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc2(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jdouble p4,jdouble p5,jdouble p6 - ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jdouble p12,jdouble p13 - ,jdouble p14,jdouble p15,jdouble p16,jdouble p17,jdouble p18,jdouble p19 - ,jdouble p20,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25 - ,jdouble p26,jdouble p27,jdouble p28,jdouble p29,jdouble p30,jdouble p31 - ,jdouble p32,jdouble p33,jdouble p34,jdouble p35,jdouble p36,jdouble p37 - ,jdouble p38,jdouble p39,jdouble p40,jdouble p41,jdouble p42,jdouble p43 - ,jdouble p44,jdouble p45,jdouble p46,jdouble p47,jdouble p48,jdouble p49 - ,jdouble p50,jdouble p51,jdouble p52,jdouble p53,jdouble p54,jdouble p55 - ,jdouble p56,jdouble p57,jdouble p58,jdouble p59,jdouble p60,jdouble p61 - ,jdouble p62,jdouble p63,jdouble p64,jdouble p65,jdouble p66,jdouble p67 - ,jdouble p68,jdouble p69,jdouble p70,jdouble p71,jdouble p72,jdouble p73 - ,jdouble p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78,jdouble p79 - ,jdouble p80,jdouble p81,jdouble p82,jdouble p83,jdouble p84,jdouble p85 - ,jdouble p86,jdouble p87,jdouble p88,jdouble p89,jdouble p90,jdouble p91 - ,jdouble p92,jdouble p93,jdouble p94,jdouble p95,jdouble p96,jdouble p97 - ,jdouble p98,jdouble p99,jdouble p100,jdouble p101,jdouble p102,jdouble p103 - ,jdouble p104,jdouble p105,jdouble p106,jdouble p107,jdouble p108,jdouble p109 - ,jdouble p110,jdouble p111,jdouble p112,jdouble p113,jdouble p114,jdouble p115 - ,jdouble p116,jdouble p117,jdouble p118,jdouble p119,jdouble p120,jdouble p121 - ,jdouble p122,jdouble p123,jdouble p124,jdouble p125,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc3(JNIEnv *e, jclass c -,jfloat p0,jint p1,jint p2,jint p3,jint p4,jfloat p5,jint p6,jfloat p7,jint p8 - ,jfloat p9,jint p10,jint p11,jfloat p12,jfloat p13,jfloat p14,jfloat p15 - ,jint p16,jint p17,jint p18,jfloat p19,jint p20,jfloat p21,jfloat p22,jfloat p23 - ,jfloat p24,jint p25,jfloat p26,jint p27,jfloat p28,jfloat p29,jfloat p30 - ,jint p31,jint p32,jfloat p33,jfloat p34,jfloat p35,jint p36,jfloat p37 - ,jint p38,jfloat p39,jint p40,jfloat p41,jfloat p42,jfloat p43,jint p44 - ,jint p45,jfloat p46,jfloat p47,jfloat p48,jfloat p49,jint p50,jint p51 - ,jint p52,jfloat p53,jint p54,jfloat p55,jint p56,jfloat p57,jfloat p58 - ,jfloat p59,jfloat p60,jint p61,jint p62,jint p63,jfloat p64,jfloat p65 - ,jfloat p66,jfloat p67,jint p68,jint p69,jfloat p70,jfloat p71,jint p72 - ,jint p73,jfloat p74,jint p75,jint p76,jint p77,jfloat p78,jfloat p79,jfloat p80 - ,jint p81,jfloat p82,jint p83,jfloat p84,jfloat p85,jfloat p86,jfloat p87 - ,jint p88,jint p89,jint p90,jfloat p91,jint p92,jint p93,jfloat p94,jfloat p95 - ,jint p96,jfloat p97,jfloat p98,jfloat p99,jint p100,jfloat p101,jfloat p102 - ,jint p103,jfloat p104,jfloat p105,jint p106,jfloat p107,jfloat p108,jint p109 - ,jfloat p110,jfloat p111,jint p112,jfloat p113,jint p114,jfloat p115,jint p116 - ,jint p117,jfloat p118,jfloat p119,jint p120,jfloat p121,jint p122,jfloat p123 - ,jint p124,jint p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%d\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%d\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc4(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jfloat p2,jbyte p3,jfloat p4,jfloat p5,jfloat p6,jbyte p7 - ,jfloat p8,jbyte p9,jfloat p10,jbyte p11,jbyte p12,jbyte p13,jfloat p14 - ,jfloat p15,jfloat p16,jfloat p17,jbyte p18,jbyte p19,jbyte p20,jbyte p21 - ,jfloat p22,jfloat p23,jbyte p24,jbyte p25,jfloat p26,jfloat p27,jfloat p28 - ,jbyte p29,jfloat p30,jfloat p31,jfloat p32,jbyte p33,jbyte p34,jfloat p35 - ,jbyte p36,jfloat p37,jbyte p38,jfloat p39,jfloat p40,jbyte p41,jfloat p42 - ,jbyte p43,jbyte p44,jfloat p45,jbyte p46,jfloat p47,jfloat p48,jbyte p49 - ,jbyte p50,jfloat p51,jbyte p52,jfloat p53,jfloat p54,jbyte p55,jfloat p56 - ,jfloat p57,jbyte p58,jfloat p59,jbyte p60,jbyte p61,jbyte p62,jfloat p63 - ,jbyte p64,jbyte p65,jbyte p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 - ,jbyte p71,jfloat p72,jfloat p73,jfloat p74,jbyte p75,jbyte p76,jfloat p77 - ,jfloat p78,jfloat p79,jfloat p80,jbyte p81,jfloat p82,jbyte p83,jfloat p84 - ,jfloat p85,jbyte p86,jfloat p87,jbyte p88,jfloat p89,jfloat p90,jbyte p91 - ,jbyte p92,jbyte p93,jbyte p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98 - ,jfloat p99,jbyte p100,jbyte p101,jfloat p102,jfloat p103,jfloat p104,jbyte p105 - ,jfloat p106,jfloat p107,jbyte p108,jfloat p109,jfloat p110,jbyte p111,jbyte p112 - ,jfloat p113,jbyte p114,jbyte p115,jfloat p116,jbyte p117,jbyte p118,jbyte p119 - ,jbyte p120,jfloat p121,jbyte p122,jbyte p123,jbyte p124,jbyte p125,jfloat p126 - ) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%d\n",p20); - fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%d\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%d\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%d\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%d\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc5(JNIEnv *e, jclass c -,jint p0,jfloat p1,jint p2,jfloat p3,jbyte p4,jbyte p5,jbyte p6,jfloat p7 - ,jint p8,jbyte p9,jfloat p10,jbyte p11,jfloat p12,jbyte p13,jbyte p14,jint p15 - ,jfloat p16,jint p17,jint p18,jint p19,jint p20,jbyte p21,jbyte p22,jbyte p23 - ,jbyte p24,jint p25,jint p26,jfloat p27,jbyte p28,jfloat p29,jint p30,jfloat p31 - ,jbyte p32,jfloat p33,jint p34,jint p35,jfloat p36,jbyte p37,jint p38,jbyte p39 - ,jbyte p40,jfloat p41,jfloat p42,jbyte p43,jbyte p44,jfloat p45,jbyte p46 - ,jbyte p47,jint p48,jint p49,jint p50,jfloat p51,jint p52,jfloat p53,jbyte p54 - ,jint p55,jint p56,jbyte p57,jint p58,jbyte p59,jint p60,jfloat p61,jint p62 - ,jfloat p63,jint p64,jfloat p65,jbyte p66,jbyte p67,jfloat p68,jbyte p69 - ,jint p70,jfloat p71,jbyte p72,jint p73,jint p74,jbyte p75,jbyte p76,jbyte p77 - ,jint p78,jbyte p79,jbyte p80,jfloat p81,jbyte p82,jint p83,jbyte p84,jint p85 - ,jint p86,jbyte p87,jint p88,jfloat p89,jint p90,jint p91,jfloat p92,jbyte p93 - ,jfloat p94,jbyte p95,jfloat p96,jint p97,jfloat p98,jfloat p99,jint p100 - ,jbyte p101,jint p102,jbyte p103,jfloat p104,jfloat p105,jfloat p106,jfloat p107 - ,jfloat p108,jfloat p109,jint p110,jint p111,jint p112,jbyte p113,jfloat p114 - ,jfloat p115,jfloat p116,jint p117,jfloat p118,jint p119,jbyte p120,jint p121 - ,jbyte p122,jbyte p123,jfloat p124,jfloat p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%d\n",p20); - fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%d\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%d\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%d\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%d\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%d\n",p110); - fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%d\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc6(JNIEnv *e, jclass c -,jdouble p0,jint p1,jint p2,jint p3,jint p4,jdouble p5,jdouble p6,jint p7 - ,jint p8,jdouble p9,jdouble p10,jint p11,jint p12,jdouble p13,jdouble p14 - ,jdouble p15,jdouble p16,jdouble p17,jdouble p18,jint p19,jint p20,jdouble p21 - ,jdouble p22,jint p23,jdouble p24,jdouble p25,jdouble p26,jint p27,jint p28 - ,jint p29,jdouble p30,jdouble p31,jdouble p32,jint p33,jint p34,jdouble p35 - ,jint p36,jint p37,jdouble p38,jdouble p39,jdouble p40,jint p41,jdouble p42 - ,jdouble p43,jint p44,jint p45,jint p46,jint p47,jdouble p48,jdouble p49 - ,jdouble p50,jint p51,jint p52,jint p53,jint p54,jdouble p55,jint p56,jint p57 - ,jdouble p58,jint p59,jdouble p60,jdouble p61,jint p62,jint p63,jdouble p64 - ,jdouble p65,jint p66,jint p67,jdouble p68,jdouble p69,jdouble p70,jint p71 - ,jint p72,jdouble p73,jint p74,jint p75,jdouble p76,jdouble p77,jdouble p78 - ,jint p79,jint p80,jint p81,jint p82,jint p83,jdouble p84,jdouble p85,jint p86 - ,jdouble p87,jdouble p88,jint p89,jdouble p90,jint p91,jint p92,jdouble p93 - ,jint p94,jint p95,jdouble p96,jdouble p97,jint p98,jdouble p99,jdouble p100 - ,jdouble p101,jint p102,jdouble p103,jdouble p104,jint p105,jint p106,jint p107 - ,jdouble p108,jint p109,jdouble p110,jdouble p111,jdouble p112,jint p113 - ,jint p114,jdouble p115,jint p116,jdouble p117,jdouble p118,jint p119,jdouble p120 - ,jdouble p121,jint p122,jint p123,jint p124,jint p125,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%d\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%d\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%d\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%d\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%d\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%d\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%d\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%d\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc7(JNIEnv *e, jclass c -,jdouble p0,jbyte p1,jdouble p2,jdouble p3,jbyte p4,jbyte p5,jbyte p6,jbyte p7 - ,jdouble p8,jdouble p9,jbyte p10,jbyte p11,jdouble p12,jdouble p13,jbyte p14 - ,jbyte p15,jbyte p16,jbyte p17,jbyte p18,jdouble p19,jdouble p20,jdouble p21 - ,jdouble p22,jbyte p23,jdouble p24,jbyte p25,jdouble p26,jbyte p27,jdouble p28 - ,jbyte p29,jbyte p30,jdouble p31,jbyte p32,jdouble p33,jbyte p34,jdouble p35 - ,jdouble p36,jdouble p37,jdouble p38,jbyte p39,jdouble p40,jdouble p41,jbyte p42 - ,jdouble p43,jbyte p44,jdouble p45,jdouble p46,jdouble p47,jdouble p48,jbyte p49 - ,jbyte p50,jdouble p51,jdouble p52,jdouble p53,jbyte p54,jdouble p55,jdouble p56 - ,jdouble p57,jdouble p58,jdouble p59,jbyte p60,jdouble p61,jdouble p62,jbyte p63 - ,jbyte p64,jbyte p65,jbyte p66,jbyte p67,jbyte p68,jdouble p69,jdouble p70 - ,jbyte p71,jdouble p72,jdouble p73,jbyte p74,jdouble p75,jbyte p76,jbyte p77 - ,jbyte p78,jbyte p79,jbyte p80,jdouble p81,jdouble p82,jbyte p83,jbyte p84 - ,jbyte p85,jbyte p86,jdouble p87,jbyte p88,jdouble p89,jdouble p90,jdouble p91 - ,jbyte p92,jbyte p93,jdouble p94,jbyte p95,jbyte p96,jbyte p97,jbyte p98 - ,jdouble p99,jbyte p100,jbyte p101,jbyte p102,jdouble p103,jdouble p104 - ,jbyte p105,jdouble p106,jbyte p107,jbyte p108,jbyte p109,jdouble p110,jbyte p111 - ,jbyte p112,jbyte p113,jbyte p114,jbyte p115,jbyte p116,jdouble p117,jbyte p118 - ,jdouble p119,jdouble p120,jbyte p121,jbyte p122,jdouble p123,jdouble p124 - ,jbyte p125,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%d\n",p29); - fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%d\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%d\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%d\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%d\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%d\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc8(JNIEnv *e, jclass c -,jbyte p0,jdouble p1,jbyte p2,jdouble p3,jint p4,jint p5,jint p6,jdouble p7 - ,jdouble p8,jint p9,jdouble p10,jbyte p11,jint p12,jbyte p13,jdouble p14 - ,jint p15,jbyte p16,jint p17,jdouble p18,jdouble p19,jbyte p20,jint p21 - ,jbyte p22,jint p23,jint p24,jbyte p25,jdouble p26,jint p27,jint p28,jbyte p29 - ,jint p30,jint p31,jbyte p32,jdouble p33,jdouble p34,jbyte p35,jdouble p36 - ,jint p37,jdouble p38,jint p39,jbyte p40,jbyte p41,jint p42,jint p43,jint p44 - ,jbyte p45,jdouble p46,jdouble p47,jint p48,jint p49,jbyte p50,jbyte p51 - ,jint p52,jint p53,jbyte p54,jbyte p55,jint p56,jint p57,jint p58,jdouble p59 - ,jbyte p60,jint p61,jdouble p62,jdouble p63,jdouble p64,jint p65,jint p66 - ,jdouble p67,jint p68,jdouble p69,jint p70,jint p71,jbyte p72,jint p73,jdouble p74 - ,jdouble p75,jbyte p76,jint p77,jbyte p78,jbyte p79,jint p80,jint p81,jint p82 - ,jdouble p83,jdouble p84,jint p85,jbyte p86,jbyte p87,jbyte p88,jbyte p89 - ,jint p90,jint p91,jdouble p92,jint p93,jdouble p94,jdouble p95,jint p96 - ,jbyte p97,jdouble p98,jdouble p99,jbyte p100,jbyte p101,jbyte p102,jbyte p103 - ,jdouble p104,jint p105,jint p106,jbyte p107,jbyte p108,jdouble p109,jdouble p110 - ,jdouble p111,jbyte p112,jdouble p113,jbyte p114,jbyte p115,jint p116,jdouble p117 - ,jint p118,jint p119,jbyte p120,jdouble p121,jbyte p122,jint p123,jint p124 - ,jint p125,jbyte p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%d\n",p20); - fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%d\n",p29); - fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%d\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%d\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%d\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%d\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%d\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc9(JNIEnv *e, jclass c -,jdouble p0,jbyte p1,jint p2,jbyte p3,jint p4,jbyte p5,jint p6,jfloat p7 - ,jfloat p8,jint p9,jdouble p10,jint p11,jfloat p12,jfloat p13,jdouble p14 - ,jint p15,jfloat p16,jbyte p17,jfloat p18,jint p19,jfloat p20,jint p21,jfloat p22 - ,jfloat p23,jdouble p24,jbyte p25,jbyte p26,jbyte p27,jbyte p28,jfloat p29 - ,jbyte p30,jbyte p31,jbyte p32,jdouble p33,jint p34,jdouble p35,jfloat p36 - ,jint p37,jdouble p38,jint p39,jdouble p40,jbyte p41,jdouble p42,jfloat p43 - ,jfloat p44,jdouble p45,jfloat p46,jint p47,jfloat p48,jint p49,jfloat p50 - ,jbyte p51,jbyte p52,jint p53,jint p54,jfloat p55,jdouble p56,jint p57,jint p58 - ,jfloat p59,jint p60,jbyte p61,jint p62,jdouble p63,jdouble p64,jint p65 - ,jbyte p66,jdouble p67,jint p68,jbyte p69,jbyte p70,jint p71,jfloat p72 - ,jfloat p73,jbyte p74,jint p75,jbyte p76,jdouble p77,jfloat p78,jdouble p79 - ,jbyte p80,jint p81,jint p82,jbyte p83,jdouble p84,jfloat p85,jdouble p86 - ,jdouble p87,jfloat p88,jbyte p89,jbyte p90,jdouble p91,jdouble p92,jdouble p93 - ,jfloat p94,jdouble p95,jfloat p96,jdouble p97,jfloat p98,jbyte p99,jfloat p100 - ,jbyte p101,jbyte p102,jfloat p103,jdouble p104,jbyte p105,jfloat p106,jdouble p107 - ,jdouble p108,jint p109,jfloat p110,jint p111,jint p112,jbyte p113,jdouble p114 - ,jbyte p115,jdouble p116,jint p117,jdouble p118,jfloat p119,jbyte p120,jfloat p121 - ,jfloat p122,jfloat p123,jdouble p124,jint p125,jbyte p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%d\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%d\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%d\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc10(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jfloat p2,jdouble p3,jfloat p4,jfloat p5,jdouble p6 - ,jfloat p7,jfloat p8,jdouble p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13 - ,jdouble p14,jfloat p15,jfloat p16,jdouble p17,jdouble p18,jdouble p19,jdouble p20 - ,jfloat p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 - ,jfloat p27,jfloat p28,jfloat p29,jdouble p30,jfloat p31,jfloat p32,jfloat p33 - ,jdouble p34,jdouble p35,jdouble p36,jdouble p37,jfloat p38,jfloat p39,jdouble p40 - ,jfloat p41,jdouble p42,jdouble p43,jfloat p44,jdouble p45,jdouble p46,jdouble p47 - ,jfloat p48,jdouble p49,jdouble p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54 - ,jfloat p55,jdouble p56,jfloat p57,jfloat p58,jdouble p59,jfloat p60,jdouble p61 - ,jdouble p62,jfloat p63,jfloat p64,jfloat p65,jfloat p66,jdouble p67,jfloat p68 - ,jdouble p69,jdouble p70,jfloat p71,jdouble p72,jdouble p73,jdouble p74 - ,jfloat p75,jdouble p76,jdouble p77,jfloat p78,jdouble p79,jfloat p80,jfloat p81 - ,jfloat p82,jfloat p83,jfloat p84,jfloat p85,jdouble p86,jdouble p87,jfloat p88 - ,jfloat p89,jdouble p90,jdouble p91,jdouble p92,jdouble p93,jfloat p94,jdouble p95 - ,jfloat p96,jdouble p97,jdouble p98,jfloat p99,jfloat p100,jfloat p101,jdouble p102 - ,jfloat p103,jfloat p104,jfloat p105,jdouble p106,jdouble p107,jdouble p108 - ,jfloat p109,jdouble p110,jfloat p111,jdouble p112,jfloat p113,jfloat p114 - ,jdouble p115,jdouble p116,jdouble p117,jdouble p118,jfloat p119,jdouble p120 - ,jfloat p121,jdouble p122,jfloat p123,jfloat p124,jfloat p125,jfloat p126 - ) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc11(JNIEnv *e, jclass c -,jdouble p0,jfloat p1,jfloat p2,jdouble p3,jint p4,jint p5,jfloat p6,jdouble p7 - ,jint p8,jint p9,jint p10,jint p11,jint p12,jdouble p13,jfloat p14,jfloat p15 - ,jdouble p16,jfloat p17,jint p18,jint p19,jdouble p20,jfloat p21,jint p22 - ,jint p23,jfloat p24,jint p25,jint p26,jint p27,jfloat p28,jfloat p29,jdouble p30 - ,jdouble p31,jint p32,jdouble p33,jfloat p34,jfloat p35,jfloat p36,jint p37 - ,jfloat p38,jdouble p39,jfloat p40,jdouble p41,jdouble p42,jdouble p43,jdouble p44 - ,jint p45,jint p46,jfloat p47,jfloat p48,jfloat p49,jfloat p50,jdouble p51 - ,jdouble p52,jdouble p53,jint p54,jfloat p55,jint p56,jdouble p57,jdouble p58 - ,jdouble p59,jdouble p60,jint p61,jfloat p62,jint p63,jfloat p64,jdouble p65 - ,jdouble p66,jfloat p67,jdouble p68,jdouble p69,jint p70,jdouble p71,jfloat p72 - ,jdouble p73,jint p74,jfloat p75,jfloat p76,jfloat p77,jfloat p78,jint p79 - ,jfloat p80,jint p81,jdouble p82,jfloat p83,jdouble p84,jfloat p85,jfloat p86 - ,jfloat p87,jdouble p88,jfloat p89,jint p90,jfloat p91,jdouble p92,jfloat p93 - ,jdouble p94,jdouble p95,jint p96,jint p97,jfloat p98,jdouble p99,jfloat p100 - ,jint p101,jdouble p102,jdouble p103,jfloat p104,jdouble p105,jint p106 - ,jfloat p107,jfloat p108,jint p109,jdouble p110,jfloat p111,jdouble p112 - ,jint p113,jint p114,jfloat p115,jfloat p116,jint p117,jdouble p118,jfloat p119 - ,jfloat p120,jfloat p121,jint p122,jdouble p123,jint p124,jfloat p125,jdouble p126 - ) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%d\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc12(JNIEnv *e, jclass c -,jdouble p0,jfloat p1,jdouble p2,jfloat p3,jfloat p4,jbyte p5,jbyte p6,jdouble p7 - ,jdouble p8,jbyte p9,jbyte p10,jfloat p11,jbyte p12,jbyte p13,jbyte p14 - ,jbyte p15,jbyte p16,jbyte p17,jdouble p18,jdouble p19,jbyte p20,jfloat p21 - ,jbyte p22,jdouble p23,jbyte p24,jfloat p25,jdouble p26,jfloat p27,jbyte p28 - ,jbyte p29,jfloat p30,jbyte p31,jfloat p32,jfloat p33,jbyte p34,jbyte p35 - ,jfloat p36,jdouble p37,jfloat p38,jfloat p39,jdouble p40,jdouble p41,jfloat p42 - ,jfloat p43,jbyte p44,jbyte p45,jdouble p46,jfloat p47,jdouble p48,jfloat p49 - ,jbyte p50,jdouble p51,jdouble p52,jfloat p53,jdouble p54,jbyte p55,jfloat p56 - ,jbyte p57,jbyte p58,jbyte p59,jfloat p60,jdouble p61,jfloat p62,jbyte p63 - ,jdouble p64,jdouble p65,jfloat p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 - ,jdouble p71,jfloat p72,jfloat p73,jdouble p74,jbyte p75,jfloat p76,jbyte p77 - ,jbyte p78,jbyte p79,jdouble p80,jdouble p81,jbyte p82,jfloat p83,jdouble p84 - ,jbyte p85,jfloat p86,jdouble p87,jfloat p88,jfloat p89,jfloat p90,jfloat p91 - ,jdouble p92,jbyte p93,jfloat p94,jbyte p95,jbyte p96,jbyte p97,jfloat p98 - ,jbyte p99,jfloat p100,jdouble p101,jfloat p102,jbyte p103,jbyte p104,jfloat p105 - ,jdouble p106,jbyte p107,jfloat p108,jbyte p109,jdouble p110,jfloat p111 - ,jfloat p112,jbyte p113,jfloat p114,jbyte p115,jfloat p116,jdouble p117 - ,jdouble p118,jdouble p119,jfloat p120,jdouble p121,jbyte p122,jbyte p123 - ,jfloat p124,jdouble p125,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%d\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%d\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%d\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%d\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%d\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc13(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jint p4,jfloat p5,jint p6,jfloat p7 - ,jint p8,jfloat p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jint p14 - ,jfloat p15,jfloat p16,jint p17,jint p18,jfloat p19,jfloat p20,jint p21 - ,jint p22,jint p23,jint p24,jint p25,jfloat p26,jint p27,jint p28,jfloat p29 - ,jint p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jint p35,jint p36 - ,jfloat p37,jfloat p38,jfloat p39,jint p40,jfloat p41,jint p42,jfloat p43 - ,jint p44,jfloat p45,jfloat p46,jfloat p47,jint p48,jfloat p49,jint p50 - ,jint p51,jfloat p52,jint p53,jfloat p54,jfloat p55,jfloat p56,jfloat p57 - ,jfloat p58,jfloat p59,jfloat p60,jfloat p61,jint p62,jfloat p63,jfloat p64 - ,jfloat p65,jint p66,jint p67,jfloat p68,jfloat p69,jfloat p70,jint p71 - ,jfloat p72,jfloat p73,jint p74,jfloat p75,jfloat p76,jfloat p77,jint p78 - ,jint p79,jint p80,jfloat p81,jint p82,jint p83,jfloat p84,jint p85,jint p86 - ,jfloat p87,jfloat p88,jfloat p89,jfloat p90,jint p91,jint p92,jfloat p93 - ,jfloat p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98,jint p99,jfloat p100 - ,jint p101,jfloat p102,jfloat p103,jint p104,jfloat p105,jfloat p106,jfloat p107 - ,jint p108,jfloat p109,jfloat p110,jfloat p111,jfloat p112,jfloat p113,jfloat p114 - ,jfloat p115,jfloat p116,jint p117,jint p118,jfloat p119,jfloat p120,jfloat p121 - ,jint p122,jfloat p123,jint p124,jfloat p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%d\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%d\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc14(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jbyte p4,jfloat p5,jfloat p6,jbyte p7 - ,jfloat p8,jbyte p9,jbyte p10,jbyte p11,jfloat p12,jfloat p13,jfloat p14 - ,jbyte p15,jfloat p16,jbyte p17,jfloat p18,jfloat p19,jfloat p20,jfloat p21 - ,jbyte p22,jbyte p23,jbyte p24,jfloat p25,jbyte p26,jfloat p27,jfloat p28 - ,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jfloat p35 - ,jbyte p36,jfloat p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jfloat p42 - ,jbyte p43,jbyte p44,jfloat p45,jbyte p46,jfloat p47,jbyte p48,jfloat p49 - ,jfloat p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54,jfloat p55,jbyte p56 - ,jfloat p57,jbyte p58,jfloat p59,jbyte p60,jfloat p61,jbyte p62,jbyte p63 - ,jfloat p64,jfloat p65,jfloat p66,jbyte p67,jfloat p68,jfloat p69,jfloat p70 - ,jbyte p71,jfloat p72,jbyte p73,jfloat p74,jfloat p75,jfloat p76,jbyte p77 - ,jfloat p78,jfloat p79,jbyte p80,jfloat p81,jfloat p82,jfloat p83,jfloat p84 - ,jbyte p85,jfloat p86,jbyte p87,jbyte p88,jbyte p89,jfloat p90,jbyte p91 - ,jfloat p92,jfloat p93,jbyte p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98 - ,jfloat p99,jfloat p100,jfloat p101,jfloat p102,jbyte p103,jbyte p104,jfloat p105 - ,jfloat p106,jfloat p107,jfloat p108,jfloat p109,jfloat p110,jbyte p111 - ,jfloat p112,jfloat p113,jbyte p114,jbyte p115,jfloat p116,jfloat p117,jfloat p118 - ,jfloat p119,jbyte p120,jbyte p121,jbyte p122,jbyte p123,jbyte p124,jfloat p125 - ,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%d\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%d\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc15(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jbyte p2,jfloat p3,jfloat p4,jfloat p5,jbyte p6,jfloat p7 - ,jbyte p8,jint p9,jfloat p10,jfloat p11,jbyte p12,jbyte p13,jbyte p14,jbyte p15 - ,jbyte p16,jfloat p17,jbyte p18,jfloat p19,jint p20,jbyte p21,jfloat p22 - ,jint p23,jbyte p24,jfloat p25,jfloat p26,jbyte p27,jfloat p28,jint p29 - ,jfloat p30,jbyte p31,jfloat p32,jfloat p33,jbyte p34,jfloat p35,jint p36 - ,jbyte p37,jint p38,jfloat p39,jfloat p40,jbyte p41,jfloat p42,jbyte p43 - ,jint p44,jfloat p45,jfloat p46,jbyte p47,jint p48,jfloat p49,jint p50,jfloat p51 - ,jfloat p52,jint p53,jbyte p54,jint p55,jbyte p56,jfloat p57,jfloat p58 - ,jfloat p59,jfloat p60,jbyte p61,jbyte p62,jbyte p63,jbyte p64,jfloat p65 - ,jint p66,jint p67,jint p68,jfloat p69,jfloat p70,jint p71,jfloat p72,jfloat p73 - ,jfloat p74,jint p75,jfloat p76,jfloat p77,jint p78,jfloat p79,jint p80 - ,jfloat p81,jfloat p82,jfloat p83,jfloat p84,jbyte p85,jint p86,jbyte p87 - ,jfloat p88,jfloat p89,jfloat p90,jint p91,jfloat p92,jbyte p93,jfloat p94 - ,jbyte p95,jint p96,jfloat p97,jfloat p98,jint p99,jfloat p100,jbyte p101 - ,jbyte p102,jfloat p103,jbyte p104,jbyte p105,jbyte p106,jint p107,jint p108 - ,jfloat p109,jfloat p110,jint p111,jfloat p112,jbyte p113,jint p114,jfloat p115 - ,jbyte p116,jbyte p117,jfloat p118,jfloat p119,jint p120,jfloat p121,jfloat p122 - ,jint p123,jfloat p124,jbyte p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%d\n",p20); - fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%d\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc16(JNIEnv *e, jclass c -,jdouble p0,jint p1,jdouble p2,jdouble p3,jdouble p4,jdouble p5,jint p6 - ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jdouble p12,jdouble p13 - ,jdouble p14,jdouble p15,jdouble p16,jdouble p17,jint p18,jint p19,jdouble p20 - ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jint p26,jdouble p27 - ,jdouble p28,jdouble p29,jdouble p30,jint p31,jdouble p32,jint p33,jint p34 - ,jdouble p35,jdouble p36,jdouble p37,jint p38,jdouble p39,jdouble p40,jdouble p41 - ,jdouble p42,jint p43,jdouble p44,jdouble p45,jint p46,jdouble p47,jdouble p48 - ,jint p49,jdouble p50,jdouble p51,jint p52,jdouble p53,jint p54,jdouble p55 - ,jint p56,jint p57,jdouble p58,jint p59,jint p60,jdouble p61,jint p62,jint p63 - ,jint p64,jdouble p65,jint p66,jint p67,jint p68,jint p69,jint p70,jdouble p71 - ,jint p72,jint p73,jdouble p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78 - ,jdouble p79,jint p80,jdouble p81,jdouble p82,jdouble p83,jdouble p84,jdouble p85 - ,jdouble p86,jdouble p87,jdouble p88,jdouble p89,jint p90,jdouble p91,jdouble p92 - ,jdouble p93,jdouble p94,jdouble p95,jdouble p96,jdouble p97,jint p98,jdouble p99 - ,jint p100,jdouble p101,jdouble p102,jdouble p103,jint p104,jdouble p105 - ,jint p106,jdouble p107,jint p108,jint p109,jdouble p110,jdouble p111,jdouble p112 - ,jint p113,jdouble p114,jdouble p115,jint p116,jdouble p117,jint p118,jint p119 - ,jdouble p120,jdouble p121,jdouble p122,jdouble p123,jdouble p124,jdouble p125 - ,jint p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%d\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%d\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%d\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%d\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%d\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc17(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jbyte p2,jdouble p3,jdouble p4,jdouble p5,jdouble p6 - ,jbyte p7,jdouble p8,jbyte p9,jdouble p10,jbyte p11,jbyte p12,jdouble p13 - ,jdouble p14,jdouble p15,jdouble p16,jbyte p17,jdouble p18,jdouble p19,jdouble p20 - ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 - ,jdouble p27,jdouble p28,jdouble p29,jdouble p30,jdouble p31,jdouble p32 - ,jdouble p33,jdouble p34,jdouble p35,jdouble p36,jdouble p37,jbyte p38,jdouble p39 - ,jdouble p40,jdouble p41,jdouble p42,jdouble p43,jdouble p44,jdouble p45 - ,jdouble p46,jbyte p47,jdouble p48,jbyte p49,jdouble p50,jbyte p51,jdouble p52 - ,jbyte p53,jbyte p54,jbyte p55,jbyte p56,jdouble p57,jbyte p58,jdouble p59 - ,jdouble p60,jbyte p61,jbyte p62,jdouble p63,jdouble p64,jbyte p65,jbyte p66 - ,jbyte p67,jdouble p68,jbyte p69,jdouble p70,jdouble p71,jbyte p72,jdouble p73 - ,jdouble p74,jdouble p75,jbyte p76,jdouble p77,jdouble p78,jdouble p79,jdouble p80 - ,jdouble p81,jbyte p82,jdouble p83,jdouble p84,jbyte p85,jbyte p86,jdouble p87 - ,jdouble p88,jdouble p89,jdouble p90,jdouble p91,jdouble p92,jbyte p93,jbyte p94 - ,jdouble p95,jdouble p96,jdouble p97,jdouble p98,jbyte p99,jdouble p100 - ,jdouble p101,jdouble p102,jdouble p103,jdouble p104,jbyte p105,jdouble p106 - ,jbyte p107,jdouble p108,jdouble p109,jdouble p110,jbyte p111,jdouble p112 - ,jdouble p113,jbyte p114,jdouble p115,jdouble p116,jbyte p117,jbyte p118 - ,jbyte p119,jdouble p120,jbyte p121,jdouble p122,jbyte p123,jdouble p124 - ,jbyte p125,jbyte p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%d\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%d\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc18(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jint p4,jint p5,jbyte p6,jint p7 - ,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jdouble p12,jbyte p13,jdouble p14 - ,jdouble p15,jbyte p16,jdouble p17,jint p18,jbyte p19,jbyte p20,jdouble p21 - ,jdouble p22,jdouble p23,jint p24,jdouble p25,jdouble p26,jint p27,jdouble p28 - ,jdouble p29,jdouble p30,jdouble p31,jdouble p32,jdouble p33,jbyte p34,jint p35 - ,jbyte p36,jdouble p37,jdouble p38,jint p39,jint p40,jint p41,jint p42,jdouble p43 - ,jdouble p44,jdouble p45,jbyte p46,jbyte p47,jdouble p48,jint p49,jbyte p50 - ,jbyte p51,jint p52,jint p53,jint p54,jdouble p55,jdouble p56,jint p57,jint p58 - ,jdouble p59,jbyte p60,jbyte p61,jint p62,jint p63,jdouble p64,jint p65 - ,jint p66,jdouble p67,jdouble p68,jdouble p69,jint p70,jdouble p71,jdouble p72 - ,jint p73,jdouble p74,jdouble p75,jint p76,jbyte p77,jdouble p78,jint p79 - ,jdouble p80,jint p81,jdouble p82,jdouble p83,jbyte p84,jdouble p85,jdouble p86 - ,jint p87,jint p88,jbyte p89,jdouble p90,jdouble p91,jdouble p92,jint p93 - ,jbyte p94,jbyte p95,jint p96,jdouble p97,jdouble p98,jdouble p99,jdouble p100 - ,jbyte p101,jbyte p102,jdouble p103,jdouble p104,jdouble p105,jint p106 - ,jint p107,jdouble p108,jint p109,jint p110,jdouble p111,jdouble p112,jbyte p113 - ,jint p114,jbyte p115,jdouble p116,jdouble p117,jint p118,jint p119,jint p120 - ,jdouble p121,jdouble p122,jdouble p123,jdouble p124,jdouble p125,jbyte p126 - ) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%d\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%d\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%d\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%d\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%d\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%d\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%d\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc19(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jint p5,jfloat p6,jfloat p7 - ,jdouble p8,jdouble p9,jint p10,jdouble p11,jdouble p12,jfloat p13,jint p14 - ,jdouble p15,jfloat p16,jint p17,jfloat p18,jdouble p19,jfloat p20,jbyte p21 - ,jdouble p22,jfloat p23,jfloat p24,jdouble p25,jfloat p26,jbyte p27,jdouble p28 - ,jfloat p29,jfloat p30,jfloat p31,jbyte p32,jfloat p33,jfloat p34,jfloat p35 - ,jint p36,jint p37,jdouble p38,jdouble p39,jint p40,jbyte p41,jfloat p42 - ,jfloat p43,jbyte p44,jbyte p45,jdouble p46,jdouble p47,jint p48,jdouble p49 - ,jdouble p50,jint p51,jdouble p52,jfloat p53,jdouble p54,jdouble p55,jfloat p56 - ,jdouble p57,jdouble p58,jdouble p59,jint p60,jint p61,jfloat p62,jfloat p63 - ,jdouble p64,jdouble p65,jint p66,jbyte p67,jfloat p68,jdouble p69,jfloat p70 - ,jfloat p71,jdouble p72,jfloat p73,jbyte p74,jint p75,jint p76,jdouble p77 - ,jfloat p78,jdouble p79,jdouble p80,jdouble p81,jdouble p82,jint p83,jfloat p84 - ,jdouble p85,jbyte p86,jbyte p87,jdouble p88,jbyte p89,jbyte p90,jbyte p91 - ,jint p92,jbyte p93,jfloat p94,jbyte p95,jint p96,jint p97,jint p98,jbyte p99 - ,jdouble p100,jint p101,jdouble p102,jfloat p103,jint p104,jfloat p105,jint p106 - ,jbyte p107,jfloat p108,jint p109,jfloat p110,jfloat p111,jfloat p112,jint p113 - ,jint p114,jfloat p115,jint p116,jdouble p117,jbyte p118,jfloat p119,jbyte p120 - ,jbyte p121,jdouble p122,jfloat p123,jfloat p124,jbyte p125,jint p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%d\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%d\n",p98); - fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%d\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc20(JNIEnv *e, jclass c -,jdouble p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jfloat p5,jfloat p6 - ,jdouble p7,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jdouble p12,jdouble p13 - ,jfloat p14,jdouble p15,jdouble p16,jdouble p17,jfloat p18,jfloat p19,jfloat p20 - ,jfloat p21,jfloat p22,jdouble p23,jdouble p24,jfloat p25,jfloat p26,jfloat p27 - ,jdouble p28,jfloat p29,jdouble p30,jfloat p31,jfloat p32,jdouble p33,jfloat p34 - ,jdouble p35,jdouble p36,jdouble p37,jdouble p38,jfloat p39,jfloat p40,jdouble p41 - ,jfloat p42,jdouble p43,jdouble p44,jfloat p45,jfloat p46,jdouble p47,jdouble p48 - ,jfloat p49,jdouble p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54,jdouble p55 - ,jdouble p56,jdouble p57,jfloat p58,jdouble p59,jfloat p60,jfloat p61,jfloat p62 - ,jfloat p63,jdouble p64,jfloat p65,jfloat p66,jfloat p67,jfloat p68,jfloat p69 - ,jdouble p70,jdouble p71,jfloat p72,jfloat p73,jdouble p74,jfloat p75,jfloat p76 - ,jfloat p77,jdouble p78,jfloat p79,jfloat p80,jfloat p81,jdouble p82,jfloat p83 - ,jdouble p84,jfloat p85,jdouble p86,jfloat p87,jdouble p88,jfloat p89,jfloat p90 - ,jfloat p91,jfloat p92,jdouble p93,jdouble p94,jdouble p95,jdouble p96,jfloat p97 - ,jfloat p98,jfloat p99,jfloat p100,jfloat p101,jfloat p102,jfloat p103,jfloat p104 - ,jfloat p105,jfloat p106,jdouble p107,jfloat p108,jfloat p109,jfloat p110 - ,jdouble p111,jdouble p112,jfloat p113,jfloat p114,jfloat p115,jfloat p116 - ,jdouble p117,jfloat p118,jfloat p119,jfloat p120,jdouble p121,jfloat p122 - ,jdouble p123,jdouble p124,jdouble p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc21(JNIEnv *e, jclass c -,jfloat p0,jint p1,jfloat p2,jfloat p3,jint p4,jint p5,jdouble p6,jfloat p7 - ,jfloat p8,jdouble p9,jint p10,jdouble p11,jdouble p12,jfloat p13,jdouble p14 - ,jdouble p15,jfloat p16,jdouble p17,jfloat p18,jdouble p19,jdouble p20,jdouble p21 - ,jfloat p22,jdouble p23,jdouble p24,jint p25,jdouble p26,jint p27,jint p28 - ,jdouble p29,jfloat p30,jfloat p31,jfloat p32,jint p33,jdouble p34,jfloat p35 - ,jdouble p36,jdouble p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jfloat p42 - ,jfloat p43,jint p44,jint p45,jdouble p46,jfloat p47,jfloat p48,jint p49 - ,jdouble p50,jdouble p51,jfloat p52,jdouble p53,jint p54,jdouble p55,jint p56 - ,jdouble p57,jdouble p58,jfloat p59,jfloat p60,jint p61,jfloat p62,jint p63 - ,jfloat p64,jdouble p65,jint p66,jfloat p67,jdouble p68,jdouble p69,jdouble p70 - ,jdouble p71,jdouble p72,jfloat p73,jint p74,jint p75,jdouble p76,jint p77 - ,jfloat p78,jfloat p79,jdouble p80,jdouble p81,jdouble p82,jint p83,jdouble p84 - ,jdouble p85,jfloat p86,jdouble p87,jint p88,jdouble p89,jfloat p90,jfloat p91 - ,jfloat p92,jdouble p93,jint p94,jfloat p95,jint p96,jfloat p97,jdouble p98 - ,jint p99,jint p100,jint p101,jint p102,jfloat p103,jfloat p104,jfloat p105 - ,jfloat p106,jint p107,jfloat p108,jdouble p109,jfloat p110,jdouble p111 - ,jdouble p112,jfloat p113,jfloat p114,jdouble p115,jdouble p116,jfloat p117 - ,jint p118,jdouble p119,jfloat p120,jfloat p121,jdouble p122,jdouble p123 - ,jfloat p124,jint p125,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc22(JNIEnv *e, jclass c -,jdouble p0,jbyte p1,jdouble p2,jfloat p3,jfloat p4,jfloat p5,jfloat p6 - ,jfloat p7,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jdouble p12,jdouble p13 - ,jbyte p14,jfloat p15,jfloat p16,jdouble p17,jfloat p18,jfloat p19,jdouble p20 - ,jfloat p21,jbyte p22,jfloat p23,jfloat p24,jdouble p25,jbyte p26,jdouble p27 - ,jdouble p28,jdouble p29,jbyte p30,jbyte p31,jbyte p32,jbyte p33,jbyte p34 - ,jdouble p35,jdouble p36,jfloat p37,jfloat p38,jdouble p39,jfloat p40,jfloat p41 - ,jfloat p42,jfloat p43,jbyte p44,jfloat p45,jfloat p46,jdouble p47,jbyte p48 - ,jbyte p49,jdouble p50,jdouble p51,jfloat p52,jfloat p53,jdouble p54,jfloat p55 - ,jdouble p56,jfloat p57,jfloat p58,jfloat p59,jfloat p60,jfloat p61,jfloat p62 - ,jdouble p63,jdouble p64,jfloat p65,jdouble p66,jdouble p67,jbyte p68,jdouble p69 - ,jdouble p70,jdouble p71,jdouble p72,jfloat p73,jbyte p74,jfloat p75,jfloat p76 - ,jfloat p77,jfloat p78,jfloat p79,jdouble p80,jdouble p81,jfloat p82,jdouble p83 - ,jbyte p84,jfloat p85,jdouble p86,jfloat p87,jdouble p88,jbyte p89,jbyte p90 - ,jdouble p91,jbyte p92,jfloat p93,jdouble p94,jbyte p95,jfloat p96,jfloat p97 - ,jdouble p98,jfloat p99,jbyte p100,jfloat p101,jdouble p102,jdouble p103 - ,jbyte p104,jdouble p105,jfloat p106,jbyte p107,jfloat p108,jbyte p109,jfloat p110 - ,jfloat p111,jdouble p112,jfloat p113,jdouble p114,jdouble p115,jfloat p116 - ,jdouble p117,jfloat p118,jfloat p119,jfloat p120,jbyte p121,jdouble p122 - ,jdouble p123,jdouble p124,jfloat p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%d\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%d\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%d\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc23(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jfloat p5,jint p6,jfloat p7 - ,jfloat p8,jfloat p9,jfloat p10,jint p11,jfloat p12,jfloat p13,jfloat p14 - ,jint p15,jfloat p16,jfloat p17,jfloat p18,jint p19,jfloat p20,jfloat p21 - ,jfloat p22,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jfloat p27,jfloat p28 - ,jfloat p29,jint p30,jfloat p31,jfloat p32,jfloat p33,jint p34,jint p35 - ,jint p36,jfloat p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jfloat p42 - ,jint p43,jfloat p44,jfloat p45,jfloat p46,jfloat p47,jint p48,jfloat p49 - ,jfloat p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54,jint p55,jfloat p56 - ,jfloat p57,jfloat p58,jfloat p59,jfloat p60,jint p61,jfloat p62,jfloat p63 - ,jint p64,jfloat p65,jint p66,jint p67,jint p68,jfloat p69,jfloat p70,jfloat p71 - ,jfloat p72,jint p73,jfloat p74,jfloat p75,jfloat p76,jfloat p77,jint p78 - ,jfloat p79,jfloat p80,jfloat p81,jfloat p82,jfloat p83,jfloat p84,jfloat p85 - ,jint p86,jfloat p87,jfloat p88,jfloat p89,jfloat p90,jint p91,jint p92 - ,jfloat p93,jint p94,jfloat p95,jint p96,jfloat p97,jfloat p98,jfloat p99 - ,jfloat p100,jfloat p101,jfloat p102,jfloat p103,jfloat p104,jfloat p105 - ,jfloat p106,jint p107,jfloat p108,jfloat p109,jfloat p110,jfloat p111,jfloat p112 - ,jint p113,jfloat p114,jfloat p115,jfloat p116,jfloat p117,jfloat p118,jint p119 - ,jfloat p120,jfloat p121,jint p122,jint p123,jfloat p124,jfloat p125,jfloat p126 - ) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%d\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%d\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%d\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc24(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jbyte p2,jbyte p3,jfloat p4,jfloat p5,jbyte p6,jbyte p7 - ,jbyte p8,jbyte p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jfloat p14 - ,jfloat p15,jfloat p16,jfloat p17,jfloat p18,jbyte p19,jfloat p20,jfloat p21 - ,jfloat p22,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jbyte p27,jfloat p28 - ,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jfloat p35 - ,jfloat p36,jbyte p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jbyte p42 - ,jfloat p43,jfloat p44,jfloat p45,jbyte p46,jbyte p47,jfloat p48,jfloat p49 - ,jfloat p50,jfloat p51,jfloat p52,jfloat p53,jbyte p54,jfloat p55,jbyte p56 - ,jbyte p57,jfloat p58,jfloat p59,jfloat p60,jfloat p61,jfloat p62,jbyte p63 - ,jbyte p64,jfloat p65,jfloat p66,jfloat p67,jbyte p68,jfloat p69,jfloat p70 - ,jfloat p71,jfloat p72,jfloat p73,jbyte p74,jfloat p75,jfloat p76,jfloat p77 - ,jfloat p78,jfloat p79,jbyte p80,jfloat p81,jfloat p82,jbyte p83,jfloat p84 - ,jbyte p85,jfloat p86,jbyte p87,jfloat p88,jbyte p89,jbyte p90,jfloat p91 - ,jfloat p92,jfloat p93,jfloat p94,jbyte p95,jbyte p96,jfloat p97,jbyte p98 - ,jfloat p99,jfloat p100,jfloat p101,jfloat p102,jfloat p103,jfloat p104 - ,jfloat p105,jbyte p106,jfloat p107,jfloat p108,jfloat p109,jfloat p110 - ,jbyte p111,jfloat p112,jfloat p113,jfloat p114,jfloat p115,jfloat p116 - ,jfloat p117,jfloat p118,jfloat p119,jfloat p120,jfloat p121,jfloat p122 - ,jfloat p123,jfloat p124,jfloat p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%d\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%d\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc25(JNIEnv *e, jclass c -,jfloat p0,jint p1,jfloat p2,jfloat p3,jfloat p4,jint p5,jint p6,jbyte p7 - ,jfloat p8,jint p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jint p14 - ,jbyte p15,jfloat p16,jfloat p17,jfloat p18,jbyte p19,jfloat p20,jbyte p21 - ,jfloat p22,jbyte p23,jfloat p24,jfloat p25,jfloat p26,jfloat p27,jfloat p28 - ,jint p29,jbyte p30,jfloat p31,jbyte p32,jfloat p33,jint p34,jint p35,jbyte p36 - ,jbyte p37,jint p38,jint p39,jfloat p40,jint p41,jfloat p42,jfloat p43,jfloat p44 - ,jfloat p45,jfloat p46,jint p47,jfloat p48,jint p49,jint p50,jint p51,jfloat p52 - ,jfloat p53,jbyte p54,jint p55,jbyte p56,jint p57,jfloat p58,jint p59,jint p60 - ,jbyte p61,jbyte p62,jint p63,jfloat p64,jfloat p65,jbyte p66,jbyte p67 - ,jbyte p68,jint p69,jbyte p70,jfloat p71,jbyte p72,jfloat p73,jfloat p74 - ,jfloat p75,jfloat p76,jbyte p77,jfloat p78,jint p79,jbyte p80,jfloat p81 - ,jfloat p82,jint p83,jfloat p84,jbyte p85,jbyte p86,jfloat p87,jfloat p88 - ,jbyte p89,jfloat p90,jfloat p91,jint p92,jfloat p93,jfloat p94,jint p95 - ,jfloat p96,jint p97,jint p98,jint p99,jint p100,jint p101,jint p102,jint p103 - ,jfloat p104,jint p105,jbyte p106,jfloat p107,jfloat p108,jint p109,jbyte p110 - ,jfloat p111,jfloat p112,jfloat p113,jbyte p114,jfloat p115,jbyte p116,jfloat p117 - ,jbyte p118,jfloat p119,jfloat p120,jfloat p121,jbyte p122,jfloat p123,jbyte p124 - ,jfloat p125,jint p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%d\n",p29); - fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%d\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%d\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%d\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%d\n",p98); - fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%d\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%d\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc26(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jdouble p4,jint p5,jdouble p6 - ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jdouble p12,jdouble p13 - ,jdouble p14,jint p15,jdouble p16,jdouble p17,jint p18,jdouble p19,jdouble p20 - ,jint p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26,jdouble p27 - ,jdouble p28,jdouble p29,jdouble p30,jint p31,jint p32,jdouble p33,jdouble p34 - ,jdouble p35,jdouble p36,jdouble p37,jdouble p38,jdouble p39,jdouble p40 - ,jdouble p41,jdouble p42,jint p43,jdouble p44,jdouble p45,jint p46,jdouble p47 - ,jint p48,jdouble p49,jdouble p50,jdouble p51,jdouble p52,jint p53,jdouble p54 - ,jdouble p55,jdouble p56,jint p57,jint p58,jdouble p59,jint p60,jdouble p61 - ,jdouble p62,jdouble p63,jdouble p64,jdouble p65,jdouble p66,jdouble p67 - ,jdouble p68,jdouble p69,jint p70,jint p71,jdouble p72,jdouble p73,jint p74 - ,jint p75,jint p76,jdouble p77,jdouble p78,jdouble p79,jdouble p80,jdouble p81 - ,jdouble p82,jdouble p83,jdouble p84,jdouble p85,jint p86,jdouble p87,jdouble p88 - ,jint p89,jdouble p90,jdouble p91,jdouble p92,jdouble p93,jint p94,jdouble p95 - ,jdouble p96,jint p97,jdouble p98,jdouble p99,jdouble p100,jdouble p101 - ,jdouble p102,jdouble p103,jdouble p104,jdouble p105,jdouble p106,jdouble p107 - ,jdouble p108,jdouble p109,jint p110,jint p111,jdouble p112,jint p113,jdouble p114 - ,jdouble p115,jdouble p116,jdouble p117,jdouble p118,jdouble p119,jint p120 - ,jint p121,jint p122,jdouble p123,jdouble p124,jdouble p125,jint p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%d\n",p110); - fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%d\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc27(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jdouble p4,jdouble p5,jdouble p6 - ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jbyte p12,jbyte p13 - ,jbyte p14,jdouble p15,jdouble p16,jbyte p17,jdouble p18,jdouble p19,jdouble p20 - ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 - ,jdouble p27,jdouble p28,jdouble p29,jbyte p30,jdouble p31,jdouble p32,jbyte p33 - ,jdouble p34,jdouble p35,jdouble p36,jdouble p37,jdouble p38,jdouble p39 - ,jdouble p40,jbyte p41,jbyte p42,jdouble p43,jbyte p44,jbyte p45,jdouble p46 - ,jdouble p47,jdouble p48,jbyte p49,jbyte p50,jbyte p51,jdouble p52,jbyte p53 - ,jdouble p54,jdouble p55,jdouble p56,jdouble p57,jbyte p58,jbyte p59,jdouble p60 - ,jdouble p61,jdouble p62,jdouble p63,jdouble p64,jdouble p65,jdouble p66 - ,jdouble p67,jbyte p68,jdouble p69,jdouble p70,jbyte p71,jdouble p72,jdouble p73 - ,jdouble p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78,jdouble p79 - ,jdouble p80,jdouble p81,jdouble p82,jdouble p83,jdouble p84,jdouble p85 - ,jdouble p86,jdouble p87,jbyte p88,jdouble p89,jbyte p90,jbyte p91,jbyte p92 - ,jdouble p93,jbyte p94,jbyte p95,jdouble p96,jbyte p97,jdouble p98,jdouble p99 - ,jdouble p100,jdouble p101,jdouble p102,jdouble p103,jdouble p104,jdouble p105 - ,jdouble p106,jdouble p107,jdouble p108,jdouble p109,jdouble p110,jdouble p111 - ,jdouble p112,jdouble p113,jdouble p114,jbyte p115,jdouble p116,jdouble p117 - ,jbyte p118,jdouble p119,jdouble p120,jbyte p121,jdouble p122,jdouble p123 - ,jdouble p124,jbyte p125,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%d\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%d\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc28(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jbyte p2,jdouble p3,jdouble p4,jdouble p5,jbyte p6 - ,jint p7,jbyte p8,jint p9,jint p10,jbyte p11,jdouble p12,jint p13,jdouble p14 - ,jdouble p15,jbyte p16,jdouble p17,jbyte p18,jdouble p19,jdouble p20,jbyte p21 - ,jdouble p22,jbyte p23,jdouble p24,jint p25,jdouble p26,jdouble p27,jbyte p28 - ,jdouble p29,jint p30,jint p31,jdouble p32,jdouble p33,jbyte p34,jbyte p35 - ,jbyte p36,jbyte p37,jdouble p38,jdouble p39,jdouble p40,jdouble p41,jint p42 - ,jdouble p43,jdouble p44,jdouble p45,jdouble p46,jdouble p47,jdouble p48 - ,jdouble p49,jint p50,jdouble p51,jdouble p52,jbyte p53,jint p54,jint p55 - ,jdouble p56,jdouble p57,jint p58,jdouble p59,jdouble p60,jdouble p61,jdouble p62 - ,jbyte p63,jint p64,jbyte p65,jdouble p66,jdouble p67,jint p68,jdouble p69 - ,jdouble p70,jdouble p71,jdouble p72,jbyte p73,jdouble p74,jdouble p75,jdouble p76 - ,jbyte p77,jbyte p78,jdouble p79,jdouble p80,jdouble p81,jdouble p82,jdouble p83 - ,jbyte p84,jdouble p85,jdouble p86,jbyte p87,jdouble p88,jbyte p89,jdouble p90 - ,jdouble p91,jint p92,jbyte p93,jdouble p94,jdouble p95,jdouble p96,jdouble p97 - ,jdouble p98,jdouble p99,jbyte p100,jbyte p101,jdouble p102,jdouble p103 - ,jbyte p104,jdouble p105,jdouble p106,jbyte p107,jint p108,jbyte p109,jbyte p110 - ,jbyte p111,jdouble p112,jint p113,jdouble p114,jbyte p115,jint p116,jdouble p117 - ,jdouble p118,jbyte p119,jbyte p120,jint p121,jdouble p122,jint p123,jbyte p124 - ,jdouble p125,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%d\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%d\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%d\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%d\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%d\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%d\n",p110); - fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%d\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%d\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc29(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jdouble p2,jdouble p3,jfloat p4,jfloat p5,jint p6,jdouble p7 - ,jfloat p8,jbyte p9,jfloat p10,jfloat p11,jfloat p12,jdouble p13,jdouble p14 - ,jint p15,jbyte p16,jfloat p17,jfloat p18,jbyte p19,jint p20,jdouble p21 - ,jfloat p22,jfloat p23,jint p24,jfloat p25,jfloat p26,jbyte p27,jdouble p28 - ,jfloat p29,jint p30,jint p31,jfloat p32,jfloat p33,jfloat p34,jdouble p35 - ,jdouble p36,jfloat p37,jdouble p38,jfloat p39,jfloat p40,jfloat p41,jdouble p42 - ,jfloat p43,jdouble p44,jdouble p45,jdouble p46,jint p47,jdouble p48,jfloat p49 - ,jbyte p50,jdouble p51,jbyte p52,jdouble p53,jfloat p54,jdouble p55,jfloat p56 - ,jbyte p57,jfloat p58,jdouble p59,jfloat p60,jfloat p61,jdouble p62,jfloat p63 - ,jdouble p64,jbyte p65,jfloat p66,jfloat p67,jint p68,jfloat p69,jdouble p70 - ,jdouble p71,jfloat p72,jdouble p73,jfloat p74,jfloat p75,jbyte p76,jfloat p77 - ,jdouble p78,jdouble p79,jfloat p80,jdouble p81,jdouble p82,jbyte p83,jdouble p84 - ,jint p85,jfloat p86,jint p87,jdouble p88,jfloat p89,jbyte p90,jbyte p91 - ,jfloat p92,jbyte p93,jdouble p94,jfloat p95,jint p96,jdouble p97,jdouble p98 - ,jfloat p99,jdouble p100,jfloat p101,jfloat p102,jdouble p103,jfloat p104 - ,jint p105,jdouble p106,jint p107,jdouble p108,jdouble p109,jfloat p110 - ,jdouble p111,jfloat p112,jdouble p113,jdouble p114,jint p115,jfloat p116 - ,jfloat p117,jint p118,jfloat p119,jdouble p120,jfloat p121,jbyte p122,jfloat p123 - ,jfloat p124,jfloat p125,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%d\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc30(JNIEnv *e, jclass c -,jfloat p0,jdouble p1,jfloat p2,jfloat p3,jfloat p4,jfloat p5,jdouble p6 - ,jfloat p7,jdouble p8,jfloat p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13 - ,jfloat p14,jfloat p15,jdouble p16,jfloat p17,jdouble p18,jfloat p19,jdouble p20 - ,jdouble p21,jdouble p22,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jfloat p27 - ,jfloat p28,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jdouble p34 - ,jfloat p35,jdouble p36,jfloat p37,jdouble p38,jfloat p39,jfloat p40,jfloat p41 - ,jdouble p42,jfloat p43,jfloat p44,jfloat p45,jfloat p46,jdouble p47,jdouble p48 - ,jdouble p49,jfloat p50,jdouble p51,jdouble p52,jfloat p53,jfloat p54,jfloat p55 - ,jdouble p56,jdouble p57,jfloat p58,jfloat p59,jfloat p60,jfloat p61,jfloat p62 - ,jfloat p63,jfloat p64,jfloat p65,jfloat p66,jfloat p67,jfloat p68,jdouble p69 - ,jfloat p70,jfloat p71,jfloat p72,jfloat p73,jfloat p74,jfloat p75,jfloat p76 - ,jdouble p77,jfloat p78,jfloat p79,jfloat p80,jdouble p81,jfloat p82,jfloat p83 - ,jfloat p84,jdouble p85,jdouble p86,jdouble p87,jfloat p88,jfloat p89,jfloat p90 - ,jfloat p91,jfloat p92,jdouble p93,jfloat p94,jfloat p95,jfloat p96,jfloat p97 - ,jfloat p98,jdouble p99,jdouble p100,jfloat p101,jfloat p102,jdouble p103 - ,jdouble p104,jfloat p105,jdouble p106,jfloat p107,jfloat p108,jfloat p109 - ,jfloat p110,jdouble p111,jfloat p112,jfloat p113,jfloat p114,jfloat p115 - ,jfloat p116,jfloat p117,jfloat p118,jfloat p119,jfloat p120,jfloat p121 - ,jfloat p122,jfloat p123,jdouble p124,jfloat p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc31(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jfloat p2,jfloat p3,jfloat p4,jdouble p5,jfloat p6 - ,jfloat p7,jdouble p8,jdouble p9,jint p10,jdouble p11,jdouble p12,jfloat p13 - ,jint p14,jdouble p15,jfloat p16,jfloat p17,jfloat p18,jfloat p19,jfloat p20 - ,jint p21,jfloat p22,jdouble p23,jint p24,jfloat p25,jdouble p26,jdouble p27 - ,jdouble p28,jfloat p29,jdouble p30,jfloat p31,jdouble p32,jfloat p33,jfloat p34 - ,jfloat p35,jdouble p36,jfloat p37,jdouble p38,jdouble p39,jint p40,jint p41 - ,jdouble p42,jfloat p43,jfloat p44,jfloat p45,jdouble p46,jdouble p47,jfloat p48 - ,jfloat p49,jdouble p50,jdouble p51,jdouble p52,jfloat p53,jint p54,jdouble p55 - ,jfloat p56,jdouble p57,jfloat p58,jfloat p59,jfloat p60,jdouble p61,jfloat p62 - ,jint p63,jdouble p64,jint p65,jint p66,jdouble p67,jdouble p68,jdouble p69 - ,jfloat p70,jfloat p71,jdouble p72,jint p73,jint p74,jfloat p75,jdouble p76 - ,jfloat p77,jfloat p78,jfloat p79,jfloat p80,jdouble p81,jdouble p82,jdouble p83 - ,jdouble p84,jdouble p85,jfloat p86,jfloat p87,jint p88,jdouble p89,jdouble p90 - ,jfloat p91,jdouble p92,jfloat p93,jint p94,jfloat p95,jfloat p96,jdouble p97 - ,jint p98,jint p99,jdouble p100,jdouble p101,jfloat p102,jfloat p103,jdouble p104 - ,jdouble p105,jdouble p106,jdouble p107,jdouble p108,jfloat p109,jfloat p110 - ,jdouble p111,jfloat p112,jdouble p113,jdouble p114,jfloat p115,jfloat p116 - ,jfloat p117,jfloat p118,jdouble p119,jint p120,jdouble p121,jfloat p122 - ,jdouble p123,jdouble p124,jdouble p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%d\n",p98); - fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc32(JNIEnv *e, jclass c -,jdouble p0,jfloat p1,jbyte p2,jfloat p3,jdouble p4,jbyte p5,jfloat p6,jfloat p7 - ,jdouble p8,jfloat p9,jfloat p10,jfloat p11,jdouble p12,jfloat p13,jfloat p14 - ,jdouble p15,jfloat p16,jbyte p17,jfloat p18,jfloat p19,jfloat p20,jfloat p21 - ,jbyte p22,jbyte p23,jbyte p24,jfloat p25,jfloat p26,jdouble p27,jbyte p28 - ,jdouble p29,jfloat p30,jdouble p31,jdouble p32,jfloat p33,jbyte p34,jfloat p35 - ,jfloat p36,jdouble p37,jfloat p38,jdouble p39,jfloat p40,jdouble p41,jbyte p42 - ,jdouble p43,jfloat p44,jdouble p45,jbyte p46,jfloat p47,jbyte p48,jfloat p49 - ,jfloat p50,jfloat p51,jfloat p52,jdouble p53,jdouble p54,jdouble p55,jfloat p56 - ,jdouble p57,jdouble p58,jfloat p59,jdouble p60,jdouble p61,jdouble p62 - ,jdouble p63,jfloat p64,jdouble p65,jdouble p66,jdouble p67,jbyte p68,jdouble p69 - ,jfloat p70,jdouble p71,jbyte p72,jdouble p73,jdouble p74,jbyte p75,jdouble p76 - ,jdouble p77,jdouble p78,jbyte p79,jdouble p80,jdouble p81,jfloat p82,jdouble p83 - ,jfloat p84,jdouble p85,jbyte p86,jdouble p87,jdouble p88,jfloat p89,jdouble p90 - ,jdouble p91,jdouble p92,jdouble p93,jbyte p94,jfloat p95,jdouble p96,jdouble p97 - ,jfloat p98,jdouble p99,jfloat p100,jdouble p101,jfloat p102,jfloat p103 - ,jbyte p104,jdouble p105,jdouble p106,jdouble p107,jfloat p108,jfloat p109 - ,jfloat p110,jbyte p111,jdouble p112,jbyte p113,jdouble p114,jdouble p115 - ,jfloat p116,jfloat p117,jfloat p118,jdouble p119,jdouble p120,jdouble p121 - ,jfloat p122,jfloat p123,jfloat p124,jbyte p125,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc33(JNIEnv *e, jclass c -,jfloat p0,jint p1,jint p2,jint p3,jfloat p4,jfloat p5,jfloat p6,jint p7 - ,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jfloat p14 - ,jfloat p15,jfloat p16,jint p17,jfloat p18,jfloat p19,jfloat p20,jfloat p21 - ,jint p22,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jfloat p27,jfloat p28 - ,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jfloat p35 - ,jfloat p36,jfloat p37,jint p38,jint p39,jint p40,jfloat p41,jfloat p42 - ,jfloat p43,jfloat p44,jint p45,jfloat p46,jfloat p47,jint p48,jfloat p49 - ,jfloat p50,jfloat p51,jfloat p52,jint p53,jfloat p54,jfloat p55,jfloat p56 - ,jfloat p57,jfloat p58,jfloat p59,jfloat p60,jint p61,jfloat p62,jfloat p63 - ,jfloat p64,jfloat p65,jint p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 - ,jint p71,jfloat p72,jfloat p73,jfloat p74,jfloat p75,jfloat p76,jfloat p77 - ,jfloat p78,jfloat p79,jfloat p80,jfloat p81,jfloat p82,jfloat p83,jfloat p84 - ,jfloat p85,jfloat p86,jfloat p87,jfloat p88,jint p89,jint p90,jfloat p91 - ,jfloat p92,jfloat p93,jint p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98 - ,jfloat p99,jfloat p100,jint p101,jfloat p102,jfloat p103,jfloat p104,jint p105 - ,jint p106,jfloat p107,jint p108,jfloat p109,jfloat p110,jfloat p111,jfloat p112 - ,jfloat p113,jfloat p114,jint p115,jint p116,jfloat p117,jfloat p118,jint p119 - ,jfloat p120,jfloat p121,jfloat p122,jfloat p123,jfloat p124,jfloat p125 - ,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%d\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%d\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc34(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jbyte p5,jfloat p6,jfloat p7 - ,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jbyte p12,jfloat p13,jfloat p14 - ,jbyte p15,jfloat p16,jfloat p17,jbyte p18,jbyte p19,jfloat p20,jfloat p21 - ,jbyte p22,jfloat p23,jfloat p24,jbyte p25,jbyte p26,jbyte p27,jfloat p28 - ,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jfloat p35 - ,jbyte p36,jfloat p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jfloat p42 - ,jfloat p43,jfloat p44,jbyte p45,jfloat p46,jbyte p47,jfloat p48,jbyte p49 - ,jfloat p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54,jfloat p55,jfloat p56 - ,jbyte p57,jfloat p58,jfloat p59,jfloat p60,jfloat p61,jbyte p62,jfloat p63 - ,jfloat p64,jfloat p65,jfloat p66,jfloat p67,jbyte p68,jbyte p69,jfloat p70 - ,jfloat p71,jfloat p72,jfloat p73,jfloat p74,jbyte p75,jfloat p76,jfloat p77 - ,jbyte p78,jfloat p79,jfloat p80,jfloat p81,jfloat p82,jfloat p83,jfloat p84 - ,jfloat p85,jfloat p86,jbyte p87,jbyte p88,jfloat p89,jfloat p90,jfloat p91 - ,jfloat p92,jfloat p93,jfloat p94,jfloat p95,jfloat p96,jbyte p97,jfloat p98 - ,jfloat p99,jfloat p100,jfloat p101,jbyte p102,jfloat p103,jfloat p104,jbyte p105 - ,jfloat p106,jfloat p107,jfloat p108,jfloat p109,jfloat p110,jfloat p111 - ,jfloat p112,jbyte p113,jfloat p114,jfloat p115,jfloat p116,jfloat p117 - ,jfloat p118,jfloat p119,jfloat p120,jfloat p121,jfloat p122,jfloat p123 - ,jfloat p124,jbyte p125,jbyte p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%d\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%d\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc35(JNIEnv *e, jclass c -,jint p0,jbyte p1,jbyte p2,jfloat p3,jfloat p4,jfloat p5,jfloat p6,jfloat p7 - ,jint p8,jfloat p9,jint p10,jfloat p11,jfloat p12,jbyte p13,jbyte p14,jfloat p15 - ,jfloat p16,jbyte p17,jbyte p18,jfloat p19,jfloat p20,jfloat p21,jfloat p22 - ,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jint p27,jfloat p28,jfloat p29 - ,jfloat p30,jbyte p31,jfloat p32,jfloat p33,jfloat p34,jfloat p35,jbyte p36 - ,jfloat p37,jint p38,jfloat p39,jbyte p40,jbyte p41,jfloat p42,jfloat p43 - ,jfloat p44,jint p45,jfloat p46,jbyte p47,jbyte p48,jint p49,jfloat p50 - ,jint p51,jfloat p52,jfloat p53,jfloat p54,jbyte p55,jbyte p56,jfloat p57 - ,jfloat p58,jfloat p59,jint p60,jint p61,jfloat p62,jint p63,jbyte p64,jfloat p65 - ,jint p66,jfloat p67,jfloat p68,jbyte p69,jfloat p70,jfloat p71,jfloat p72 - ,jint p73,jfloat p74,jfloat p75,jfloat p76,jbyte p77,jfloat p78,jfloat p79 - ,jfloat p80,jbyte p81,jfloat p82,jbyte p83,jfloat p84,jfloat p85,jbyte p86 - ,jfloat p87,jfloat p88,jfloat p89,jfloat p90,jbyte p91,jfloat p92,jfloat p93 - ,jfloat p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98,jint p99,jfloat p100 - ,jfloat p101,jint p102,jfloat p103,jfloat p104,jbyte p105,jfloat p106,jint p107 - ,jfloat p108,jfloat p109,jfloat p110,jfloat p111,jfloat p112,jint p113,jfloat p114 - ,jfloat p115,jfloat p116,jfloat p117,jbyte p118,jfloat p119,jbyte p120,jfloat p121 - ,jfloat p122,jint p123,jfloat p124,jfloat p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc36(JNIEnv *e, jclass c -,jint p0,jint p1,jdouble p2,jdouble p3,jdouble p4,jdouble p5,jdouble p6 - ,jint p7,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jdouble p12,jdouble p13 - ,jdouble p14,jdouble p15,jdouble p16,jdouble p17,jint p18,jint p19,jdouble p20 - ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 - ,jdouble p27,jdouble p28,jdouble p29,jdouble p30,jdouble p31,jdouble p32 - ,jdouble p33,jdouble p34,jint p35,jdouble p36,jdouble p37,jdouble p38,jdouble p39 - ,jdouble p40,jdouble p41,jdouble p42,jdouble p43,jint p44,jdouble p45,jdouble p46 - ,jint p47,jint p48,jdouble p49,jdouble p50,jdouble p51,jdouble p52,jdouble p53 - ,jdouble p54,jdouble p55,jint p56,jdouble p57,jdouble p58,jdouble p59,jdouble p60 - ,jdouble p61,jdouble p62,jdouble p63,jdouble p64,jdouble p65,jdouble p66 - ,jdouble p67,jdouble p68,jdouble p69,jint p70,jdouble p71,jint p72,jdouble p73 - ,jdouble p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78,jdouble p79 - ,jint p80,jdouble p81,jdouble p82,jdouble p83,jdouble p84,jdouble p85,jdouble p86 - ,jdouble p87,jdouble p88,jdouble p89,jdouble p90,jdouble p91,jint p92,jdouble p93 - ,jdouble p94,jdouble p95,jdouble p96,jdouble p97,jdouble p98,jint p99,jint p100 - ,jint p101,jint p102,jint p103,jint p104,jint p105,jint p106,jdouble p107 - ,jdouble p108,jdouble p109,jint p110,jdouble p111,jdouble p112,jdouble p113 - ,jdouble p114,jdouble p115,jdouble p116,jdouble p117,jdouble p118,jdouble p119 - ,jdouble p120,jdouble p121,jdouble p122,jdouble p123,jdouble p124,jdouble p125 - ,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%d\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%d\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%d\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%d\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc37(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jdouble p4,jdouble p5,jdouble p6 - ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jbyte p11,jdouble p12,jdouble p13 - ,jdouble p14,jdouble p15,jdouble p16,jdouble p17,jdouble p18,jdouble p19 - ,jdouble p20,jdouble p21,jbyte p22,jbyte p23,jdouble p24,jdouble p25,jbyte p26 - ,jdouble p27,jdouble p28,jdouble p29,jdouble p30,jdouble p31,jdouble p32 - ,jdouble p33,jdouble p34,jdouble p35,jdouble p36,jdouble p37,jbyte p38,jbyte p39 - ,jdouble p40,jdouble p41,jdouble p42,jdouble p43,jdouble p44,jbyte p45,jdouble p46 - ,jdouble p47,jdouble p48,jbyte p49,jdouble p50,jdouble p51,jdouble p52,jdouble p53 - ,jdouble p54,jdouble p55,jbyte p56,jbyte p57,jdouble p58,jdouble p59,jdouble p60 - ,jdouble p61,jdouble p62,jdouble p63,jdouble p64,jdouble p65,jbyte p66,jdouble p67 - ,jdouble p68,jdouble p69,jdouble p70,jbyte p71,jdouble p72,jdouble p73,jdouble p74 - ,jdouble p75,jdouble p76,jdouble p77,jdouble p78,jdouble p79,jdouble p80 - ,jdouble p81,jdouble p82,jdouble p83,jdouble p84,jdouble p85,jdouble p86 - ,jdouble p87,jdouble p88,jdouble p89,jdouble p90,jdouble p91,jdouble p92 - ,jdouble p93,jdouble p94,jdouble p95,jbyte p96,jbyte p97,jdouble p98,jdouble p99 - ,jdouble p100,jdouble p101,jdouble p102,jdouble p103,jdouble p104,jdouble p105 - ,jdouble p106,jdouble p107,jdouble p108,jbyte p109,jdouble p110,jdouble p111 - ,jdouble p112,jdouble p113,jdouble p114,jdouble p115,jdouble p116,jdouble p117 - ,jbyte p118,jdouble p119,jdouble p120,jdouble p121,jdouble p122,jdouble p123 - ,jbyte p124,jdouble p125,jbyte p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%d\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%d\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc38(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jdouble p2,jint p3,jint p4,jdouble p5,jdouble p6 - ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jint p11,jdouble p12,jdouble p13 - ,jint p14,jbyte p15,jdouble p16,jdouble p17,jdouble p18,jdouble p19,jint p20 - ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jint p25,jdouble p26,jint p27 - ,jbyte p28,jdouble p29,jbyte p30,jdouble p31,jdouble p32,jint p33,jdouble p34 - ,jint p35,jbyte p36,jbyte p37,jdouble p38,jdouble p39,jdouble p40,jdouble p41 - ,jint p42,jdouble p43,jdouble p44,jdouble p45,jdouble p46,jdouble p47,jint p48 - ,jdouble p49,jint p50,jint p51,jdouble p52,jbyte p53,jdouble p54,jdouble p55 - ,jbyte p56,jdouble p57,jdouble p58,jdouble p59,jdouble p60,jdouble p61,jbyte p62 - ,jdouble p63,jdouble p64,jdouble p65,jbyte p66,jint p67,jdouble p68,jdouble p69 - ,jdouble p70,jdouble p71,jdouble p72,jbyte p73,jdouble p74,jdouble p75,jdouble p76 - ,jbyte p77,jdouble p78,jdouble p79,jdouble p80,jdouble p81,jdouble p82,jint p83 - ,jdouble p84,jdouble p85,jdouble p86,jint p87,jdouble p88,jint p89,jdouble p90 - ,jdouble p91,jdouble p92,jdouble p93,jdouble p94,jint p95,jbyte p96,jbyte p97 - ,jdouble p98,jint p99,jdouble p100,jdouble p101,jdouble p102,jdouble p103 - ,jdouble p104,jdouble p105,jdouble p106,jdouble p107,jdouble p108,jdouble p109 - ,jdouble p110,jdouble p111,jint p112,jdouble p113,jdouble p114,jdouble p115 - ,jdouble p116,jbyte p117,jdouble p118,jdouble p119,jbyte p120,jint p121 - ,jdouble p122,jint p123,jdouble p124,jdouble p125,jbyte p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%d\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%d\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%d\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc39(JNIEnv *e, jclass c -,jdouble p0,jfloat p1,jdouble p2,jbyte p3,jdouble p4,jint p5,jdouble p6 - ,jfloat p7,jfloat p8,jdouble p9,jint p10,jbyte p11,jfloat p12,jdouble p13 - ,jint p14,jint p15,jfloat p16,jbyte p17,jdouble p18,jdouble p19,jfloat p20 - ,jfloat p21,jdouble p22,jfloat p23,jfloat p24,jdouble p25,jfloat p26,jfloat p27 - ,jfloat p28,jfloat p29,jfloat p30,jdouble p31,jdouble p32,jdouble p33,jfloat p34 - ,jdouble p35,jfloat p36,jdouble p37,jfloat p38,jfloat p39,jfloat p40,jint p41 - ,jbyte p42,jdouble p43,jfloat p44,jfloat p45,jint p46,jbyte p47,jfloat p48 - ,jdouble p49,jdouble p50,jfloat p51,jfloat p52,jfloat p53,jdouble p54,jint p55 - ,jfloat p56,jfloat p57,jfloat p58,jfloat p59,jfloat p60,jdouble p61,jdouble p62 - ,jfloat p63,jfloat p64,jfloat p65,jdouble p66,jfloat p67,jdouble p68,jdouble p69 - ,jdouble p70,jdouble p71,jdouble p72,jdouble p73,jdouble p74,jfloat p75 - ,jint p76,jfloat p77,jdouble p78,jdouble p79,jdouble p80,jdouble p81,jbyte p82 - ,jfloat p83,jfloat p84,jfloat p85,jfloat p86,jdouble p87,jfloat p88,jfloat p89 - ,jfloat p90,jfloat p91,jfloat p92,jdouble p93,jfloat p94,jdouble p95,jfloat p96 - ,jdouble p97,jfloat p98,jfloat p99,jdouble p100,jdouble p101,jfloat p102 - ,jfloat p103,jdouble p104,jdouble p105,jfloat p106,jbyte p107,jdouble p108 - ,jfloat p109,jfloat p110,jdouble p111,jdouble p112,jdouble p113,jdouble p114 - ,jdouble p115,jdouble p116,jfloat p117,jdouble p118,jfloat p119,jfloat p120 - ,jfloat p121,jfloat p122,jfloat p123,jdouble p124,jfloat p125,jfloat p126 - ) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc40(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jfloat p2,jdouble p3,jdouble p4,jfloat p5,jdouble p6 - ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jdouble p12,jfloat p13 - ,jfloat p14,jdouble p15,jfloat p16,jfloat p17,jdouble p18,jfloat p19,jdouble p20 - ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 - ,jfloat p27,jfloat p28,jdouble p29,jdouble p30,jdouble p31,jfloat p32,jfloat p33 - ,jfloat p34,jfloat p35,jdouble p36,jfloat p37,jfloat p38,jfloat p39,jdouble p40 - ,jfloat p41,jdouble p42,jdouble p43,jfloat p44,jdouble p45,jdouble p46,jdouble p47 - ,jfloat p48,jdouble p49,jdouble p50,jdouble p51,jdouble p52,jfloat p53,jdouble p54 - ,jdouble p55,jdouble p56,jdouble p57,jdouble p58,jdouble p59,jdouble p60 - ,jdouble p61,jdouble p62,jfloat p63,jfloat p64,jfloat p65,jfloat p66,jfloat p67 - ,jdouble p68,jdouble p69,jdouble p70,jdouble p71,jdouble p72,jdouble p73 - ,jfloat p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78,jdouble p79 - ,jfloat p80,jdouble p81,jdouble p82,jfloat p83,jdouble p84,jdouble p85,jdouble p86 - ,jfloat p87,jfloat p88,jdouble p89,jfloat p90,jdouble p91,jfloat p92,jfloat p93 - ,jfloat p94,jfloat p95,jdouble p96,jfloat p97,jfloat p98,jdouble p99,jdouble p100 - ,jdouble p101,jdouble p102,jfloat p103,jdouble p104,jdouble p105,jdouble p106 - ,jdouble p107,jdouble p108,jdouble p109,jfloat p110,jfloat p111,jdouble p112 - ,jdouble p113,jdouble p114,jdouble p115,jdouble p116,jdouble p117,jdouble p118 - ,jdouble p119,jfloat p120,jdouble p121,jdouble p122,jdouble p123,jdouble p124 - ,jdouble p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc41(JNIEnv *e, jclass c -,jfloat p0,jdouble p1,jint p2,jdouble p3,jint p4,jfloat p5,jfloat p6,jfloat p7 - ,jint p8,jint p9,jfloat p10,jdouble p11,jdouble p12,jdouble p13,jint p14 - ,jdouble p15,jdouble p16,jfloat p17,jdouble p18,jdouble p19,jdouble p20 - ,jint p21,jdouble p22,jfloat p23,jdouble p24,jfloat p25,jdouble p26,jdouble p27 - ,jint p28,jdouble p29,jdouble p30,jint p31,jdouble p32,jdouble p33,jfloat p34 - ,jint p35,jdouble p36,jint p37,jint p38,jdouble p39,jfloat p40,jint p41 - ,jdouble p42,jdouble p43,jdouble p44,jdouble p45,jint p46,jdouble p47,jfloat p48 - ,jfloat p49,jfloat p50,jdouble p51,jdouble p52,jfloat p53,jfloat p54,jdouble p55 - ,jfloat p56,jfloat p57,jdouble p58,jfloat p59,jdouble p60,jfloat p61,jdouble p62 - ,jfloat p63,jdouble p64,jdouble p65,jdouble p66,jdouble p67,jdouble p68 - ,jdouble p69,jfloat p70,jfloat p71,jdouble p72,jfloat p73,jdouble p74,jfloat p75 - ,jint p76,jfloat p77,jdouble p78,jint p79,jfloat p80,jfloat p81,jdouble p82 - ,jdouble p83,jdouble p84,jdouble p85,jdouble p86,jfloat p87,jfloat p88,jfloat p89 - ,jdouble p90,jint p91,jfloat p92,jdouble p93,jfloat p94,jfloat p95,jfloat p96 - ,jfloat p97,jfloat p98,jdouble p99,jfloat p100,jint p101,jdouble p102,jfloat p103 - ,jdouble p104,jdouble p105,jfloat p106,jfloat p107,jdouble p108,jfloat p109 - ,jfloat p110,jdouble p111,jfloat p112,jdouble p113,jfloat p114,jfloat p115 - ,jfloat p116,jdouble p117,jint p118,jfloat p119,jint p120,jdouble p121,jdouble p122 - ,jint p123,jdouble p124,jfloat p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%d\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc42(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jdouble p2,jdouble p3,jfloat p4,jdouble p5,jdouble p6 - ,jfloat p7,jdouble p8,jdouble p9,jfloat p10,jdouble p11,jbyte p12,jfloat p13 - ,jfloat p14,jfloat p15,jdouble p16,jdouble p17,jfloat p18,jdouble p19,jdouble p20 - ,jdouble p21,jfloat p22,jfloat p23,jdouble p24,jfloat p25,jdouble p26,jfloat p27 - ,jfloat p28,jfloat p29,jfloat p30,jfloat p31,jdouble p32,jfloat p33,jbyte p34 - ,jfloat p35,jdouble p36,jfloat p37,jdouble p38,jfloat p39,jdouble p40,jbyte p41 - ,jbyte p42,jdouble p43,jfloat p44,jdouble p45,jfloat p46,jfloat p47,jdouble p48 - ,jdouble p49,jfloat p50,jdouble p51,jdouble p52,jdouble p53,jdouble p54 - ,jfloat p55,jdouble p56,jfloat p57,jbyte p58,jdouble p59,jfloat p60,jdouble p61 - ,jdouble p62,jdouble p63,jfloat p64,jfloat p65,jdouble p66,jdouble p67,jbyte p68 - ,jfloat p69,jfloat p70,jdouble p71,jfloat p72,jfloat p73,jdouble p74,jdouble p75 - ,jfloat p76,jfloat p77,jfloat p78,jdouble p79,jdouble p80,jdouble p81,jbyte p82 - ,jfloat p83,jdouble p84,jdouble p85,jdouble p86,jdouble p87,jdouble p88 - ,jdouble p89,jfloat p90,jdouble p91,jfloat p92,jbyte p93,jfloat p94,jdouble p95 - ,jdouble p96,jfloat p97,jdouble p98,jfloat p99,jfloat p100,jfloat p101,jdouble p102 - ,jdouble p103,jdouble p104,jfloat p105,jfloat p106,jfloat p107,jfloat p108 - ,jdouble p109,jfloat p110,jdouble p111,jdouble p112,jdouble p113,jfloat p114 - ,jdouble p115,jfloat p116,jbyte p117,jdouble p118,jfloat p119,jdouble p120 - ,jfloat p121,jbyte p122,jfloat p123,jdouble p124,jfloat p125,jfloat p126 - ) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc43(JNIEnv *e, jclass c -,jfloat p0,jint p1,jfloat p2,jfloat p3,jfloat p4,jfloat p5,jfloat p6,jint p7 - ,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jint p14 - ,jfloat p15,jfloat p16,jfloat p17,jfloat p18,jfloat p19,jfloat p20,jfloat p21 - ,jfloat p22,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jfloat p27,jfloat p28 - ,jfloat p29,jfloat p30,jfloat p31,jint p32,jfloat p33,jfloat p34,jfloat p35 - ,jfloat p36,jfloat p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jint p42 - ,jfloat p43,jfloat p44,jfloat p45,jfloat p46,jfloat p47,jfloat p48,jint p49 - ,jint p50,jint p51,jfloat p52,jfloat p53,jfloat p54,jfloat p55,jfloat p56 - ,jfloat p57,jfloat p58,jfloat p59,jfloat p60,jint p61,jfloat p62,jint p63 - ,jfloat p64,jfloat p65,jfloat p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 - ,jfloat p71,jfloat p72,jfloat p73,jfloat p74,jfloat p75,jfloat p76,jfloat p77 - ,jfloat p78,jint p79,jint p80,jint p81,jfloat p82,jfloat p83,jfloat p84 - ,jfloat p85,jfloat p86,jfloat p87,jfloat p88,jfloat p89,jfloat p90,jfloat p91 - ,jfloat p92,jfloat p93,jfloat p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98 - ,jfloat p99,jfloat p100,jfloat p101,jfloat p102,jfloat p103,jfloat p104 - ,jfloat p105,jfloat p106,jfloat p107,jfloat p108,jfloat p109,jfloat p110 - ,jint p111,jfloat p112,jfloat p113,jfloat p114,jfloat p115,jfloat p116,jfloat p117 - ,jfloat p118,jfloat p119,jfloat p120,jfloat p121,jfloat p122,jfloat p123 - ,jfloat p124,jint p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); - fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc44(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jbyte p5,jfloat p6,jfloat p7 - ,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jfloat p14 - ,jbyte p15,jfloat p16,jfloat p17,jfloat p18,jbyte p19,jfloat p20,jfloat p21 - ,jfloat p22,jfloat p23,jfloat p24,jbyte p25,jfloat p26,jfloat p27,jfloat p28 - ,jfloat p29,jfloat p30,jfloat p31,jbyte p32,jbyte p33,jfloat p34,jfloat p35 - ,jfloat p36,jfloat p37,jbyte p38,jfloat p39,jfloat p40,jbyte p41,jfloat p42 - ,jfloat p43,jfloat p44,jfloat p45,jfloat p46,jfloat p47,jbyte p48,jfloat p49 - ,jbyte p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54,jfloat p55,jfloat p56 - ,jfloat p57,jfloat p58,jbyte p59,jfloat p60,jfloat p61,jfloat p62,jfloat p63 - ,jfloat p64,jfloat p65,jbyte p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 - ,jbyte p71,jfloat p72,jbyte p73,jbyte p74,jfloat p75,jfloat p76,jbyte p77 - ,jbyte p78,jfloat p79,jfloat p80,jfloat p81,jfloat p82,jfloat p83,jfloat p84 - ,jfloat p85,jfloat p86,jfloat p87,jfloat p88,jfloat p89,jfloat p90,jfloat p91 - ,jfloat p92,jbyte p93,jfloat p94,jfloat p95,jfloat p96,jbyte p97,jfloat p98 - ,jfloat p99,jfloat p100,jbyte p101,jfloat p102,jfloat p103,jfloat p104,jfloat p105 - ,jfloat p106,jfloat p107,jbyte p108,jfloat p109,jfloat p110,jfloat p111 - ,jfloat p112,jbyte p113,jfloat p114,jfloat p115,jfloat p116,jbyte p117,jfloat p118 - ,jfloat p119,jfloat p120,jbyte p121,jfloat p122,jfloat p123,jfloat p124 - ,jfloat p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%d\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc45(JNIEnv *e, jclass c -,jbyte p0,jbyte p1,jfloat p2,jfloat p3,jfloat p4,jbyte p5,jint p6,jfloat p7 - ,jfloat p8,jbyte p9,jfloat p10,jbyte p11,jbyte p12,jfloat p13,jfloat p14 - ,jfloat p15,jfloat p16,jbyte p17,jfloat p18,jint p19,jint p20,jfloat p21 - ,jfloat p22,jfloat p23,jbyte p24,jbyte p25,jfloat p26,jfloat p27,jbyte p28 - ,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jint p35 - ,jfloat p36,jint p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jfloat p42 - ,jbyte p43,jfloat p44,jint p45,jbyte p46,jfloat p47,jfloat p48,jfloat p49 - ,jbyte p50,jfloat p51,jbyte p52,jfloat p53,jfloat p54,jfloat p55,jfloat p56 - ,jfloat p57,jfloat p58,jfloat p59,jint p60,jint p61,jfloat p62,jbyte p63 - ,jfloat p64,jint p65,jfloat p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 - ,jfloat p71,jfloat p72,jfloat p73,jfloat p74,jint p75,jfloat p76,jfloat p77 - ,jbyte p78,jfloat p79,jfloat p80,jfloat p81,jfloat p82,jbyte p83,jint p84 - ,jbyte p85,jfloat p86,jint p87,jfloat p88,jfloat p89,jfloat p90,jfloat p91 - ,jfloat p92,jint p93,jfloat p94,jfloat p95,jint p96,jfloat p97,jbyte p98 - ,jfloat p99,jbyte p100,jfloat p101,jint p102,jfloat p103,jfloat p104,jint p105 - ,jfloat p106,jfloat p107,jint p108,jfloat p109,jfloat p110,jfloat p111,jfloat p112 - ,jint p113,jfloat p114,jfloat p115,jfloat p116,jfloat p117,jfloat p118,jint p119 - ,jfloat p120,jbyte p121,jfloat p122,jfloat p123,jfloat p124,jbyte p125,jfloat p126 - ) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%d\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%d\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); - fprintf(file,"p84=%d\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%d\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%d\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc46(JNIEnv *e, jclass c -,jint p0,jdouble p1,jdouble p2,jdouble p3,jdouble p4,jdouble p5,jdouble p6 - ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jint p11,jdouble p12,jdouble p13 - ,jdouble p14,jdouble p15,jint p16,jdouble p17,jdouble p18,jdouble p19,jdouble p20 - ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 - ,jdouble p27,jint p28,jdouble p29,jdouble p30,jdouble p31,jdouble p32,jdouble p33 - ,jdouble p34,jdouble p35,jint p36,jint p37,jdouble p38,jint p39,jdouble p40 - ,jdouble p41,jdouble p42,jdouble p43,jdouble p44,jdouble p45,jdouble p46 - ,jdouble p47,jdouble p48,jdouble p49,jdouble p50,jdouble p51,jint p52,jdouble p53 - ,jdouble p54,jdouble p55,jdouble p56,jdouble p57,jdouble p58,jdouble p59 - ,jdouble p60,jdouble p61,jdouble p62,jdouble p63,jint p64,jdouble p65,jdouble p66 - ,jint p67,jint p68,jdouble p69,jdouble p70,jdouble p71,jdouble p72,jdouble p73 - ,jdouble p74,jdouble p75,jdouble p76,jint p77,jint p78,jdouble p79,jdouble p80 - ,jdouble p81,jint p82,jdouble p83,jdouble p84,jint p85,jdouble p86,jdouble p87 - ,jdouble p88,jint p89,jdouble p90,jdouble p91,jdouble p92,jint p93,jdouble p94 - ,jint p95,jdouble p96,jdouble p97,jdouble p98,jdouble p99,jdouble p100,jdouble p101 - ,jint p102,jdouble p103,jdouble p104,jdouble p105,jdouble p106,jdouble p107 - ,jdouble p108,jdouble p109,jdouble p110,jdouble p111,jdouble p112,jdouble p113 - ,jdouble p114,jdouble p115,jint p116,jint p117,jdouble p118,jdouble p119 - ,jdouble p120,jint p121,jdouble p122,jint p123,jint p124,jdouble p125,jdouble p126 - ) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc47(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jbyte p4,jdouble p5,jdouble p6 - ,jdouble p7,jbyte p8,jbyte p9,jdouble p10,jdouble p11,jdouble p12,jdouble p13 - ,jdouble p14,jdouble p15,jdouble p16,jdouble p17,jdouble p18,jdouble p19 - ,jdouble p20,jdouble p21,jbyte p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 - ,jbyte p27,jdouble p28,jdouble p29,jdouble p30,jdouble p31,jdouble p32,jdouble p33 - ,jdouble p34,jdouble p35,jdouble p36,jbyte p37,jbyte p38,jdouble p39,jdouble p40 - ,jdouble p41,jdouble p42,jdouble p43,jdouble p44,jdouble p45,jbyte p46,jdouble p47 - ,jdouble p48,jdouble p49,jdouble p50,jdouble p51,jbyte p52,jdouble p53,jdouble p54 - ,jdouble p55,jdouble p56,jdouble p57,jdouble p58,jdouble p59,jdouble p60 - ,jdouble p61,jdouble p62,jdouble p63,jdouble p64,jdouble p65,jdouble p66 - ,jdouble p67,jdouble p68,jdouble p69,jbyte p70,jdouble p71,jdouble p72,jdouble p73 - ,jdouble p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78,jdouble p79 - ,jdouble p80,jdouble p81,jdouble p82,jdouble p83,jdouble p84,jdouble p85 - ,jdouble p86,jdouble p87,jdouble p88,jdouble p89,jdouble p90,jdouble p91 - ,jdouble p92,jdouble p93,jbyte p94,jdouble p95,jdouble p96,jdouble p97,jdouble p98 - ,jdouble p99,jdouble p100,jbyte p101,jdouble p102,jdouble p103,jbyte p104 - ,jdouble p105,jdouble p106,jdouble p107,jdouble p108,jdouble p109,jdouble p110 - ,jdouble p111,jdouble p112,jdouble p113,jbyte p114,jdouble p115,jdouble p116 - ,jdouble p117,jdouble p118,jdouble p119,jbyte p120,jdouble p121,jbyte p122 - ,jdouble p123,jdouble p124,jdouble p125,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%d\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc48(JNIEnv *e, jclass c -,jint p0,jdouble p1,jdouble p2,jdouble p3,jbyte p4,jdouble p5,jdouble p6 - ,jdouble p7,jdouble p8,jbyte p9,jint p10,jdouble p11,jbyte p12,jint p13 - ,jdouble p14,jdouble p15,jdouble p16,jdouble p17,jdouble p18,jint p19,jdouble p20 - ,jdouble p21,jint p22,jdouble p23,jdouble p24,jint p25,jdouble p26,jint p27 - ,jbyte p28,jbyte p29,jdouble p30,jdouble p31,jdouble p32,jbyte p33,jdouble p34 - ,jdouble p35,jdouble p36,jdouble p37,jdouble p38,jdouble p39,jdouble p40 - ,jdouble p41,jbyte p42,jint p43,jdouble p44,jbyte p45,jdouble p46,jbyte p47 - ,jdouble p48,jdouble p49,jbyte p50,jbyte p51,jdouble p52,jdouble p53,jint p54 - ,jdouble p55,jdouble p56,jint p57,jdouble p58,jdouble p59,jdouble p60,jdouble p61 - ,jint p62,jdouble p63,jdouble p64,jdouble p65,jbyte p66,jdouble p67,jdouble p68 - ,jdouble p69,jdouble p70,jdouble p71,jdouble p72,jbyte p73,jdouble p74,jdouble p75 - ,jint p76,jint p77,jint p78,jbyte p79,jdouble p80,jdouble p81,jbyte p82 - ,jdouble p83,jdouble p84,jbyte p85,jdouble p86,jint p87,jint p88,jdouble p89 - ,jdouble p90,jdouble p91,jdouble p92,jdouble p93,jint p94,jdouble p95,jdouble p96 - ,jdouble p97,jbyte p98,jdouble p99,jbyte p100,jbyte p101,jdouble p102,jdouble p103 - ,jdouble p104,jint p105,jdouble p106,jdouble p107,jdouble p108,jbyte p109 - ,jdouble p110,jdouble p111,jdouble p112,jdouble p113,jdouble p114,jdouble p115 - ,jdouble p116,jdouble p117,jdouble p118,jdouble p119,jint p120,jdouble p121 - ,jdouble p122,jdouble p123,jdouble p124,jdouble p125,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%d\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); - fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%d\n",p77); - fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%d\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc49(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jdouble p2,jfloat p3,jfloat p4,jbyte p5,jdouble p6 - ,jint p7,jdouble p8,jfloat p9,jbyte p10,jfloat p11,jdouble p12,jfloat p13 - ,jdouble p14,jdouble p15,jdouble p16,jfloat p17,jfloat p18,jdouble p19,jfloat p20 - ,jfloat p21,jint p22,jfloat p23,jbyte p24,jfloat p25,jbyte p26,jdouble p27 - ,jdouble p28,jdouble p29,jdouble p30,jdouble p31,jdouble p32,jint p33,jfloat p34 - ,jfloat p35,jbyte p36,jfloat p37,jfloat p38,jfloat p39,jdouble p40,jbyte p41 - ,jint p42,jfloat p43,jdouble p44,jfloat p45,jdouble p46,jint p47,jbyte p48 - ,jdouble p49,jfloat p50,jdouble p51,jfloat p52,jfloat p53,jfloat p54,jfloat p55 - ,jfloat p56,jdouble p57,jbyte p58,jfloat p59,jfloat p60,jfloat p61,jfloat p62 - ,jfloat p63,jfloat p64,jfloat p65,jbyte p66,jdouble p67,jbyte p68,jfloat p69 - ,jfloat p70,jdouble p71,jdouble p72,jdouble p73,jint p74,jdouble p75,jfloat p76 - ,jfloat p77,jfloat p78,jfloat p79,jdouble p80,jfloat p81,jdouble p82,jfloat p83 - ,jfloat p84,jint p85,jfloat p86,jdouble p87,jdouble p88,jfloat p89,jint p90 - ,jdouble p91,jdouble p92,jdouble p93,jfloat p94,jfloat p95,jdouble p96,jdouble p97 - ,jfloat p98,jdouble p99,jfloat p100,jfloat p101,jfloat p102,jfloat p103 - ,jdouble p104,jfloat p105,jdouble p106,jfloat p107,jdouble p108,jfloat p109 - ,jfloat p110,jdouble p111,jfloat p112,jbyte p113,jfloat p114,jdouble p115 - ,jdouble p116,jfloat p117,jdouble p118,jdouble p119,jbyte p120,jfloat p121 - ,jfloat p122,jbyte p123,jdouble p124,jdouble p125,jfloat p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%d\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); - fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); - fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc50(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jfloat p4,jfloat p5,jdouble p6 - ,jfloat p7,jdouble p8,jfloat p9,jdouble p10,jdouble p11,jdouble p12,jdouble p13 - ,jdouble p14,jdouble p15,jfloat p16,jdouble p17,jfloat p18,jdouble p19,jfloat p20 - ,jdouble p21,jfloat p22,jdouble p23,jdouble p24,jdouble p25,jfloat p26,jdouble p27 - ,jdouble p28,jdouble p29,jdouble p30,jdouble p31,jfloat p32,jfloat p33,jdouble p34 - ,jdouble p35,jdouble p36,jdouble p37,jfloat p38,jdouble p39,jdouble p40 - ,jdouble p41,jdouble p42,jdouble p43,jdouble p44,jdouble p45,jdouble p46 - ,jfloat p47,jdouble p48,jfloat p49,jdouble p50,jdouble p51,jdouble p52,jdouble p53 - ,jdouble p54,jdouble p55,jdouble p56,jdouble p57,jdouble p58,jdouble p59 - ,jdouble p60,jdouble p61,jfloat p62,jfloat p63,jdouble p64,jdouble p65,jdouble p66 - ,jdouble p67,jdouble p68,jdouble p69,jdouble p70,jfloat p71,jdouble p72 - ,jdouble p73,jfloat p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78 - ,jdouble p79,jdouble p80,jdouble p81,jdouble p82,jfloat p83,jfloat p84,jdouble p85 - ,jdouble p86,jfloat p87,jdouble p88,jdouble p89,jfloat p90,jdouble p91,jdouble p92 - ,jdouble p93,jfloat p94,jdouble p95,jfloat p96,jdouble p97,jdouble p98,jfloat p99 - ,jdouble p100,jfloat p101,jdouble p102,jdouble p103,jdouble p104,jdouble p105 - ,jdouble p106,jdouble p107,jdouble p108,jdouble p109,jfloat p110,jdouble p111 - ,jdouble p112,jdouble p113,jdouble p114,jfloat p115,jdouble p116,jdouble p117 - ,jdouble p118,jfloat p119,jdouble p120,jdouble p121,jdouble p122,jdouble p123 - ,jdouble p124,jdouble p125,jdouble p126) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc51(JNIEnv *e, jclass c -,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jdouble p5,jfloat p6 - ,jfloat p7,jdouble p8,jdouble p9,jint p10,jfloat p11,jdouble p12,jdouble p13 - ,jfloat p14,jdouble p15,jdouble p16,jdouble p17,jdouble p18,jdouble p19 - ,jfloat p20,jdouble p21,jfloat p22,jint p23,jdouble p24,jdouble p25,jfloat p26 - ,jint p27,jdouble p28,jfloat p29,jfloat p30,jdouble p31,jint p32,jint p33 - ,jfloat p34,jfloat p35,jdouble p36,jfloat p37,jfloat p38,jfloat p39,jfloat p40 - ,jfloat p41,jdouble p42,jdouble p43,jdouble p44,jint p45,jdouble p46,jfloat p47 - ,jfloat p48,jdouble p49,jdouble p50,jfloat p51,jfloat p52,jfloat p53,jdouble p54 - ,jfloat p55,jdouble p56,jfloat p57,jfloat p58,jint p59,jint p60,jdouble p61 - ,jdouble p62,jdouble p63,jfloat p64,jfloat p65,jdouble p66,jint p67,jint p68 - ,jfloat p69,jint p70,jdouble p71,jint p72,jfloat p73,jfloat p74,jdouble p75 - ,jdouble p76,jdouble p77,jfloat p78,jfloat p79,jfloat p80,jdouble p81,jdouble p82 - ,jfloat p83,jfloat p84,jdouble p85,jfloat p86,jint p87,jfloat p88,jfloat p89 - ,jdouble p90,jfloat p91,jdouble p92,jdouble p93,jint p94,jfloat p95,jfloat p96 - ,jfloat p97,jdouble p98,jdouble p99,jdouble p100,jdouble p101,jfloat p102 - ,jfloat p103,jdouble p104,jfloat p105,jdouble p106,jdouble p107,jfloat p108 - ,jfloat p109,jdouble p110,jfloat p111,jfloat p112,jfloat p113,jfloat p114 - ,jfloat p115,jdouble p116,jfloat p117,jdouble p118,jdouble p119,jdouble p120 - ,jfloat p121,jfloat p122,jfloat p123,jdouble p124,jdouble p125,jfloat p126 - ) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%d\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); - fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%d\n",p59); - fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} -JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc52(JNIEnv *e, jclass c -,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jdouble p4,jbyte p5,jfloat p6 - ,jdouble p7,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jdouble p12,jfloat p13 - ,jdouble p14,jdouble p15,jdouble p16,jfloat p17,jfloat p18,jdouble p19,jdouble p20 - ,jdouble p21,jdouble p22,jfloat p23,jdouble p24,jfloat p25,jfloat p26,jdouble p27 - ,jdouble p28,jfloat p29,jdouble p30,jfloat p31,jfloat p32,jfloat p33,jdouble p34 - ,jdouble p35,jdouble p36,jfloat p37,jfloat p38,jdouble p39,jdouble p40,jfloat p41 - ,jfloat p42,jfloat p43,jfloat p44,jbyte p45,jfloat p46,jdouble p47,jfloat p48 - ,jfloat p49,jdouble p50,jfloat p51,jbyte p52,jfloat p53,jfloat p54,jdouble p55 - ,jfloat p56,jdouble p57,jbyte p58,jdouble p59,jdouble p60,jdouble p61,jdouble p62 - ,jfloat p63,jdouble p64,jbyte p65,jfloat p66,jfloat p67,jbyte p68,jdouble p69 - ,jbyte p70,jdouble p71,jdouble p72,jdouble p73,jfloat p74,jdouble p75,jbyte p76 - ,jdouble p77,jdouble p78,jdouble p79,jdouble p80,jfloat p81,jdouble p82 - ,jdouble p83,jdouble p84,jfloat p85,jfloat p86,jfloat p87,jfloat p88,jdouble p89 - ,jfloat p90,jfloat p91,jfloat p92,jdouble p93,jbyte p94,jdouble p95,jfloat p96 - ,jfloat p97,jdouble p98,jdouble p99,jfloat p100,jdouble p101,jbyte p102 - ,jbyte p103,jfloat p104,jfloat p105,jdouble p106,jfloat p107,jbyte p108 - ,jfloat p109,jdouble p110,jfloat p111,jbyte p112,jbyte p113,jdouble p114 - ,jdouble p115,jdouble p116,jbyte p117,jfloat p118,jdouble p119,jdouble p120 - ,jfloat p121,jdouble p122,jdouble p123,jdouble p124,jdouble p125,jfloat p126 - ) -{ - FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); - fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); - fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); - fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); - fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); - fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); - fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); - fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); - fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); - fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); - fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); - fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); - fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); - fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); - fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); - fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); - fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); - fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); - fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); - fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); - fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); - fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); - fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); - fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); - fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); - fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); - fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); - fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); - fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); - fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); - fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); - fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); - fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); - fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); - fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%e\n",p104); - fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); - fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); - fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%d\n",p113); - fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); - fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); - fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); - fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); - fprintf(file,"p126=%e\n",p126); - fclose(file); -} diff --git a/test/hotspot/jtreg/vmTestbase/vm/jit/LongTransitions/libLTTest.cpp b/test/hotspot/jtreg/vmTestbase/vm/jit/LongTransitions/libLTTest.cpp new file mode 100644 index 00000000000..f18f41ef1d3 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/vm/jit/LongTransitions/libLTTest.cpp @@ -0,0 +1,3469 @@ +/* + * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc1(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jfloat p5,jfloat p6,jfloat p7 + ,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jfloat p14 + ,jfloat p15,jfloat p16,jfloat p17,jfloat p18,jfloat p19,jfloat p20,jfloat p21 + ,jfloat p22,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jfloat p27,jfloat p28 + ,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jfloat p35 + ,jfloat p36,jfloat p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jfloat p42 + ,jfloat p43,jfloat p44,jfloat p45,jfloat p46,jfloat p47,jfloat p48,jfloat p49 + ,jfloat p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54,jfloat p55,jfloat p56 + ,jfloat p57,jfloat p58,jfloat p59,jfloat p60,jfloat p61,jfloat p62,jfloat p63 + ,jfloat p64,jfloat p65,jfloat p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 + ,jfloat p71,jfloat p72,jfloat p73,jfloat p74,jfloat p75,jfloat p76,jfloat p77 + ,jfloat p78,jfloat p79,jfloat p80,jfloat p81,jfloat p82,jfloat p83,jfloat p84 + ,jfloat p85,jfloat p86,jfloat p87,jfloat p88,jfloat p89,jfloat p90,jfloat p91 + ,jfloat p92,jfloat p93,jfloat p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98 + ,jfloat p99,jfloat p100,jfloat p101,jfloat p102,jfloat p103,jfloat p104 + ,jfloat p105,jfloat p106,jfloat p107,jfloat p108,jfloat p109,jfloat p110 + ,jfloat p111,jfloat p112,jfloat p113,jfloat p114,jfloat p115,jfloat p116 + ,jfloat p117,jfloat p118,jfloat p119,jfloat p120,jfloat p121,jfloat p122 + ,jfloat p123,jfloat p124,jfloat p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc2(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jdouble p4,jdouble p5,jdouble p6 + ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jdouble p12,jdouble p13 + ,jdouble p14,jdouble p15,jdouble p16,jdouble p17,jdouble p18,jdouble p19 + ,jdouble p20,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25 + ,jdouble p26,jdouble p27,jdouble p28,jdouble p29,jdouble p30,jdouble p31 + ,jdouble p32,jdouble p33,jdouble p34,jdouble p35,jdouble p36,jdouble p37 + ,jdouble p38,jdouble p39,jdouble p40,jdouble p41,jdouble p42,jdouble p43 + ,jdouble p44,jdouble p45,jdouble p46,jdouble p47,jdouble p48,jdouble p49 + ,jdouble p50,jdouble p51,jdouble p52,jdouble p53,jdouble p54,jdouble p55 + ,jdouble p56,jdouble p57,jdouble p58,jdouble p59,jdouble p60,jdouble p61 + ,jdouble p62,jdouble p63,jdouble p64,jdouble p65,jdouble p66,jdouble p67 + ,jdouble p68,jdouble p69,jdouble p70,jdouble p71,jdouble p72,jdouble p73 + ,jdouble p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78,jdouble p79 + ,jdouble p80,jdouble p81,jdouble p82,jdouble p83,jdouble p84,jdouble p85 + ,jdouble p86,jdouble p87,jdouble p88,jdouble p89,jdouble p90,jdouble p91 + ,jdouble p92,jdouble p93,jdouble p94,jdouble p95,jdouble p96,jdouble p97 + ,jdouble p98,jdouble p99,jdouble p100,jdouble p101,jdouble p102,jdouble p103 + ,jdouble p104,jdouble p105,jdouble p106,jdouble p107,jdouble p108,jdouble p109 + ,jdouble p110,jdouble p111,jdouble p112,jdouble p113,jdouble p114,jdouble p115 + ,jdouble p116,jdouble p117,jdouble p118,jdouble p119,jdouble p120,jdouble p121 + ,jdouble p122,jdouble p123,jdouble p124,jdouble p125,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc3(JNIEnv *e, jclass c +,jfloat p0,jint p1,jint p2,jint p3,jint p4,jfloat p5,jint p6,jfloat p7,jint p8 + ,jfloat p9,jint p10,jint p11,jfloat p12,jfloat p13,jfloat p14,jfloat p15 + ,jint p16,jint p17,jint p18,jfloat p19,jint p20,jfloat p21,jfloat p22,jfloat p23 + ,jfloat p24,jint p25,jfloat p26,jint p27,jfloat p28,jfloat p29,jfloat p30 + ,jint p31,jint p32,jfloat p33,jfloat p34,jfloat p35,jint p36,jfloat p37 + ,jint p38,jfloat p39,jint p40,jfloat p41,jfloat p42,jfloat p43,jint p44 + ,jint p45,jfloat p46,jfloat p47,jfloat p48,jfloat p49,jint p50,jint p51 + ,jint p52,jfloat p53,jint p54,jfloat p55,jint p56,jfloat p57,jfloat p58 + ,jfloat p59,jfloat p60,jint p61,jint p62,jint p63,jfloat p64,jfloat p65 + ,jfloat p66,jfloat p67,jint p68,jint p69,jfloat p70,jfloat p71,jint p72 + ,jint p73,jfloat p74,jint p75,jint p76,jint p77,jfloat p78,jfloat p79,jfloat p80 + ,jint p81,jfloat p82,jint p83,jfloat p84,jfloat p85,jfloat p86,jfloat p87 + ,jint p88,jint p89,jint p90,jfloat p91,jint p92,jint p93,jfloat p94,jfloat p95 + ,jint p96,jfloat p97,jfloat p98,jfloat p99,jint p100,jfloat p101,jfloat p102 + ,jint p103,jfloat p104,jfloat p105,jint p106,jfloat p107,jfloat p108,jint p109 + ,jfloat p110,jfloat p111,jint p112,jfloat p113,jint p114,jfloat p115,jint p116 + ,jint p117,jfloat p118,jfloat p119,jint p120,jfloat p121,jint p122,jfloat p123 + ,jint p124,jint p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%d\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%d\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc4(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jfloat p2,jbyte p3,jfloat p4,jfloat p5,jfloat p6,jbyte p7 + ,jfloat p8,jbyte p9,jfloat p10,jbyte p11,jbyte p12,jbyte p13,jfloat p14 + ,jfloat p15,jfloat p16,jfloat p17,jbyte p18,jbyte p19,jbyte p20,jbyte p21 + ,jfloat p22,jfloat p23,jbyte p24,jbyte p25,jfloat p26,jfloat p27,jfloat p28 + ,jbyte p29,jfloat p30,jfloat p31,jfloat p32,jbyte p33,jbyte p34,jfloat p35 + ,jbyte p36,jfloat p37,jbyte p38,jfloat p39,jfloat p40,jbyte p41,jfloat p42 + ,jbyte p43,jbyte p44,jfloat p45,jbyte p46,jfloat p47,jfloat p48,jbyte p49 + ,jbyte p50,jfloat p51,jbyte p52,jfloat p53,jfloat p54,jbyte p55,jfloat p56 + ,jfloat p57,jbyte p58,jfloat p59,jbyte p60,jbyte p61,jbyte p62,jfloat p63 + ,jbyte p64,jbyte p65,jbyte p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 + ,jbyte p71,jfloat p72,jfloat p73,jfloat p74,jbyte p75,jbyte p76,jfloat p77 + ,jfloat p78,jfloat p79,jfloat p80,jbyte p81,jfloat p82,jbyte p83,jfloat p84 + ,jfloat p85,jbyte p86,jfloat p87,jbyte p88,jfloat p89,jfloat p90,jbyte p91 + ,jbyte p92,jbyte p93,jbyte p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98 + ,jfloat p99,jbyte p100,jbyte p101,jfloat p102,jfloat p103,jfloat p104,jbyte p105 + ,jfloat p106,jfloat p107,jbyte p108,jfloat p109,jfloat p110,jbyte p111,jbyte p112 + ,jfloat p113,jbyte p114,jbyte p115,jfloat p116,jbyte p117,jbyte p118,jbyte p119 + ,jbyte p120,jfloat p121,jbyte p122,jbyte p123,jbyte p124,jbyte p125,jfloat p126 + ) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%d\n",p20); + fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%d\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%d\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%d\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%d\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc5(JNIEnv *e, jclass c +,jint p0,jfloat p1,jint p2,jfloat p3,jbyte p4,jbyte p5,jbyte p6,jfloat p7 + ,jint p8,jbyte p9,jfloat p10,jbyte p11,jfloat p12,jbyte p13,jbyte p14,jint p15 + ,jfloat p16,jint p17,jint p18,jint p19,jint p20,jbyte p21,jbyte p22,jbyte p23 + ,jbyte p24,jint p25,jint p26,jfloat p27,jbyte p28,jfloat p29,jint p30,jfloat p31 + ,jbyte p32,jfloat p33,jint p34,jint p35,jfloat p36,jbyte p37,jint p38,jbyte p39 + ,jbyte p40,jfloat p41,jfloat p42,jbyte p43,jbyte p44,jfloat p45,jbyte p46 + ,jbyte p47,jint p48,jint p49,jint p50,jfloat p51,jint p52,jfloat p53,jbyte p54 + ,jint p55,jint p56,jbyte p57,jint p58,jbyte p59,jint p60,jfloat p61,jint p62 + ,jfloat p63,jint p64,jfloat p65,jbyte p66,jbyte p67,jfloat p68,jbyte p69 + ,jint p70,jfloat p71,jbyte p72,jint p73,jint p74,jbyte p75,jbyte p76,jbyte p77 + ,jint p78,jbyte p79,jbyte p80,jfloat p81,jbyte p82,jint p83,jbyte p84,jint p85 + ,jint p86,jbyte p87,jint p88,jfloat p89,jint p90,jint p91,jfloat p92,jbyte p93 + ,jfloat p94,jbyte p95,jfloat p96,jint p97,jfloat p98,jfloat p99,jint p100 + ,jbyte p101,jint p102,jbyte p103,jfloat p104,jfloat p105,jfloat p106,jfloat p107 + ,jfloat p108,jfloat p109,jint p110,jint p111,jint p112,jbyte p113,jfloat p114 + ,jfloat p115,jfloat p116,jint p117,jfloat p118,jint p119,jbyte p120,jint p121 + ,jbyte p122,jbyte p123,jfloat p124,jfloat p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%d\n",p20); + fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%d\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%d\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%d\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%d\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%d\n",p110); + fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%d\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc6(JNIEnv *e, jclass c +,jdouble p0,jint p1,jint p2,jint p3,jint p4,jdouble p5,jdouble p6,jint p7 + ,jint p8,jdouble p9,jdouble p10,jint p11,jint p12,jdouble p13,jdouble p14 + ,jdouble p15,jdouble p16,jdouble p17,jdouble p18,jint p19,jint p20,jdouble p21 + ,jdouble p22,jint p23,jdouble p24,jdouble p25,jdouble p26,jint p27,jint p28 + ,jint p29,jdouble p30,jdouble p31,jdouble p32,jint p33,jint p34,jdouble p35 + ,jint p36,jint p37,jdouble p38,jdouble p39,jdouble p40,jint p41,jdouble p42 + ,jdouble p43,jint p44,jint p45,jint p46,jint p47,jdouble p48,jdouble p49 + ,jdouble p50,jint p51,jint p52,jint p53,jint p54,jdouble p55,jint p56,jint p57 + ,jdouble p58,jint p59,jdouble p60,jdouble p61,jint p62,jint p63,jdouble p64 + ,jdouble p65,jint p66,jint p67,jdouble p68,jdouble p69,jdouble p70,jint p71 + ,jint p72,jdouble p73,jint p74,jint p75,jdouble p76,jdouble p77,jdouble p78 + ,jint p79,jint p80,jint p81,jint p82,jint p83,jdouble p84,jdouble p85,jint p86 + ,jdouble p87,jdouble p88,jint p89,jdouble p90,jint p91,jint p92,jdouble p93 + ,jint p94,jint p95,jdouble p96,jdouble p97,jint p98,jdouble p99,jdouble p100 + ,jdouble p101,jint p102,jdouble p103,jdouble p104,jint p105,jint p106,jint p107 + ,jdouble p108,jint p109,jdouble p110,jdouble p111,jdouble p112,jint p113 + ,jint p114,jdouble p115,jint p116,jdouble p117,jdouble p118,jint p119,jdouble p120 + ,jdouble p121,jint p122,jint p123,jint p124,jint p125,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%d\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%d\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%d\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%d\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%d\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%d\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%d\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%d\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc7(JNIEnv *e, jclass c +,jdouble p0,jbyte p1,jdouble p2,jdouble p3,jbyte p4,jbyte p5,jbyte p6,jbyte p7 + ,jdouble p8,jdouble p9,jbyte p10,jbyte p11,jdouble p12,jdouble p13,jbyte p14 + ,jbyte p15,jbyte p16,jbyte p17,jbyte p18,jdouble p19,jdouble p20,jdouble p21 + ,jdouble p22,jbyte p23,jdouble p24,jbyte p25,jdouble p26,jbyte p27,jdouble p28 + ,jbyte p29,jbyte p30,jdouble p31,jbyte p32,jdouble p33,jbyte p34,jdouble p35 + ,jdouble p36,jdouble p37,jdouble p38,jbyte p39,jdouble p40,jdouble p41,jbyte p42 + ,jdouble p43,jbyte p44,jdouble p45,jdouble p46,jdouble p47,jdouble p48,jbyte p49 + ,jbyte p50,jdouble p51,jdouble p52,jdouble p53,jbyte p54,jdouble p55,jdouble p56 + ,jdouble p57,jdouble p58,jdouble p59,jbyte p60,jdouble p61,jdouble p62,jbyte p63 + ,jbyte p64,jbyte p65,jbyte p66,jbyte p67,jbyte p68,jdouble p69,jdouble p70 + ,jbyte p71,jdouble p72,jdouble p73,jbyte p74,jdouble p75,jbyte p76,jbyte p77 + ,jbyte p78,jbyte p79,jbyte p80,jdouble p81,jdouble p82,jbyte p83,jbyte p84 + ,jbyte p85,jbyte p86,jdouble p87,jbyte p88,jdouble p89,jdouble p90,jdouble p91 + ,jbyte p92,jbyte p93,jdouble p94,jbyte p95,jbyte p96,jbyte p97,jbyte p98 + ,jdouble p99,jbyte p100,jbyte p101,jbyte p102,jdouble p103,jdouble p104 + ,jbyte p105,jdouble p106,jbyte p107,jbyte p108,jbyte p109,jdouble p110,jbyte p111 + ,jbyte p112,jbyte p113,jbyte p114,jbyte p115,jbyte p116,jdouble p117,jbyte p118 + ,jdouble p119,jdouble p120,jbyte p121,jbyte p122,jdouble p123,jdouble p124 + ,jbyte p125,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%d\n",p29); + fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%d\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%d\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%d\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%d\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%d\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc8(JNIEnv *e, jclass c +,jbyte p0,jdouble p1,jbyte p2,jdouble p3,jint p4,jint p5,jint p6,jdouble p7 + ,jdouble p8,jint p9,jdouble p10,jbyte p11,jint p12,jbyte p13,jdouble p14 + ,jint p15,jbyte p16,jint p17,jdouble p18,jdouble p19,jbyte p20,jint p21 + ,jbyte p22,jint p23,jint p24,jbyte p25,jdouble p26,jint p27,jint p28,jbyte p29 + ,jint p30,jint p31,jbyte p32,jdouble p33,jdouble p34,jbyte p35,jdouble p36 + ,jint p37,jdouble p38,jint p39,jbyte p40,jbyte p41,jint p42,jint p43,jint p44 + ,jbyte p45,jdouble p46,jdouble p47,jint p48,jint p49,jbyte p50,jbyte p51 + ,jint p52,jint p53,jbyte p54,jbyte p55,jint p56,jint p57,jint p58,jdouble p59 + ,jbyte p60,jint p61,jdouble p62,jdouble p63,jdouble p64,jint p65,jint p66 + ,jdouble p67,jint p68,jdouble p69,jint p70,jint p71,jbyte p72,jint p73,jdouble p74 + ,jdouble p75,jbyte p76,jint p77,jbyte p78,jbyte p79,jint p80,jint p81,jint p82 + ,jdouble p83,jdouble p84,jint p85,jbyte p86,jbyte p87,jbyte p88,jbyte p89 + ,jint p90,jint p91,jdouble p92,jint p93,jdouble p94,jdouble p95,jint p96 + ,jbyte p97,jdouble p98,jdouble p99,jbyte p100,jbyte p101,jbyte p102,jbyte p103 + ,jdouble p104,jint p105,jint p106,jbyte p107,jbyte p108,jdouble p109,jdouble p110 + ,jdouble p111,jbyte p112,jdouble p113,jbyte p114,jbyte p115,jint p116,jdouble p117 + ,jint p118,jint p119,jbyte p120,jdouble p121,jbyte p122,jint p123,jint p124 + ,jint p125,jbyte p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%d\n",p20); + fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%d\n",p29); + fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%d\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%d\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%d\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%d\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%d\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc9(JNIEnv *e, jclass c +,jdouble p0,jbyte p1,jint p2,jbyte p3,jint p4,jbyte p5,jint p6,jfloat p7 + ,jfloat p8,jint p9,jdouble p10,jint p11,jfloat p12,jfloat p13,jdouble p14 + ,jint p15,jfloat p16,jbyte p17,jfloat p18,jint p19,jfloat p20,jint p21,jfloat p22 + ,jfloat p23,jdouble p24,jbyte p25,jbyte p26,jbyte p27,jbyte p28,jfloat p29 + ,jbyte p30,jbyte p31,jbyte p32,jdouble p33,jint p34,jdouble p35,jfloat p36 + ,jint p37,jdouble p38,jint p39,jdouble p40,jbyte p41,jdouble p42,jfloat p43 + ,jfloat p44,jdouble p45,jfloat p46,jint p47,jfloat p48,jint p49,jfloat p50 + ,jbyte p51,jbyte p52,jint p53,jint p54,jfloat p55,jdouble p56,jint p57,jint p58 + ,jfloat p59,jint p60,jbyte p61,jint p62,jdouble p63,jdouble p64,jint p65 + ,jbyte p66,jdouble p67,jint p68,jbyte p69,jbyte p70,jint p71,jfloat p72 + ,jfloat p73,jbyte p74,jint p75,jbyte p76,jdouble p77,jfloat p78,jdouble p79 + ,jbyte p80,jint p81,jint p82,jbyte p83,jdouble p84,jfloat p85,jdouble p86 + ,jdouble p87,jfloat p88,jbyte p89,jbyte p90,jdouble p91,jdouble p92,jdouble p93 + ,jfloat p94,jdouble p95,jfloat p96,jdouble p97,jfloat p98,jbyte p99,jfloat p100 + ,jbyte p101,jbyte p102,jfloat p103,jdouble p104,jbyte p105,jfloat p106,jdouble p107 + ,jdouble p108,jint p109,jfloat p110,jint p111,jint p112,jbyte p113,jdouble p114 + ,jbyte p115,jdouble p116,jint p117,jdouble p118,jfloat p119,jbyte p120,jfloat p121 + ,jfloat p122,jfloat p123,jdouble p124,jint p125,jbyte p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%d\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%d\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%d\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc10(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jfloat p2,jdouble p3,jfloat p4,jfloat p5,jdouble p6 + ,jfloat p7,jfloat p8,jdouble p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13 + ,jdouble p14,jfloat p15,jfloat p16,jdouble p17,jdouble p18,jdouble p19,jdouble p20 + ,jfloat p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 + ,jfloat p27,jfloat p28,jfloat p29,jdouble p30,jfloat p31,jfloat p32,jfloat p33 + ,jdouble p34,jdouble p35,jdouble p36,jdouble p37,jfloat p38,jfloat p39,jdouble p40 + ,jfloat p41,jdouble p42,jdouble p43,jfloat p44,jdouble p45,jdouble p46,jdouble p47 + ,jfloat p48,jdouble p49,jdouble p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54 + ,jfloat p55,jdouble p56,jfloat p57,jfloat p58,jdouble p59,jfloat p60,jdouble p61 + ,jdouble p62,jfloat p63,jfloat p64,jfloat p65,jfloat p66,jdouble p67,jfloat p68 + ,jdouble p69,jdouble p70,jfloat p71,jdouble p72,jdouble p73,jdouble p74 + ,jfloat p75,jdouble p76,jdouble p77,jfloat p78,jdouble p79,jfloat p80,jfloat p81 + ,jfloat p82,jfloat p83,jfloat p84,jfloat p85,jdouble p86,jdouble p87,jfloat p88 + ,jfloat p89,jdouble p90,jdouble p91,jdouble p92,jdouble p93,jfloat p94,jdouble p95 + ,jfloat p96,jdouble p97,jdouble p98,jfloat p99,jfloat p100,jfloat p101,jdouble p102 + ,jfloat p103,jfloat p104,jfloat p105,jdouble p106,jdouble p107,jdouble p108 + ,jfloat p109,jdouble p110,jfloat p111,jdouble p112,jfloat p113,jfloat p114 + ,jdouble p115,jdouble p116,jdouble p117,jdouble p118,jfloat p119,jdouble p120 + ,jfloat p121,jdouble p122,jfloat p123,jfloat p124,jfloat p125,jfloat p126 + ) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc11(JNIEnv *e, jclass c +,jdouble p0,jfloat p1,jfloat p2,jdouble p3,jint p4,jint p5,jfloat p6,jdouble p7 + ,jint p8,jint p9,jint p10,jint p11,jint p12,jdouble p13,jfloat p14,jfloat p15 + ,jdouble p16,jfloat p17,jint p18,jint p19,jdouble p20,jfloat p21,jint p22 + ,jint p23,jfloat p24,jint p25,jint p26,jint p27,jfloat p28,jfloat p29,jdouble p30 + ,jdouble p31,jint p32,jdouble p33,jfloat p34,jfloat p35,jfloat p36,jint p37 + ,jfloat p38,jdouble p39,jfloat p40,jdouble p41,jdouble p42,jdouble p43,jdouble p44 + ,jint p45,jint p46,jfloat p47,jfloat p48,jfloat p49,jfloat p50,jdouble p51 + ,jdouble p52,jdouble p53,jint p54,jfloat p55,jint p56,jdouble p57,jdouble p58 + ,jdouble p59,jdouble p60,jint p61,jfloat p62,jint p63,jfloat p64,jdouble p65 + ,jdouble p66,jfloat p67,jdouble p68,jdouble p69,jint p70,jdouble p71,jfloat p72 + ,jdouble p73,jint p74,jfloat p75,jfloat p76,jfloat p77,jfloat p78,jint p79 + ,jfloat p80,jint p81,jdouble p82,jfloat p83,jdouble p84,jfloat p85,jfloat p86 + ,jfloat p87,jdouble p88,jfloat p89,jint p90,jfloat p91,jdouble p92,jfloat p93 + ,jdouble p94,jdouble p95,jint p96,jint p97,jfloat p98,jdouble p99,jfloat p100 + ,jint p101,jdouble p102,jdouble p103,jfloat p104,jdouble p105,jint p106 + ,jfloat p107,jfloat p108,jint p109,jdouble p110,jfloat p111,jdouble p112 + ,jint p113,jint p114,jfloat p115,jfloat p116,jint p117,jdouble p118,jfloat p119 + ,jfloat p120,jfloat p121,jint p122,jdouble p123,jint p124,jfloat p125,jdouble p126 + ) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%d\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc12(JNIEnv *e, jclass c +,jdouble p0,jfloat p1,jdouble p2,jfloat p3,jfloat p4,jbyte p5,jbyte p6,jdouble p7 + ,jdouble p8,jbyte p9,jbyte p10,jfloat p11,jbyte p12,jbyte p13,jbyte p14 + ,jbyte p15,jbyte p16,jbyte p17,jdouble p18,jdouble p19,jbyte p20,jfloat p21 + ,jbyte p22,jdouble p23,jbyte p24,jfloat p25,jdouble p26,jfloat p27,jbyte p28 + ,jbyte p29,jfloat p30,jbyte p31,jfloat p32,jfloat p33,jbyte p34,jbyte p35 + ,jfloat p36,jdouble p37,jfloat p38,jfloat p39,jdouble p40,jdouble p41,jfloat p42 + ,jfloat p43,jbyte p44,jbyte p45,jdouble p46,jfloat p47,jdouble p48,jfloat p49 + ,jbyte p50,jdouble p51,jdouble p52,jfloat p53,jdouble p54,jbyte p55,jfloat p56 + ,jbyte p57,jbyte p58,jbyte p59,jfloat p60,jdouble p61,jfloat p62,jbyte p63 + ,jdouble p64,jdouble p65,jfloat p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 + ,jdouble p71,jfloat p72,jfloat p73,jdouble p74,jbyte p75,jfloat p76,jbyte p77 + ,jbyte p78,jbyte p79,jdouble p80,jdouble p81,jbyte p82,jfloat p83,jdouble p84 + ,jbyte p85,jfloat p86,jdouble p87,jfloat p88,jfloat p89,jfloat p90,jfloat p91 + ,jdouble p92,jbyte p93,jfloat p94,jbyte p95,jbyte p96,jbyte p97,jfloat p98 + ,jbyte p99,jfloat p100,jdouble p101,jfloat p102,jbyte p103,jbyte p104,jfloat p105 + ,jdouble p106,jbyte p107,jfloat p108,jbyte p109,jdouble p110,jfloat p111 + ,jfloat p112,jbyte p113,jfloat p114,jbyte p115,jfloat p116,jdouble p117 + ,jdouble p118,jdouble p119,jfloat p120,jdouble p121,jbyte p122,jbyte p123 + ,jfloat p124,jdouble p125,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%d\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%d\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%d\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%d\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%d\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc13(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jint p4,jfloat p5,jint p6,jfloat p7 + ,jint p8,jfloat p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jint p14 + ,jfloat p15,jfloat p16,jint p17,jint p18,jfloat p19,jfloat p20,jint p21 + ,jint p22,jint p23,jint p24,jint p25,jfloat p26,jint p27,jint p28,jfloat p29 + ,jint p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jint p35,jint p36 + ,jfloat p37,jfloat p38,jfloat p39,jint p40,jfloat p41,jint p42,jfloat p43 + ,jint p44,jfloat p45,jfloat p46,jfloat p47,jint p48,jfloat p49,jint p50 + ,jint p51,jfloat p52,jint p53,jfloat p54,jfloat p55,jfloat p56,jfloat p57 + ,jfloat p58,jfloat p59,jfloat p60,jfloat p61,jint p62,jfloat p63,jfloat p64 + ,jfloat p65,jint p66,jint p67,jfloat p68,jfloat p69,jfloat p70,jint p71 + ,jfloat p72,jfloat p73,jint p74,jfloat p75,jfloat p76,jfloat p77,jint p78 + ,jint p79,jint p80,jfloat p81,jint p82,jint p83,jfloat p84,jint p85,jint p86 + ,jfloat p87,jfloat p88,jfloat p89,jfloat p90,jint p91,jint p92,jfloat p93 + ,jfloat p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98,jint p99,jfloat p100 + ,jint p101,jfloat p102,jfloat p103,jint p104,jfloat p105,jfloat p106,jfloat p107 + ,jint p108,jfloat p109,jfloat p110,jfloat p111,jfloat p112,jfloat p113,jfloat p114 + ,jfloat p115,jfloat p116,jint p117,jint p118,jfloat p119,jfloat p120,jfloat p121 + ,jint p122,jfloat p123,jint p124,jfloat p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%d\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%d\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc14(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jbyte p4,jfloat p5,jfloat p6,jbyte p7 + ,jfloat p8,jbyte p9,jbyte p10,jbyte p11,jfloat p12,jfloat p13,jfloat p14 + ,jbyte p15,jfloat p16,jbyte p17,jfloat p18,jfloat p19,jfloat p20,jfloat p21 + ,jbyte p22,jbyte p23,jbyte p24,jfloat p25,jbyte p26,jfloat p27,jfloat p28 + ,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jfloat p35 + ,jbyte p36,jfloat p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jfloat p42 + ,jbyte p43,jbyte p44,jfloat p45,jbyte p46,jfloat p47,jbyte p48,jfloat p49 + ,jfloat p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54,jfloat p55,jbyte p56 + ,jfloat p57,jbyte p58,jfloat p59,jbyte p60,jfloat p61,jbyte p62,jbyte p63 + ,jfloat p64,jfloat p65,jfloat p66,jbyte p67,jfloat p68,jfloat p69,jfloat p70 + ,jbyte p71,jfloat p72,jbyte p73,jfloat p74,jfloat p75,jfloat p76,jbyte p77 + ,jfloat p78,jfloat p79,jbyte p80,jfloat p81,jfloat p82,jfloat p83,jfloat p84 + ,jbyte p85,jfloat p86,jbyte p87,jbyte p88,jbyte p89,jfloat p90,jbyte p91 + ,jfloat p92,jfloat p93,jbyte p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98 + ,jfloat p99,jfloat p100,jfloat p101,jfloat p102,jbyte p103,jbyte p104,jfloat p105 + ,jfloat p106,jfloat p107,jfloat p108,jfloat p109,jfloat p110,jbyte p111 + ,jfloat p112,jfloat p113,jbyte p114,jbyte p115,jfloat p116,jfloat p117,jfloat p118 + ,jfloat p119,jbyte p120,jbyte p121,jbyte p122,jbyte p123,jbyte p124,jfloat p125 + ,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%d\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%d\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc15(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jbyte p2,jfloat p3,jfloat p4,jfloat p5,jbyte p6,jfloat p7 + ,jbyte p8,jint p9,jfloat p10,jfloat p11,jbyte p12,jbyte p13,jbyte p14,jbyte p15 + ,jbyte p16,jfloat p17,jbyte p18,jfloat p19,jint p20,jbyte p21,jfloat p22 + ,jint p23,jbyte p24,jfloat p25,jfloat p26,jbyte p27,jfloat p28,jint p29 + ,jfloat p30,jbyte p31,jfloat p32,jfloat p33,jbyte p34,jfloat p35,jint p36 + ,jbyte p37,jint p38,jfloat p39,jfloat p40,jbyte p41,jfloat p42,jbyte p43 + ,jint p44,jfloat p45,jfloat p46,jbyte p47,jint p48,jfloat p49,jint p50,jfloat p51 + ,jfloat p52,jint p53,jbyte p54,jint p55,jbyte p56,jfloat p57,jfloat p58 + ,jfloat p59,jfloat p60,jbyte p61,jbyte p62,jbyte p63,jbyte p64,jfloat p65 + ,jint p66,jint p67,jint p68,jfloat p69,jfloat p70,jint p71,jfloat p72,jfloat p73 + ,jfloat p74,jint p75,jfloat p76,jfloat p77,jint p78,jfloat p79,jint p80 + ,jfloat p81,jfloat p82,jfloat p83,jfloat p84,jbyte p85,jint p86,jbyte p87 + ,jfloat p88,jfloat p89,jfloat p90,jint p91,jfloat p92,jbyte p93,jfloat p94 + ,jbyte p95,jint p96,jfloat p97,jfloat p98,jint p99,jfloat p100,jbyte p101 + ,jbyte p102,jfloat p103,jbyte p104,jbyte p105,jbyte p106,jint p107,jint p108 + ,jfloat p109,jfloat p110,jint p111,jfloat p112,jbyte p113,jint p114,jfloat p115 + ,jbyte p116,jbyte p117,jfloat p118,jfloat p119,jint p120,jfloat p121,jfloat p122 + ,jint p123,jfloat p124,jbyte p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%d\n",p20); + fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%d\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc16(JNIEnv *e, jclass c +,jdouble p0,jint p1,jdouble p2,jdouble p3,jdouble p4,jdouble p5,jint p6 + ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jdouble p12,jdouble p13 + ,jdouble p14,jdouble p15,jdouble p16,jdouble p17,jint p18,jint p19,jdouble p20 + ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jint p26,jdouble p27 + ,jdouble p28,jdouble p29,jdouble p30,jint p31,jdouble p32,jint p33,jint p34 + ,jdouble p35,jdouble p36,jdouble p37,jint p38,jdouble p39,jdouble p40,jdouble p41 + ,jdouble p42,jint p43,jdouble p44,jdouble p45,jint p46,jdouble p47,jdouble p48 + ,jint p49,jdouble p50,jdouble p51,jint p52,jdouble p53,jint p54,jdouble p55 + ,jint p56,jint p57,jdouble p58,jint p59,jint p60,jdouble p61,jint p62,jint p63 + ,jint p64,jdouble p65,jint p66,jint p67,jint p68,jint p69,jint p70,jdouble p71 + ,jint p72,jint p73,jdouble p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78 + ,jdouble p79,jint p80,jdouble p81,jdouble p82,jdouble p83,jdouble p84,jdouble p85 + ,jdouble p86,jdouble p87,jdouble p88,jdouble p89,jint p90,jdouble p91,jdouble p92 + ,jdouble p93,jdouble p94,jdouble p95,jdouble p96,jdouble p97,jint p98,jdouble p99 + ,jint p100,jdouble p101,jdouble p102,jdouble p103,jint p104,jdouble p105 + ,jint p106,jdouble p107,jint p108,jint p109,jdouble p110,jdouble p111,jdouble p112 + ,jint p113,jdouble p114,jdouble p115,jint p116,jdouble p117,jint p118,jint p119 + ,jdouble p120,jdouble p121,jdouble p122,jdouble p123,jdouble p124,jdouble p125 + ,jint p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%d\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%d\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%d\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%d\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%d\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc17(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jbyte p2,jdouble p3,jdouble p4,jdouble p5,jdouble p6 + ,jbyte p7,jdouble p8,jbyte p9,jdouble p10,jbyte p11,jbyte p12,jdouble p13 + ,jdouble p14,jdouble p15,jdouble p16,jbyte p17,jdouble p18,jdouble p19,jdouble p20 + ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 + ,jdouble p27,jdouble p28,jdouble p29,jdouble p30,jdouble p31,jdouble p32 + ,jdouble p33,jdouble p34,jdouble p35,jdouble p36,jdouble p37,jbyte p38,jdouble p39 + ,jdouble p40,jdouble p41,jdouble p42,jdouble p43,jdouble p44,jdouble p45 + ,jdouble p46,jbyte p47,jdouble p48,jbyte p49,jdouble p50,jbyte p51,jdouble p52 + ,jbyte p53,jbyte p54,jbyte p55,jbyte p56,jdouble p57,jbyte p58,jdouble p59 + ,jdouble p60,jbyte p61,jbyte p62,jdouble p63,jdouble p64,jbyte p65,jbyte p66 + ,jbyte p67,jdouble p68,jbyte p69,jdouble p70,jdouble p71,jbyte p72,jdouble p73 + ,jdouble p74,jdouble p75,jbyte p76,jdouble p77,jdouble p78,jdouble p79,jdouble p80 + ,jdouble p81,jbyte p82,jdouble p83,jdouble p84,jbyte p85,jbyte p86,jdouble p87 + ,jdouble p88,jdouble p89,jdouble p90,jdouble p91,jdouble p92,jbyte p93,jbyte p94 + ,jdouble p95,jdouble p96,jdouble p97,jdouble p98,jbyte p99,jdouble p100 + ,jdouble p101,jdouble p102,jdouble p103,jdouble p104,jbyte p105,jdouble p106 + ,jbyte p107,jdouble p108,jdouble p109,jdouble p110,jbyte p111,jdouble p112 + ,jdouble p113,jbyte p114,jdouble p115,jdouble p116,jbyte p117,jbyte p118 + ,jbyte p119,jdouble p120,jbyte p121,jdouble p122,jbyte p123,jdouble p124 + ,jbyte p125,jbyte p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%d\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%d\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc18(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jint p4,jint p5,jbyte p6,jint p7 + ,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jdouble p12,jbyte p13,jdouble p14 + ,jdouble p15,jbyte p16,jdouble p17,jint p18,jbyte p19,jbyte p20,jdouble p21 + ,jdouble p22,jdouble p23,jint p24,jdouble p25,jdouble p26,jint p27,jdouble p28 + ,jdouble p29,jdouble p30,jdouble p31,jdouble p32,jdouble p33,jbyte p34,jint p35 + ,jbyte p36,jdouble p37,jdouble p38,jint p39,jint p40,jint p41,jint p42,jdouble p43 + ,jdouble p44,jdouble p45,jbyte p46,jbyte p47,jdouble p48,jint p49,jbyte p50 + ,jbyte p51,jint p52,jint p53,jint p54,jdouble p55,jdouble p56,jint p57,jint p58 + ,jdouble p59,jbyte p60,jbyte p61,jint p62,jint p63,jdouble p64,jint p65 + ,jint p66,jdouble p67,jdouble p68,jdouble p69,jint p70,jdouble p71,jdouble p72 + ,jint p73,jdouble p74,jdouble p75,jint p76,jbyte p77,jdouble p78,jint p79 + ,jdouble p80,jint p81,jdouble p82,jdouble p83,jbyte p84,jdouble p85,jdouble p86 + ,jint p87,jint p88,jbyte p89,jdouble p90,jdouble p91,jdouble p92,jint p93 + ,jbyte p94,jbyte p95,jint p96,jdouble p97,jdouble p98,jdouble p99,jdouble p100 + ,jbyte p101,jbyte p102,jdouble p103,jdouble p104,jdouble p105,jint p106 + ,jint p107,jdouble p108,jint p109,jint p110,jdouble p111,jdouble p112,jbyte p113 + ,jint p114,jbyte p115,jdouble p116,jdouble p117,jint p118,jint p119,jint p120 + ,jdouble p121,jdouble p122,jdouble p123,jdouble p124,jdouble p125,jbyte p126 + ) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%d\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%d\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%d\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%d\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%d\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%d\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%d\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc19(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jint p5,jfloat p6,jfloat p7 + ,jdouble p8,jdouble p9,jint p10,jdouble p11,jdouble p12,jfloat p13,jint p14 + ,jdouble p15,jfloat p16,jint p17,jfloat p18,jdouble p19,jfloat p20,jbyte p21 + ,jdouble p22,jfloat p23,jfloat p24,jdouble p25,jfloat p26,jbyte p27,jdouble p28 + ,jfloat p29,jfloat p30,jfloat p31,jbyte p32,jfloat p33,jfloat p34,jfloat p35 + ,jint p36,jint p37,jdouble p38,jdouble p39,jint p40,jbyte p41,jfloat p42 + ,jfloat p43,jbyte p44,jbyte p45,jdouble p46,jdouble p47,jint p48,jdouble p49 + ,jdouble p50,jint p51,jdouble p52,jfloat p53,jdouble p54,jdouble p55,jfloat p56 + ,jdouble p57,jdouble p58,jdouble p59,jint p60,jint p61,jfloat p62,jfloat p63 + ,jdouble p64,jdouble p65,jint p66,jbyte p67,jfloat p68,jdouble p69,jfloat p70 + ,jfloat p71,jdouble p72,jfloat p73,jbyte p74,jint p75,jint p76,jdouble p77 + ,jfloat p78,jdouble p79,jdouble p80,jdouble p81,jdouble p82,jint p83,jfloat p84 + ,jdouble p85,jbyte p86,jbyte p87,jdouble p88,jbyte p89,jbyte p90,jbyte p91 + ,jint p92,jbyte p93,jfloat p94,jbyte p95,jint p96,jint p97,jint p98,jbyte p99 + ,jdouble p100,jint p101,jdouble p102,jfloat p103,jint p104,jfloat p105,jint p106 + ,jbyte p107,jfloat p108,jint p109,jfloat p110,jfloat p111,jfloat p112,jint p113 + ,jint p114,jfloat p115,jint p116,jdouble p117,jbyte p118,jfloat p119,jbyte p120 + ,jbyte p121,jdouble p122,jfloat p123,jfloat p124,jbyte p125,jint p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%d\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%d\n",p98); + fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%d\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc20(JNIEnv *e, jclass c +,jdouble p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jfloat p5,jfloat p6 + ,jdouble p7,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jdouble p12,jdouble p13 + ,jfloat p14,jdouble p15,jdouble p16,jdouble p17,jfloat p18,jfloat p19,jfloat p20 + ,jfloat p21,jfloat p22,jdouble p23,jdouble p24,jfloat p25,jfloat p26,jfloat p27 + ,jdouble p28,jfloat p29,jdouble p30,jfloat p31,jfloat p32,jdouble p33,jfloat p34 + ,jdouble p35,jdouble p36,jdouble p37,jdouble p38,jfloat p39,jfloat p40,jdouble p41 + ,jfloat p42,jdouble p43,jdouble p44,jfloat p45,jfloat p46,jdouble p47,jdouble p48 + ,jfloat p49,jdouble p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54,jdouble p55 + ,jdouble p56,jdouble p57,jfloat p58,jdouble p59,jfloat p60,jfloat p61,jfloat p62 + ,jfloat p63,jdouble p64,jfloat p65,jfloat p66,jfloat p67,jfloat p68,jfloat p69 + ,jdouble p70,jdouble p71,jfloat p72,jfloat p73,jdouble p74,jfloat p75,jfloat p76 + ,jfloat p77,jdouble p78,jfloat p79,jfloat p80,jfloat p81,jdouble p82,jfloat p83 + ,jdouble p84,jfloat p85,jdouble p86,jfloat p87,jdouble p88,jfloat p89,jfloat p90 + ,jfloat p91,jfloat p92,jdouble p93,jdouble p94,jdouble p95,jdouble p96,jfloat p97 + ,jfloat p98,jfloat p99,jfloat p100,jfloat p101,jfloat p102,jfloat p103,jfloat p104 + ,jfloat p105,jfloat p106,jdouble p107,jfloat p108,jfloat p109,jfloat p110 + ,jdouble p111,jdouble p112,jfloat p113,jfloat p114,jfloat p115,jfloat p116 + ,jdouble p117,jfloat p118,jfloat p119,jfloat p120,jdouble p121,jfloat p122 + ,jdouble p123,jdouble p124,jdouble p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc21(JNIEnv *e, jclass c +,jfloat p0,jint p1,jfloat p2,jfloat p3,jint p4,jint p5,jdouble p6,jfloat p7 + ,jfloat p8,jdouble p9,jint p10,jdouble p11,jdouble p12,jfloat p13,jdouble p14 + ,jdouble p15,jfloat p16,jdouble p17,jfloat p18,jdouble p19,jdouble p20,jdouble p21 + ,jfloat p22,jdouble p23,jdouble p24,jint p25,jdouble p26,jint p27,jint p28 + ,jdouble p29,jfloat p30,jfloat p31,jfloat p32,jint p33,jdouble p34,jfloat p35 + ,jdouble p36,jdouble p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jfloat p42 + ,jfloat p43,jint p44,jint p45,jdouble p46,jfloat p47,jfloat p48,jint p49 + ,jdouble p50,jdouble p51,jfloat p52,jdouble p53,jint p54,jdouble p55,jint p56 + ,jdouble p57,jdouble p58,jfloat p59,jfloat p60,jint p61,jfloat p62,jint p63 + ,jfloat p64,jdouble p65,jint p66,jfloat p67,jdouble p68,jdouble p69,jdouble p70 + ,jdouble p71,jdouble p72,jfloat p73,jint p74,jint p75,jdouble p76,jint p77 + ,jfloat p78,jfloat p79,jdouble p80,jdouble p81,jdouble p82,jint p83,jdouble p84 + ,jdouble p85,jfloat p86,jdouble p87,jint p88,jdouble p89,jfloat p90,jfloat p91 + ,jfloat p92,jdouble p93,jint p94,jfloat p95,jint p96,jfloat p97,jdouble p98 + ,jint p99,jint p100,jint p101,jint p102,jfloat p103,jfloat p104,jfloat p105 + ,jfloat p106,jint p107,jfloat p108,jdouble p109,jfloat p110,jdouble p111 + ,jdouble p112,jfloat p113,jfloat p114,jdouble p115,jdouble p116,jfloat p117 + ,jint p118,jdouble p119,jfloat p120,jfloat p121,jdouble p122,jdouble p123 + ,jfloat p124,jint p125,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc22(JNIEnv *e, jclass c +,jdouble p0,jbyte p1,jdouble p2,jfloat p3,jfloat p4,jfloat p5,jfloat p6 + ,jfloat p7,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jdouble p12,jdouble p13 + ,jbyte p14,jfloat p15,jfloat p16,jdouble p17,jfloat p18,jfloat p19,jdouble p20 + ,jfloat p21,jbyte p22,jfloat p23,jfloat p24,jdouble p25,jbyte p26,jdouble p27 + ,jdouble p28,jdouble p29,jbyte p30,jbyte p31,jbyte p32,jbyte p33,jbyte p34 + ,jdouble p35,jdouble p36,jfloat p37,jfloat p38,jdouble p39,jfloat p40,jfloat p41 + ,jfloat p42,jfloat p43,jbyte p44,jfloat p45,jfloat p46,jdouble p47,jbyte p48 + ,jbyte p49,jdouble p50,jdouble p51,jfloat p52,jfloat p53,jdouble p54,jfloat p55 + ,jdouble p56,jfloat p57,jfloat p58,jfloat p59,jfloat p60,jfloat p61,jfloat p62 + ,jdouble p63,jdouble p64,jfloat p65,jdouble p66,jdouble p67,jbyte p68,jdouble p69 + ,jdouble p70,jdouble p71,jdouble p72,jfloat p73,jbyte p74,jfloat p75,jfloat p76 + ,jfloat p77,jfloat p78,jfloat p79,jdouble p80,jdouble p81,jfloat p82,jdouble p83 + ,jbyte p84,jfloat p85,jdouble p86,jfloat p87,jdouble p88,jbyte p89,jbyte p90 + ,jdouble p91,jbyte p92,jfloat p93,jdouble p94,jbyte p95,jfloat p96,jfloat p97 + ,jdouble p98,jfloat p99,jbyte p100,jfloat p101,jdouble p102,jdouble p103 + ,jbyte p104,jdouble p105,jfloat p106,jbyte p107,jfloat p108,jbyte p109,jfloat p110 + ,jfloat p111,jdouble p112,jfloat p113,jdouble p114,jdouble p115,jfloat p116 + ,jdouble p117,jfloat p118,jfloat p119,jfloat p120,jbyte p121,jdouble p122 + ,jdouble p123,jdouble p124,jfloat p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%d\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%d\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%d\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc23(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jfloat p5,jint p6,jfloat p7 + ,jfloat p8,jfloat p9,jfloat p10,jint p11,jfloat p12,jfloat p13,jfloat p14 + ,jint p15,jfloat p16,jfloat p17,jfloat p18,jint p19,jfloat p20,jfloat p21 + ,jfloat p22,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jfloat p27,jfloat p28 + ,jfloat p29,jint p30,jfloat p31,jfloat p32,jfloat p33,jint p34,jint p35 + ,jint p36,jfloat p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jfloat p42 + ,jint p43,jfloat p44,jfloat p45,jfloat p46,jfloat p47,jint p48,jfloat p49 + ,jfloat p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54,jint p55,jfloat p56 + ,jfloat p57,jfloat p58,jfloat p59,jfloat p60,jint p61,jfloat p62,jfloat p63 + ,jint p64,jfloat p65,jint p66,jint p67,jint p68,jfloat p69,jfloat p70,jfloat p71 + ,jfloat p72,jint p73,jfloat p74,jfloat p75,jfloat p76,jfloat p77,jint p78 + ,jfloat p79,jfloat p80,jfloat p81,jfloat p82,jfloat p83,jfloat p84,jfloat p85 + ,jint p86,jfloat p87,jfloat p88,jfloat p89,jfloat p90,jint p91,jint p92 + ,jfloat p93,jint p94,jfloat p95,jint p96,jfloat p97,jfloat p98,jfloat p99 + ,jfloat p100,jfloat p101,jfloat p102,jfloat p103,jfloat p104,jfloat p105 + ,jfloat p106,jint p107,jfloat p108,jfloat p109,jfloat p110,jfloat p111,jfloat p112 + ,jint p113,jfloat p114,jfloat p115,jfloat p116,jfloat p117,jfloat p118,jint p119 + ,jfloat p120,jfloat p121,jint p122,jint p123,jfloat p124,jfloat p125,jfloat p126 + ) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%d\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%d\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%d\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc24(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jbyte p2,jbyte p3,jfloat p4,jfloat p5,jbyte p6,jbyte p7 + ,jbyte p8,jbyte p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jfloat p14 + ,jfloat p15,jfloat p16,jfloat p17,jfloat p18,jbyte p19,jfloat p20,jfloat p21 + ,jfloat p22,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jbyte p27,jfloat p28 + ,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jfloat p35 + ,jfloat p36,jbyte p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jbyte p42 + ,jfloat p43,jfloat p44,jfloat p45,jbyte p46,jbyte p47,jfloat p48,jfloat p49 + ,jfloat p50,jfloat p51,jfloat p52,jfloat p53,jbyte p54,jfloat p55,jbyte p56 + ,jbyte p57,jfloat p58,jfloat p59,jfloat p60,jfloat p61,jfloat p62,jbyte p63 + ,jbyte p64,jfloat p65,jfloat p66,jfloat p67,jbyte p68,jfloat p69,jfloat p70 + ,jfloat p71,jfloat p72,jfloat p73,jbyte p74,jfloat p75,jfloat p76,jfloat p77 + ,jfloat p78,jfloat p79,jbyte p80,jfloat p81,jfloat p82,jbyte p83,jfloat p84 + ,jbyte p85,jfloat p86,jbyte p87,jfloat p88,jbyte p89,jbyte p90,jfloat p91 + ,jfloat p92,jfloat p93,jfloat p94,jbyte p95,jbyte p96,jfloat p97,jbyte p98 + ,jfloat p99,jfloat p100,jfloat p101,jfloat p102,jfloat p103,jfloat p104 + ,jfloat p105,jbyte p106,jfloat p107,jfloat p108,jfloat p109,jfloat p110 + ,jbyte p111,jfloat p112,jfloat p113,jfloat p114,jfloat p115,jfloat p116 + ,jfloat p117,jfloat p118,jfloat p119,jfloat p120,jfloat p121,jfloat p122 + ,jfloat p123,jfloat p124,jfloat p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%d\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%d\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc25(JNIEnv *e, jclass c +,jfloat p0,jint p1,jfloat p2,jfloat p3,jfloat p4,jint p5,jint p6,jbyte p7 + ,jfloat p8,jint p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jint p14 + ,jbyte p15,jfloat p16,jfloat p17,jfloat p18,jbyte p19,jfloat p20,jbyte p21 + ,jfloat p22,jbyte p23,jfloat p24,jfloat p25,jfloat p26,jfloat p27,jfloat p28 + ,jint p29,jbyte p30,jfloat p31,jbyte p32,jfloat p33,jint p34,jint p35,jbyte p36 + ,jbyte p37,jint p38,jint p39,jfloat p40,jint p41,jfloat p42,jfloat p43,jfloat p44 + ,jfloat p45,jfloat p46,jint p47,jfloat p48,jint p49,jint p50,jint p51,jfloat p52 + ,jfloat p53,jbyte p54,jint p55,jbyte p56,jint p57,jfloat p58,jint p59,jint p60 + ,jbyte p61,jbyte p62,jint p63,jfloat p64,jfloat p65,jbyte p66,jbyte p67 + ,jbyte p68,jint p69,jbyte p70,jfloat p71,jbyte p72,jfloat p73,jfloat p74 + ,jfloat p75,jfloat p76,jbyte p77,jfloat p78,jint p79,jbyte p80,jfloat p81 + ,jfloat p82,jint p83,jfloat p84,jbyte p85,jbyte p86,jfloat p87,jfloat p88 + ,jbyte p89,jfloat p90,jfloat p91,jint p92,jfloat p93,jfloat p94,jint p95 + ,jfloat p96,jint p97,jint p98,jint p99,jint p100,jint p101,jint p102,jint p103 + ,jfloat p104,jint p105,jbyte p106,jfloat p107,jfloat p108,jint p109,jbyte p110 + ,jfloat p111,jfloat p112,jfloat p113,jbyte p114,jfloat p115,jbyte p116,jfloat p117 + ,jbyte p118,jfloat p119,jfloat p120,jfloat p121,jbyte p122,jfloat p123,jbyte p124 + ,jfloat p125,jint p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%d\n",p29); + fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%d\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%d\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%d\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%d\n",p98); + fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%d\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%d\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc26(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jdouble p4,jint p5,jdouble p6 + ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jdouble p12,jdouble p13 + ,jdouble p14,jint p15,jdouble p16,jdouble p17,jint p18,jdouble p19,jdouble p20 + ,jint p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26,jdouble p27 + ,jdouble p28,jdouble p29,jdouble p30,jint p31,jint p32,jdouble p33,jdouble p34 + ,jdouble p35,jdouble p36,jdouble p37,jdouble p38,jdouble p39,jdouble p40 + ,jdouble p41,jdouble p42,jint p43,jdouble p44,jdouble p45,jint p46,jdouble p47 + ,jint p48,jdouble p49,jdouble p50,jdouble p51,jdouble p52,jint p53,jdouble p54 + ,jdouble p55,jdouble p56,jint p57,jint p58,jdouble p59,jint p60,jdouble p61 + ,jdouble p62,jdouble p63,jdouble p64,jdouble p65,jdouble p66,jdouble p67 + ,jdouble p68,jdouble p69,jint p70,jint p71,jdouble p72,jdouble p73,jint p74 + ,jint p75,jint p76,jdouble p77,jdouble p78,jdouble p79,jdouble p80,jdouble p81 + ,jdouble p82,jdouble p83,jdouble p84,jdouble p85,jint p86,jdouble p87,jdouble p88 + ,jint p89,jdouble p90,jdouble p91,jdouble p92,jdouble p93,jint p94,jdouble p95 + ,jdouble p96,jint p97,jdouble p98,jdouble p99,jdouble p100,jdouble p101 + ,jdouble p102,jdouble p103,jdouble p104,jdouble p105,jdouble p106,jdouble p107 + ,jdouble p108,jdouble p109,jint p110,jint p111,jdouble p112,jint p113,jdouble p114 + ,jdouble p115,jdouble p116,jdouble p117,jdouble p118,jdouble p119,jint p120 + ,jint p121,jint p122,jdouble p123,jdouble p124,jdouble p125,jint p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%d\n",p110); + fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%d\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc27(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jdouble p4,jdouble p5,jdouble p6 + ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jbyte p12,jbyte p13 + ,jbyte p14,jdouble p15,jdouble p16,jbyte p17,jdouble p18,jdouble p19,jdouble p20 + ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 + ,jdouble p27,jdouble p28,jdouble p29,jbyte p30,jdouble p31,jdouble p32,jbyte p33 + ,jdouble p34,jdouble p35,jdouble p36,jdouble p37,jdouble p38,jdouble p39 + ,jdouble p40,jbyte p41,jbyte p42,jdouble p43,jbyte p44,jbyte p45,jdouble p46 + ,jdouble p47,jdouble p48,jbyte p49,jbyte p50,jbyte p51,jdouble p52,jbyte p53 + ,jdouble p54,jdouble p55,jdouble p56,jdouble p57,jbyte p58,jbyte p59,jdouble p60 + ,jdouble p61,jdouble p62,jdouble p63,jdouble p64,jdouble p65,jdouble p66 + ,jdouble p67,jbyte p68,jdouble p69,jdouble p70,jbyte p71,jdouble p72,jdouble p73 + ,jdouble p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78,jdouble p79 + ,jdouble p80,jdouble p81,jdouble p82,jdouble p83,jdouble p84,jdouble p85 + ,jdouble p86,jdouble p87,jbyte p88,jdouble p89,jbyte p90,jbyte p91,jbyte p92 + ,jdouble p93,jbyte p94,jbyte p95,jdouble p96,jbyte p97,jdouble p98,jdouble p99 + ,jdouble p100,jdouble p101,jdouble p102,jdouble p103,jdouble p104,jdouble p105 + ,jdouble p106,jdouble p107,jdouble p108,jdouble p109,jdouble p110,jdouble p111 + ,jdouble p112,jdouble p113,jdouble p114,jbyte p115,jdouble p116,jdouble p117 + ,jbyte p118,jdouble p119,jdouble p120,jbyte p121,jdouble p122,jdouble p123 + ,jdouble p124,jbyte p125,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%d\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%d\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc28(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jbyte p2,jdouble p3,jdouble p4,jdouble p5,jbyte p6 + ,jint p7,jbyte p8,jint p9,jint p10,jbyte p11,jdouble p12,jint p13,jdouble p14 + ,jdouble p15,jbyte p16,jdouble p17,jbyte p18,jdouble p19,jdouble p20,jbyte p21 + ,jdouble p22,jbyte p23,jdouble p24,jint p25,jdouble p26,jdouble p27,jbyte p28 + ,jdouble p29,jint p30,jint p31,jdouble p32,jdouble p33,jbyte p34,jbyte p35 + ,jbyte p36,jbyte p37,jdouble p38,jdouble p39,jdouble p40,jdouble p41,jint p42 + ,jdouble p43,jdouble p44,jdouble p45,jdouble p46,jdouble p47,jdouble p48 + ,jdouble p49,jint p50,jdouble p51,jdouble p52,jbyte p53,jint p54,jint p55 + ,jdouble p56,jdouble p57,jint p58,jdouble p59,jdouble p60,jdouble p61,jdouble p62 + ,jbyte p63,jint p64,jbyte p65,jdouble p66,jdouble p67,jint p68,jdouble p69 + ,jdouble p70,jdouble p71,jdouble p72,jbyte p73,jdouble p74,jdouble p75,jdouble p76 + ,jbyte p77,jbyte p78,jdouble p79,jdouble p80,jdouble p81,jdouble p82,jdouble p83 + ,jbyte p84,jdouble p85,jdouble p86,jbyte p87,jdouble p88,jbyte p89,jdouble p90 + ,jdouble p91,jint p92,jbyte p93,jdouble p94,jdouble p95,jdouble p96,jdouble p97 + ,jdouble p98,jdouble p99,jbyte p100,jbyte p101,jdouble p102,jdouble p103 + ,jbyte p104,jdouble p105,jdouble p106,jbyte p107,jint p108,jbyte p109,jbyte p110 + ,jbyte p111,jdouble p112,jint p113,jdouble p114,jbyte p115,jint p116,jdouble p117 + ,jdouble p118,jbyte p119,jbyte p120,jint p121,jdouble p122,jint p123,jbyte p124 + ,jdouble p125,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%d\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%d\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%d\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%d\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%d\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%d\n",p110); + fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%d\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%d\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc29(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jdouble p2,jdouble p3,jfloat p4,jfloat p5,jint p6,jdouble p7 + ,jfloat p8,jbyte p9,jfloat p10,jfloat p11,jfloat p12,jdouble p13,jdouble p14 + ,jint p15,jbyte p16,jfloat p17,jfloat p18,jbyte p19,jint p20,jdouble p21 + ,jfloat p22,jfloat p23,jint p24,jfloat p25,jfloat p26,jbyte p27,jdouble p28 + ,jfloat p29,jint p30,jint p31,jfloat p32,jfloat p33,jfloat p34,jdouble p35 + ,jdouble p36,jfloat p37,jdouble p38,jfloat p39,jfloat p40,jfloat p41,jdouble p42 + ,jfloat p43,jdouble p44,jdouble p45,jdouble p46,jint p47,jdouble p48,jfloat p49 + ,jbyte p50,jdouble p51,jbyte p52,jdouble p53,jfloat p54,jdouble p55,jfloat p56 + ,jbyte p57,jfloat p58,jdouble p59,jfloat p60,jfloat p61,jdouble p62,jfloat p63 + ,jdouble p64,jbyte p65,jfloat p66,jfloat p67,jint p68,jfloat p69,jdouble p70 + ,jdouble p71,jfloat p72,jdouble p73,jfloat p74,jfloat p75,jbyte p76,jfloat p77 + ,jdouble p78,jdouble p79,jfloat p80,jdouble p81,jdouble p82,jbyte p83,jdouble p84 + ,jint p85,jfloat p86,jint p87,jdouble p88,jfloat p89,jbyte p90,jbyte p91 + ,jfloat p92,jbyte p93,jdouble p94,jfloat p95,jint p96,jdouble p97,jdouble p98 + ,jfloat p99,jdouble p100,jfloat p101,jfloat p102,jdouble p103,jfloat p104 + ,jint p105,jdouble p106,jint p107,jdouble p108,jdouble p109,jfloat p110 + ,jdouble p111,jfloat p112,jdouble p113,jdouble p114,jint p115,jfloat p116 + ,jfloat p117,jint p118,jfloat p119,jdouble p120,jfloat p121,jbyte p122,jfloat p123 + ,jfloat p124,jfloat p125,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%d\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc30(JNIEnv *e, jclass c +,jfloat p0,jdouble p1,jfloat p2,jfloat p3,jfloat p4,jfloat p5,jdouble p6 + ,jfloat p7,jdouble p8,jfloat p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13 + ,jfloat p14,jfloat p15,jdouble p16,jfloat p17,jdouble p18,jfloat p19,jdouble p20 + ,jdouble p21,jdouble p22,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jfloat p27 + ,jfloat p28,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jdouble p34 + ,jfloat p35,jdouble p36,jfloat p37,jdouble p38,jfloat p39,jfloat p40,jfloat p41 + ,jdouble p42,jfloat p43,jfloat p44,jfloat p45,jfloat p46,jdouble p47,jdouble p48 + ,jdouble p49,jfloat p50,jdouble p51,jdouble p52,jfloat p53,jfloat p54,jfloat p55 + ,jdouble p56,jdouble p57,jfloat p58,jfloat p59,jfloat p60,jfloat p61,jfloat p62 + ,jfloat p63,jfloat p64,jfloat p65,jfloat p66,jfloat p67,jfloat p68,jdouble p69 + ,jfloat p70,jfloat p71,jfloat p72,jfloat p73,jfloat p74,jfloat p75,jfloat p76 + ,jdouble p77,jfloat p78,jfloat p79,jfloat p80,jdouble p81,jfloat p82,jfloat p83 + ,jfloat p84,jdouble p85,jdouble p86,jdouble p87,jfloat p88,jfloat p89,jfloat p90 + ,jfloat p91,jfloat p92,jdouble p93,jfloat p94,jfloat p95,jfloat p96,jfloat p97 + ,jfloat p98,jdouble p99,jdouble p100,jfloat p101,jfloat p102,jdouble p103 + ,jdouble p104,jfloat p105,jdouble p106,jfloat p107,jfloat p108,jfloat p109 + ,jfloat p110,jdouble p111,jfloat p112,jfloat p113,jfloat p114,jfloat p115 + ,jfloat p116,jfloat p117,jfloat p118,jfloat p119,jfloat p120,jfloat p121 + ,jfloat p122,jfloat p123,jdouble p124,jfloat p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc31(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jfloat p2,jfloat p3,jfloat p4,jdouble p5,jfloat p6 + ,jfloat p7,jdouble p8,jdouble p9,jint p10,jdouble p11,jdouble p12,jfloat p13 + ,jint p14,jdouble p15,jfloat p16,jfloat p17,jfloat p18,jfloat p19,jfloat p20 + ,jint p21,jfloat p22,jdouble p23,jint p24,jfloat p25,jdouble p26,jdouble p27 + ,jdouble p28,jfloat p29,jdouble p30,jfloat p31,jdouble p32,jfloat p33,jfloat p34 + ,jfloat p35,jdouble p36,jfloat p37,jdouble p38,jdouble p39,jint p40,jint p41 + ,jdouble p42,jfloat p43,jfloat p44,jfloat p45,jdouble p46,jdouble p47,jfloat p48 + ,jfloat p49,jdouble p50,jdouble p51,jdouble p52,jfloat p53,jint p54,jdouble p55 + ,jfloat p56,jdouble p57,jfloat p58,jfloat p59,jfloat p60,jdouble p61,jfloat p62 + ,jint p63,jdouble p64,jint p65,jint p66,jdouble p67,jdouble p68,jdouble p69 + ,jfloat p70,jfloat p71,jdouble p72,jint p73,jint p74,jfloat p75,jdouble p76 + ,jfloat p77,jfloat p78,jfloat p79,jfloat p80,jdouble p81,jdouble p82,jdouble p83 + ,jdouble p84,jdouble p85,jfloat p86,jfloat p87,jint p88,jdouble p89,jdouble p90 + ,jfloat p91,jdouble p92,jfloat p93,jint p94,jfloat p95,jfloat p96,jdouble p97 + ,jint p98,jint p99,jdouble p100,jdouble p101,jfloat p102,jfloat p103,jdouble p104 + ,jdouble p105,jdouble p106,jdouble p107,jdouble p108,jfloat p109,jfloat p110 + ,jdouble p111,jfloat p112,jdouble p113,jdouble p114,jfloat p115,jfloat p116 + ,jfloat p117,jfloat p118,jdouble p119,jint p120,jdouble p121,jfloat p122 + ,jdouble p123,jdouble p124,jdouble p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%d\n",p98); + fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc32(JNIEnv *e, jclass c +,jdouble p0,jfloat p1,jbyte p2,jfloat p3,jdouble p4,jbyte p5,jfloat p6,jfloat p7 + ,jdouble p8,jfloat p9,jfloat p10,jfloat p11,jdouble p12,jfloat p13,jfloat p14 + ,jdouble p15,jfloat p16,jbyte p17,jfloat p18,jfloat p19,jfloat p20,jfloat p21 + ,jbyte p22,jbyte p23,jbyte p24,jfloat p25,jfloat p26,jdouble p27,jbyte p28 + ,jdouble p29,jfloat p30,jdouble p31,jdouble p32,jfloat p33,jbyte p34,jfloat p35 + ,jfloat p36,jdouble p37,jfloat p38,jdouble p39,jfloat p40,jdouble p41,jbyte p42 + ,jdouble p43,jfloat p44,jdouble p45,jbyte p46,jfloat p47,jbyte p48,jfloat p49 + ,jfloat p50,jfloat p51,jfloat p52,jdouble p53,jdouble p54,jdouble p55,jfloat p56 + ,jdouble p57,jdouble p58,jfloat p59,jdouble p60,jdouble p61,jdouble p62 + ,jdouble p63,jfloat p64,jdouble p65,jdouble p66,jdouble p67,jbyte p68,jdouble p69 + ,jfloat p70,jdouble p71,jbyte p72,jdouble p73,jdouble p74,jbyte p75,jdouble p76 + ,jdouble p77,jdouble p78,jbyte p79,jdouble p80,jdouble p81,jfloat p82,jdouble p83 + ,jfloat p84,jdouble p85,jbyte p86,jdouble p87,jdouble p88,jfloat p89,jdouble p90 + ,jdouble p91,jdouble p92,jdouble p93,jbyte p94,jfloat p95,jdouble p96,jdouble p97 + ,jfloat p98,jdouble p99,jfloat p100,jdouble p101,jfloat p102,jfloat p103 + ,jbyte p104,jdouble p105,jdouble p106,jdouble p107,jfloat p108,jfloat p109 + ,jfloat p110,jbyte p111,jdouble p112,jbyte p113,jdouble p114,jdouble p115 + ,jfloat p116,jfloat p117,jfloat p118,jdouble p119,jdouble p120,jdouble p121 + ,jfloat p122,jfloat p123,jfloat p124,jbyte p125,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc33(JNIEnv *e, jclass c +,jfloat p0,jint p1,jint p2,jint p3,jfloat p4,jfloat p5,jfloat p6,jint p7 + ,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jfloat p14 + ,jfloat p15,jfloat p16,jint p17,jfloat p18,jfloat p19,jfloat p20,jfloat p21 + ,jint p22,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jfloat p27,jfloat p28 + ,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jfloat p35 + ,jfloat p36,jfloat p37,jint p38,jint p39,jint p40,jfloat p41,jfloat p42 + ,jfloat p43,jfloat p44,jint p45,jfloat p46,jfloat p47,jint p48,jfloat p49 + ,jfloat p50,jfloat p51,jfloat p52,jint p53,jfloat p54,jfloat p55,jfloat p56 + ,jfloat p57,jfloat p58,jfloat p59,jfloat p60,jint p61,jfloat p62,jfloat p63 + ,jfloat p64,jfloat p65,jint p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 + ,jint p71,jfloat p72,jfloat p73,jfloat p74,jfloat p75,jfloat p76,jfloat p77 + ,jfloat p78,jfloat p79,jfloat p80,jfloat p81,jfloat p82,jfloat p83,jfloat p84 + ,jfloat p85,jfloat p86,jfloat p87,jfloat p88,jint p89,jint p90,jfloat p91 + ,jfloat p92,jfloat p93,jint p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98 + ,jfloat p99,jfloat p100,jint p101,jfloat p102,jfloat p103,jfloat p104,jint p105 + ,jint p106,jfloat p107,jint p108,jfloat p109,jfloat p110,jfloat p111,jfloat p112 + ,jfloat p113,jfloat p114,jint p115,jint p116,jfloat p117,jfloat p118,jint p119 + ,jfloat p120,jfloat p121,jfloat p122,jfloat p123,jfloat p124,jfloat p125 + ,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%d\n",p115);fprintf(file,"p116=%d\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%d\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc34(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jbyte p5,jfloat p6,jfloat p7 + ,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jbyte p12,jfloat p13,jfloat p14 + ,jbyte p15,jfloat p16,jfloat p17,jbyte p18,jbyte p19,jfloat p20,jfloat p21 + ,jbyte p22,jfloat p23,jfloat p24,jbyte p25,jbyte p26,jbyte p27,jfloat p28 + ,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jfloat p35 + ,jbyte p36,jfloat p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jfloat p42 + ,jfloat p43,jfloat p44,jbyte p45,jfloat p46,jbyte p47,jfloat p48,jbyte p49 + ,jfloat p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54,jfloat p55,jfloat p56 + ,jbyte p57,jfloat p58,jfloat p59,jfloat p60,jfloat p61,jbyte p62,jfloat p63 + ,jfloat p64,jfloat p65,jfloat p66,jfloat p67,jbyte p68,jbyte p69,jfloat p70 + ,jfloat p71,jfloat p72,jfloat p73,jfloat p74,jbyte p75,jfloat p76,jfloat p77 + ,jbyte p78,jfloat p79,jfloat p80,jfloat p81,jfloat p82,jfloat p83,jfloat p84 + ,jfloat p85,jfloat p86,jbyte p87,jbyte p88,jfloat p89,jfloat p90,jfloat p91 + ,jfloat p92,jfloat p93,jfloat p94,jfloat p95,jfloat p96,jbyte p97,jfloat p98 + ,jfloat p99,jfloat p100,jfloat p101,jbyte p102,jfloat p103,jfloat p104,jbyte p105 + ,jfloat p106,jfloat p107,jfloat p108,jfloat p109,jfloat p110,jfloat p111 + ,jfloat p112,jbyte p113,jfloat p114,jfloat p115,jfloat p116,jfloat p117 + ,jfloat p118,jfloat p119,jfloat p120,jfloat p121,jfloat p122,jfloat p123 + ,jfloat p124,jbyte p125,jbyte p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%d\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%d\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc35(JNIEnv *e, jclass c +,jint p0,jbyte p1,jbyte p2,jfloat p3,jfloat p4,jfloat p5,jfloat p6,jfloat p7 + ,jint p8,jfloat p9,jint p10,jfloat p11,jfloat p12,jbyte p13,jbyte p14,jfloat p15 + ,jfloat p16,jbyte p17,jbyte p18,jfloat p19,jfloat p20,jfloat p21,jfloat p22 + ,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jint p27,jfloat p28,jfloat p29 + ,jfloat p30,jbyte p31,jfloat p32,jfloat p33,jfloat p34,jfloat p35,jbyte p36 + ,jfloat p37,jint p38,jfloat p39,jbyte p40,jbyte p41,jfloat p42,jfloat p43 + ,jfloat p44,jint p45,jfloat p46,jbyte p47,jbyte p48,jint p49,jfloat p50 + ,jint p51,jfloat p52,jfloat p53,jfloat p54,jbyte p55,jbyte p56,jfloat p57 + ,jfloat p58,jfloat p59,jint p60,jint p61,jfloat p62,jint p63,jbyte p64,jfloat p65 + ,jint p66,jfloat p67,jfloat p68,jbyte p69,jfloat p70,jfloat p71,jfloat p72 + ,jint p73,jfloat p74,jfloat p75,jfloat p76,jbyte p77,jfloat p78,jfloat p79 + ,jfloat p80,jbyte p81,jfloat p82,jbyte p83,jfloat p84,jfloat p85,jbyte p86 + ,jfloat p87,jfloat p88,jfloat p89,jfloat p90,jbyte p91,jfloat p92,jfloat p93 + ,jfloat p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98,jint p99,jfloat p100 + ,jfloat p101,jint p102,jfloat p103,jfloat p104,jbyte p105,jfloat p106,jint p107 + ,jfloat p108,jfloat p109,jfloat p110,jfloat p111,jfloat p112,jint p113,jfloat p114 + ,jfloat p115,jfloat p116,jfloat p117,jbyte p118,jfloat p119,jbyte p120,jfloat p121 + ,jfloat p122,jint p123,jfloat p124,jfloat p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%d\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%d\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%d\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc36(JNIEnv *e, jclass c +,jint p0,jint p1,jdouble p2,jdouble p3,jdouble p4,jdouble p5,jdouble p6 + ,jint p7,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jdouble p12,jdouble p13 + ,jdouble p14,jdouble p15,jdouble p16,jdouble p17,jint p18,jint p19,jdouble p20 + ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 + ,jdouble p27,jdouble p28,jdouble p29,jdouble p30,jdouble p31,jdouble p32 + ,jdouble p33,jdouble p34,jint p35,jdouble p36,jdouble p37,jdouble p38,jdouble p39 + ,jdouble p40,jdouble p41,jdouble p42,jdouble p43,jint p44,jdouble p45,jdouble p46 + ,jint p47,jint p48,jdouble p49,jdouble p50,jdouble p51,jdouble p52,jdouble p53 + ,jdouble p54,jdouble p55,jint p56,jdouble p57,jdouble p58,jdouble p59,jdouble p60 + ,jdouble p61,jdouble p62,jdouble p63,jdouble p64,jdouble p65,jdouble p66 + ,jdouble p67,jdouble p68,jdouble p69,jint p70,jdouble p71,jint p72,jdouble p73 + ,jdouble p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78,jdouble p79 + ,jint p80,jdouble p81,jdouble p82,jdouble p83,jdouble p84,jdouble p85,jdouble p86 + ,jdouble p87,jdouble p88,jdouble p89,jdouble p90,jdouble p91,jint p92,jdouble p93 + ,jdouble p94,jdouble p95,jdouble p96,jdouble p97,jdouble p98,jint p99,jint p100 + ,jint p101,jint p102,jint p103,jint p104,jint p105,jint p106,jdouble p107 + ,jdouble p108,jdouble p109,jint p110,jdouble p111,jdouble p112,jdouble p113 + ,jdouble p114,jdouble p115,jdouble p116,jdouble p117,jdouble p118,jdouble p119 + ,jdouble p120,jdouble p121,jdouble p122,jdouble p123,jdouble p124,jdouble p125 + ,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%d\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%d\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%d\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%d\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%d\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%d\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%d\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc37(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jdouble p4,jdouble p5,jdouble p6 + ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jbyte p11,jdouble p12,jdouble p13 + ,jdouble p14,jdouble p15,jdouble p16,jdouble p17,jdouble p18,jdouble p19 + ,jdouble p20,jdouble p21,jbyte p22,jbyte p23,jdouble p24,jdouble p25,jbyte p26 + ,jdouble p27,jdouble p28,jdouble p29,jdouble p30,jdouble p31,jdouble p32 + ,jdouble p33,jdouble p34,jdouble p35,jdouble p36,jdouble p37,jbyte p38,jbyte p39 + ,jdouble p40,jdouble p41,jdouble p42,jdouble p43,jdouble p44,jbyte p45,jdouble p46 + ,jdouble p47,jdouble p48,jbyte p49,jdouble p50,jdouble p51,jdouble p52,jdouble p53 + ,jdouble p54,jdouble p55,jbyte p56,jbyte p57,jdouble p58,jdouble p59,jdouble p60 + ,jdouble p61,jdouble p62,jdouble p63,jdouble p64,jdouble p65,jbyte p66,jdouble p67 + ,jdouble p68,jdouble p69,jdouble p70,jbyte p71,jdouble p72,jdouble p73,jdouble p74 + ,jdouble p75,jdouble p76,jdouble p77,jdouble p78,jdouble p79,jdouble p80 + ,jdouble p81,jdouble p82,jdouble p83,jdouble p84,jdouble p85,jdouble p86 + ,jdouble p87,jdouble p88,jdouble p89,jdouble p90,jdouble p91,jdouble p92 + ,jdouble p93,jdouble p94,jdouble p95,jbyte p96,jbyte p97,jdouble p98,jdouble p99 + ,jdouble p100,jdouble p101,jdouble p102,jdouble p103,jdouble p104,jdouble p105 + ,jdouble p106,jdouble p107,jdouble p108,jbyte p109,jdouble p110,jdouble p111 + ,jdouble p112,jdouble p113,jdouble p114,jdouble p115,jdouble p116,jdouble p117 + ,jbyte p118,jdouble p119,jdouble p120,jdouble p121,jdouble p122,jdouble p123 + ,jbyte p124,jdouble p125,jbyte p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%d\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%d\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc38(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jdouble p2,jint p3,jint p4,jdouble p5,jdouble p6 + ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jint p11,jdouble p12,jdouble p13 + ,jint p14,jbyte p15,jdouble p16,jdouble p17,jdouble p18,jdouble p19,jint p20 + ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jint p25,jdouble p26,jint p27 + ,jbyte p28,jdouble p29,jbyte p30,jdouble p31,jdouble p32,jint p33,jdouble p34 + ,jint p35,jbyte p36,jbyte p37,jdouble p38,jdouble p39,jdouble p40,jdouble p41 + ,jint p42,jdouble p43,jdouble p44,jdouble p45,jdouble p46,jdouble p47,jint p48 + ,jdouble p49,jint p50,jint p51,jdouble p52,jbyte p53,jdouble p54,jdouble p55 + ,jbyte p56,jdouble p57,jdouble p58,jdouble p59,jdouble p60,jdouble p61,jbyte p62 + ,jdouble p63,jdouble p64,jdouble p65,jbyte p66,jint p67,jdouble p68,jdouble p69 + ,jdouble p70,jdouble p71,jdouble p72,jbyte p73,jdouble p74,jdouble p75,jdouble p76 + ,jbyte p77,jdouble p78,jdouble p79,jdouble p80,jdouble p81,jdouble p82,jint p83 + ,jdouble p84,jdouble p85,jdouble p86,jint p87,jdouble p88,jint p89,jdouble p90 + ,jdouble p91,jdouble p92,jdouble p93,jdouble p94,jint p95,jbyte p96,jbyte p97 + ,jdouble p98,jint p99,jdouble p100,jdouble p101,jdouble p102,jdouble p103 + ,jdouble p104,jdouble p105,jdouble p106,jdouble p107,jdouble p108,jdouble p109 + ,jdouble p110,jdouble p111,jint p112,jdouble p113,jdouble p114,jdouble p115 + ,jdouble p116,jbyte p117,jdouble p118,jdouble p119,jbyte p120,jint p121 + ,jdouble p122,jint p123,jdouble p124,jdouble p125,jbyte p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%d\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%d\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%d\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%d\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%d\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%d\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%d\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc39(JNIEnv *e, jclass c +,jdouble p0,jfloat p1,jdouble p2,jbyte p3,jdouble p4,jint p5,jdouble p6 + ,jfloat p7,jfloat p8,jdouble p9,jint p10,jbyte p11,jfloat p12,jdouble p13 + ,jint p14,jint p15,jfloat p16,jbyte p17,jdouble p18,jdouble p19,jfloat p20 + ,jfloat p21,jdouble p22,jfloat p23,jfloat p24,jdouble p25,jfloat p26,jfloat p27 + ,jfloat p28,jfloat p29,jfloat p30,jdouble p31,jdouble p32,jdouble p33,jfloat p34 + ,jdouble p35,jfloat p36,jdouble p37,jfloat p38,jfloat p39,jfloat p40,jint p41 + ,jbyte p42,jdouble p43,jfloat p44,jfloat p45,jint p46,jbyte p47,jfloat p48 + ,jdouble p49,jdouble p50,jfloat p51,jfloat p52,jfloat p53,jdouble p54,jint p55 + ,jfloat p56,jfloat p57,jfloat p58,jfloat p59,jfloat p60,jdouble p61,jdouble p62 + ,jfloat p63,jfloat p64,jfloat p65,jdouble p66,jfloat p67,jdouble p68,jdouble p69 + ,jdouble p70,jdouble p71,jdouble p72,jdouble p73,jdouble p74,jfloat p75 + ,jint p76,jfloat p77,jdouble p78,jdouble p79,jdouble p80,jdouble p81,jbyte p82 + ,jfloat p83,jfloat p84,jfloat p85,jfloat p86,jdouble p87,jfloat p88,jfloat p89 + ,jfloat p90,jfloat p91,jfloat p92,jdouble p93,jfloat p94,jdouble p95,jfloat p96 + ,jdouble p97,jfloat p98,jfloat p99,jdouble p100,jdouble p101,jfloat p102 + ,jfloat p103,jdouble p104,jdouble p105,jfloat p106,jbyte p107,jdouble p108 + ,jfloat p109,jfloat p110,jdouble p111,jdouble p112,jdouble p113,jdouble p114 + ,jdouble p115,jdouble p116,jfloat p117,jdouble p118,jfloat p119,jfloat p120 + ,jfloat p121,jfloat p122,jfloat p123,jdouble p124,jfloat p125,jfloat p126 + ) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%d\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%d\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%d\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc40(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jfloat p2,jdouble p3,jdouble p4,jfloat p5,jdouble p6 + ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jdouble p11,jdouble p12,jfloat p13 + ,jfloat p14,jdouble p15,jfloat p16,jfloat p17,jdouble p18,jfloat p19,jdouble p20 + ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 + ,jfloat p27,jfloat p28,jdouble p29,jdouble p30,jdouble p31,jfloat p32,jfloat p33 + ,jfloat p34,jfloat p35,jdouble p36,jfloat p37,jfloat p38,jfloat p39,jdouble p40 + ,jfloat p41,jdouble p42,jdouble p43,jfloat p44,jdouble p45,jdouble p46,jdouble p47 + ,jfloat p48,jdouble p49,jdouble p50,jdouble p51,jdouble p52,jfloat p53,jdouble p54 + ,jdouble p55,jdouble p56,jdouble p57,jdouble p58,jdouble p59,jdouble p60 + ,jdouble p61,jdouble p62,jfloat p63,jfloat p64,jfloat p65,jfloat p66,jfloat p67 + ,jdouble p68,jdouble p69,jdouble p70,jdouble p71,jdouble p72,jdouble p73 + ,jfloat p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78,jdouble p79 + ,jfloat p80,jdouble p81,jdouble p82,jfloat p83,jdouble p84,jdouble p85,jdouble p86 + ,jfloat p87,jfloat p88,jdouble p89,jfloat p90,jdouble p91,jfloat p92,jfloat p93 + ,jfloat p94,jfloat p95,jdouble p96,jfloat p97,jfloat p98,jdouble p99,jdouble p100 + ,jdouble p101,jdouble p102,jfloat p103,jdouble p104,jdouble p105,jdouble p106 + ,jdouble p107,jdouble p108,jdouble p109,jfloat p110,jfloat p111,jdouble p112 + ,jdouble p113,jdouble p114,jdouble p115,jdouble p116,jdouble p117,jdouble p118 + ,jdouble p119,jfloat p120,jdouble p121,jdouble p122,jdouble p123,jdouble p124 + ,jdouble p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc41(JNIEnv *e, jclass c +,jfloat p0,jdouble p1,jint p2,jdouble p3,jint p4,jfloat p5,jfloat p6,jfloat p7 + ,jint p8,jint p9,jfloat p10,jdouble p11,jdouble p12,jdouble p13,jint p14 + ,jdouble p15,jdouble p16,jfloat p17,jdouble p18,jdouble p19,jdouble p20 + ,jint p21,jdouble p22,jfloat p23,jdouble p24,jfloat p25,jdouble p26,jdouble p27 + ,jint p28,jdouble p29,jdouble p30,jint p31,jdouble p32,jdouble p33,jfloat p34 + ,jint p35,jdouble p36,jint p37,jint p38,jdouble p39,jfloat p40,jint p41 + ,jdouble p42,jdouble p43,jdouble p44,jdouble p45,jint p46,jdouble p47,jfloat p48 + ,jfloat p49,jfloat p50,jdouble p51,jdouble p52,jfloat p53,jfloat p54,jdouble p55 + ,jfloat p56,jfloat p57,jdouble p58,jfloat p59,jdouble p60,jfloat p61,jdouble p62 + ,jfloat p63,jdouble p64,jdouble p65,jdouble p66,jdouble p67,jdouble p68 + ,jdouble p69,jfloat p70,jfloat p71,jdouble p72,jfloat p73,jdouble p74,jfloat p75 + ,jint p76,jfloat p77,jdouble p78,jint p79,jfloat p80,jfloat p81,jdouble p82 + ,jdouble p83,jdouble p84,jdouble p85,jdouble p86,jfloat p87,jfloat p88,jfloat p89 + ,jdouble p90,jint p91,jfloat p92,jdouble p93,jfloat p94,jfloat p95,jfloat p96 + ,jfloat p97,jfloat p98,jdouble p99,jfloat p100,jint p101,jdouble p102,jfloat p103 + ,jdouble p104,jdouble p105,jfloat p106,jfloat p107,jdouble p108,jfloat p109 + ,jfloat p110,jdouble p111,jfloat p112,jdouble p113,jfloat p114,jfloat p115 + ,jfloat p116,jdouble p117,jint p118,jfloat p119,jint p120,jdouble p121,jdouble p122 + ,jint p123,jdouble p124,jfloat p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%d\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%d\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%d\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%d\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%d\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%d\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc42(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jdouble p2,jdouble p3,jfloat p4,jdouble p5,jdouble p6 + ,jfloat p7,jdouble p8,jdouble p9,jfloat p10,jdouble p11,jbyte p12,jfloat p13 + ,jfloat p14,jfloat p15,jdouble p16,jdouble p17,jfloat p18,jdouble p19,jdouble p20 + ,jdouble p21,jfloat p22,jfloat p23,jdouble p24,jfloat p25,jdouble p26,jfloat p27 + ,jfloat p28,jfloat p29,jfloat p30,jfloat p31,jdouble p32,jfloat p33,jbyte p34 + ,jfloat p35,jdouble p36,jfloat p37,jdouble p38,jfloat p39,jdouble p40,jbyte p41 + ,jbyte p42,jdouble p43,jfloat p44,jdouble p45,jfloat p46,jfloat p47,jdouble p48 + ,jdouble p49,jfloat p50,jdouble p51,jdouble p52,jdouble p53,jdouble p54 + ,jfloat p55,jdouble p56,jfloat p57,jbyte p58,jdouble p59,jfloat p60,jdouble p61 + ,jdouble p62,jdouble p63,jfloat p64,jfloat p65,jdouble p66,jdouble p67,jbyte p68 + ,jfloat p69,jfloat p70,jdouble p71,jfloat p72,jfloat p73,jdouble p74,jdouble p75 + ,jfloat p76,jfloat p77,jfloat p78,jdouble p79,jdouble p80,jdouble p81,jbyte p82 + ,jfloat p83,jdouble p84,jdouble p85,jdouble p86,jdouble p87,jdouble p88 + ,jdouble p89,jfloat p90,jdouble p91,jfloat p92,jbyte p93,jfloat p94,jdouble p95 + ,jdouble p96,jfloat p97,jdouble p98,jfloat p99,jfloat p100,jfloat p101,jdouble p102 + ,jdouble p103,jdouble p104,jfloat p105,jfloat p106,jfloat p107,jfloat p108 + ,jdouble p109,jfloat p110,jdouble p111,jdouble p112,jdouble p113,jfloat p114 + ,jdouble p115,jfloat p116,jbyte p117,jdouble p118,jfloat p119,jdouble p120 + ,jfloat p121,jbyte p122,jfloat p123,jdouble p124,jfloat p125,jfloat p126 + ) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%d\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc43(JNIEnv *e, jclass c +,jfloat p0,jint p1,jfloat p2,jfloat p3,jfloat p4,jfloat p5,jfloat p6,jint p7 + ,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jint p14 + ,jfloat p15,jfloat p16,jfloat p17,jfloat p18,jfloat p19,jfloat p20,jfloat p21 + ,jfloat p22,jfloat p23,jfloat p24,jfloat p25,jfloat p26,jfloat p27,jfloat p28 + ,jfloat p29,jfloat p30,jfloat p31,jint p32,jfloat p33,jfloat p34,jfloat p35 + ,jfloat p36,jfloat p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jint p42 + ,jfloat p43,jfloat p44,jfloat p45,jfloat p46,jfloat p47,jfloat p48,jint p49 + ,jint p50,jint p51,jfloat p52,jfloat p53,jfloat p54,jfloat p55,jfloat p56 + ,jfloat p57,jfloat p58,jfloat p59,jfloat p60,jint p61,jfloat p62,jint p63 + ,jfloat p64,jfloat p65,jfloat p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 + ,jfloat p71,jfloat p72,jfloat p73,jfloat p74,jfloat p75,jfloat p76,jfloat p77 + ,jfloat p78,jint p79,jint p80,jint p81,jfloat p82,jfloat p83,jfloat p84 + ,jfloat p85,jfloat p86,jfloat p87,jfloat p88,jfloat p89,jfloat p90,jfloat p91 + ,jfloat p92,jfloat p93,jfloat p94,jfloat p95,jfloat p96,jfloat p97,jfloat p98 + ,jfloat p99,jfloat p100,jfloat p101,jfloat p102,jfloat p103,jfloat p104 + ,jfloat p105,jfloat p106,jfloat p107,jfloat p108,jfloat p109,jfloat p110 + ,jint p111,jfloat p112,jfloat p113,jfloat p114,jfloat p115,jfloat p116,jfloat p117 + ,jfloat p118,jfloat p119,jfloat p120,jfloat p121,jfloat p122,jfloat p123 + ,jfloat p124,jint p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%d\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%d\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%d\n",p80); + fprintf(file,"p81=%d\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%d\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc44(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jbyte p5,jfloat p6,jfloat p7 + ,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jfloat p12,jfloat p13,jfloat p14 + ,jbyte p15,jfloat p16,jfloat p17,jfloat p18,jbyte p19,jfloat p20,jfloat p21 + ,jfloat p22,jfloat p23,jfloat p24,jbyte p25,jfloat p26,jfloat p27,jfloat p28 + ,jfloat p29,jfloat p30,jfloat p31,jbyte p32,jbyte p33,jfloat p34,jfloat p35 + ,jfloat p36,jfloat p37,jbyte p38,jfloat p39,jfloat p40,jbyte p41,jfloat p42 + ,jfloat p43,jfloat p44,jfloat p45,jfloat p46,jfloat p47,jbyte p48,jfloat p49 + ,jbyte p50,jfloat p51,jfloat p52,jfloat p53,jfloat p54,jfloat p55,jfloat p56 + ,jfloat p57,jfloat p58,jbyte p59,jfloat p60,jfloat p61,jfloat p62,jfloat p63 + ,jfloat p64,jfloat p65,jbyte p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 + ,jbyte p71,jfloat p72,jbyte p73,jbyte p74,jfloat p75,jfloat p76,jbyte p77 + ,jbyte p78,jfloat p79,jfloat p80,jfloat p81,jfloat p82,jfloat p83,jfloat p84 + ,jfloat p85,jfloat p86,jfloat p87,jfloat p88,jfloat p89,jfloat p90,jfloat p91 + ,jfloat p92,jbyte p93,jfloat p94,jfloat p95,jfloat p96,jbyte p97,jfloat p98 + ,jfloat p99,jfloat p100,jbyte p101,jfloat p102,jfloat p103,jfloat p104,jfloat p105 + ,jfloat p106,jfloat p107,jbyte p108,jfloat p109,jfloat p110,jfloat p111 + ,jfloat p112,jbyte p113,jfloat p114,jfloat p115,jfloat p116,jbyte p117,jfloat p118 + ,jfloat p119,jfloat p120,jbyte p121,jfloat p122,jfloat p123,jfloat p124 + ,jfloat p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%d\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%d\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%d\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%d\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc45(JNIEnv *e, jclass c +,jbyte p0,jbyte p1,jfloat p2,jfloat p3,jfloat p4,jbyte p5,jint p6,jfloat p7 + ,jfloat p8,jbyte p9,jfloat p10,jbyte p11,jbyte p12,jfloat p13,jfloat p14 + ,jfloat p15,jfloat p16,jbyte p17,jfloat p18,jint p19,jint p20,jfloat p21 + ,jfloat p22,jfloat p23,jbyte p24,jbyte p25,jfloat p26,jfloat p27,jbyte p28 + ,jfloat p29,jfloat p30,jfloat p31,jfloat p32,jfloat p33,jfloat p34,jint p35 + ,jfloat p36,jint p37,jfloat p38,jfloat p39,jfloat p40,jfloat p41,jfloat p42 + ,jbyte p43,jfloat p44,jint p45,jbyte p46,jfloat p47,jfloat p48,jfloat p49 + ,jbyte p50,jfloat p51,jbyte p52,jfloat p53,jfloat p54,jfloat p55,jfloat p56 + ,jfloat p57,jfloat p58,jfloat p59,jint p60,jint p61,jfloat p62,jbyte p63 + ,jfloat p64,jint p65,jfloat p66,jfloat p67,jfloat p68,jfloat p69,jfloat p70 + ,jfloat p71,jfloat p72,jfloat p73,jfloat p74,jint p75,jfloat p76,jfloat p77 + ,jbyte p78,jfloat p79,jfloat p80,jfloat p81,jfloat p82,jbyte p83,jint p84 + ,jbyte p85,jfloat p86,jint p87,jfloat p88,jfloat p89,jfloat p90,jfloat p91 + ,jfloat p92,jint p93,jfloat p94,jfloat p95,jint p96,jfloat p97,jbyte p98 + ,jfloat p99,jbyte p100,jfloat p101,jint p102,jfloat p103,jfloat p104,jint p105 + ,jfloat p106,jfloat p107,jint p108,jfloat p109,jfloat p110,jfloat p111,jfloat p112 + ,jint p113,jfloat p114,jfloat p115,jfloat p116,jfloat p117,jfloat p118,jint p119 + ,jfloat p120,jbyte p121,jfloat p122,jfloat p123,jfloat p124,jbyte p125,jfloat p126 + ) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%d\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%d\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%d\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%d\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%d\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%d\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%d\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%d\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%d\n",p83); + fprintf(file,"p84=%d\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%d\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%d\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%d\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%d\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc46(JNIEnv *e, jclass c +,jint p0,jdouble p1,jdouble p2,jdouble p3,jdouble p4,jdouble p5,jdouble p6 + ,jdouble p7,jdouble p8,jdouble p9,jdouble p10,jint p11,jdouble p12,jdouble p13 + ,jdouble p14,jdouble p15,jint p16,jdouble p17,jdouble p18,jdouble p19,jdouble p20 + ,jdouble p21,jdouble p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 + ,jdouble p27,jint p28,jdouble p29,jdouble p30,jdouble p31,jdouble p32,jdouble p33 + ,jdouble p34,jdouble p35,jint p36,jint p37,jdouble p38,jint p39,jdouble p40 + ,jdouble p41,jdouble p42,jdouble p43,jdouble p44,jdouble p45,jdouble p46 + ,jdouble p47,jdouble p48,jdouble p49,jdouble p50,jdouble p51,jint p52,jdouble p53 + ,jdouble p54,jdouble p55,jdouble p56,jdouble p57,jdouble p58,jdouble p59 + ,jdouble p60,jdouble p61,jdouble p62,jdouble p63,jint p64,jdouble p65,jdouble p66 + ,jint p67,jint p68,jdouble p69,jdouble p70,jdouble p71,jdouble p72,jdouble p73 + ,jdouble p74,jdouble p75,jdouble p76,jint p77,jint p78,jdouble p79,jdouble p80 + ,jdouble p81,jint p82,jdouble p83,jdouble p84,jint p85,jdouble p86,jdouble p87 + ,jdouble p88,jint p89,jdouble p90,jdouble p91,jdouble p92,jint p93,jdouble p94 + ,jint p95,jdouble p96,jdouble p97,jdouble p98,jdouble p99,jdouble p100,jdouble p101 + ,jint p102,jdouble p103,jdouble p104,jdouble p105,jdouble p106,jdouble p107 + ,jdouble p108,jdouble p109,jdouble p110,jdouble p111,jdouble p112,jdouble p113 + ,jdouble p114,jdouble p115,jint p116,jint p117,jdouble p118,jdouble p119 + ,jdouble p120,jint p121,jdouble p122,jint p123,jint p124,jdouble p125,jdouble p126 + ) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%d\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%d\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%d\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%d\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%d\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%d\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%d\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%d\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%d\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%d\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc47(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jbyte p4,jdouble p5,jdouble p6 + ,jdouble p7,jbyte p8,jbyte p9,jdouble p10,jdouble p11,jdouble p12,jdouble p13 + ,jdouble p14,jdouble p15,jdouble p16,jdouble p17,jdouble p18,jdouble p19 + ,jdouble p20,jdouble p21,jbyte p22,jdouble p23,jdouble p24,jdouble p25,jdouble p26 + ,jbyte p27,jdouble p28,jdouble p29,jdouble p30,jdouble p31,jdouble p32,jdouble p33 + ,jdouble p34,jdouble p35,jdouble p36,jbyte p37,jbyte p38,jdouble p39,jdouble p40 + ,jdouble p41,jdouble p42,jdouble p43,jdouble p44,jdouble p45,jbyte p46,jdouble p47 + ,jdouble p48,jdouble p49,jdouble p50,jdouble p51,jbyte p52,jdouble p53,jdouble p54 + ,jdouble p55,jdouble p56,jdouble p57,jdouble p58,jdouble p59,jdouble p60 + ,jdouble p61,jdouble p62,jdouble p63,jdouble p64,jdouble p65,jdouble p66 + ,jdouble p67,jdouble p68,jdouble p69,jbyte p70,jdouble p71,jdouble p72,jdouble p73 + ,jdouble p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78,jdouble p79 + ,jdouble p80,jdouble p81,jdouble p82,jdouble p83,jdouble p84,jdouble p85 + ,jdouble p86,jdouble p87,jdouble p88,jdouble p89,jdouble p90,jdouble p91 + ,jdouble p92,jdouble p93,jbyte p94,jdouble p95,jdouble p96,jdouble p97,jdouble p98 + ,jdouble p99,jdouble p100,jbyte p101,jdouble p102,jdouble p103,jbyte p104 + ,jdouble p105,jdouble p106,jdouble p107,jdouble p108,jdouble p109,jdouble p110 + ,jdouble p111,jdouble p112,jdouble p113,jbyte p114,jdouble p115,jdouble p116 + ,jdouble p117,jdouble p118,jdouble p119,jbyte p120,jdouble p121,jbyte p122 + ,jdouble p123,jdouble p124,jdouble p125,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%d\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%d\n",p37);fprintf(file,"p38=%d\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%d\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%d\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%d\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%d\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc48(JNIEnv *e, jclass c +,jint p0,jdouble p1,jdouble p2,jdouble p3,jbyte p4,jdouble p5,jdouble p6 + ,jdouble p7,jdouble p8,jbyte p9,jint p10,jdouble p11,jbyte p12,jint p13 + ,jdouble p14,jdouble p15,jdouble p16,jdouble p17,jdouble p18,jint p19,jdouble p20 + ,jdouble p21,jint p22,jdouble p23,jdouble p24,jint p25,jdouble p26,jint p27 + ,jbyte p28,jbyte p29,jdouble p30,jdouble p31,jdouble p32,jbyte p33,jdouble p34 + ,jdouble p35,jdouble p36,jdouble p37,jdouble p38,jdouble p39,jdouble p40 + ,jdouble p41,jbyte p42,jint p43,jdouble p44,jbyte p45,jdouble p46,jbyte p47 + ,jdouble p48,jdouble p49,jbyte p50,jbyte p51,jdouble p52,jdouble p53,jint p54 + ,jdouble p55,jdouble p56,jint p57,jdouble p58,jdouble p59,jdouble p60,jdouble p61 + ,jint p62,jdouble p63,jdouble p64,jdouble p65,jbyte p66,jdouble p67,jdouble p68 + ,jdouble p69,jdouble p70,jdouble p71,jdouble p72,jbyte p73,jdouble p74,jdouble p75 + ,jint p76,jint p77,jint p78,jbyte p79,jdouble p80,jdouble p81,jbyte p82 + ,jdouble p83,jdouble p84,jbyte p85,jdouble p86,jint p87,jint p88,jdouble p89 + ,jdouble p90,jdouble p91,jdouble p92,jdouble p93,jint p94,jdouble p95,jdouble p96 + ,jdouble p97,jbyte p98,jdouble p99,jbyte p100,jbyte p101,jdouble p102,jdouble p103 + ,jdouble p104,jint p105,jdouble p106,jdouble p107,jdouble p108,jbyte p109 + ,jdouble p110,jdouble p111,jdouble p112,jdouble p113,jdouble p114,jdouble p115 + ,jdouble p116,jdouble p117,jdouble p118,jdouble p119,jint p120,jdouble p121 + ,jdouble p122,jdouble p123,jdouble p124,jdouble p125,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%d\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%d\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%d\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%d\n",p12);fprintf(file,"p13=%d\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%d\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%d\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%d\n",p28);fprintf(file,"p29=%d\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%d\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%d\n",p50); + fprintf(file,"p51=%d\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%d\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%d\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%d\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%d\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%d\n",p77); + fprintf(file,"p78=%d\n",p78);fprintf(file,"p79=%d\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%d\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%d\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%d\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%d\n",p100);fprintf(file,"p101=%d\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%d\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%d\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc49(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jdouble p2,jfloat p3,jfloat p4,jbyte p5,jdouble p6 + ,jint p7,jdouble p8,jfloat p9,jbyte p10,jfloat p11,jdouble p12,jfloat p13 + ,jdouble p14,jdouble p15,jdouble p16,jfloat p17,jfloat p18,jdouble p19,jfloat p20 + ,jfloat p21,jint p22,jfloat p23,jbyte p24,jfloat p25,jbyte p26,jdouble p27 + ,jdouble p28,jdouble p29,jdouble p30,jdouble p31,jdouble p32,jint p33,jfloat p34 + ,jfloat p35,jbyte p36,jfloat p37,jfloat p38,jfloat p39,jdouble p40,jbyte p41 + ,jint p42,jfloat p43,jdouble p44,jfloat p45,jdouble p46,jint p47,jbyte p48 + ,jdouble p49,jfloat p50,jdouble p51,jfloat p52,jfloat p53,jfloat p54,jfloat p55 + ,jfloat p56,jdouble p57,jbyte p58,jfloat p59,jfloat p60,jfloat p61,jfloat p62 + ,jfloat p63,jfloat p64,jfloat p65,jbyte p66,jdouble p67,jbyte p68,jfloat p69 + ,jfloat p70,jdouble p71,jdouble p72,jdouble p73,jint p74,jdouble p75,jfloat p76 + ,jfloat p77,jfloat p78,jfloat p79,jdouble p80,jfloat p81,jdouble p82,jfloat p83 + ,jfloat p84,jint p85,jfloat p86,jdouble p87,jdouble p88,jfloat p89,jint p90 + ,jdouble p91,jdouble p92,jdouble p93,jfloat p94,jfloat p95,jdouble p96,jdouble p97 + ,jfloat p98,jdouble p99,jfloat p100,jfloat p101,jfloat p102,jfloat p103 + ,jdouble p104,jfloat p105,jdouble p106,jfloat p107,jdouble p108,jfloat p109 + ,jfloat p110,jdouble p111,jfloat p112,jbyte p113,jfloat p114,jdouble p115 + ,jdouble p116,jfloat p117,jdouble p118,jdouble p119,jbyte p120,jfloat p121 + ,jfloat p122,jbyte p123,jdouble p124,jdouble p125,jfloat p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%d\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%d\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%d\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%d\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%d\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%d\n",p41); + fprintf(file,"p42=%d\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%d\n",p47); + fprintf(file,"p48=%d\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%d\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%d\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%d\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%d\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%d\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%d\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc50(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jfloat p4,jfloat p5,jdouble p6 + ,jfloat p7,jdouble p8,jfloat p9,jdouble p10,jdouble p11,jdouble p12,jdouble p13 + ,jdouble p14,jdouble p15,jfloat p16,jdouble p17,jfloat p18,jdouble p19,jfloat p20 + ,jdouble p21,jfloat p22,jdouble p23,jdouble p24,jdouble p25,jfloat p26,jdouble p27 + ,jdouble p28,jdouble p29,jdouble p30,jdouble p31,jfloat p32,jfloat p33,jdouble p34 + ,jdouble p35,jdouble p36,jdouble p37,jfloat p38,jdouble p39,jdouble p40 + ,jdouble p41,jdouble p42,jdouble p43,jdouble p44,jdouble p45,jdouble p46 + ,jfloat p47,jdouble p48,jfloat p49,jdouble p50,jdouble p51,jdouble p52,jdouble p53 + ,jdouble p54,jdouble p55,jdouble p56,jdouble p57,jdouble p58,jdouble p59 + ,jdouble p60,jdouble p61,jfloat p62,jfloat p63,jdouble p64,jdouble p65,jdouble p66 + ,jdouble p67,jdouble p68,jdouble p69,jdouble p70,jfloat p71,jdouble p72 + ,jdouble p73,jfloat p74,jdouble p75,jdouble p76,jdouble p77,jdouble p78 + ,jdouble p79,jdouble p80,jdouble p81,jdouble p82,jfloat p83,jfloat p84,jdouble p85 + ,jdouble p86,jfloat p87,jdouble p88,jdouble p89,jfloat p90,jdouble p91,jdouble p92 + ,jdouble p93,jfloat p94,jdouble p95,jfloat p96,jdouble p97,jdouble p98,jfloat p99 + ,jdouble p100,jfloat p101,jdouble p102,jdouble p103,jdouble p104,jdouble p105 + ,jdouble p106,jdouble p107,jdouble p108,jdouble p109,jfloat p110,jdouble p111 + ,jdouble p112,jdouble p113,jdouble p114,jfloat p115,jdouble p116,jdouble p117 + ,jdouble p118,jfloat p119,jdouble p120,jdouble p121,jdouble p122,jdouble p123 + ,jdouble p124,jdouble p125,jdouble p126) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%e\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%e\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%e\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%e\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc51(JNIEnv *e, jclass c +,jfloat p0,jfloat p1,jfloat p2,jfloat p3,jfloat p4,jdouble p5,jfloat p6 + ,jfloat p7,jdouble p8,jdouble p9,jint p10,jfloat p11,jdouble p12,jdouble p13 + ,jfloat p14,jdouble p15,jdouble p16,jdouble p17,jdouble p18,jdouble p19 + ,jfloat p20,jdouble p21,jfloat p22,jint p23,jdouble p24,jdouble p25,jfloat p26 + ,jint p27,jdouble p28,jfloat p29,jfloat p30,jdouble p31,jint p32,jint p33 + ,jfloat p34,jfloat p35,jdouble p36,jfloat p37,jfloat p38,jfloat p39,jfloat p40 + ,jfloat p41,jdouble p42,jdouble p43,jdouble p44,jint p45,jdouble p46,jfloat p47 + ,jfloat p48,jdouble p49,jdouble p50,jfloat p51,jfloat p52,jfloat p53,jdouble p54 + ,jfloat p55,jdouble p56,jfloat p57,jfloat p58,jint p59,jint p60,jdouble p61 + ,jdouble p62,jdouble p63,jfloat p64,jfloat p65,jdouble p66,jint p67,jint p68 + ,jfloat p69,jint p70,jdouble p71,jint p72,jfloat p73,jfloat p74,jdouble p75 + ,jdouble p76,jdouble p77,jfloat p78,jfloat p79,jfloat p80,jdouble p81,jdouble p82 + ,jfloat p83,jfloat p84,jdouble p85,jfloat p86,jint p87,jfloat p88,jfloat p89 + ,jdouble p90,jfloat p91,jdouble p92,jdouble p93,jint p94,jfloat p95,jfloat p96 + ,jfloat p97,jdouble p98,jdouble p99,jdouble p100,jdouble p101,jfloat p102 + ,jfloat p103,jdouble p104,jfloat p105,jdouble p106,jdouble p107,jfloat p108 + ,jfloat p109,jdouble p110,jfloat p111,jfloat p112,jfloat p113,jfloat p114 + ,jfloat p115,jdouble p116,jfloat p117,jdouble p118,jdouble p119,jdouble p120 + ,jfloat p121,jfloat p122,jfloat p123,jdouble p124,jdouble p125,jfloat p126 + ) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%e\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%d\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%d\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%d\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%d\n",p32); + fprintf(file,"p33=%d\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%e\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%e\n",p58);fprintf(file,"p59=%d\n",p59); + fprintf(file,"p60=%d\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%e\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%d\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%d\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%e\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%d\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%e\n",p102);fprintf(file,"p103=%e\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%e\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%e\n",p112);fprintf(file,"p113=%e\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%e\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} +JNIEXPORT void JNICALL Java_vm_jit_LongTransitions_LTTest_nativeFnc52(JNIEnv *e, jclass c +,jdouble p0,jdouble p1,jdouble p2,jdouble p3,jdouble p4,jbyte p5,jfloat p6 + ,jdouble p7,jfloat p8,jfloat p9,jfloat p10,jfloat p11,jdouble p12,jfloat p13 + ,jdouble p14,jdouble p15,jdouble p16,jfloat p17,jfloat p18,jdouble p19,jdouble p20 + ,jdouble p21,jdouble p22,jfloat p23,jdouble p24,jfloat p25,jfloat p26,jdouble p27 + ,jdouble p28,jfloat p29,jdouble p30,jfloat p31,jfloat p32,jfloat p33,jdouble p34 + ,jdouble p35,jdouble p36,jfloat p37,jfloat p38,jdouble p39,jdouble p40,jfloat p41 + ,jfloat p42,jfloat p43,jfloat p44,jbyte p45,jfloat p46,jdouble p47,jfloat p48 + ,jfloat p49,jdouble p50,jfloat p51,jbyte p52,jfloat p53,jfloat p54,jdouble p55 + ,jfloat p56,jdouble p57,jbyte p58,jdouble p59,jdouble p60,jdouble p61,jdouble p62 + ,jfloat p63,jdouble p64,jbyte p65,jfloat p66,jfloat p67,jbyte p68,jdouble p69 + ,jbyte p70,jdouble p71,jdouble p72,jdouble p73,jfloat p74,jdouble p75,jbyte p76 + ,jdouble p77,jdouble p78,jdouble p79,jdouble p80,jfloat p81,jdouble p82 + ,jdouble p83,jdouble p84,jfloat p85,jfloat p86,jfloat p87,jfloat p88,jdouble p89 + ,jfloat p90,jfloat p91,jfloat p92,jdouble p93,jbyte p94,jdouble p95,jfloat p96 + ,jfloat p97,jdouble p98,jdouble p99,jfloat p100,jdouble p101,jbyte p102 + ,jbyte p103,jfloat p104,jfloat p105,jdouble p106,jfloat p107,jbyte p108 + ,jfloat p109,jdouble p110,jfloat p111,jbyte p112,jbyte p113,jdouble p114 + ,jdouble p115,jdouble p116,jbyte p117,jfloat p118,jdouble p119,jdouble p120 + ,jfloat p121,jdouble p122,jdouble p123,jdouble p124,jdouble p125,jfloat p126 + ) +{ + FILE *file=fopen("LTTest_c.txt","a");fprintf(file,"p0=%e\n",p0);fprintf(file,"p1=%e\n",p1);fprintf(file,"p2=%e\n",p2); + fprintf(file,"p3=%e\n",p3);fprintf(file,"p4=%e\n",p4);fprintf(file,"p5=%d\n",p5); + fprintf(file,"p6=%e\n",p6);fprintf(file,"p7=%e\n",p7);fprintf(file,"p8=%e\n",p8); + fprintf(file,"p9=%e\n",p9);fprintf(file,"p10=%e\n",p10);fprintf(file,"p11=%e\n",p11); + fprintf(file,"p12=%e\n",p12);fprintf(file,"p13=%e\n",p13);fprintf(file,"p14=%e\n",p14); + fprintf(file,"p15=%e\n",p15);fprintf(file,"p16=%e\n",p16);fprintf(file,"p17=%e\n",p17); + fprintf(file,"p18=%e\n",p18);fprintf(file,"p19=%e\n",p19);fprintf(file,"p20=%e\n",p20); + fprintf(file,"p21=%e\n",p21);fprintf(file,"p22=%e\n",p22);fprintf(file,"p23=%e\n",p23); + fprintf(file,"p24=%e\n",p24);fprintf(file,"p25=%e\n",p25);fprintf(file,"p26=%e\n",p26); + fprintf(file,"p27=%e\n",p27);fprintf(file,"p28=%e\n",p28);fprintf(file,"p29=%e\n",p29); + fprintf(file,"p30=%e\n",p30);fprintf(file,"p31=%e\n",p31);fprintf(file,"p32=%e\n",p32); + fprintf(file,"p33=%e\n",p33);fprintf(file,"p34=%e\n",p34);fprintf(file,"p35=%e\n",p35); + fprintf(file,"p36=%e\n",p36);fprintf(file,"p37=%e\n",p37);fprintf(file,"p38=%e\n",p38); + fprintf(file,"p39=%e\n",p39);fprintf(file,"p40=%e\n",p40);fprintf(file,"p41=%e\n",p41); + fprintf(file,"p42=%e\n",p42);fprintf(file,"p43=%e\n",p43);fprintf(file,"p44=%e\n",p44); + fprintf(file,"p45=%d\n",p45);fprintf(file,"p46=%e\n",p46);fprintf(file,"p47=%e\n",p47); + fprintf(file,"p48=%e\n",p48);fprintf(file,"p49=%e\n",p49);fprintf(file,"p50=%e\n",p50); + fprintf(file,"p51=%e\n",p51);fprintf(file,"p52=%d\n",p52);fprintf(file,"p53=%e\n",p53); + fprintf(file,"p54=%e\n",p54);fprintf(file,"p55=%e\n",p55);fprintf(file,"p56=%e\n",p56); + fprintf(file,"p57=%e\n",p57);fprintf(file,"p58=%d\n",p58);fprintf(file,"p59=%e\n",p59); + fprintf(file,"p60=%e\n",p60);fprintf(file,"p61=%e\n",p61);fprintf(file,"p62=%e\n",p62); + fprintf(file,"p63=%e\n",p63);fprintf(file,"p64=%e\n",p64);fprintf(file,"p65=%d\n",p65); + fprintf(file,"p66=%e\n",p66);fprintf(file,"p67=%e\n",p67);fprintf(file,"p68=%d\n",p68); + fprintf(file,"p69=%e\n",p69);fprintf(file,"p70=%d\n",p70);fprintf(file,"p71=%e\n",p71); + fprintf(file,"p72=%e\n",p72);fprintf(file,"p73=%e\n",p73);fprintf(file,"p74=%e\n",p74); + fprintf(file,"p75=%e\n",p75);fprintf(file,"p76=%d\n",p76);fprintf(file,"p77=%e\n",p77); + fprintf(file,"p78=%e\n",p78);fprintf(file,"p79=%e\n",p79);fprintf(file,"p80=%e\n",p80); + fprintf(file,"p81=%e\n",p81);fprintf(file,"p82=%e\n",p82);fprintf(file,"p83=%e\n",p83); + fprintf(file,"p84=%e\n",p84);fprintf(file,"p85=%e\n",p85);fprintf(file,"p86=%e\n",p86); + fprintf(file,"p87=%e\n",p87);fprintf(file,"p88=%e\n",p88);fprintf(file,"p89=%e\n",p89); + fprintf(file,"p90=%e\n",p90);fprintf(file,"p91=%e\n",p91);fprintf(file,"p92=%e\n",p92); + fprintf(file,"p93=%e\n",p93);fprintf(file,"p94=%d\n",p94);fprintf(file,"p95=%e\n",p95); + fprintf(file,"p96=%e\n",p96);fprintf(file,"p97=%e\n",p97);fprintf(file,"p98=%e\n",p98); + fprintf(file,"p99=%e\n",p99);fprintf(file,"p100=%e\n",p100);fprintf(file,"p101=%e\n",p101); + fprintf(file,"p102=%d\n",p102);fprintf(file,"p103=%d\n",p103);fprintf(file,"p104=%e\n",p104); + fprintf(file,"p105=%e\n",p105);fprintf(file,"p106=%e\n",p106);fprintf(file,"p107=%e\n",p107); + fprintf(file,"p108=%d\n",p108);fprintf(file,"p109=%e\n",p109);fprintf(file,"p110=%e\n",p110); + fprintf(file,"p111=%e\n",p111);fprintf(file,"p112=%d\n",p112);fprintf(file,"p113=%d\n",p113); + fprintf(file,"p114=%e\n",p114);fprintf(file,"p115=%e\n",p115);fprintf(file,"p116=%e\n",p116); + fprintf(file,"p117=%d\n",p117);fprintf(file,"p118=%e\n",p118);fprintf(file,"p119=%e\n",p119); + fprintf(file,"p120=%e\n",p120);fprintf(file,"p121=%e\n",p121);fprintf(file,"p122=%e\n",p122); + fprintf(file,"p123=%e\n",p123);fprintf(file,"p124=%e\n",p124);fprintf(file,"p125=%e\n",p125); + fprintf(file,"p126=%e\n",p126); + fclose(file); +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/IndyRedefineClass.c b/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/IndyRedefineClass.c deleted file mode 100644 index 51550502029..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/IndyRedefineClass.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" -#include "mlvmJvmtiUtils.h" - -static jvmtiEnv* gJvmtiEnv = NULL; - -static jboolean gIsMethodEntryWorking = JNI_FALSE; -static jboolean gIsSingleStepWorking = JNI_FALSE; -static jboolean gIsErrorOccured = JNI_FALSE; - -static jboolean gIsDebuggerCompatible = JNI_FALSE; - -static jint gPopFrameDepth = 2; - -typedef struct TLS { - jint countOfFramesToPop; -} TLSStruct; - -static char * gszRedefineTriggerMethodName = "NONE"; -static char * gszRedefinedClassFileName = "NONE"; -static jboolean gIsClassRedefined = JNI_FALSE; - -JNIEXPORT void JNICALL -Java_vm_mlvm_indy_func_jvmti_share_IndyRedefineClass_setRedefineTriggerMethodName(JNIEnv * pEnv, jclass clazz, jstring name) { - copyFromJString(pEnv, name, &gszRedefineTriggerMethodName); - NSK_DISPLAY1("Setting redefine trigger method name to %s\n", gszRedefineTriggerMethodName); -} - -JNIEXPORT void JNICALL -Java_vm_mlvm_indy_func_jvmti_share_IndyRedefineClass_setRedefinedClassFileName(JNIEnv * pEnv, jclass clazz, jstring name) { - copyFromJString(pEnv, name, &gszRedefinedClassFileName); - NSK_DISPLAY1("Setting redefined class name to %s\n", gszRedefinedClassFileName); - gIsClassRedefined = JNI_FALSE; -} - -JNIEXPORT void JNICALL -Java_vm_mlvm_indy_func_jvmti_share_IndyRedefineClass_setPopFrameDepthAfterRedefine(JNIEnv * pEnv, jclass clazz, jint depth) { - gPopFrameDepth = depth; -} - -JNIEXPORT jboolean JNICALL -Java_vm_mlvm_indy_func_jvmti_share_IndyRedefineClass_checkStatus(JNIEnv * pEnv, jclass clazz) { - NSK_DISPLAY0("The following values should be non-zero for test to pass:\n"); - NSK_DISPLAY1("Method entry event fired? %i\n", gIsMethodEntryWorking); - NSK_DISPLAY1("Single step event fired? %i\n", gIsSingleStepWorking); - NSK_DISPLAY0("The following value should be zero for test to pass:\n"); - NSK_DISPLAY1("Any other error occured? %i\n", gIsErrorOccured); - return gIsMethodEntryWorking && gIsSingleStepWorking && ! gIsErrorOccured; -} - -static void popFrameLogic(jvmtiEnv * jvmti_env, jthread thread) { - - TLSStruct * tls = (TLSStruct *) getTLS(jvmti_env, thread, sizeof(TLSStruct)); - - if ( ! tls ) - return; - - if ( tls->countOfFramesToPop <= 0 ) { - - NSK_DISPLAY0("Disabling single step\n"); - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, NULL)) ) - gIsErrorOccured = JNI_TRUE; - - } else { - - NSK_DISPLAY0("Enabling single step\n"); - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL)) ) - gIsErrorOccured = JNI_TRUE; - - if ( tls->countOfFramesToPop == 1 ) { - NSK_DISPLAY0("Popping a frame\n"); - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB2(PopFrame, jvmti_env, thread)) ) - gIsErrorOccured = JNI_TRUE; - } else { - NSK_DISPLAY0("Forcing early return\n"); - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB2(ForceEarlyReturnVoid, jvmti_env, thread)) ) - gIsErrorOccured = JNI_TRUE; - } - - --tls->countOfFramesToPop; - } -} - -static void JNICALL -MethodEntry(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method) { - - struct MethodName * mn; - TLSStruct * tls; - jclass clazz; - - gIsMethodEntryWorking = JNI_TRUE; - mn = getMethodName(jvmti_env, method); - if ( ! mn ) - return; - - if ( strcmp(mn->methodName, gszRedefineTriggerMethodName) != 0 ) { - free(mn); - return; - } - - NSK_DISPLAY2("Entering redefine tigger method: %s.%s\n", mn->classSig, mn->methodName); - free(mn); mn = NULL; - - if ( gIsClassRedefined ) { - NSK_DISPLAY0("Class is already redefined.\n"); - return; - } - - NSK_DISPLAY1("Redefining class %s\n", gszRedefinedClassFileName); - - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, jvmti_env, method, &clazz)) ) - return; - - if ( ! NSK_VERIFY(nsk_jvmti_redefineClass(jvmti_env, clazz, gszRedefinedClassFileName)) ) { - gIsErrorOccured = JNI_TRUE; - return; - } - - gIsClassRedefined = JNI_TRUE; - - tls = (TLSStruct *) getTLS(jvmti_env, thread, sizeof(TLSStruct)); - tls->countOfFramesToPop = gPopFrameDepth; - - popFrameLogic(jvmti_env, thread); -} - -static void JNICALL -SingleStep(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jlocation location) { - - char * locStr; - gIsSingleStepWorking = JNI_TRUE; - locStr = locationToString(jvmti_env, method, location); - - if (locStr == NULL) { - NSK_DISPLAY0("Error in Single step event: locationToString failed\n"); - gIsErrorOccured = JNI_TRUE; - } else { - NSK_DISPLAY1("Single step event: %s\n", locStr); - free(locStr); - } - - popFrameLogic(jvmti_env, thread); -} - -jint Agent_Initialize(JavaVM * vm, char * options, void * reserved) { - jvmtiEventCallbacks callbacks; - jvmtiCapabilities caps; - - if ( ! NSK_VERIFY(nsk_jvmti_parseOptions(options)) ) - return JNI_ERR; - - if ( ! NSK_VERIFY((gJvmtiEnv = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL) ) - return JNI_ERR; - - if ( nsk_jvmti_findOptionValue("debuggerCompatible") ) { - gIsDebuggerCompatible = JNI_TRUE; - } - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_method_entry_events = 1; - caps.can_generate_single_step_events = 1; - caps.can_pop_frame = 1; - caps.can_force_early_return = 1; - caps.can_redefine_classes = 1; - - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, gJvmtiEnv, &caps)) ) - return JNI_ERR; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.MethodEntry = &MethodEntry; - callbacks.SingleStep = &SingleStep; - - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, gJvmtiEnv, &callbacks, sizeof(callbacks))) ) - return JNI_ERR; - - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, NULL) ) ) - return JNI_ERR; - - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, NULL) ) ) - return JNI_ERR; - - return JNI_OK; -} diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/IndyRedefineClass.cpp b/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/IndyRedefineClass.cpp new file mode 100644 index 00000000000..2d3ee3339ef --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/IndyRedefineClass.cpp @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" +#include "mlvmJvmtiUtils.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jvmtiEnv* gJvmtiEnv = NULL; + +static jboolean gIsMethodEntryWorking = JNI_FALSE; +static jboolean gIsSingleStepWorking = JNI_FALSE; +static jboolean gIsErrorOccured = JNI_FALSE; + +static jboolean gIsDebuggerCompatible = JNI_FALSE; + +static jint gPopFrameDepth = 2; + +typedef struct TLS { + jint countOfFramesToPop; +} TLSStruct; + +static char * gszRedefineTriggerMethodName = (char*) "NONE"; +static char * gszRedefinedClassFileName = (char*) "NONE"; +static jboolean gIsClassRedefined = JNI_FALSE; + +JNIEXPORT void JNICALL +Java_vm_mlvm_indy_func_jvmti_share_IndyRedefineClass_setRedefineTriggerMethodName(JNIEnv * pEnv, jclass clazz, jstring name) { + copyFromJString(pEnv, name, &gszRedefineTriggerMethodName); + NSK_DISPLAY1("Setting redefine trigger method name to %s\n", gszRedefineTriggerMethodName); +} + +JNIEXPORT void JNICALL +Java_vm_mlvm_indy_func_jvmti_share_IndyRedefineClass_setRedefinedClassFileName(JNIEnv * pEnv, jclass clazz, jstring name) { + copyFromJString(pEnv, name, &gszRedefinedClassFileName); + NSK_DISPLAY1("Setting redefined class name to %s\n", gszRedefinedClassFileName); + gIsClassRedefined = JNI_FALSE; +} + +JNIEXPORT void JNICALL +Java_vm_mlvm_indy_func_jvmti_share_IndyRedefineClass_setPopFrameDepthAfterRedefine(JNIEnv * pEnv, jclass clazz, jint depth) { + gPopFrameDepth = depth; +} + +JNIEXPORT jboolean JNICALL +Java_vm_mlvm_indy_func_jvmti_share_IndyRedefineClass_checkStatus(JNIEnv * pEnv, jclass clazz) { + NSK_DISPLAY0("The following values should be non-zero for test to pass:\n"); + NSK_DISPLAY1("Method entry event fired? %i\n", gIsMethodEntryWorking); + NSK_DISPLAY1("Single step event fired? %i\n", gIsSingleStepWorking); + NSK_DISPLAY0("The following value should be zero for test to pass:\n"); + NSK_DISPLAY1("Any other error occured? %i\n", gIsErrorOccured); + return gIsMethodEntryWorking && gIsSingleStepWorking && ! gIsErrorOccured; +} + +static void popFrameLogic(jvmtiEnv * jvmti_env, jthread thread) { + + TLSStruct * tls = (TLSStruct *) getTLS(jvmti_env, thread, sizeof(TLSStruct)); + + if ( ! tls ) + return; + + if ( tls->countOfFramesToPop <= 0 ) { + + NSK_DISPLAY0("Disabling single step\n"); + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, NULL)) ) + gIsErrorOccured = JNI_TRUE; + + } else { + + NSK_DISPLAY0("Enabling single step\n"); + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL)) ) + gIsErrorOccured = JNI_TRUE; + + if ( tls->countOfFramesToPop == 1 ) { + NSK_DISPLAY0("Popping a frame\n"); + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB2(PopFrame, jvmti_env, thread)) ) + gIsErrorOccured = JNI_TRUE; + } else { + NSK_DISPLAY0("Forcing early return\n"); + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB2(ForceEarlyReturnVoid, jvmti_env, thread)) ) + gIsErrorOccured = JNI_TRUE; + } + + --tls->countOfFramesToPop; + } +} + +static void JNICALL +MethodEntry(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method) { + + struct MethodName * mn; + TLSStruct * tls; + jclass clazz; + + gIsMethodEntryWorking = JNI_TRUE; + mn = getMethodName(jvmti_env, method); + if ( ! mn ) + return; + + if ( strcmp(mn->methodName, gszRedefineTriggerMethodName) != 0 ) { + free(mn); + return; + } + + NSK_DISPLAY2("Entering redefine tigger method: %s.%s\n", mn->classSig, mn->methodName); + free(mn); mn = NULL; + + if ( gIsClassRedefined ) { + NSK_DISPLAY0("Class is already redefined.\n"); + return; + } + + NSK_DISPLAY1("Redefining class %s\n", gszRedefinedClassFileName); + + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, jvmti_env, method, &clazz)) ) + return; + + if ( ! NSK_VERIFY(nsk_jvmti_redefineClass(jvmti_env, clazz, gszRedefinedClassFileName)) ) { + gIsErrorOccured = JNI_TRUE; + return; + } + + gIsClassRedefined = JNI_TRUE; + + tls = (TLSStruct *) getTLS(jvmti_env, thread, sizeof(TLSStruct)); + tls->countOfFramesToPop = gPopFrameDepth; + + popFrameLogic(jvmti_env, thread); +} + +static void JNICALL +SingleStep(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jlocation location) { + + char * locStr; + gIsSingleStepWorking = JNI_TRUE; + locStr = locationToString(jvmti_env, method, location); + + if (locStr == NULL) { + NSK_DISPLAY0("Error in Single step event: locationToString failed\n"); + gIsErrorOccured = JNI_TRUE; + } else { + NSK_DISPLAY1("Single step event: %s\n", locStr); + free(locStr); + } + + popFrameLogic(jvmti_env, thread); +} + +jint Agent_Initialize(JavaVM * vm, char * options, void * reserved) { + jvmtiEventCallbacks callbacks; + jvmtiCapabilities caps; + + if ( ! NSK_VERIFY(nsk_jvmti_parseOptions(options)) ) + return JNI_ERR; + + if ( ! NSK_VERIFY((gJvmtiEnv = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL) ) + return JNI_ERR; + + if ( nsk_jvmti_findOptionValue("debuggerCompatible") ) { + gIsDebuggerCompatible = JNI_TRUE; + } + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_method_entry_events = 1; + caps.can_generate_single_step_events = 1; + caps.can_pop_frame = 1; + caps.can_force_early_return = 1; + caps.can_redefine_classes = 1; + + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, gJvmtiEnv, &caps)) ) + return JNI_ERR; + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.MethodEntry = &MethodEntry; + callbacks.SingleStep = &SingleStep; + + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, gJvmtiEnv, &callbacks, sizeof(callbacks))) ) + return JNI_ERR; + + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, NULL) ) ) + return JNI_ERR; + + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, NULL) ) ) + return JNI_ERR; + + return JNI_OK; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/libIndyRedefineClass.c b/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/libIndyRedefineClass.c deleted file mode 100644 index ae29f7ffa71..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/libIndyRedefineClass.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "agent_common.c" -#include "JVMTITools.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "native_thread.c" -#include "agent_tools.c" -#include "jvmti_tools.c" -#include "mlvmJvmtiUtils.c" -#include "IndyRedefineClass.c" diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/libIndyRedefineClass.cpp b/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/libIndyRedefineClass.cpp new file mode 100644 index 00000000000..e36da2e7d5b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/libIndyRedefineClass.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "agent_common.cpp" +#include "JVMTITools.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "native_thread.cpp" +#include "agent_tools.cpp" +#include "jvmti_tools.cpp" +#include "mlvmJvmtiUtils.cpp" +#include "IndyRedefineClass.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/libstepBreakPopReturn.c b/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/libstepBreakPopReturn.c deleted file mode 100644 index cc33aa4e361..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/libstepBreakPopReturn.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "agent_common.c" -#include "native_thread.c" -#include "agent_tools.c" -#include "JVMTITools.c" -#include "nsk_tools.c" -#include "jni_tools.c" -#include "jvmti_tools.c" -#include "mlvmJvmtiUtils.c" -#include "stepBreakPopReturn.c" diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/libstepBreakPopReturn.cpp b/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/libstepBreakPopReturn.cpp new file mode 100644 index 00000000000..f156096a2f7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/libstepBreakPopReturn.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "agent_common.cpp" +#include "native_thread.cpp" +#include "agent_tools.cpp" +#include "JVMTITools.cpp" +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "jvmti_tools.cpp" +#include "mlvmJvmtiUtils.cpp" +#include "stepBreakPopReturn.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/stepBreakPopReturn.c b/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/stepBreakPopReturn.c deleted file mode 100644 index 1b3f8d29ee1..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/stepBreakPopReturn.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" -#include "mlvmJvmtiUtils.h" - -static jvmtiEnv* gJvmtiEnv = NULL; - -static char * gszDebuggeeMethodName = "NONE"; -static char * gszDebuggeeClassName = "NONE"; -static jboolean gIsMethodEntryWorking = JNI_FALSE; -static jboolean gIsSingleStepWorking = JNI_FALSE; -static jboolean gIsBreakpointWorking = JNI_FALSE; -static jboolean gErrorHappened = JNI_FALSE; - -static jboolean gIsBreakpointSet = JNI_FALSE; -static jboolean gIsFirstCall = JNI_TRUE; -static jboolean gIsDebuggerCompatible = JNI_FALSE; - -JNIEXPORT void JNICALL -Java_vm_mlvm_indy_func_jvmti_stepBreakPopReturn_INDIFY_1Test_setDebuggeeMethodName(JNIEnv * pEnv, jclass clazz, jstring name) { - copyFromJString(pEnv, name, &gszDebuggeeMethodName); - NSK_DISPLAY1("Setting debuggee method name to %s\n", gszDebuggeeMethodName); -} - -JNIEXPORT void JNICALL -Java_vm_mlvm_indy_func_jvmti_stepBreakPopReturn_INDIFY_1Test_setDebuggeeClassName(JNIEnv * pEnv, jclass clazz, jstring name) { - copyFromJString(pEnv, name, &gszDebuggeeClassName); - NSK_DISPLAY1("Setting debuggee class name to %s\n", gszDebuggeeClassName); -} - -JNIEXPORT jboolean JNICALL -Java_vm_mlvm_indy_func_jvmti_stepBreakPopReturn_INDIFY_1Test_checkStatus(JNIEnv * pEnv, jclass clazz) { - NSK_DISPLAY1("Are we running in debugger-compatible mode? %i\n", gIsDebuggerCompatible); - NSK_DISPLAY0("The following values should be non-zero for test to pass:\n"); - NSK_DISPLAY1("Method entry event fired? %i\n", gIsMethodEntryWorking); - NSK_DISPLAY1("Single step event fired? %i\n", gIsSingleStepWorking); - if ( ! gIsDebuggerCompatible ) - NSK_DISPLAY1("Breakpoint event fired? %i\n", gIsBreakpointWorking); - - return gIsMethodEntryWorking && !gErrorHappened && gIsSingleStepWorking - && (gIsBreakpointWorking || gIsDebuggerCompatible); -} - -static void JNICALL -MethodEntry(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method) { - - struct MethodName * mn; - - mn = getMethodName(jvmti_env, method); - if ( ! mn ) - return; - - if ( strcmp(mn->classSig, gszDebuggeeClassName) == 0 ) { - NSK_DISPLAY2("Entering method: %s.%s\n", mn->classSig, mn->methodName); - - if ( strcmp(mn->methodName, gszDebuggeeMethodName) == 0 ) { - gIsMethodEntryWorking = JNI_TRUE; - - if ( ! gIsBreakpointSet ) - NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL)); - } - } - - free(mn); -} - -static void JNICALL -SingleStep(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jlocation location) { - - char * locStr; - gIsSingleStepWorking = JNI_TRUE; - - locStr = locationToString(jvmti_env, method, location); - - if (locStr == NULL) { - NSK_DISPLAY0("Error: Single step event has no location\n"); - gErrorHappened = JNI_TRUE; - } else { - NSK_DISPLAY1("Single step event: %s\n", locStr); - free(locStr); - } - - NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, NULL)); - - if ( ! gIsDebuggerCompatible ) { - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetBreakpoint, jvmti_env, method, location)) ) - return; - - NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_ENABLE, JVMTI_EVENT_BREAKPOINT, NULL)); - gIsBreakpointSet = JNI_TRUE; - - NSK_DISPLAY0("Pop a frame\n"); - NSK_JVMTI_VERIFY(NSK_CPP_STUB2(PopFrame, gJvmtiEnv, thread)); - } else { - if ( gIsFirstCall ) { - NSK_DISPLAY0("Pop a frame\n"); - NSK_JVMTI_VERIFY(NSK_CPP_STUB2(PopFrame, gJvmtiEnv, thread)); - gIsFirstCall = JNI_FALSE; - } else { - gIsFirstCall = JNI_TRUE; - } - } -} - -static void JNICALL -Breakpoint(jvmtiEnv *jvmti_env, - JNIEnv* jni_env, - jthread thread, - jmethodID method, - jlocation location) { - - - char * locStr; - gIsBreakpointWorking = JNI_TRUE; - - locStr = locationToString(jvmti_env, method, location); - if (locStr == NULL) { - NSK_DISPLAY0("Error: Breakpoint event has no location\n"); - gErrorHappened = JNI_TRUE; - } else { - NSK_DISPLAY1("Breakpoint event at: %s\n", locStr); - free(locStr); - } - - NSK_JVMTI_VERIFY(NSK_CPP_STUB3(ClearBreakpoint, jvmti_env, method, location)); - NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_DISABLE, JVMTI_EVENT_BREAKPOINT, NULL)); - gIsBreakpointSet = JNI_FALSE; - - NSK_DISPLAY0("Forcing early return.\n"); - NSK_JVMTI_VERIFY(NSK_CPP_STUB3(ForceEarlyReturnInt, jvmti_env, thread, 0)); -} - -jint Agent_Initialize(JavaVM * vm, char * options, void * reserved) { - jvmtiEventCallbacks callbacks; - jvmtiCapabilities caps; - - if ( ! NSK_VERIFY(nsk_jvmti_parseOptions(options)) ) - return JNI_ERR; - - if ( ! NSK_VERIFY((gJvmtiEnv = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL) ) - return JNI_ERR; - - if ( nsk_jvmti_findOptionValue("debuggerCompatible") ) { - gIsDebuggerCompatible = JNI_TRUE; - } - - memset(&caps, 0, sizeof(caps)); - caps.can_generate_method_entry_events = 1; - caps.can_generate_single_step_events = 1; - caps.can_generate_breakpoint_events = ! gIsDebuggerCompatible; - caps.can_pop_frame = 1; - caps.can_force_early_return = 1; - - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, gJvmtiEnv, &caps)) ) - return JNI_ERR; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.MethodEntry = &MethodEntry; - callbacks.SingleStep = &SingleStep; - callbacks.Breakpoint = &Breakpoint; - - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, gJvmtiEnv, &callbacks, sizeof(callbacks))) ) - return JNI_ERR; - - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, NULL) ) ) - return JNI_ERR; - - return JNI_OK; -} diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/stepBreakPopReturn.cpp b/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/stepBreakPopReturn.cpp new file mode 100644 index 00000000000..b8633af9598 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/stepBreakPopReturn/stepBreakPopReturn.cpp @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" +#include "mlvmJvmtiUtils.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static jvmtiEnv* gJvmtiEnv = NULL; + +static char * gszDebuggeeMethodName = (char*) "NONE"; +static char * gszDebuggeeClassName = (char*) "NONE"; +static jboolean gIsMethodEntryWorking = JNI_FALSE; +static jboolean gIsSingleStepWorking = JNI_FALSE; +static jboolean gIsBreakpointWorking = JNI_FALSE; +static jboolean gErrorHappened = JNI_FALSE; + +static jboolean gIsBreakpointSet = JNI_FALSE; +static jboolean gIsFirstCall = JNI_TRUE; +static jboolean gIsDebuggerCompatible = JNI_FALSE; + +JNIEXPORT void JNICALL +Java_vm_mlvm_indy_func_jvmti_stepBreakPopReturn_INDIFY_1Test_setDebuggeeMethodName(JNIEnv * pEnv, jclass clazz, jstring name) { + copyFromJString(pEnv, name, &gszDebuggeeMethodName); + NSK_DISPLAY1("Setting debuggee method name to %s\n", gszDebuggeeMethodName); +} + +JNIEXPORT void JNICALL +Java_vm_mlvm_indy_func_jvmti_stepBreakPopReturn_INDIFY_1Test_setDebuggeeClassName(JNIEnv * pEnv, jclass clazz, jstring name) { + copyFromJString(pEnv, name, &gszDebuggeeClassName); + NSK_DISPLAY1("Setting debuggee class name to %s\n", gszDebuggeeClassName); +} + +JNIEXPORT jboolean JNICALL +Java_vm_mlvm_indy_func_jvmti_stepBreakPopReturn_INDIFY_1Test_checkStatus(JNIEnv * pEnv, jclass clazz) { + NSK_DISPLAY1("Are we running in debugger-compatible mode? %i\n", gIsDebuggerCompatible); + NSK_DISPLAY0("The following values should be non-zero for test to pass:\n"); + NSK_DISPLAY1("Method entry event fired? %i\n", gIsMethodEntryWorking); + NSK_DISPLAY1("Single step event fired? %i\n", gIsSingleStepWorking); + if ( ! gIsDebuggerCompatible ) + NSK_DISPLAY1("Breakpoint event fired? %i\n", gIsBreakpointWorking); + + return gIsMethodEntryWorking && !gErrorHappened && gIsSingleStepWorking + && (gIsBreakpointWorking || gIsDebuggerCompatible); +} + +static void JNICALL +MethodEntry(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method) { + + struct MethodName * mn; + + mn = getMethodName(jvmti_env, method); + if ( ! mn ) + return; + + if ( strcmp(mn->classSig, gszDebuggeeClassName) == 0 ) { + NSK_DISPLAY2("Entering method: %s.%s\n", mn->classSig, mn->methodName); + + if ( strcmp(mn->methodName, gszDebuggeeMethodName) == 0 ) { + gIsMethodEntryWorking = JNI_TRUE; + + if ( ! gIsBreakpointSet ) + NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL)); + } + } + + free(mn); +} + +static void JNICALL +SingleStep(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jlocation location) { + + char * locStr; + gIsSingleStepWorking = JNI_TRUE; + + locStr = locationToString(jvmti_env, method, location); + + if (locStr == NULL) { + NSK_DISPLAY0("Error: Single step event has no location\n"); + gErrorHappened = JNI_TRUE; + } else { + NSK_DISPLAY1("Single step event: %s\n", locStr); + free(locStr); + } + + NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, NULL)); + + if ( ! gIsDebuggerCompatible ) { + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetBreakpoint, jvmti_env, method, location)) ) + return; + + NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_ENABLE, JVMTI_EVENT_BREAKPOINT, NULL)); + gIsBreakpointSet = JNI_TRUE; + + NSK_DISPLAY0("Pop a frame\n"); + NSK_JVMTI_VERIFY(NSK_CPP_STUB2(PopFrame, gJvmtiEnv, thread)); + } else { + if ( gIsFirstCall ) { + NSK_DISPLAY0("Pop a frame\n"); + NSK_JVMTI_VERIFY(NSK_CPP_STUB2(PopFrame, gJvmtiEnv, thread)); + gIsFirstCall = JNI_FALSE; + } else { + gIsFirstCall = JNI_TRUE; + } + } +} + +static void JNICALL +Breakpoint(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jlocation location) { + + + char * locStr; + gIsBreakpointWorking = JNI_TRUE; + + locStr = locationToString(jvmti_env, method, location); + if (locStr == NULL) { + NSK_DISPLAY0("Error: Breakpoint event has no location\n"); + gErrorHappened = JNI_TRUE; + } else { + NSK_DISPLAY1("Breakpoint event at: %s\n", locStr); + free(locStr); + } + + NSK_JVMTI_VERIFY(NSK_CPP_STUB3(ClearBreakpoint, jvmti_env, method, location)); + NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_DISABLE, JVMTI_EVENT_BREAKPOINT, NULL)); + gIsBreakpointSet = JNI_FALSE; + + NSK_DISPLAY0("Forcing early return.\n"); + NSK_JVMTI_VERIFY(NSK_CPP_STUB3(ForceEarlyReturnInt, jvmti_env, thread, 0)); +} + +jint Agent_Initialize(JavaVM * vm, char * options, void * reserved) { + jvmtiEventCallbacks callbacks; + jvmtiCapabilities caps; + + if ( ! NSK_VERIFY(nsk_jvmti_parseOptions(options)) ) + return JNI_ERR; + + if ( ! NSK_VERIFY((gJvmtiEnv = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL) ) + return JNI_ERR; + + if ( nsk_jvmti_findOptionValue("debuggerCompatible") ) { + gIsDebuggerCompatible = JNI_TRUE; + } + + memset(&caps, 0, sizeof(caps)); + caps.can_generate_method_entry_events = 1; + caps.can_generate_single_step_events = 1; + caps.can_generate_breakpoint_events = ! gIsDebuggerCompatible; + caps.can_pop_frame = 1; + caps.can_force_early_return = 1; + + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, gJvmtiEnv, &caps)) ) + return JNI_ERR; + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.MethodEntry = &MethodEntry; + callbacks.SingleStep = &SingleStep; + callbacks.Breakpoint = &Breakpoint; + + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, gJvmtiEnv, &callbacks, sizeof(callbacks))) ) + return JNI_ERR; + + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, NULL) ) ) + return JNI_ERR; + + return JNI_OK; +} +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/libnativeAndMH.c b/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/libnativeAndMH.c deleted file mode 100644 index 1575dcd6649..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/libnativeAndMH.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "nsk_tools.c" -#include "jni_tools.c" -#include "nativeAndMH.c" diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/libnativeAndMH.cpp b/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/libnativeAndMH.cpp new file mode 100644 index 00000000000..4fba71fc5a7 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/libnativeAndMH.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "nsk_tools.cpp" +#include "jni_tools.cpp" +#include "nativeAndMH.cpp" diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/nativeAndMH.c b/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/nativeAndMH.c deleted file mode 100644 index 41b501b8710..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/nativeAndMH.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jni.h" -#include "jni_tools.h" - -#define ARGS_COUNT 6 - -JNIEXPORT jobject JNICALL -Java_vm_mlvm_meth_stress_jni_nativeAndMH_Test_native01( - JNIEnv * pEnv, jclass clazz, - jstring a1, - jobject a2, - jobject a3, - jobject a4, - jobject a5, - jobject a6, - jobject mhToCall) -{ - jclass mhClass; - jmethodID mid; - jclass objectClass; - jobjectArray arguments; - jobject result; - - if ( ! NSK_JNI_VERIFY(pEnv, (mhClass = NSK_CPP_STUB2(GetObjectClass, pEnv, mhToCall)) != NULL) ) - return NULL; - - if ( ! NSK_JNI_VERIFY(pEnv, NULL != (mid = NSK_CPP_STUB4(GetMethodID, pEnv, mhClass, - "invokeWithArguments", - "([Ljava/lang/Object;)Ljava/lang/Object;"))) ) - return NULL; - - NSK_JNI_VERIFY(pEnv, NULL != (objectClass = NSK_CPP_STUB2(FindClass, pEnv, "java/lang/Object"))); - - NSK_JNI_VERIFY(pEnv, NULL != (arguments = NSK_CPP_STUB4(NewObjectArray, pEnv, ARGS_COUNT, objectClass, NULL))); - - NSK_JNI_VERIFY_VOID(pEnv, NSK_CPP_STUB4(SetObjectArrayElement, pEnv, arguments, 0, a1)); - NSK_JNI_VERIFY_VOID(pEnv, NSK_CPP_STUB4(SetObjectArrayElement, pEnv, arguments, 1, a2)); - NSK_JNI_VERIFY_VOID(pEnv, NSK_CPP_STUB4(SetObjectArrayElement, pEnv, arguments, 2, a3)); - NSK_JNI_VERIFY_VOID(pEnv, NSK_CPP_STUB4(SetObjectArrayElement, pEnv, arguments, 3, a4)); - NSK_JNI_VERIFY_VOID(pEnv, NSK_CPP_STUB4(SetObjectArrayElement, pEnv, arguments, 4, a5)); - NSK_JNI_VERIFY_VOID(pEnv, NSK_CPP_STUB4(SetObjectArrayElement, pEnv, arguments, 5, a6)); - - // Swap arguments - NSK_JNI_VERIFY(pEnv, NULL != (result = NSK_CPP_STUB4(CallObjectMethod, pEnv, mhToCall, mid, arguments))); - return result; -} - diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/nativeAndMH.cpp b/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/nativeAndMH.cpp new file mode 100644 index 00000000000..07bb4e49ab8 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/stress/jni/nativeAndMH/nativeAndMH.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jni.h" +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ARGS_COUNT 6 + +JNIEXPORT jobject JNICALL +Java_vm_mlvm_meth_stress_jni_nativeAndMH_Test_native01( + JNIEnv * pEnv, jclass clazz, + jstring a1, + jobject a2, + jobject a3, + jobject a4, + jobject a5, + jobject a6, + jobject mhToCall) +{ + jclass mhClass; + jmethodID mid; + jclass objectClass; + jobjectArray arguments; + jobject result; + + if ( ! NSK_JNI_VERIFY(pEnv, (mhClass = NSK_CPP_STUB2(GetObjectClass, pEnv, mhToCall)) != NULL) ) + return NULL; + + if ( ! NSK_JNI_VERIFY(pEnv, NULL != (mid = NSK_CPP_STUB4(GetMethodID, pEnv, mhClass, + "invokeWithArguments", + "([Ljava/lang/Object;)Ljava/lang/Object;"))) ) + return NULL; + + NSK_JNI_VERIFY(pEnv, NULL != (objectClass = NSK_CPP_STUB2(FindClass, pEnv, "java/lang/Object"))); + + NSK_JNI_VERIFY(pEnv, NULL != (arguments = NSK_CPP_STUB4(NewObjectArray, pEnv, ARGS_COUNT, objectClass, NULL))); + + NSK_JNI_VERIFY_VOID(pEnv, NSK_CPP_STUB4(SetObjectArrayElement, pEnv, arguments, 0, a1)); + NSK_JNI_VERIFY_VOID(pEnv, NSK_CPP_STUB4(SetObjectArrayElement, pEnv, arguments, 1, a2)); + NSK_JNI_VERIFY_VOID(pEnv, NSK_CPP_STUB4(SetObjectArrayElement, pEnv, arguments, 2, a3)); + NSK_JNI_VERIFY_VOID(pEnv, NSK_CPP_STUB4(SetObjectArrayElement, pEnv, arguments, 3, a4)); + NSK_JNI_VERIFY_VOID(pEnv, NSK_CPP_STUB4(SetObjectArrayElement, pEnv, arguments, 4, a5)); + NSK_JNI_VERIFY_VOID(pEnv, NSK_CPP_STUB4(SetObjectArrayElement, pEnv, arguments, 5, a6)); + + // Swap arguments + NSK_JNI_VERIFY(pEnv, NULL != (result = NSK_CPP_STUB4(CallObjectMethod, pEnv, mhToCall, mid, arguments))); + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.c b/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.c deleted file mode 100644 index f3411172d68..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include "jvmti.h" -#include "agent_common.h" -#include "JVMTITools.h" -#include "jvmti_tools.h" -#include "mlvmJvmtiUtils.h" - -void copyFromJString(JNIEnv * pEnv, jstring src, char ** dst) { - const char * pStr; - jsize len; - - if ( ! NSK_VERIFY((pStr = NSK_CPP_STUB3(GetStringUTFChars, pEnv, src, NULL)) != NULL) ) { - return; - } - - len = NSK_CPP_STUB2(GetStringUTFLength, pEnv, src) + 1; - *dst = malloc(len); - strncpy(*dst, pStr, len); - - NSK_CPP_STUB3(ReleaseStringUTFChars, pEnv, src, pStr); -} - -struct MethodName * getMethodName(jvmtiEnv * pJvmtiEnv, jmethodID method) { - char * szName; - char * szSignature; - jclass clazz; - struct MethodName * mn; - - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, pJvmtiEnv, method, &szName, NULL, NULL)) ) { - return NULL; - } - - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, pJvmtiEnv, method, &clazz)) ) { - NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, pJvmtiEnv, (void *) szName)); - return NULL; - } - - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, pJvmtiEnv, clazz, &szSignature, NULL)) ) { - NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, pJvmtiEnv, (void *) szName)); - return NULL; - } - - mn = malloc(sizeof(MethodNameStruct)); - strncpy(mn->methodName, szName, sizeof(mn->methodName) - 1); - mn->methodName[sizeof(mn->methodName) - 1] = '\0'; - strncpy(mn->classSig, szSignature, sizeof(mn->classSig) - 1); - mn->classSig[sizeof(mn->classSig) - 1] = '\0'; - - NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, pJvmtiEnv, (void *) szName)); - NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, pJvmtiEnv, (void *) szSignature)); - return mn; -} - -char * locationToString(jvmtiEnv * pJvmtiEnv, jmethodID method, jlocation location) { - struct MethodName * pMN; - int len; - char * result; - const char * const format = "%s .%s :" JLONG_FORMAT; - - pMN = getMethodName(pJvmtiEnv, method); - if ( ! pMN ) - return strdup("NONE"); - - len = snprintf(NULL, 0, format, pMN->classSig, pMN->methodName, location) + 1; - - if (len <= 0) { - free(pMN); - return NULL; - } - - result = malloc(len); - if (result == NULL) { - free(pMN); - return NULL; - } - - snprintf(result, len, format, pMN->classSig, pMN->methodName, location); - - free(pMN); - return result; -} - -void * getTLS(jvmtiEnv * pJvmtiEnv, jthread thread, jsize sizeToAllocate) { - void * tls; - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadLocalStorage, pJvmtiEnv, thread, &tls)) ) - return NULL; - - if ( ! tls) { - if ( ! NSK_VERIFY((tls = malloc(sizeToAllocate)) != NULL) ) - return NULL; - - memset(tls, 0, sizeToAllocate); - - if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetThreadLocalStorage, pJvmtiEnv, thread, tls)) ) - return NULL; - } - - return tls; -} diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.cpp b/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.cpp new file mode 100644 index 00000000000..2f756713c31 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jvmti.h" +#include "agent_common.h" +#include "JVMTITools.h" +#include "jvmti_tools.h" +#include "mlvmJvmtiUtils.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void copyFromJString(JNIEnv * pEnv, jstring src, char ** dst) { + const char * pStr; + jsize len; + + if ( ! NSK_VERIFY((pStr = NSK_CPP_STUB3(GetStringUTFChars, pEnv, src, NULL)) != NULL) ) { + return; + } + + len = NSK_CPP_STUB2(GetStringUTFLength, pEnv, src) + 1; + *dst = (char*) malloc(len); + strncpy(*dst, pStr, len); + + NSK_CPP_STUB3(ReleaseStringUTFChars, pEnv, src, pStr); +} + +struct MethodName * getMethodName(jvmtiEnv * pJvmtiEnv, jmethodID method) { + char * szName; + char * szSignature; + jclass clazz; + struct MethodName * mn; + + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, pJvmtiEnv, method, &szName, NULL, NULL)) ) { + return NULL; + } + + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass, pJvmtiEnv, method, &clazz)) ) { + NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, pJvmtiEnv, (unsigned char*) szName)); + return NULL; + } + + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, pJvmtiEnv, clazz, &szSignature, NULL)) ) { + NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, pJvmtiEnv, (unsigned char*) szName)); + return NULL; + } + + mn = (MethodName*) malloc(sizeof(MethodNameStruct)); + + strncpy(mn->methodName, szName, sizeof(mn->methodName) - 1); + mn->methodName[sizeof(mn->methodName) - 1] = '\0'; + + strncpy(mn->classSig, szSignature, sizeof(mn->classSig) - 1); + mn->classSig[sizeof(mn->classSig) - 1] = '\0'; + + NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, pJvmtiEnv, (unsigned char*) szName)); + NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, pJvmtiEnv, (unsigned char*) szSignature)); + return mn; +} + +char * locationToString(jvmtiEnv * pJvmtiEnv, jmethodID method, jlocation location) { + struct MethodName * pMN; + int len; + char * result; + const char * const format = "%s .%s :" JLONG_FORMAT; + + pMN = getMethodName(pJvmtiEnv, method); + if ( ! pMN ) + return strdup("NONE"); + + len = snprintf(NULL, 0, format, pMN->classSig, pMN->methodName, location) + 1; + + if (len <= 0) { + free(pMN); + return NULL; + } + + result = (char*) malloc(len); + if (result == NULL) { + free(pMN); + return NULL; + } + + snprintf(result, len, format, pMN->classSig, pMN->methodName, location); + + free(pMN); + return result; +} + +void * getTLS(jvmtiEnv * pJvmtiEnv, jthread thread, jsize sizeToAllocate) { + void * tls; + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadLocalStorage, pJvmtiEnv, thread, &tls)) ) + return NULL; + + if ( ! tls) { + if ( ! NSK_VERIFY((tls = malloc(sizeToAllocate)) != NULL) ) + return NULL; + + memset(tls, 0, sizeToAllocate); + + if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetThreadLocalStorage, pJvmtiEnv, thread, tls)) ) + return NULL; + } + + return tls; +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.h b/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.h index c2fb91c6319..dcc9e3ce21d 100644 --- a/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.h +++ b/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.h @@ -26,6 +26,10 @@ #include "jvmti.h" +#ifdef __cplusplus +extern "C" { +#endif + void copyFromJString(JNIEnv * pEnv, jstring src, char ** dst); struct MethodName { @@ -38,5 +42,8 @@ struct MethodName * getMethodName(jvmtiEnv * pJvmtiEnv, jmethodID method); char * locationToString(jvmtiEnv * pJvmtiEnv, jmethodID method, jlocation location); void * getTLS(jvmtiEnv * pJvmtiEnv, jthread thread, jsize sizeToAllocate); +#ifdef __cplusplus +} +#endif #endif /* MLVMJVMTIUTILS_H_ */ diff --git a/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/libredefineClasses.c b/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/libredefineClasses.c deleted file mode 100644 index b61dd15e3ef..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/libredefineClasses.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "redefineClasses.c" -#include "jni_tools.c" -#include "nsk_tools.c" -#include "JVMTITools.c" -#include "jvmti_tools.c" -#include "agent_tools.c" -#include "native_thread.c" - diff --git a/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/libredefineClasses.cpp b/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/libredefineClasses.cpp new file mode 100644 index 00000000000..33f1353e32b --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/libredefineClasses.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "redefineClasses.cpp" +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "JVMTITools.cpp" +#include "jvmti_tools.cpp" +#include "agent_tools.cpp" +#include "native_thread.cpp" + diff --git a/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/redefineClasses.c b/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/redefineClasses.cpp similarity index 100% rename from test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/redefineClasses.c rename to test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/redefineClasses.cpp diff --git a/test/hotspot/jtreg/vmTestbase/vm/share/ProcessUtils.c b/test/hotspot/jtreg/vmTestbase/vm/share/ProcessUtils.c deleted file mode 100644 index 2b3bf8db6be..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/share/ProcessUtils.c +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include "jni.h" -#include "native_thread.h" -#ifdef _WIN32 -#include -#include -#include -#include -#else /* _WIN32 */ -#include -#include -#endif /* _WIN32 */ -#include "jni_tools.h" - -/* - * Class: vm_share_ProcessUtils - * Method: sendSignal - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_vm_share_ProcessUtils_sendSignal -(JNIEnv *env, jclass class, jint signalNum) { -#ifdef _WIN32 -/* TODO TODO TODO - int dw; - LPVOID lpMsgBuf; - if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0)) { - dw = GetLastError(); - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - dw, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &lpMsgBuf, - 0, - NULL - ); - printf("%s\n", (LPTSTR)lpMsgBuf); - LocalFree(lpMsgBuf); - return JNI_FALSE; - } - */ - return JNI_TRUE; -#else /* _WIN32 */ - if (kill(getpid(), signalNum) < 0) - return JNI_FALSE; - return JNI_TRUE; -#endif /* _WIN32 */ -} - -/* - * Class: vm_share_ProcessUtils - * Method: sendCtrlBreak - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_vm_share_ProcessUtils_sendCtrlBreak -(JNIEnv *env, jclass class) { -#ifdef _WIN32 - int dw; - LPVOID lpMsgBuf; - if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0)) { - dw = GetLastError(); - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - dw, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &lpMsgBuf, - 0, - NULL - ); - printf("%s\n", (LPTSTR)lpMsgBuf); - LocalFree(lpMsgBuf); - return JNI_FALSE; - } - return JNI_TRUE; -#else /* _WIN32 */ - if (kill(getpid(), SIGQUIT) < 0) - return JNI_FALSE; - return JNI_TRUE; -#endif /* _WIN32 */ -} - -#ifdef _WIN32 -static BOOL (WINAPI *_MiniDumpWriteDump) ( HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, PMINIDUMP_EXCEPTION_INFORMATION, - PMINIDUMP_USER_STREAM_INFORMATION, PMINIDUMP_CALLBACK_INFORMATION); -void reportLastError(const char *msg) { - long errcode = GetLastError(); - if (errcode != 0) { - DWORD len = 0; - char *buf; - size_t n = (size_t)FormatMessage( - FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER, - NULL, - errcode, - 0, - (LPSTR) &buf, - (DWORD)len, - NULL); - if (n > 3) { - /* Drop final '.', CR, LF */ - if (buf[n - 1] == '\n') n--; - if (buf[n - 1] == '\r') n--; - if (buf[n - 1] == '.') n--; - buf[n] = '\0'; - } - printf("%s: %s\n", msg, buf); - LocalFree(buf); - } -} - -#endif /* _WIN32 */ - -jboolean doDumpCore() { -#ifdef _WIN32 - char path[MAX_PATH]; - DWORD size; - DWORD pathLen = (DWORD) sizeof(path); - HINSTANCE dbghelp; - MINIDUMP_EXCEPTION_INFORMATION* pmei; - - HANDLE hProcess = GetCurrentProcess(); - DWORD processId = GetCurrentProcessId(); - HANDLE dumpFile; - MINIDUMP_TYPE dumpType; - static const char* cwd; - static const char* name = "DBGHELP.DLL"; - - printf("# TEST: creating Windows minidump...\n"); - if ((size = GetSystemDirectory(path, pathLen)) > 0) { - strcat(path, "\\"); - strcat(path, name); - dbghelp = LoadLibrary(path); - if (dbghelp == NULL) - reportLastError("Load DBGHELP.DLL from system directory"); - } else { - printf("GetSystemDirectory returned 0\n"); - } - - // try Windows directory - if (dbghelp == NULL && ((size = GetWindowsDirectory(path, pathLen)) > 6)) { - strcat(path, "\\"); - strcat(path, name); - dbghelp = LoadLibrary(path); - if (dbghelp == NULL) { - reportLastError("Load DBGHELP.DLL from Windows directory"); - } - } - if (dbghelp == NULL) { - printf("Failed to load DBGHELP.DLL\n"); - return JNI_FALSE; - } - - _MiniDumpWriteDump = ( - BOOL(WINAPI *)( HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, PMINIDUMP_EXCEPTION_INFORMATION, - PMINIDUMP_USER_STREAM_INFORMATION, PMINIDUMP_CALLBACK_INFORMATION)) GetProcAddress(dbghelp, "MiniDumpWriteDump"); - - if (_MiniDumpWriteDump == NULL) { - printf("Failed to find MiniDumpWriteDump() in module dbghelp.dll"); - return JNI_FALSE; - } - dumpType = (MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithHandleData); - - // Older versions of dbghelp.h doesn't contain all the dumptypes we want, dbghelp.h with - // API_VERSION_NUMBER 11 or higher contains the ones we want though -#if API_VERSION_NUMBER >= 11 - dumpType = (MINIDUMP_TYPE)(dumpType | MiniDumpWithFullMemoryInfo | MiniDumpWithThreadInfo | - MiniDumpWithUnloadedModules); -#endif - - dumpFile = CreateFile("core.mdmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - - if (dumpFile == INVALID_HANDLE_VALUE) { - reportLastError("Failed to create file for dumping"); - return JNI_FALSE; - } - pmei = NULL; - - - // Older versions of dbghelp.dll (the one shipped with Win2003 for example) may not support all - // the dump types we really want. If first call fails, lets fall back to just use MiniDumpWithFullMemory then. - if (_MiniDumpWriteDump(hProcess, processId, dumpFile, dumpType, pmei, NULL, NULL) == FALSE && - _MiniDumpWriteDump(hProcess, processId, dumpFile, (MINIDUMP_TYPE)MiniDumpWithFullMemory, pmei, NULL, NULL) == FALSE) { - reportLastError("Call to MiniDumpWriteDump() failed"); - return JNI_FALSE; - } - - CloseHandle(dumpFile); - printf("# TEST: minidump created\n"); - // Emulate Unix behaviour - exit process. - ExitProcess(137); - - return JNI_TRUE; -#else /* _WIN32 */ - if (kill(getpid(), SIGSEGV) < 0) - return JNI_FALSE; - return JNI_TRUE; -#endif /* _WIN32 */ - -} - -/* - * Class: vm_share_ProcessUtils - * Method: dumpCore - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_vm_share_ProcessUtils_dumpCore - (JNIEnv *env, jclass class) -{ - return doDumpCore(); -} - -/* - * Class: vm_share_ProcessUtils - * Method: getPid - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_vm_share_ProcessUtils_getPid - (JNIEnv *env, jclass class) { -#ifdef _WIN32 - return _getpid(); -#else /* _WIN32 */ - return getpid(); -#endif /* _WIN32 */ -} - - -/* - * Class: vm_share_ProcessUtils - * Method: getPid - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_vm_share_ProcessUtils_getWindowsPid - (JNIEnv *env, jclass class, jlong handle) { -#ifdef _WIN32 - return GetProcessId((HANDLE) handle); -#else /* _WIN32 */ - return -1; -#endif /* _WIN32 */ -} diff --git a/test/hotspot/jtreg/vmTestbase/vm/share/ProcessUtils.cpp b/test/hotspot/jtreg/vmTestbase/vm/share/ProcessUtils.cpp new file mode 100644 index 00000000000..f12054fdd08 --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/vm/share/ProcessUtils.cpp @@ -0,0 +1,266 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +#include "jni.h" +#include "native_thread.h" +#ifdef _WIN32 +#include +#include +#include +#include +#else /* _WIN32 */ +#include +#include +#endif /* _WIN32 */ +#include "jni_tools.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: vm_share_ProcessUtils + * Method: sendSignal + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_vm_share_ProcessUtils_sendSignal +(JNIEnv *env, jclass klass, jint signalNum) { +#ifdef _WIN32 +/* TODO TODO TODO + int dw; + LPVOID lpMsgBuf; + if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0)) { + dw = GetLastError(); + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + dw, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpMsgBuf, + 0, + NULL + ); + printf("%s\n", (LPTSTR)lpMsgBuf); + LocalFree(lpMsgBuf); + return JNI_FALSE; + } + */ + return JNI_TRUE; +#else /* _WIN32 */ + if (kill(getpid(), signalNum) < 0) + return JNI_FALSE; + return JNI_TRUE; +#endif /* _WIN32 */ +} + +/* + * Class: vm_share_ProcessUtils + * Method: sendCtrlBreak + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_vm_share_ProcessUtils_sendCtrlBreak +(JNIEnv *env, jclass klass) { +#ifdef _WIN32 + int dw; + LPVOID lpMsgBuf; + if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0)) { + dw = GetLastError(); + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + dw, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpMsgBuf, + 0, + NULL + ); + printf("%s\n", (LPTSTR)lpMsgBuf); + LocalFree(lpMsgBuf); + return JNI_FALSE; + } + return JNI_TRUE; +#else /* _WIN32 */ + if (kill(getpid(), SIGQUIT) < 0) + return JNI_FALSE; + return JNI_TRUE; +#endif /* _WIN32 */ +} + +#ifdef _WIN32 +static BOOL (WINAPI *_MiniDumpWriteDump) ( HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, PMINIDUMP_EXCEPTION_INFORMATION, + PMINIDUMP_USER_STREAM_INFORMATION, PMINIDUMP_CALLBACK_INFORMATION); +void reportLastError(const char *msg) { + long errcode = GetLastError(); + if (errcode != 0) { + DWORD len = 0; + char *buf; + size_t n = (size_t)FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, + errcode, + 0, + (LPSTR) &buf, + (DWORD)len, + NULL); + if (n > 3) { + /* Drop final '.', CR, LF */ + if (buf[n - 1] == '\n') n--; + if (buf[n - 1] == '\r') n--; + if (buf[n - 1] == '.') n--; + buf[n] = '\0'; + } + printf("%s: %s\n", msg, buf); + LocalFree(buf); + } +} + +#endif /* _WIN32 */ + +jboolean doDumpCore() { +#ifdef _WIN32 + char path[MAX_PATH]; + DWORD size; + DWORD pathLen = (DWORD) sizeof(path); + HINSTANCE dbghelp; + MINIDUMP_EXCEPTION_INFORMATION* pmei; + + HANDLE hProcess = GetCurrentProcess(); + DWORD processId = GetCurrentProcessId(); + HANDLE dumpFile; + MINIDUMP_TYPE dumpType; + static const char* cwd; + static const char* name = "DBGHELP.DLL"; + + printf("# TEST: creating Windows minidump...\n"); + if ((size = GetSystemDirectory(path, pathLen)) > 0) { + strcat(path, "\\"); + strcat(path, name); + dbghelp = LoadLibrary(path); + if (dbghelp == NULL) + reportLastError("Load DBGHELP.DLL from system directory"); + } else { + printf("GetSystemDirectory returned 0\n"); + } + + // try Windows directory + if (dbghelp == NULL && ((size = GetWindowsDirectory(path, pathLen)) > 6)) { + strcat(path, "\\"); + strcat(path, name); + dbghelp = LoadLibrary(path); + if (dbghelp == NULL) { + reportLastError("Load DBGHELP.DLL from Windows directory"); + } + } + if (dbghelp == NULL) { + printf("Failed to load DBGHELP.DLL\n"); + return JNI_FALSE; + } + + _MiniDumpWriteDump = ( + BOOL(WINAPI *)( HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, PMINIDUMP_EXCEPTION_INFORMATION, + PMINIDUMP_USER_STREAM_INFORMATION, PMINIDUMP_CALLBACK_INFORMATION)) GetProcAddress(dbghelp, "MiniDumpWriteDump"); + + if (_MiniDumpWriteDump == NULL) { + printf("Failed to find MiniDumpWriteDump() in module dbghelp.dll"); + return JNI_FALSE; + } + dumpType = (MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithHandleData); + + // Older versions of dbghelp.h doesn't contain all the dumptypes we want, dbghelp.h with + // API_VERSION_NUMBER 11 or higher contains the ones we want though +#if API_VERSION_NUMBER >= 11 + dumpType = (MINIDUMP_TYPE)(dumpType | MiniDumpWithFullMemoryInfo | MiniDumpWithThreadInfo | + MiniDumpWithUnloadedModules); +#endif + + dumpFile = CreateFile("core.mdmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + + if (dumpFile == INVALID_HANDLE_VALUE) { + reportLastError("Failed to create file for dumping"); + return JNI_FALSE; + } + pmei = NULL; + + + // Older versions of dbghelp.dll (the one shipped with Win2003 for example) may not support all + // the dump types we really want. If first call fails, lets fall back to just use MiniDumpWithFullMemory then. + if (_MiniDumpWriteDump(hProcess, processId, dumpFile, dumpType, pmei, NULL, NULL) == FALSE && + _MiniDumpWriteDump(hProcess, processId, dumpFile, (MINIDUMP_TYPE)MiniDumpWithFullMemory, pmei, NULL, NULL) == FALSE) { + reportLastError("Call to MiniDumpWriteDump() failed"); + return JNI_FALSE; + } + + CloseHandle(dumpFile); + printf("# TEST: minidump created\n"); + // Emulate Unix behaviour - exit process. + ExitProcess(137); + + return JNI_TRUE; +#else /* _WIN32 */ + if (kill(getpid(), SIGSEGV) < 0) + return JNI_FALSE; + return JNI_TRUE; +#endif /* _WIN32 */ + +} + +/* + * Class: vm_share_ProcessUtils + * Method: dumpCore + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_vm_share_ProcessUtils_dumpCore + (JNIEnv *env, jclass klass) +{ + return doDumpCore(); +} + +/* + * Class: vm_share_ProcessUtils + * Method: getPid + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_vm_share_ProcessUtils_getPid + (JNIEnv *env, jclass klass) { +#ifdef _WIN32 + return _getpid(); +#else /* _WIN32 */ + return getpid(); +#endif /* _WIN32 */ +} + + +/* + * Class: vm_share_ProcessUtils + * Method: getPid + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_vm_share_ProcessUtils_getWindowsPid + (JNIEnv *env, jclass klass, jlong handle) { +#ifdef _WIN32 + return GetProcessId((HANDLE) handle); +#else /* _WIN32 */ + return -1; +#endif /* _WIN32 */ +} + +#ifdef __cplusplus +} +#endif diff --git a/test/hotspot/jtreg/vmTestbase/vm/share/libProcessUtils.c b/test/hotspot/jtreg/vmTestbase/vm/share/libProcessUtils.c deleted file mode 100644 index 12dbc8e4787..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/share/libProcessUtils.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_tools.c" -#include "nsk_tools.c" -#include "ProcessUtils.c" - diff --git a/test/hotspot/jtreg/vmTestbase/vm/share/libProcessUtils.cpp b/test/hotspot/jtreg/vmTestbase/vm/share/libProcessUtils.cpp new file mode 100644 index 00000000000..ad65285c6cb --- /dev/null +++ b/test/hotspot/jtreg/vmTestbase/vm/share/libProcessUtils.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni_tools.cpp" +#include "nsk_tools.cpp" +#include "ProcessUtils.cpp" +